From 1c3aaa7be2e95b869cbc708f50182dc359bea817 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 14 May 2024 14:51:06 +0300 Subject: [PATCH] add (Signed)AggregateAndProof SSZ tests (#6285) --- beacon_chain/consensus_object_pools/spec_cache.nim | 2 +- beacon_chain/spec/beaconstate.nim | 6 +++--- beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim | 2 +- beacon_chain/spec/forks_light_client.nim | 2 +- beacon_chain/spec/state_transition_block.nim | 8 ++++---- beacon_chain/validators/beacon_validators.nim | 6 +++--- beacon_chain/validators/message_router_mev.nim | 2 +- research/wss_sim.nim | 2 +- .../electra/test_fixture_ssz_consensus_objects.nim | 6 ++---- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/beacon_chain/consensus_object_pools/spec_cache.nim b/beacon_chain/consensus_object_pools/spec_cache.nim index 4fbda9759..c58b93fb2 100644 --- a/beacon_chain/consensus_object_pools/spec_cache.nim +++ b/beacon_chain/consensus_object_pools/spec_cache.nim @@ -16,7 +16,7 @@ import ../spec/datatypes/base, ./block_pools_types, blockchain_dag -debugRaiseAssert "probably just need Electra shortLog here" +debugComment "probably just need Electra shortLog here" import ../spec/forks # prune this, it's for electra attestation logging export diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 87d0db2d4..8cd7a8eaf 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -938,7 +938,7 @@ proc check_attestation*( return err("Electra attestation data index not 0") var participants_count = 0 - debugRaiseAssert "cache doesn't know about forks" + debugComment "cache doesn't know about forks" for index in attestation.committee_bits.oneIndices: if not (index.uint64 < get_committee_count_per_slot( state, data.target.epoch, cache)): @@ -1548,7 +1548,7 @@ func queue_entire_balance_and_reset_validator( let validator = addr state.validators.mitem(index) validator[].effective_balance = 0.Gwei validator[].activation_eligibility_epoch = FAR_FUTURE_EPOCH - debugRaiseAssert "check hashlist add return" + debugComment "check hashlist add return" discard state.pending_balance_deposits.add PendingBalanceDeposit( index: index, amount: balance) @@ -1975,7 +1975,7 @@ func upgrade_to_electra*( # churn for index, validator in post.validators: if has_compounding_withdrawal_credential(validator): - debugRaiseAssert "in theory truncating" + debugComment "in theory truncating" queue_excess_active_balance(post[], ValidatorIndex(index)) post diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index cf1af3677..5e518d274 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -1967,7 +1967,7 @@ proc readValue*(reader: var JsonReader[RestJson], value.electraBody.execution_payload.excess_blob_gas, ep_src.excess_blob_gas.get()) - debugRaiseAssert "electra support missing, including attslashing/atts" + debugComment "electra support missing, including attslashing/atts" ## RestPublishedBeaconBlock proc readValue*(reader: var JsonReader[RestJson], diff --git a/beacon_chain/spec/forks_light_client.nim b/beacon_chain/spec/forks_light_client.nim index 318e780a9..780ba4739 100644 --- a/beacon_chain/spec/forks_light_client.nim +++ b/beacon_chain/spec/forks_light_client.nim @@ -961,7 +961,7 @@ func toLightClientHeader*( electra.SignedBeaconBlock | electra.TrustedSignedBeaconBlock, kind: static LightClientDataFork): auto = when blck is electra.SignedBeaconBlock or blck is electra.TrustedSignedBeaconBlock: - debugRaiseAssert "toLightClientHeader electra missing" + debugComment "toLightClientHeader electra missing" default(deneb.LightClientHeader) elif kind == LightClientDataFork.Deneb: blck.toDenebLightClientHeader() diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 86108788e..c43722e30 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -601,7 +601,7 @@ proc process_consolidation*( target_validator.withdrawal_credentials.data.toOpenArray(12, 31)): return err("Consolidation: source and target don't have same withdrawal address") - debugRaiseAssert "this is per spec, near-verbatim, but Nimbus generally factors this out into spec/signatures.nim. so, create verify_consolidation_signature infra there, call here" + debugComment "this is per spec, near-verbatim, but Nimbus generally factors this out into spec/signatures.nim. so, create verify_consolidation_signature infra there, call here" # Verify consolidation is signed by the source and the target let domain = compute_domain( @@ -610,7 +610,7 @@ proc process_consolidation*( signing_root = compute_signing_root(consolidation, domain) pubkeys = [source_validator[].pubkey, target_validator.pubkey] - debugRaiseAssert "as a good example, this trustedsig hack typically/should live in spec/signatures.nim" + debugComment "as a good example, this trustedsig hack typically/should live in spec/signatures.nim" when not (signed_consolidation.signature is TrustedSig): if not blsFastAggregateVerify( pubkeys, signing_root.data, signed_consolidation.signature): @@ -621,7 +621,7 @@ proc process_consolidation*( cfg, state, source_validator[].effective_balance, cache) source_validator[].withdrawable_epoch = source_validator[].exit_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY - debugRaiseAssert "check HashList add return value" + debugComment "check HashList add return value" discard state.pending_consolidations.add(PendingConsolidation( source_index: consolidation.source_index, target_index: consolidation.target_index @@ -706,7 +706,7 @@ proc process_operations( discard ? process_execution_layer_withdrawal_request( cfg, state, op, default(ExitQueueInfo), cache) for op in body.execution_payload.deposit_receipts: - debugRaiseAssert "combine with previous bloom filter construction" + debugComment "combine with previous bloom filter construction" let bloom_filter = constructBloomFilter(state.validators.asSeq) ? process_deposit_receipt(cfg, state, bloom_filter[], op, {}) for op in body.consolidations: diff --git a/beacon_chain/validators/beacon_validators.nim b/beacon_chain/validators/beacon_validators.nim index f11498de0..8a35815e0 100644 --- a/beacon_chain/validators/beacon_validators.nim +++ b/beacon_chain/validators/beacon_validators.nim @@ -497,7 +497,7 @@ proc makeBeaconBlockForHeadAndSlot*( warn "Eth1 deposits not available. Skipping block proposal", slot return err("Eth1 deposits not available") - debugRaiseAssert "b_v makeBeaconBlockForHeadAndSlot doesn't know how to get Electra attestations because attpool doesn't either" + debugComment "b_v makeBeaconBlockForHeadAndSlot doesn't know how to get Electra attestations because attpool doesn't either" let attestations = when PayloadType.kind == ConsensusFork.Electra: @@ -672,7 +672,7 @@ proc constructSignableBlindedBlock[T: electra_mev.SignedBlindedBeaconBlock]( blindedBlock.message.body.blob_kzg_commitments, blindedBundle.blob_kzg_commitments) - debugRaiseAssert "check for any additional electra mev requirements" + debugComment "check for any additional electra mev requirements" blindedBlock @@ -722,7 +722,7 @@ func constructPlainBlindedBlock[T: electra_mev.BlindedBeaconBlock]( blindedBlock.body.blob_kzg_commitments, blindedBundle.blob_kzg_commitments) - debugRaiseAssert "check for any additional electra mev requirements" + debugComment "check for any additional electra mev requirements" blindedBlock diff --git a/beacon_chain/validators/message_router_mev.nim b/beacon_chain/validators/message_router_mev.nim index 48d8a550e..5abdc64ef 100644 --- a/beacon_chain/validators/message_router_mev.nim +++ b/beacon_chain/validators/message_router_mev.nim @@ -32,7 +32,7 @@ macro copyFields*( dst: untyped, src: untyped, fieldNames: static[seq[string]]): untyped = result = newStmtList() for name in fieldNames: - debugRaiseAssert "deposit_receipts_root and exits_root are not currently filled in anywhere properly, so blinded electra proposals will fail" + debugComment "deposit_receipts_root and exits_root are not currently filled in anywhere properly, so blinded electra proposals will fail" if name notin [ # These fields are the ones which vary between the blinded and # unblinded objects, and can't simply be copied. diff --git a/research/wss_sim.nim b/research/wss_sim.nim index bda959dd0..d0a390c4b 100644 --- a/research/wss_sim.nim +++ b/research/wss_sim.nim @@ -287,7 +287,7 @@ cli do(validatorsDir: string, secretsDir: string, graffitiValue, when typeof(payload).kind == ConsensusFork.Electra: block: - debugRaiseAssert "wss_sim electra aggregates" + debugComment "wss_sim electra aggregates" default(seq[electra.Attestation]) else: blockAggregates, diff --git a/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim b/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim index 4726166d4..11e854cf8 100644 --- a/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim @@ -99,8 +99,6 @@ proc loadExpectedHashTreeRoot( # Test runner # ---------------------------------------------------------------- -debugRaiseAssert "re-enable AggregateAndProof and SignedAggregateAndProof" - suite "EF - Electra - SSZ consensus objects " & preset(): doAssert dirExists(SSZDir), "You need to run the \"download_test_vectors.sh\" script to retrieve the consensus spec test vectors." for pathKind, sszType in walkDir(SSZDir, relative = true, checkDir = true): @@ -118,7 +116,7 @@ suite "EF - Electra - SSZ consensus objects " & preset(): let hash = loadExpectedHashTreeRoot(path) case sszType: - of "AggregateAndProof": discard # checkSSZ(AggregateAndProof, path, hash) + of "AggregateAndProof": checkSSZ(electra.AggregateAndProof, path, hash) of "Attestation": checkSSZ(electra.Attestation, path, hash) of "AttestationData": checkSSZ(AttestationData, path, hash) of "AttesterSlashing": checkSSZ(electra.AttesterSlashing, path, hash) @@ -165,7 +163,7 @@ suite "EF - Electra - SSZ consensus objects " & preset(): of "PowBlock": checkSSZ(PowBlock, path, hash) of "ProposerSlashing": checkSSZ(ProposerSlashing, path, hash) of "SignedAggregateAndProof": - discard #checkSSZ(SignedAggregateAndProof, path, hash) + checkSSZ(electra.SignedAggregateAndProof, path, hash) of "SignedBeaconBlock": checkSSZ(electra.SignedBeaconBlock, path, hash) of "SignedBeaconBlockHeader":