Skip to content
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

add attestation pool checks for aggregating across committees #6915

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
5 changes: 3 additions & 2 deletions AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
## Attestation pool electra processing [Preset: mainnet]
```diff
+ Aggregated attestations with disjoint comittee bits into a single on-chain aggregate [Pres OK
+ Aggregating across committees [Preset: mainnet] OK
+ Attestations with disjoint comittee bits and equal data into single on-chain aggregate [Pr OK
+ Can add and retrieve simple electra attestations [Preset: mainnet] OK
+ Working with electra aggregates [Preset: mainnet] OK
```
OK: 4/4 Fail: 0/4 Skip: 0/4
OK: 5/5 Fail: 0/5 Skip: 0/5
## Attestation pool processing [Preset: mainnet]
```diff
+ Attestation from different branch [Preset: mainnet] OK
Expand Down Expand Up @@ -1149,4 +1150,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9

---TOTAL---
OK: 778/783 Fail: 0/783 Skip: 5/783
OK: 779/784 Fail: 0/784 Skip: 5/784
74 changes: 72 additions & 2 deletions tests/test_attestation_pool.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -1105,4 +1105,74 @@ suite "Attestation pool electra processing" & preset():
# Total aggregations size should be one for that root
check:
pool[].getElectraAggregatedAttestation(1.Slot, hash_tree_root(att4.data),
0.CommitteeIndex).get().aggregation_bits.countOnes() == 1
0.CommitteeIndex).get().aggregation_bits.countOnes() == 1

proc verifyAttestationSignature(
pool: AttestationPool,
state: ref ForkedHashedBeaconState,
cache: var StateCache,
attestation: electra.Attestation): bool =
withState(state[]):
when consensusFork == ConsensusFork.Electra:
let
fork = pool.dag.cfg.forkAtEpoch(forkyState.data.slot.epoch)
attesting_indices = get_attesting_indices(
forkyState.data, attestation.data, attestation.aggregation_bits,
attestation.committee_bits, cache)
verify_attestation_signature(
fork, pool.dag.genesis_validators_root, attestation.data,
attesting_indices.mapIt(forkyState.data.validators.item(it).pubkey),
attestation.signature)
else:
raiseAssert "must be electra"

test "Aggregating across committees" & preset():
# Add attestation from different committee
var maxSlot = 0.Slot
for i in 0 ..< 4:
let
bc = get_beacon_committee(
state[], getStateField(state[], slot), i.CommitteeIndex, cache)
att = makeElectraAttestation(
state[], state[].latest_block_root, bc[0], cache)
var att2 = makeElectraAttestation(
state[], state[].latest_block_root, bc[1], cache)
att2.combine(att)

pool[].addAttestation(
att, @[bc[0]], att.aggregation_bits.len, att.loadSig,
att.data.slot.start_beacon_time)

pool[].addAttestation(
att2, @[bc[0], bc[1]], att2.aggregation_bits.len, att2.loadSig,
att2.data.slot.start_beacon_time)

pool[].addAttestation(
att, @[bc[0]], att.aggregation_bits.len, att.loadSig,
att.data.slot.start_beacon_time)

pool[].addAttestation(
att2, @[bc[0], bc[1]], att2.aggregation_bits.len, att2.loadSig,
att2.data.slot.start_beacon_time)

if att.data.slot > maxSlot:
maxSlot = att.data.slot

check process_slots(
defaultRuntimeConfig, state[],
maxSlot + MIN_ATTESTATION_INCLUSION_DELAY, cache,
info, {}).isOk()

let attestations = pool[].getElectraAttestationsForBlock(state[], cache)
check:
attestations.len() == 2
attestations[0].aggregation_bits.countOnes() == 4
attestations[0].committee_bits.countOnes() == 2
attestations[1].aggregation_bits.countOnes() == 4
attestations[1].committee_bits.countOnes() == 2
check_attestation(
state[].electraData.data, attestations[0], {}, cache, true).isOk
check_attestation(
state[].electraData.data, attestations[1], {}, cache, true).isOk
pool[].verifyAttestationSignature(state, cache, attestations[0])
pool[].verifyAttestationSignature(state, cache, attestations[1])
Loading