Skip to content

Commit

Permalink
improve SingleAttestation shortLog
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Dec 22, 2024
1 parent 4bc562f commit 659d03d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 15 additions & 4 deletions beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,16 @@ proc validateAttestation*(
# defined by attestation.data.beacon_block_root -- i.e.
# get_checkpoint_block(store, attestation.data.beacon_block_root,
# store.finalized_checkpoint.epoch) == store.finalized_checkpoint.root

var sig: CookedSig
let shufflingRefMissing =
pool.dag.findShufflingRef(target.blck.bid, target.slot.epoch).isNone
if shufflingRefMissing:
# getShufflingRef might be slow here, so first try to eliminate by
# signature check
sig = attestation.signature.load().valueOr:
return pool.checkedReject("SingleAttestation: unable to load signature")

let shufflingRef =
pool.dag.getShufflingRef(target.blck, target.slot.epoch, false).valueOr:
# Target is verified - shouldn't happen
Expand All @@ -1050,7 +1060,6 @@ proc validateAttestation*(
shufflingRef, attestation.data.slot,
attestation.committee_index.CommitteeIndex)
index_in_committee = find(beacon_committee, validator_index)
doAssert index_in_committee < beacon_committee.len
if index_in_committee < 0:
return pool.checkedReject("SingleAttestation: attester index not in beacon committee")

Expand All @@ -1077,10 +1086,12 @@ proc validateAttestation*(

# In the spec, is_valid_indexed_attestation is used to verify the signature -
# here, we do a batch verification instead
let sig = attestation.signature.load().valueOr:
return pool.checkedReject("SingleAttestation: unable to load signature")
if not shufflingRefMissing:
# findShufflingRef did find a cached ShufflingRef, which means the early
# signature check was skipped, so do it now.
sig = attestation.signature.load().valueOr:
return pool.checkedReject("SingleAttestation: unable to load signature")

echo "FOOBAR4: ", beacon_committee.len, "; ", index_in_committee
ok((validator_index, beacon_committee.len, index_in_committee, sig))

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
Expand Down
2 changes: 2 additions & 0 deletions beacon_chain/spec/datatypes/electra.nim
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ func shortLog*(v: electra.Attestation | electra.TrustedAttestation): auto =

func shortLog*(v: SingleAttestation): auto =
(
committee_index: v.committee_index,
attester_index: v.attester_index,
data: shortLog(v.data),
signature: shortLog(v.signature)
)
Expand Down

0 comments on commit 659d03d

Please sign in to comment.