diff --git a/ConsensusSpecPreset-mainnet.md b/ConsensusSpecPreset-mainnet.md index 17e8ae99d..918c78388 100644 --- a/ConsensusSpecPreset-mainnet.md +++ b/ConsensusSpecPreset-mainnet.md @@ -188,19 +188,6 @@ ConsensusSpecPreset-mainnet + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: mainne OK -+ [Invalid] bad_everything_regular_payload OK -+ [Invalid] bad_execution_first_payload OK -+ [Invalid] bad_execution_regular_payload OK -+ [Invalid] bad_number_regular_payload OK -+ [Invalid] bad_parent_hash_regular_payload OK -+ [Invalid] bad_random_first_payload OK -+ [Invalid] bad_random_regular_payload OK -+ [Invalid] bad_timestamp_first_payload OK -+ [Invalid] bad_timestamp_regular_payload OK -+ [Invalid] gaslimit_lower_minus_regular_payload OK -+ [Invalid] gaslimit_minimum_minus_regular_payload OK -+ [Invalid] gaslimit_upper_plus_regular_payload OK -+ [Invalid] gasused_gaslimit_plus_regular_payload OK + [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK + [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: mainnet] OK + [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: mainnet] OK @@ -334,16 +321,6 @@ ConsensusSpecPreset-mainnet + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: mainnet OK + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: mainne OK -+ [Valid] gaslimit_lower_regular_payload OK -+ [Valid] gaslimit_max_first_payload OK -+ [Valid] gaslimit_minimum_regular_payload OK -+ [Valid] gaslimit_upper_regular_payload OK -+ [Valid] gaslimit_zero_first_payload OK -+ [Valid] gasused_gaslimit_regular_payload OK -+ [Valid] success_first_payload OK -+ [Valid] success_first_payload_with_gap_slot OK -+ [Valid] success_regular_payload OK -+ [Valid] success_regular_payload_with_gap_slot OK + altair_fork_random_0 OK + altair_fork_random_1 OK + altair_fork_random_2 OK @@ -361,7 +338,7 @@ ConsensusSpecPreset-mainnet + fork_random_misc_balances OK + next_sync_committee_merkle_proof OK ``` -OK: 358/358 Fail: 0/358 Skip: 0/358 +OK: 335/335 Fail: 0/335 Skip: 0/335 ## Attestation ```diff + [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK @@ -1028,6 +1005,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1 + Testing VoluntaryExit OK ``` OK: 27/27 Fail: 0/27 Skip: 0/27 +## Execution Payload +```diff ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK +``` +OK: 23/23 Fail: 0/23 Skip: 0/23 ## Proposer Slashing ```diff + [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK diff --git a/ConsensusSpecPreset-minimal.md b/ConsensusSpecPreset-minimal.md index 54f7b5adf..bfbdada90 100644 --- a/ConsensusSpecPreset-minimal.md +++ b/ConsensusSpecPreset-minimal.md @@ -190,19 +190,6 @@ ConsensusSpecPreset-minimal + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK + [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: minima OK -+ [Invalid] bad_everything_regular_payload OK -+ [Invalid] bad_execution_first_payload OK -+ [Invalid] bad_execution_regular_payload OK -+ [Invalid] bad_number_regular_payload OK -+ [Invalid] bad_parent_hash_regular_payload OK -+ [Invalid] bad_random_first_payload OK -+ [Invalid] bad_random_regular_payload OK -+ [Invalid] bad_timestamp_first_payload OK -+ [Invalid] bad_timestamp_regular_payload OK -+ [Invalid] gaslimit_lower_minus_regular_payload OK -+ [Invalid] gaslimit_minimum_minus_regular_payload OK -+ [Invalid] gaslimit_upper_plus_regular_payload OK -+ [Invalid] gasused_gaslimit_plus_regular_payload OK + [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK + [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: minimal] OK + [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: minimal] OK @@ -351,20 +338,10 @@ ConsensusSpecPreset-minimal + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: minimal OK + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK + [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: minima OK -+ [Valid] gaslimit_lower_regular_payload OK -+ [Valid] gaslimit_max_first_payload OK -+ [Valid] gaslimit_minimum_regular_payload OK -+ [Valid] gaslimit_upper_regular_payload OK -+ [Valid] gaslimit_zero_first_payload OK -+ [Valid] gasused_gaslimit_regular_payload OK -+ [Valid] success_first_payload OK -+ [Valid] success_first_payload_with_gap_slot OK -+ [Valid] success_regular_payload OK -+ [Valid] success_regular_payload_with_gap_slot OK + finality_root_merkle_proof OK + next_sync_committee_merkle_proof OK ``` -OK: 361/361 Fail: 0/361 Skip: 0/361 +OK: 338/338 Fail: 0/338 Skip: 0/338 ## Attestation ```diff + [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK @@ -1065,6 +1042,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1 + Testing VoluntaryExit OK ``` OK: 27/27 Fail: 0/27 Skip: 0/27 +## Execution Payload +```diff ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK ++ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK ++ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK +``` +OK: 23/23 Fail: 0/23 Skip: 0/23 ## Proposer Slashing ```diff + [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK diff --git a/beacon_chain/consensus_object_pools/exit_pool.nim b/beacon_chain/consensus_object_pools/exit_pool.nim index 7d8f8ceed..236afa09f 100644 --- a/beacon_chain/consensus_object_pools/exit_pool.nim +++ b/beacon_chain/consensus_object_pools/exit_pool.nim @@ -9,7 +9,7 @@ import # Standard libraries - std/[deques, sets, intsets], + std/[deques, sets], # Status libraries chronicles, # Internal @@ -17,7 +17,7 @@ import ../spec/datatypes/[phase0, altair, merge], ./blockchain_dag -export phase0, altair, merge, deques, intsets, sets, blockchain_dag +export phase0, altair, merge, deques, sets, blockchain_dag logScope: topics = "exitpool" @@ -43,13 +43,13 @@ type voluntary_exits*: Deque[SignedVoluntaryExit] ## \ ## Not a function of chain DAG branch; just used as a FIFO queue for blocks - prior_seen_attester_slashed_indices*: IntSet ## \ + prior_seen_attester_slashed_indices*: HashSet[uint64] ## \ ## Records attester-slashed indices seen. - prior_seen_proposer_slashed_indices*: IntSet ## \ + prior_seen_proposer_slashed_indices*: HashSet[uint64] ## \ ## Records proposer-slashed indices seen. - prior_seen_voluntary_exit_indices*: IntSet ##\ + prior_seen_voluntary_exit_indices*: HashSet[uint64] ##\ ## Records voluntary exit indices seen. dag*: ChainDAGRef @@ -79,18 +79,13 @@ func addExitMessage*(subpool: var auto, exitMessage, bound: auto) = doAssert subpool.lenu64 <= bound iterator getValidatorIndices(attester_slashing: AttesterSlashing): uint64 = - # TODO rely on sortedness and do this sans memory allocations, but it's only - # when producing a beacon block, which is rare bottlenecked elsewhere. - let - attestation_1_indices = - attester_slashing.attestation_1.attesting_indices.asSeq - attestation_2_indices = - attester_slashing.attestation_2.attesting_indices.asSeq - attester_slashed_indices = - toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices) + let attestation_2_indices = + toHashSet(attester_slashing.attestation_2.attesting_indices.asSeq) - for validator_index in attester_slashed_indices: - yield validator_index.uint64 + for validator_index in attester_slashing.attestation_1.attesting_indices.asSeq: + if validator_index notin attestation_2_indices: + continue + yield validator_index iterator getValidatorIndices(proposer_slashing: ProposerSlashing): uint64 = yield proposer_slashing.signed_header_1.message.proposer_index @@ -152,4 +147,4 @@ func getBeaconBlockExits*(pool: var ExitPool, state: SomeBeaconState): BeaconBlo pool.voluntary_exits, state.validators.asSeq(), indices, res.voluntary_exits) - res \ No newline at end of file + res diff --git a/beacon_chain/consensus_object_pools/spec_cache.nim b/beacon_chain/consensus_object_pools/spec_cache.nim index 2585bb2b9..fc97b58b8 100644 --- a/beacon_chain/consensus_object_pools/spec_cache.nim +++ b/beacon_chain/consensus_object_pools/spec_cache.nim @@ -8,7 +8,7 @@ {.push raises: [Defect].} import - std/[intsets], + std/sequtils, chronicles, ../extras, ../spec/[helpers, network, signatures, validator], @@ -173,9 +173,8 @@ func makeAttestationData*( # https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#validator-assignments iterator get_committee_assignments*( - epochRef: EpochRef, validator_indices: IntSet): - tuple[validatorIndices: IntSet, - committeeIndex: CommitteeIndex, + epochRef: EpochRef, validator_indices: HashSet[ValidatorIndex]): + tuple[committeeIndex: CommitteeIndex, subnet_id: SubnetId, slot: Slot] = let committees_per_slot = get_committee_count_per_slot(epochRef) @@ -186,12 +185,10 @@ iterator get_committee_assignments*( for index in 0'u64 ..< committees_per_slot: let idx = index.CommitteeIndex - includedIndices = - toIntSet(get_beacon_committee(epochRef, slot, idx)) * - validator_indices - if includedIndices.len > 0: + if anyIt( + get_beacon_committee(epochRef, slot, idx), it in validator_indices): yield ( - includedIndices, idx, + idx, compute_subnet_for_attestation(committees_per_slot, slot, idx), slot) diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index 9b42bdb4b..abdf2d062 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -8,8 +8,6 @@ {.push raises: [Defect].} import - # Standard library - std/[intsets], # Status chronicles, chronos, metrics, stew/results, @@ -669,7 +667,7 @@ proc validateAttesterSlashing*( attestation_2_indices = attester_slashing.attestation_2.attesting_indices.asSeq attester_slashed_indices = - toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices) + toHashSet(attestation_1_indices) * toHashSet(attestation_2_indices) if not disjoint( attester_slashed_indices, pool.prior_seen_attester_slashed_indices): @@ -699,7 +697,7 @@ proc validateProposerSlashing*( # [IGNORE] The proposer slashing is the first valid proposer slashing # received for the proposer with index # proposer_slashing.signed_header_1.message.proposer_index. - if proposer_slashing.signed_header_1.message.proposer_index.int in + if proposer_slashing.signed_header_1.message.proposer_index in pool.prior_seen_proposer_slashed_indices: return errIgnore( "ProposerSlashing: proposer-slashed index already proposer-slashed") @@ -711,7 +709,7 @@ proc validateProposerSlashing*( return err((ValidationResult.Reject, proposer_slashing_validity.error)) pool.prior_seen_proposer_slashed_indices.incl( - proposer_slashing.signed_header_1.message.proposer_index.int) + proposer_slashing.signed_header_1.message.proposer_index) pool.proposer_slashings.addExitMessage( proposer_slashing, PROPOSER_SLASHINGS_BOUND) ok(true) @@ -729,7 +727,7 @@ proc validateVoluntaryExit*( # Given that getStateField(pool.dag.headState, validators) is a seq, # signed_voluntary_exit.message.validator_index.int is already valid, but # check explicitly if one changes that data structure. - if signed_voluntary_exit.message.validator_index.int in + if signed_voluntary_exit.message.validator_index in pool.prior_seen_voluntary_exit_indices: return errIgnore("VoluntaryExit: validator index already voluntarily exited") @@ -742,7 +740,7 @@ proc validateVoluntaryExit*( return err((ValidationResult.Reject, voluntary_exit_validity.error)) pool.prior_seen_voluntary_exit_indices.incl( - signed_voluntary_exit.message.validator_index.int) + signed_voluntary_exit.message.validator_index) pool.voluntary_exits.addExitMessage( signed_voluntary_exit, VOLUNTARY_EXITS_BOUND) diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index 2b4d309a0..c175dc973 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -24,9 +24,6 @@ {.push raises: [Defect].} -# std/[intsets, json, strutils, tables], -# stew/byteutils, - import std/[macros, typetraits, sets, hashes], chronicles, diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index 7676be990..a08942400 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -31,7 +31,7 @@ export json_serialization import - std/[macros, hashes, intsets, strutils, tables, typetraits], + std/[macros, hashes, strutils, tables, typetraits], stew/[assign2, byteutils], chronicles, chronos/timer, @@ -694,15 +694,6 @@ template `==`*(x: uint64, y: ValidatorIndex): bool = template `==`*(x: ValidatorIndex, y: uint64): bool = uint64(x) == y -# TODO Nim 1.4, but not Nim 1.2, defines a function by this name, which works -# only on openArray[int]. They do the same thing, so either's fine, when both -# overloads match. The Nim 1.4 stdlib doesn't int-convert but it's a no-op in -# its case regardless. -func toIntSet*[T](x: openArray[T]): IntSet = - result = initIntSet() - for item in items(x): - result.incl(item.int) - template `==`*(x, y: CommitteeIndex): bool = distinctBase(x) == distinctBase(y) diff --git a/beacon_chain/spec/datatypes/phase0.nim b/beacon_chain/spec/datatypes/phase0.nim index df50440b5..0e6b43179 100644 --- a/beacon_chain/spec/datatypes/phase0.nim +++ b/beacon_chain/spec/datatypes/phase0.nim @@ -28,7 +28,7 @@ import ./base export base import - std/[macros, intsets, json, strutils, tables], + std/[macros, json, strutils, tables], stew/[assign2, byteutils], chronicles, json_serialization/types as jsonTypes diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index abddc90e1..f58d156b8 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -20,7 +20,7 @@ {.push raises: [Defect].} import - std/[algorithm, intsets, options, sequtils, sets, tables], + std/[algorithm, options, sequtils, sets, tables], chronicles, metrics, ../extras, ./datatypes/[phase0, altair, merge], @@ -213,9 +213,10 @@ proc check_attester_slashing*( var slashed_indices: seq[ValidatorIndex] - for index in sorted(toSeq(intersection( - toIntSet(attestation_1.attesting_indices.asSeq), - toIntSet(attestation_2.attesting_indices.asSeq)).items), system.cmp): + let attesting_indices_2 = toHashSet(attestation_2.attesting_indices.asSeq) + for index in sorted(filterIt( + attestation_1.attesting_indices.asSeq, it in attesting_indices_2), + system.cmp): if is_slashable_validator( state.validators.asSeq()[index], get_current_epoch(state)): slashed_indices.add index.ValidatorIndex diff --git a/beacon_chain/validators/action_tracker.nim b/beacon_chain/validators/action_tracker.nim index fbf8d0809..bf978dfc8 100644 --- a/beacon_chain/validators/action_tracker.nim +++ b/beacon_chain/validators/action_tracker.nim @@ -1,5 +1,5 @@ import - std/[sequtils, intsets, sets, tables], + std/[sequtils, sets, tables], chronicles, bearssl, eth/p2p/discoveryv5/random2, @@ -167,14 +167,12 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) = return tracker.lastCalculatedEpoch = epoch - let - validatorIndices = toIntSet(toSeq(tracker.knownValidators.keys())) + let validatorIndices = toHashSet(toSeq(tracker.knownValidators.keys())) # Update proposals tracker.proposingSlots[epoch mod 2] = 0 for i, proposer in epochRef.beacon_proposers: - # TODO unsafe int conversion - if proposer.isSome and proposer.get().int in validatorIndices: + if proposer.isSome and proposer.get() in validatorIndices: tracker.proposingSlots[epoch mod 2] = tracker.proposingSlots[epoch mod 2] or (1'u32 shl i) @@ -183,7 +181,7 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) = # The relevant bitmaps are 32 bits each. static: doAssert SLOTS_PER_EPOCH <= 32 - for (validatorIndices, committeeIndex, subnet_id, slot) in + for (committeeIndex, subnet_id, slot) in get_committee_assignments(epochRef, validatorIndices): doAssert compute_epoch_at_slot(slot) == epoch diff --git a/tests/consensus_spec/altair/test_fixture_operations.nim b/tests/consensus_spec/altair/test_fixture_operations.nim index 277baece9..ddea54f5a 100644 --- a/tests/consensus_spec/altair/test_fixture_operations.nim +++ b/tests/consensus_spec/altair/test_fixture_operations.nim @@ -9,7 +9,7 @@ import # Standard library - os, sequtils, sets, + std/[os, sequtils, sets], # Utilities chronicles, unittest2, diff --git a/tests/consensus_spec/altair/test_fixture_ssz_consensus_objects.nim b/tests/consensus_spec/altair/test_fixture_ssz_consensus_objects.nim index f71177eac..38fadfa24 100644 --- a/tests/consensus_spec/altair/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/altair/test_fixture_ssz_consensus_objects.nim @@ -36,13 +36,6 @@ type # Some have a signing_root field signing_root {.defaultVal: "".}: string - # https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/validator.md#eth1block - Eth1Block = object - timestamp: uint64 - deposit_root: Eth2Digest - deposit_count: uint64 - # All other eth1 block fields - # Note this only tracks HashTreeRoot # Checking the values against the yaml file is TODO (require more flexible Yaml parser) diff --git a/tests/consensus_spec/fixtures_utils.nim b/tests/consensus_spec/fixtures_utils.nim index 092c74e57..68ca3d509 100644 --- a/tests/consensus_spec/fixtures_utils.nim +++ b/tests/consensus_spec/fixtures_utils.nim @@ -40,6 +40,13 @@ type rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT] penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT] + # https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/phase0/validator.md#eth1block + Eth1Block* = object + timestamp*: uint64 + deposit_root*: Eth2Digest + deposit_count*: uint64 + # All other eth1 block fields + const FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios" diff --git a/tests/consensus_spec/merge/all_merge_fixtures.nim b/tests/consensus_spec/merge/all_merge_fixtures.nim index 5e8e87804..8e54df624 100644 --- a/tests/consensus_spec/merge/all_merge_fixtures.nim +++ b/tests/consensus_spec/merge/all_merge_fixtures.nim @@ -9,7 +9,6 @@ import ./test_fixture_operations, - ./test_fixture_operations_execution_payload, ./test_fixture_sanity_blocks, ./test_fixture_sanity_slots, ./test_fixture_ssz_consensus_objects, diff --git a/tests/consensus_spec/merge/test_fixture_operations.nim b/tests/consensus_spec/merge/test_fixture_operations.nim index ebf6de40e..558a463c9 100644 --- a/tests/consensus_spec/merge/test_fixture_operations.nim +++ b/tests/consensus_spec/merge/test_fixture_operations.nim @@ -9,7 +9,7 @@ import # Standard library - os, + std/[os, sequtils, sets, strutils], # Utilities chronicles, unittest2, @@ -28,12 +28,18 @@ const OpAttSlashingDir = OpDir/"attester_slashing" OpBlockHeaderDir = OpDir/"block_header" OpDepositsDir = OpDir/"deposit" + OpExecutionPayloadDir = OpDir/"execution_payload" OpProposerSlashingDir = OpDir/"proposer_slashing" OpSyncAggregateDir = OpDir/"sync_aggregate" OpVoluntaryExitDir = OpDir/"voluntary_exit" baseDescription = "Ethereum Foundation - Merge - Operations - " +doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) == + toHashSet([OpAttestationsDir, OpAttSlashingDir, OpBlockHeaderDir, + OpDepositsDir, OpExecutionPayloadDir, OpProposerSlashingDir, + OpSyncAggregateDir, OpVoluntaryExitDir]) + proc runTest[T, U]( testSuiteDir: string, testSuiteName: string, applyFile: string, applyProc: U, identifier: string) = @@ -116,6 +122,22 @@ suite baseDescription & "Deposit " & preset(): runTest[Deposit, typeof applyDeposit]( OpDepositsDir, "Deposit", "deposit", applyDeposit, path) +suite baseDescription & "Execution Payload " & preset(): + for path in walkTests(OpExecutionPayloadDir): + proc applyExecutionPayload( + preState: var merge.BeaconState, executionPayload: ExecutionPayload): + Result[void, cstring] = + let payloadValid = + readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"). + contains("execution_valid: true") + func executePayload(_: ExecutionPayload): bool = payloadValid + process_execution_payload( + preState, executionPayload, executePayload) + + runTest[ExecutionPayload, typeof applyExecutionPayload]( + OpExecutionPayloadDir, "Execution Payload", "execution_payload", + applyExecutionPayload, path) + suite baseDescription & "Proposer Slashing " & preset(): proc applyProposerSlashing( preState: var merge.BeaconState, proposerSlashing: ProposerSlashing): diff --git a/tests/consensus_spec/merge/test_fixture_operations_execution_payload.nim b/tests/consensus_spec/merge/test_fixture_operations_execution_payload.nim deleted file mode 100644 index 315ede86d..000000000 --- a/tests/consensus_spec/merge/test_fixture_operations_execution_payload.nim +++ /dev/null @@ -1,68 +0,0 @@ -# beacon_chain -# Copyright (c) 2018-2021 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). -# at your option. This file may not be copied, modified, or distributed except according to those terms. - -{.used.} - -import - # Standard library - std/os, std/strutils, - # Utilities - stew/results, - # Beacon chain internals - ../../../beacon_chain/spec/state_transition_block, - ../../../beacon_chain/spec/datatypes/merge, - # Test utilities - ../../testutil, - ../fixtures_utils, - ../../helpers/debug_state - -const OpExecutionPayloadDir = SszTestsDir/const_preset/"merge"/"operations"/"execution_payload"/"pyspec_tests" - -proc runTest(identifier: string) = - let testDir = OpExecutionPayloadDir / identifier - - proc `testImpl _ voluntary_exit _ identifier`() = - - let - prefix = - if existsFile(testDir/"post.ssz_snappy"): - "[Valid] " - else: - "[Invalid] " - payloadValid = readFile( - testDir/"execution.yaml").contains("execution_valid: true") - - func executePayload(_: ExecutionPayload): bool = payloadValid - - test prefix & identifier: - var - preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, merge.BeaconState)) - - let - executionPayload = parseTest( - testDir/"execution_payload.ssz_snappy", SSZ, ExecutionPayload) - done = process_execution_payload( - preState[], executionPayload, executePayload) - - if existsFile(testDir/"post.ssz_snappy"): - let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, merge.BeaconState)) - - check: - done.isOk() - preState[].hash_tree_root() == postState[].hash_tree_root() - reportDiff(preState, postState) - else: - check: done.isErr() # No post state = processing should fail - - `testImpl _ voluntary_exit _ identifier`() - -suite "Ethereum Foundation - Merge - Operations - Execution Payload " & preset(): - for kind, path in walkDir( - OpExecutionPayloadDir, relative = true, checkDir = true): - runTest(path) diff --git a/tests/consensus_spec/merge/test_fixture_ssz_consensus_objects.nim b/tests/consensus_spec/merge/test_fixture_ssz_consensus_objects.nim index 6ab55e898..4602fd37b 100644 --- a/tests/consensus_spec/merge/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/merge/test_fixture_ssz_consensus_objects.nim @@ -36,13 +36,6 @@ type # Some have a signing_root field signing_root {.defaultVal: "".}: string - # https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.3/specs/phase0/validator.md#eth1block - Eth1Block = object - timestamp: uint64 - deposit_root: Eth2Digest - deposit_count: uint64 - # All other eth1 block fields - # Note this only tracks HashTreeRoot # Checking the values against the yaml file is TODO (require more flexible Yaml parser) diff --git a/tests/consensus_spec/phase0/test_fixture_operations.nim b/tests/consensus_spec/phase0/test_fixture_operations.nim index 1febfc0a1..0b4bce269 100644 --- a/tests/consensus_spec/phase0/test_fixture_operations.nim +++ b/tests/consensus_spec/phase0/test_fixture_operations.nim @@ -9,7 +9,7 @@ import # Standard library - os, sequtils, sets, + std/[os, sequtils, sets], # Utilities chronicles, unittest2, diff --git a/tests/consensus_spec/phase0/test_fixture_ssz_consensus_objects.nim b/tests/consensus_spec/phase0/test_fixture_ssz_consensus_objects.nim index 342779631..63d8488b8 100644 --- a/tests/consensus_spec/phase0/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/phase0/test_fixture_ssz_consensus_objects.nim @@ -36,13 +36,6 @@ type # Some have a signing_root field signing_root {.defaultVal: "".}: string - # https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#eth1block - Eth1Block = object - timestamp: uint64 - deposit_root: Eth2Digest - deposit_count: uint64 - # All other eth1 block fields - # Note this only tracks HashTreeRoot # Checking the values against the yaml file is TODO (require more flexible Yaml parser) diff --git a/tests/mocking/mock_attestations.nim b/tests/mocking/mock_attestations.nim index 5d975e675..2170b63af 100644 --- a/tests/mocking/mock_attestations.nim +++ b/tests/mocking/mock_attestations.nim @@ -9,8 +9,6 @@ # --------------------------------------------------------------- import - # Standard library - intsets, # Status chronicles, # Specs