1
1
# beacon_chain
2
- # Copyright (c) 2018-2024 Status Research & Development GmbH
2
+ # Copyright (c) 2018-2025 Status Research & Development GmbH
3
3
# Licensed and distributed under either of
4
4
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
5
5
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -1105,4 +1105,74 @@ suite "Attestation pool electra processing" & preset():
1105
1105
# Total aggregations size should be one for that root
1106
1106
check:
1107
1107
pool[].getElectraAggregatedAttestation(1 .Slot, hash_tree_root(att4.data),
1108
- 0 .CommitteeIndex).get().aggregation_bits.countOnes() == 1
1108
+ 0 .CommitteeIndex).get().aggregation_bits.countOnes() == 1
1109
+
1110
+ proc verifyAttestationSignature(
1111
+ pool: AttestationPool,
1112
+ state: ref ForkedHashedBeaconState,
1113
+ cache: var StateCache,
1114
+ attestation: electra.Attestation): bool =
1115
+ withState(state[]):
1116
+ when consensusFork == ConsensusFork.Electra:
1117
+ let
1118
+ fork = pool.dag.cfg.forkAtEpoch(forkyState.data.slot.epoch)
1119
+ attesting_indices = get_attesting_indices(
1120
+ forkyState.data, attestation.data, attestation.aggregation_bits,
1121
+ attestation.committee_bits, cache)
1122
+ verify_attestation_signature(
1123
+ fork, pool.dag.genesis_validators_root, attestation.data,
1124
+ attesting_indices.mapIt(forkyState.data.validators.item(it).pubkey),
1125
+ attestation.signature)
1126
+ else :
1127
+ raiseAssert " must be electra"
1128
+
1129
+ test " Aggregating across committees" & preset():
1130
+ # Add attestation from different committee
1131
+ var maxSlot = 0 .Slot
1132
+ for i in 0 ..< 4 :
1133
+ let
1134
+ bc = get_beacon_committee(
1135
+ state[], getStateField(state[], slot), i.CommitteeIndex, cache)
1136
+ att = makeElectraAttestation(
1137
+ state[], state[].latest_block_root, bc[0 ], cache)
1138
+ var att2 = makeElectraAttestation(
1139
+ state[], state[].latest_block_root, bc[1 ], cache)
1140
+ att2.combine(att)
1141
+
1142
+ pool[].addAttestation(
1143
+ att, @ [bc[0 ]], att.aggregation_bits.len, att.loadSig,
1144
+ att.data.slot.start_beacon_time)
1145
+
1146
+ pool[].addAttestation(
1147
+ att2, @ [bc[0 ], bc[1 ]], att2.aggregation_bits.len, att2.loadSig,
1148
+ att2.data.slot.start_beacon_time)
1149
+
1150
+ pool[].addAttestation(
1151
+ att, @ [bc[0 ]], att.aggregation_bits.len, att.loadSig,
1152
+ att.data.slot.start_beacon_time)
1153
+
1154
+ pool[].addAttestation(
1155
+ att2, @ [bc[0 ], bc[1 ]], att2.aggregation_bits.len, att2.loadSig,
1156
+ att2.data.slot.start_beacon_time)
1157
+
1158
+ if att.data.slot > maxSlot:
1159
+ maxSlot = att.data.slot
1160
+
1161
+ check process_slots(
1162
+ defaultRuntimeConfig, state[],
1163
+ maxSlot + MIN_ATTESTATION_INCLUSION_DELAY, cache,
1164
+ info, {}).isOk()
1165
+
1166
+ let attestations = pool[].getElectraAttestationsForBlock(state[], cache)
1167
+ check:
1168
+ attestations.len() == 2
1169
+ attestations[0 ].aggregation_bits.countOnes() == 4
1170
+ attestations[0 ].committee_bits.countOnes() == 2
1171
+ attestations[1 ].aggregation_bits.countOnes() == 4
1172
+ attestations[1 ].committee_bits.countOnes() == 2
1173
+ check_attestation(
1174
+ state[].electraData.data, attestations[0 ], {}, cache, true ).isOk
1175
+ check_attestation(
1176
+ state[].electraData.data, attestations[1 ], {}, cache, true ).isOk
1177
+ pool[].verifyAttestationSignature(state, cache, attestations[0 ])
1178
+ pool[].verifyAttestationSignature(state, cache, attestations[1 ])
0 commit comments