From e70fa6d6de5ae6259e0bfcda8e8a639abb957319 Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 29 Apr 2024 02:19:10 +0000 Subject: [PATCH] rename ElectraIndexedAttestation/ElectraAttesterSlashing for consistency (#6252) --- beacon_chain/spec/beaconstate.nim | 4 ++-- beacon_chain/spec/datatypes/electra.nim | 23 ++++++++----------- .../eth2_apis/eth2_rest_serialization.nim | 4 ++-- beacon_chain/spec/mev/electra_mev.nim | 2 +- beacon_chain/spec/state_transition_block.nim | 15 ++++++------ .../electra/test_fixture_operations.nim | 4 ++-- .../test_fixture_ssz_consensus_objects.nim | 4 ++-- ...xture_light_client_single_merkle_proof.nim | 18 +++++++-------- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index a8f5921dc..3c81abe02 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -533,8 +533,8 @@ func is_eligible_for_activation*( # https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation proc is_valid_indexed_attestation*( state: ForkyBeaconState, - indexed_attestation: SomeIndexedAttestation | ElectraIndexedAttestation | - TrustedElectraIndexedAttestation, + indexed_attestation: SomeIndexedAttestation | electra.IndexedAttestation | + electra.TrustedIndexedAttestation, flags: UpdateFlags): Result[void, cstring] = ## Check if ``indexed_attestation`` is not empty, has sorted and unique ## indices and has a valid aggregate signature. diff --git a/beacon_chain/spec/datatypes/electra.nim b/beacon_chain/spec/datatypes/electra.nim index fa456a2c7..09a1a83e5 100644 --- a/beacon_chain/spec/datatypes/electra.nim +++ b/beacon_chain/spec/datatypes/electra.nim @@ -48,9 +48,6 @@ const CURRENT_SYNC_COMMITTEE_GINDEX = 86.GeneralizedIndex # current_sync_committee NEXT_SYNC_COMMITTEE_GINDEX = 87.GeneralizedIndex # next_sync_committee -debugRaiseAssert "rename ElectraIndexedAttestation to IndexedAttestation" -debugRaiseAssert "rename ElectraAttesterSlashing to AttesterSlashing" - type # https://github.com/ethereum/consensus-specs/blob/94a0b6c581f2809aa8aca4ef7ee6fbb63f9d74e9/specs/electra/beacon-chain.md#depositreceipt DepositReceipt* = object @@ -61,13 +58,13 @@ type index*: uint64 # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#indexedattestation - ElectraIndexedAttestation* = object + IndexedAttestation* = object attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT] data*: AttestationData signature*: ValidatorSig - TrustedElectraIndexedAttestation* = object + TrustedIndexedAttestation* = object # The Trusted version, at the moment, implies that the cryptographic signature was checked. # It DOES NOT imply that the state transition was verified. # Currently the code MUST verify the state transition as soon as the signature is verified @@ -77,11 +74,11 @@ type signature*: TrustedSig # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#attesterslashing - ElectraAttesterSlashing* = object - attestation_1*: ElectraIndexedAttestation # [Modified in Electra:EIP7549] - attestation_2*: ElectraIndexedAttestation # [Modified in Electra:EIP7549] + AttesterSlashing* = object + attestation_1*: IndexedAttestation # [Modified in Electra:EIP7549] + attestation_2*: IndexedAttestation # [Modified in Electra:EIP7549] - TrustedElectraAttesterSlashing* = object + TrustedAttesterSlashing* = object # The Trusted version, at the moment, implies that the cryptographic signature was checked. # It DOES NOT imply that the state transition was verified. # Currently the code MUST verify the state transition as soon as the signature is verified @@ -461,7 +458,7 @@ type # Operations proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS] attester_slashings*: - List[ElectraAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] + List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] ## [Modified in Electra:EIP7549] attestations*: List[electra.Attestation, Limit MAX_ATTESTATIONS_ELECTRA] ## [Modified in Electra:EIP7549] @@ -502,7 +499,7 @@ type proposer_slashings*: List[TrustedProposerSlashing, Limit MAX_PROPOSER_SLASHINGS] attester_slashings*: - List[TrustedElectraAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] + List[TrustedAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] ## [Modified in Electra:EIP7549] attestations*: List[TrustedAttestation, Limit MAX_ATTESTATIONS_ELECTRA] ## [Modified in Electra:EIP7549] @@ -531,7 +528,7 @@ type proposer_slashings*: List[TrustedProposerSlashing, Limit MAX_PROPOSER_SLASHINGS] attester_slashings*: - List[TrustedElectraAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] + List[TrustedAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] ## [Modified in Electra:EIP7549] attestations*: List[TrustedAttestation, Limit MAX_ATTESTATIONS_ELECTRA] ## [Modified in Electra:EIP7549] @@ -708,7 +705,7 @@ debugRaiseAssert "this whole section with getValidatorIndices/shortLog needs ref from std/sets import toHashSet -iterator getValidatorIndices*(attester_slashing: ElectraAttesterSlashing | TrustedElectraAttesterSlashing): uint64 = +iterator getValidatorIndices*(attester_slashing: AttesterSlashing | TrustedAttesterSlashing): uint64 = template attestation_1(): auto = attester_slashing.attestation_1 template attestation_2(): auto = attester_slashing.attestation_2 diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 2b38ca5dc..f7c58eae5 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -247,14 +247,14 @@ RestJson.useDefaultSerializationFor( deneb_mev.SignedBlindedBeaconBlock, deneb_mev.SignedBuilderBid, electra.Attestation, - ElectraAttesterSlashing, + electra.AttesterSlashing, electra.BeaconBlock, electra.BeaconState, electra.BeaconBlockBody, electra.BlockContents, electra.ExecutionPayload, electra.ExecutionPayloadHeader, - ElectraIndexedAttestation, + electra.IndexedAttestation, electra.SignedBeaconBlock, electra.TrustedAttestation, electra_mev.BlindedBeaconBlock, diff --git a/beacon_chain/spec/mev/electra_mev.nim b/beacon_chain/spec/mev/electra_mev.nim index 232b904d6..994d07c07 100644 --- a/beacon_chain/spec/mev/electra_mev.nim +++ b/beacon_chain/spec/mev/electra_mev.nim @@ -34,7 +34,7 @@ type graffiti*: GraffitiBytes proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS] attester_slashings*: - List[ElectraAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] + List[electra.AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS_ELECTRA] attestations*: List[electra.Attestation, Limit MAX_ATTESTATIONS_ELECTRA] deposits*: List[Deposit, Limit MAX_DEPOSITS] voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS] diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index a3c6d52df..a784956c5 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -208,8 +208,8 @@ func is_slashable_attestation_data( # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#attester-slashings proc check_attester_slashing*( state: ForkyBeaconState, - attester_slashing: SomeAttesterSlashing | ElectraAttesterSlashing | - TrustedElectraAttesterSlashing, + attester_slashing: SomeAttesterSlashing | electra.AttesterSlashing | + electra.TrustedAttesterSlashing, flags: UpdateFlags): Result[seq[ValidatorIndex], cstring] = let attestation_1 = attester_slashing.attestation_1 @@ -243,8 +243,8 @@ proc check_attester_slashing*( proc check_attester_slashing*( state: var ForkedHashedBeaconState, - attester_slashing: SomeAttesterSlashing | ElectraAttesterSlashing | - TrustedElectraAttesterSlashing, + attester_slashing: SomeAttesterSlashing | electra.AttesterSlashing | + electra.TrustedAttesterSlashing, flags: UpdateFlags): Result[seq[ValidatorIndex], cstring] = withState(state): check_attester_slashing(forkyState.data, attester_slashing, flags) @@ -253,8 +253,8 @@ proc check_attester_slashing*( proc process_attester_slashing*( cfg: RuntimeConfig, state: var ForkyBeaconState, - attester_slashing: SomeAttesterSlashing | ElectraAttesterSlashing | - TrustedElectraAttesterSlashing, + attester_slashing: SomeAttesterSlashing | electra.AttesterSlashing | + electra.TrustedAttesterSlashing, flags: UpdateFlags, exit_queue_info: ExitQueueInfo, cache: var StateCache ): Result[(Gwei, ExitQueueInfo), cstring] = @@ -1108,7 +1108,8 @@ func process_execution_layer_withdrawal_request*( compute_exit_epoch_and_update_churn(cfg, state, to_withdraw, cache) withdrawable_epoch = Epoch(exit_queue_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY) - debugRaiseAssert "check return value of HashList.add" + + # In theory can fail, but failing/early returning here is indistinguishable discard state.pending_partial_withdrawals.add(PendingPartialWithdrawal( index: index.uint64, amount: to_withdraw, diff --git a/tests/consensus_spec/electra/test_fixture_operations.nim b/tests/consensus_spec/electra/test_fixture_operations.nim index c75e5b611..8a241a908 100644 --- a/tests/consensus_spec/electra/test_fixture_operations.nim +++ b/tests/consensus_spec/electra/test_fixture_operations.nim @@ -106,7 +106,7 @@ suite baseDescription & "Attestation " & preset(): suite baseDescription & "Attester Slashing " & preset(): proc applyAttesterSlashing( preState: var electra.BeaconState, - attesterSlashing: ElectraAttesterSlashing): Result[void, cstring] = + attesterSlashing: electra.AttesterSlashing): Result[void, cstring] = var cache: StateCache doAssert (? process_attester_slashing( defaultRuntimeConfig, preState, attesterSlashing, {}, @@ -114,7 +114,7 @@ suite baseDescription & "Attester Slashing " & preset(): ok() for path in walkTests(OpAttSlashingDir): - runTest[ElectraAttesterSlashing, typeof applyAttesterSlashing]( + runTest[electra.AttesterSlashing, typeof applyAttesterSlashing]( OpAttSlashingDir, suiteName, "Attester Slashing", "attester_slashing", applyAttesterSlashing, path) 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 6af4b2323..4726166d4 100644 --- a/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/electra/test_fixture_ssz_consensus_objects.nim @@ -121,7 +121,7 @@ suite "EF - Electra - SSZ consensus objects " & preset(): of "AggregateAndProof": discard # checkSSZ(AggregateAndProof, path, hash) of "Attestation": checkSSZ(electra.Attestation, path, hash) of "AttestationData": checkSSZ(AttestationData, path, hash) - of "AttesterSlashing": checkSSZ(ElectraAttesterSlashing, path, hash) + of "AttesterSlashing": checkSSZ(electra.AttesterSlashing, path, hash) of "BeaconBlock": checkSSZ(electra.BeaconBlock, path, hash) of "BeaconBlockBody": checkSSZ(electra.BeaconBlockBody, path, hash) of "BeaconBlockHeader": checkSSZ(BeaconBlockHeader, path, hash) @@ -147,7 +147,7 @@ suite "EF - Electra - SSZ consensus objects " & preset(): of "ForkData": checkSSZ(ForkData, path, hash) of "HistoricalBatch": checkSSZ(HistoricalBatch, path, hash) of "HistoricalSummary": checkSSZ(HistoricalSummary, path, hash) - of "IndexedAttestation": checkSSZ(ElectraIndexedAttestation, path, hash) + of "IndexedAttestation": checkSSZ(electra.IndexedAttestation, path, hash) of "LightClientBootstrap": checkSSZ(electra.LightClientBootstrap, path, hash) of "LightClientHeader": checkSSZ(electra.LightClientHeader, path, hash) diff --git a/tests/consensus_spec/test_fixture_light_client_single_merkle_proof.nim b/tests/consensus_spec/test_fixture_light_client_single_merkle_proof.nim index 32145d99e..183b07666 100644 --- a/tests/consensus_spec/test_fixture_light_client_single_merkle_proof.nim +++ b/tests/consensus_spec/test_fixture_light_client_single_merkle_proof.nim @@ -68,13 +68,11 @@ suite "EF - Light client - Single merkle proof" & preset(): continue let objName = path withConsensusFork(fork): - debugRaiseAssert "" - when consensusFork != ConsensusFork.Electra: - for kind, path in walkDir(suitePath, relative = true, checkDir = true): - case objName - of "BeaconBlockBody": - runTest(suiteName, suitePath/path, consensusFork.BeaconBlockBody) - of "BeaconState": - runTest(suiteName, suitePath/path, consensusFork.BeaconState) - else: - raiseAssert "Unknown test object: " & suitePath/path \ No newline at end of file + for kind, path in walkDir(suitePath, relative = true, checkDir = true): + case objName + of "BeaconBlockBody": + runTest(suiteName, suitePath/path, consensusFork.BeaconBlockBody) + of "BeaconState": + runTest(suiteName, suitePath/path, consensusFork.BeaconState) + else: + raiseAssert "Unknown test object: " & suitePath/path \ No newline at end of file