Skip to content

Commit c00dc1e

Browse files
Add validitiy asserts on values returned by the consensus engine (#18)
* Remove asserts from consensus validity checks * Add asserts on values returned by the consensus engine
1 parent 47198f7 commit c00dc1e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/dvspec/consensus.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ def consensus_is_valid_attestation_data(slashing_db: SlashingDB,
2525
attestation_data: AttestationData, attestation_duty: AttestationDuty) -> bool:
2626
"""Determines if the given attestation is valid for the attestation duty.
2727
"""
28-
assert attestation_data.slot == attestation_duty.slot
29-
assert attestation_data.index == attestation_duty.committee_index
30-
assert not is_slashable_attestation_data(slashing_db, attestation_data, attestation_duty.pubkey)
31-
return True
28+
return \
29+
attestation_data.slot == attestation_duty.slot and \
30+
attestation_data.index == attestation_duty.committee_index and \
31+
not is_slashable_attestation_data(slashing_db, attestation_data, attestation_duty.pubkey)
32+
3233

3334

3435
def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: AttestationDuty) -> AttestationData:
@@ -44,10 +45,9 @@ def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: Attestat
4445
def consensus_is_valid_block(slashing_db: SlashingDB, block: BeaconBlock, proposer_duty: ProposerDuty) -> bool:
4546
"""Determines if the given block is valid for the proposer duty.
4647
"""
47-
assert block.slot == proposer_duty.slot
48-
# TODO: Assert correct block.proposer_index
49-
assert not is_slashable_block(slashing_db, block, proposer_duty.pubkey)
50-
return True
48+
# TODO: Add correct block.proposer_index check \
49+
return block.slot == proposer_duty.slot and \
50+
not is_slashable_block(slashing_db, block, proposer_duty.pubkey)
5151

5252

5353
def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) -> AttestationData:

src/dvspec/spec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
cache_sync_committee_contribution_for_vc,
2525
)
2626
from .consensus import (
27+
consensus_is_valid_attestation_data,
28+
consensus_is_valid_block,
29+
consensus_is_valid_sync_committee_contribution,
2730
consensus_on_attestation,
2831
consensus_on_block,
2932
consensus_on_sync_committee_contribution,
@@ -119,6 +122,7 @@ def serve_attestation_duty(slashing_db: SlashingDB, attestation_duty: Attestatio
119122
# Only a single consensus_on_attestation instance should be
120123
# running at any given time
121124
attestation_data = consensus_on_attestation(slashing_db, attestation_duty)
125+
assert consensus_is_valid_attestation_data(slashing_db, attestation_data, attestation_duty)
122126
# Release lock on consensus_on_attestation here.
123127
# Add attestation to slashing DB
124128
update_attestation_slashing_db(slashing_db, attestation_data, attestation_duty.pubkey)
@@ -141,6 +145,7 @@ def serve_proposer_duty(slashing_db: SlashingDB, proposer_duty: ProposerDuty) ->
141145
# Only a single consensus_on_block instance should be
142146
# running at any given time
143147
block = consensus_on_block(slashing_db, proposer_duty)
148+
assert consensus_is_valid_block(slashing_db, block, proposer_duty)
144149
# Release lock on consensus_on_block here.
145150
# Add block to slashing DB
146151
update_block_slashing_db(slashing_db, block, proposer_duty.pubkey)
@@ -158,6 +163,7 @@ def serve_sync_committee_duty(slashing_db: SlashingDB, sync_committee_duty: Sync
158163
# Only a single consensus_on_sync_committee_contribution instance should be
159164
# running at any given time
160165
sync_committee_contribution = consensus_on_sync_committee_contribution(sync_committee_duty)
166+
assert consensus_is_valid_sync_committee_contribution(sync_committee_contribution, sync_committee_duty)
161167
# Release lock on consensus_on_block here.
162168
# TODO: Update slashing DB with sync committee contribution
163169
# Cache decided sync committee contribution value to provide to VC

0 commit comments

Comments
 (0)