Skip to content

Add postconditions in consensus using nagini #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ eth2spec==1.1.2
# dev requirements
mypy
flake8
nagini

# test requirements
pytest
21 changes: 13 additions & 8 deletions src/dvspec/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
is_slashable_block,
)

from nagini_contracts.contracts import *


"""
Consensus Specification
Expand All @@ -25,10 +27,11 @@ def consensus_is_valid_attestation_data(slashing_db: SlashingDB,
attestation_data: AttestationData, attestation_duty: AttestationDuty) -> bool:
"""Determines if the given attestation is valid for the attestation duty.
"""
assert attestation_data.slot == attestation_duty.slot
assert attestation_data.index == attestation_duty.committee_index
assert not is_slashable_attestation_data(slashing_db, attestation_data, attestation_duty.pubkey)
return True
return \
attestation_data.slot == attestation_duty.slot and \
attestation_data.index == attestation_duty.committee_index and \
not is_slashable_attestation_data(slashing_db, attestation_data, attestation_duty.pubkey)



def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: AttestationDuty) -> AttestationData:
Expand All @@ -38,16 +41,16 @@ def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: Attestat
The consensus protocol must use `consensus_is_valid_attestation_data` to determine
validity of the proposed attestation value.
"""
Ensures(consensus_is_valid_attestation_data(slashing_db, Result(), attestation_duty));
pass


def consensus_is_valid_block(slashing_db: SlashingDB, block: BeaconBlock, proposer_duty: ProposerDuty) -> bool:
"""Determines if the given block is valid for the proposer duty.
"""
assert block.slot == proposer_duty.slot
# TODO: Assert correct block.proposer_index
assert not is_slashable_block(slashing_db, block, proposer_duty.pubkey)
return True
# TODO: Add correct block.proposer_index check \
return block.slot == proposer_duty.slot and \
not is_slashable_block(slashing_db, block, proposer_duty.pubkey)


def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) -> AttestationData:
Expand All @@ -57,6 +60,7 @@ def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) ->
The consensus protocol must use `consensus_is_valid_block` to determine
validity of the proposed block value.
"""
Ensures(consensus_is_valid_block(slashing_db, Result(), proposer_duty));
pass


Expand All @@ -75,4 +79,5 @@ def consensus_on_sync_committee_contribution(sync_committee_duty: SyncCommitteeD
The consensus protocol must use `consensus_is_valid_sync_committee_contribution` to determine
validity of the proposed block value.
"""
Ensures(consensus_is_valid_sync_committee_contribution(sync_committee_duty, Result()));
pass