From 95775e1b904b1f97d19ec69669bd6ddc1114aef4 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 11 Jun 2021 16:05:19 +0600 Subject: [PATCH 1/7] Add randao to execution payload --- specs/merge/beacon-chain.md | 10 +++- specs/merge/validator.md | 25 ++++++--- .../pyspec/eth2spec/test/helpers/block.py | 11 +++- .../test/helpers/execution_payload.py | 7 +-- .../test_process_execution_payload.py | 51 +++++++++---------- 5 files changed, 66 insertions(+), 38 deletions(-) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 697bd0c96b..c19a406f05 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -105,6 +105,7 @@ class ExecutionPayload(Container): timestamp: uint64 receipt_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] + randao: Bytes32 # 'difficulty' in the yellow paper transactions: List[OpaqueTransaction, MAX_EXECUTION_TRANSACTIONS] ``` @@ -126,6 +127,7 @@ class ExecutionPayloadHeader(Container): timestamp: uint64 receipt_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] + randao: Bytes32 transactions_root: Root ``` @@ -198,7 +200,9 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: process_operations(state, block.body) # Pre-merge, skip execution payload processing if is_execution_enabled(state, block): - process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) # [New in Merge] + # [New in Merge] + randao_mix = get_randao_mix(state, get_current_epoch(state)) + process_execution_payload(state, block.body.execution_payload, randao_mix, EXECUTION_ENGINE) ``` #### Execution payload processing @@ -208,6 +212,7 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: ```python def process_execution_payload(state: BeaconState, execution_payload: ExecutionPayload, + randao_mix: Bytes32, execution_engine: ExecutionEngine) -> None: """ Note: This function is designed to be able to be run in parallel with the other `process_block` sub-functions @@ -215,6 +220,7 @@ def process_execution_payload(state: BeaconState, if is_transition_completed(state): assert execution_payload.parent_hash == state.latest_execution_payload_header.block_hash assert execution_payload.number == state.latest_execution_payload_header.number + 1 + assert execution_payload.randao == randao_mix assert execution_payload.timestamp == compute_time_at_slot(state, state.slot) @@ -231,6 +237,7 @@ def process_execution_payload(state: BeaconState, timestamp=execution_payload.timestamp, receipt_root=execution_payload.receipt_root, logs_bloom=execution_payload.logs_bloom, + randao=execution_payload.randao, transactions_root=hash_tree_root(execution_payload.transactions), ) ``` @@ -289,6 +296,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, timestamp=eth1_timestamp, receipt_root=Bytes32(), logs_bloom=ByteVector[BYTES_PER_LOGS_BLOOM](), + randao=eth1_block_hash, transactions_root=Root(), ) diff --git a/specs/merge/validator.md b/specs/merge/validator.md index c5a7a4c789..6b86aae75e 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -49,7 +49,7 @@ The body of this function is implementation dependent. The Consensus API may be used to implement this with an external execution engine. ```python -def assemble_block(self: ExecutionEngine, block_hash: Hash32, timestamp: uint64) -> ExecutionPayload: +def assemble_block(self: ExecutionEngine, block_hash: Hash32, timestamp: uint64, randao: Bytes32) -> ExecutionPayload: ... ``` @@ -70,8 +70,23 @@ Let `get_pow_chain_head() -> PowBlock` be the function that returns the head of * Set `block.body.execution_payload = get_execution_payload(state, transition_store, execution_engine)` where: ```python +def compute_randao_mix(state: BeaconState, randao_reveal: BLSSignature) -> Bytes32: + epoch = get_current_epoch(state) + return xor(get_randao_mix(state, epoch), hash(randao_reveal)) + + +def produce_execution_payload(state: BeaconState, + parent_hash: Hash32, + randao_reveal: BLSSignature, + execution_engine: ExecutionEngine) -> ExecutionPayload: + timestamp = compute_time_at_slot(state, state.slot) + randao = compute_randao_mix(state, randao_reveal) + return execution_engine.assemble_block(parent_hash, timestamp, randao) + + def get_execution_payload(state: BeaconState, transition_store: TransitionStore, + randao_reveal: BLSSignature, execution_engine: ExecutionEngine) -> ExecutionPayload: if not is_transition_completed(state): pow_block = get_pow_chain_head() @@ -80,11 +95,9 @@ def get_execution_payload(state: BeaconState, return ExecutionPayload() else: # Signify merge via producing on top of the last PoW block - timestamp = compute_time_at_slot(state, state.slot) - return execution_engine.assemble_block(pow_block.block_hash, timestamp) + return produce_execution_payload(state, pow_block.block_hash, timestamp, randao_reveal) # Post-merge, normal payload - execution_parent_hash = state.latest_execution_payload_header.block_hash - timestamp = compute_time_at_slot(state, state.slot) - return execution_engine.assemble_block(execution_parent_hash, timestamp) + parent_hash = state.latest_execution_payload_header.block_hash + return produce_execution_payload(state, parent_hash, timestamp, randao_reveal) ``` diff --git a/tests/core/pyspec/eth2spec/test/helpers/block.py b/tests/core/pyspec/eth2spec/test/helpers/block.py index 0dd9dc98e9..3781f0d503 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/block.py +++ b/tests/core/pyspec/eth2spec/test/helpers/block.py @@ -35,6 +35,11 @@ def apply_randao_reveal(spec, state, block, proposer_index=None): block.body.randao_reveal = bls.Sign(privkey, signing_root) +def compute_randao_mix(spec, state, randao_reveal): + epoch = spec.get_current_epoch(state) + return spec.xor(spec.get_randao_mix(state, epoch), spec.hash(randao_reveal)) + + # Fully ignore the function if BLS is off, beacon-proposer index calculation is slow. @only_with_bls() def apply_sig(spec, state, signed_block, proposer_index=None): @@ -93,13 +98,15 @@ def build_empty_block(spec, state, slot=None): empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index empty_block.parent_root = parent_block_root + apply_randao_reveal(spec, state, empty_block) + if is_post_altair(spec): empty_block.body.sync_aggregate.sync_committee_signature = spec.G2_POINT_AT_INFINITY if is_post_merge(spec): - empty_block.body.execution_payload = build_empty_execution_payload(spec, state) + randao_mix = compute_randao_mix(spec, state, empty_block.body.randao_reveal) + empty_block.body.execution_payload = build_empty_execution_payload(spec, state, randao_mix) - apply_randao_reveal(spec, state, empty_block) return empty_block diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 7774aa4d9f..661abe964e 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,4 +1,4 @@ -def build_empty_execution_payload(spec, state): +def build_empty_execution_payload(spec, state, randao_mix): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. """ @@ -17,6 +17,7 @@ def build_empty_execution_payload(spec, state): timestamp=timestamp, receipt_root=b"no receipts here" + b"\x00" * 16, # TODO: root of empty MPT may be better. logs_bloom=spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](), # TODO: zeroed logs bloom for empty logs ok? + randao=randao_mix, transactions=empty_txs, ) # TODO: real RLP + block hash logic would be nice, requires RLP and keccak256 dependency however. @@ -24,7 +25,6 @@ def build_empty_execution_payload(spec, state): return payload - def get_execution_payload_header(spec, execution_payload): return spec.ExecutionPayloadHeader( block_hash=execution_payload.block_hash, @@ -37,6 +37,7 @@ def get_execution_payload_header(spec, execution_payload): timestamp=execution_payload.timestamp, receipt_root=execution_payload.receipt_root, logs_bloom=execution_payload.logs_bloom, + randao=execution_payload.randao, transactions_root=spec.hash_tree_root(execution_payload.transactions) ) @@ -46,7 +47,7 @@ def build_state_with_incomplete_transition(spec, state): def build_state_with_complete_transition(spec, state): - pre_state_payload = build_empty_execution_payload(spec, state) + pre_state_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) payload_header = get_execution_payload_header(spec, pre_state_payload) return build_state_with_execution_payload_header(spec, state, payload_header) diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index 5edd319603..04fb0df302 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -7,8 +7,7 @@ from eth2spec.test.context import spec_state_test, expect_assertion_error, with_merge_and_later from eth2spec.test.helpers.state import next_slot - -def run_execution_payload_processing(spec, state, execution_payload, valid=True, execution_valid=True): +def run_execution_payload_processing(spec, state, execution_payload, randao_mix, valid=True, execution_valid=True): """ Run ``process_execution_payload``, yielding: - pre-state ('pre') @@ -32,11 +31,11 @@ def new_block(self, payload) -> bool: return execution_valid if not valid: - expect_assertion_error(lambda: spec.process_execution_payload(state, execution_payload, TestEngine())) + expect_assertion_error(lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) yield 'post', None return - spec.process_execution_payload(state, execution_payload, TestEngine()) + spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine()) # Make sure we called the engine assert called_new_block @@ -54,9 +53,9 @@ def test_success_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) @with_merge_and_later @@ -67,9 +66,9 @@ def test_success_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) @with_merge_and_later @@ -81,9 +80,9 @@ def test_success_first_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) @with_merge_and_later @@ -95,9 +94,9 @@ def test_success_regular_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) @with_merge_and_later @@ -110,9 +109,9 @@ def test_bad_execution_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) @with_merge_and_later @@ -125,9 +124,9 @@ def test_bad_execution_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) @with_merge_and_later @@ -138,10 +137,10 @@ def test_bad_parent_hash_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) execution_payload.parent_hash = spec.Hash32() - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) @with_merge_and_later @@ -152,10 +151,10 @@ def test_bad_number_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) @with_merge_and_later @@ -166,11 +165,11 @@ def test_bad_everything_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) execution_payload.parent_hash = spec.Hash32() execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) @with_merge_and_later @@ -181,10 +180,10 @@ def test_bad_timestamp_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) @with_merge_and_later @@ -195,7 +194,7 @@ def test_bad_timestamp_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state) + execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) From 7d617bc7c0351ce581726c6ea5a5dcc9ea0e9936 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 11 Jun 2021 22:46:24 +0600 Subject: [PATCH 2/7] Fix timestamp passed to produce_execution_payload --- specs/merge/validator.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/merge/validator.md b/specs/merge/validator.md index 6b86aae75e..d196d8fae4 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -95,9 +95,9 @@ def get_execution_payload(state: BeaconState, return ExecutionPayload() else: # Signify merge via producing on top of the last PoW block - return produce_execution_payload(state, pow_block.block_hash, timestamp, randao_reveal) + return produce_execution_payload(state, pow_block.block_hash, randao_reveal) # Post-merge, normal payload parent_hash = state.latest_execution_payload_header.block_hash - return produce_execution_payload(state, parent_hash, timestamp, randao_reveal) + return produce_execution_payload(state, parent_hash, randao_reveal) ``` From 2e87a6b44e71a0f399c1aaf8fd4c94cea44adea9 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 11 Jun 2021 22:50:11 +0600 Subject: [PATCH 3/7] Apply review comments --- specs/merge/beacon-chain.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index c19a406f05..2265844e62 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -198,9 +198,8 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: process_randao(state, block.body) process_eth1_data(state, block.body) process_operations(state, block.body) - # Pre-merge, skip execution payload processing + # [New in Merge] Pre-merge, skip execution payload processing if is_execution_enabled(state, block): - # [New in Merge] randao_mix = get_randao_mix(state, get_current_epoch(state)) process_execution_payload(state, block.body.execution_payload, randao_mix, EXECUTION_ENGINE) ``` @@ -252,6 +251,7 @@ This helper function is only for initializing the state for pure Merge testnets def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, eth1_timestamp: uint64, deposits: Sequence[Deposit]) -> BeaconState: + randao_seed = eth1_block_hash fork = Fork( previous_version=GENESIS_FORK_VERSION, current_version=MERGE_FORK_VERSION, # [Modified in Merge] @@ -262,7 +262,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, fork=fork, eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy + randao_mixes=[randao_seed] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy ) # Process deposits @@ -296,7 +296,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, timestamp=eth1_timestamp, receipt_root=Bytes32(), logs_bloom=ByteVector[BYTES_PER_LOGS_BLOOM](), - randao=eth1_block_hash, + randao=randao_seed, transactions_root=Root(), ) From cc20b80103c8d55c05cb624e28b631eb852d9644 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 15 Jun 2021 14:55:06 +0600 Subject: [PATCH 4/7] Fix linter, add more test helpers --- setup.py | 2 +- specs/merge/validator.md | 4 +- .../test/helpers/execution_payload.py | 5 ++ .../test_process_execution_payload.py | 53 ++++++++++--------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/setup.py b/setup.py index 9ecf8261fd..24ac6dd0c4 100644 --- a/setup.py +++ b/setup.py @@ -532,7 +532,7 @@ def set_head(self, block_hash: Hash32) -> bool: def finalize_block(self, block_hash: Hash32) -> bool: return True - def assemble_block(self, block_hash: Hash32, timestamp: uint64) -> ExecutionPayload: + def assemble_block(self, block_hash: Hash32, timestamp: uint64, randao: Bytes32) -> ExecutionPayload: raise NotImplementedError("no default block production") diff --git a/specs/merge/validator.md b/specs/merge/validator.md index d196d8fae4..adbf63e843 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -95,9 +95,9 @@ def get_execution_payload(state: BeaconState, return ExecutionPayload() else: # Signify merge via producing on top of the last PoW block - return produce_execution_payload(state, pow_block.block_hash, randao_reveal) + return produce_execution_payload(state, pow_block.block_hash, randao_reveal, execution_engine) # Post-merge, normal payload parent_hash = state.latest_execution_payload_header.block_hash - return produce_execution_payload(state, parent_hash, randao_reveal) + return produce_execution_payload(state, parent_hash, randao_reveal, execution_engine) ``` diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 661abe964e..a84494e74b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,3 +1,7 @@ +def build_empty_execution_payload_with_randao(spec, state): + return build_empty_execution_payload(spec, state, spec.Bytes32()) + + def build_empty_execution_payload(spec, state, randao_mix): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. @@ -25,6 +29,7 @@ def build_empty_execution_payload(spec, state, randao_mix): return payload + def get_execution_payload_header(spec, execution_payload): return spec.ExecutionPayloadHeader( block_hash=execution_payload.block_hash, diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index 04fb0df302..d5e3a796ef 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -1,5 +1,5 @@ from eth2spec.test.helpers.execution_payload import ( - build_empty_execution_payload, + build_empty_execution_payload_with_randao, get_execution_payload_header, build_state_with_incomplete_transition, build_state_with_complete_transition, @@ -7,7 +7,8 @@ from eth2spec.test.context import spec_state_test, expect_assertion_error, with_merge_and_later from eth2spec.test.helpers.state import next_slot -def run_execution_payload_processing(spec, state, execution_payload, randao_mix, valid=True, execution_valid=True): + +def run_execution_payload_processing(spec, state, execution_payload, valid=True, execution_valid=True): """ Run ``process_execution_payload``, yielding: - pre-state ('pre') @@ -21,6 +22,7 @@ def run_execution_payload_processing(spec, state, execution_payload, randao_mix, yield 'execution', {'execution_valid': execution_valid} yield 'execution_payload', execution_payload + randao_mix = spec.Bytes32() called_new_block = False class TestEngine(spec.NoopExecutionEngine): @@ -31,7 +33,8 @@ def new_block(self, payload) -> bool: return execution_valid if not valid: - expect_assertion_error(lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) + expect_assertion_error( + lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) yield 'post', None return @@ -53,9 +56,9 @@ def test_success_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -66,9 +69,9 @@ def test_success_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -80,9 +83,9 @@ def test_success_first_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -94,9 +97,9 @@ def test_success_regular_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -109,9 +112,9 @@ def test_bad_execution_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @with_merge_and_later @@ -124,9 +127,9 @@ def test_bad_execution_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @with_merge_and_later @@ -137,10 +140,10 @@ def test_bad_parent_hash_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.parent_hash = spec.Hash32() - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -151,10 +154,10 @@ def test_bad_number_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -165,11 +168,11 @@ def test_bad_everything_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.parent_hash = spec.Hash32() execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -180,10 +183,10 @@ def test_bad_timestamp_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -194,7 +197,7 @@ def test_bad_timestamp_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) From 6e86d8a6968ab705ec95e16fc43e7dc20ec6edbb Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 17 Jun 2021 21:20:17 +0600 Subject: [PATCH 5/7] Rename randao->random, other fixes as per review --- setup.py | 2 +- specs/merge/beacon-chain.md | 10 ++++---- specs/merge/validator.md | 6 ++--- .../pyspec/eth2spec/test/helpers/block.py | 7 +----- .../test/helpers/execution_payload.py | 8 +++---- .../test_process_execution_payload.py | 24 +++++++++---------- 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/setup.py b/setup.py index 24ac6dd0c4..2abd363bf9 100644 --- a/setup.py +++ b/setup.py @@ -532,7 +532,7 @@ def set_head(self, block_hash: Hash32) -> bool: def finalize_block(self, block_hash: Hash32) -> bool: return True - def assemble_block(self, block_hash: Hash32, timestamp: uint64, randao: Bytes32) -> ExecutionPayload: + def assemble_block(self, block_hash: Hash32, timestamp: uint64, random: Bytes32) -> ExecutionPayload: raise NotImplementedError("no default block production") diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 2265844e62..b1bbb57e6e 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -105,7 +105,7 @@ class ExecutionPayload(Container): timestamp: uint64 receipt_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] - randao: Bytes32 # 'difficulty' in the yellow paper + random: Bytes32 # 'difficulty' in the yellow paper transactions: List[OpaqueTransaction, MAX_EXECUTION_TRANSACTIONS] ``` @@ -127,7 +127,7 @@ class ExecutionPayloadHeader(Container): timestamp: uint64 receipt_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] - randao: Bytes32 + random: Bytes32 transactions_root: Root ``` @@ -219,7 +219,7 @@ def process_execution_payload(state: BeaconState, if is_transition_completed(state): assert execution_payload.parent_hash == state.latest_execution_payload_header.block_hash assert execution_payload.number == state.latest_execution_payload_header.number + 1 - assert execution_payload.randao == randao_mix + assert execution_payload.random == randao_mix assert execution_payload.timestamp == compute_time_at_slot(state, state.slot) @@ -236,7 +236,7 @@ def process_execution_payload(state: BeaconState, timestamp=execution_payload.timestamp, receipt_root=execution_payload.receipt_root, logs_bloom=execution_payload.logs_bloom, - randao=execution_payload.randao, + random=execution_payload.random, transactions_root=hash_tree_root(execution_payload.transactions), ) ``` @@ -296,7 +296,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, timestamp=eth1_timestamp, receipt_root=Bytes32(), logs_bloom=ByteVector[BYTES_PER_LOGS_BLOOM](), - randao=randao_seed, + random=randao_seed, transactions_root=Root(), ) diff --git a/specs/merge/validator.md b/specs/merge/validator.md index adbf63e843..7910132e61 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -49,7 +49,7 @@ The body of this function is implementation dependent. The Consensus API may be used to implement this with an external execution engine. ```python -def assemble_block(self: ExecutionEngine, block_hash: Hash32, timestamp: uint64, randao: Bytes32) -> ExecutionPayload: +def assemble_block(self: ExecutionEngine, block_hash: Hash32, timestamp: uint64, random: Bytes32) -> ExecutionPayload: ... ``` @@ -80,8 +80,8 @@ def produce_execution_payload(state: BeaconState, randao_reveal: BLSSignature, execution_engine: ExecutionEngine) -> ExecutionPayload: timestamp = compute_time_at_slot(state, state.slot) - randao = compute_randao_mix(state, randao_reveal) - return execution_engine.assemble_block(parent_hash, timestamp, randao) + randao_mix = compute_randao_mix(state, randao_reveal) + return execution_engine.assemble_block(parent_hash, timestamp, randao_mix) def get_execution_payload(state: BeaconState, diff --git a/tests/core/pyspec/eth2spec/test/helpers/block.py b/tests/core/pyspec/eth2spec/test/helpers/block.py index 3781f0d503..b8f7c4bcb3 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/block.py +++ b/tests/core/pyspec/eth2spec/test/helpers/block.py @@ -35,11 +35,6 @@ def apply_randao_reveal(spec, state, block, proposer_index=None): block.body.randao_reveal = bls.Sign(privkey, signing_root) -def compute_randao_mix(spec, state, randao_reveal): - epoch = spec.get_current_epoch(state) - return spec.xor(spec.get_randao_mix(state, epoch), spec.hash(randao_reveal)) - - # Fully ignore the function if BLS is off, beacon-proposer index calculation is slow. @only_with_bls() def apply_sig(spec, state, signed_block, proposer_index=None): @@ -104,7 +99,7 @@ def build_empty_block(spec, state, slot=None): empty_block.body.sync_aggregate.sync_committee_signature = spec.G2_POINT_AT_INFINITY if is_post_merge(spec): - randao_mix = compute_randao_mix(spec, state, empty_block.body.randao_reveal) + randao_mix = spec.compute_randao_mix(state, empty_block.body.randao_reveal) empty_block.body.execution_payload = build_empty_execution_payload(spec, state, randao_mix) return empty_block diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index a84494e74b..d14bdfa888 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,8 +1,8 @@ -def build_empty_execution_payload_with_randao(spec, state): +def build_empty_execution_payload_with_zeroed_random(spec, state): return build_empty_execution_payload(spec, state, spec.Bytes32()) -def build_empty_execution_payload(spec, state, randao_mix): +def build_empty_execution_payload(spec, state, random): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. """ @@ -21,7 +21,7 @@ def build_empty_execution_payload(spec, state, randao_mix): timestamp=timestamp, receipt_root=b"no receipts here" + b"\x00" * 16, # TODO: root of empty MPT may be better. logs_bloom=spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](), # TODO: zeroed logs bloom for empty logs ok? - randao=randao_mix, + random=random, transactions=empty_txs, ) # TODO: real RLP + block hash logic would be nice, requires RLP and keccak256 dependency however. @@ -42,7 +42,7 @@ def get_execution_payload_header(spec, execution_payload): timestamp=execution_payload.timestamp, receipt_root=execution_payload.receipt_root, logs_bloom=execution_payload.logs_bloom, - randao=execution_payload.randao, + random=execution_payload.random, transactions_root=spec.hash_tree_root(execution_payload.transactions) ) diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index d5e3a796ef..e2a2bf6638 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -1,5 +1,5 @@ from eth2spec.test.helpers.execution_payload import ( - build_empty_execution_payload_with_randao, + build_empty_execution_payload_with_zeroed_random, get_execution_payload_header, build_state_with_incomplete_transition, build_state_with_complete_transition, @@ -56,7 +56,7 @@ def test_success_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -69,7 +69,7 @@ def test_success_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -83,7 +83,7 @@ def test_success_first_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -97,7 +97,7 @@ def test_success_regular_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -112,7 +112,7 @@ def test_bad_execution_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @@ -127,7 +127,7 @@ def test_bad_execution_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @@ -140,7 +140,7 @@ def test_bad_parent_hash_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) execution_payload.parent_hash = spec.Hash32() yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -154,7 +154,7 @@ def test_bad_number_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) execution_payload.number = execution_payload.number + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -168,7 +168,7 @@ def test_bad_everything_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) execution_payload.parent_hash = spec.Hash32() execution_payload.number = execution_payload.number + 1 @@ -183,7 +183,7 @@ def test_bad_timestamp_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -197,7 +197,7 @@ def test_bad_timestamp_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_randao(spec, state) + execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) From ac19aa3e2d1533d933d504661b39341b18f086ad Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 22 Jun 2021 14:23:26 +0600 Subject: [PATCH 6/7] Accept polishing suggested by Justin --- specs/merge/beacon-chain.md | 18 +++++------- .../test/helpers/execution_payload.py | 11 ++++--- .../test_process_execution_payload.py | 29 +++++++++---------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 47e69e9182..7823a664df 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -191,25 +191,22 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None: process_eth1_data(state, block.body) process_operations(state, block.body) if is_execution_enabled(state, block.body): - # [New in Merge] - randao_mix = get_randao_mix(state, get_current_epoch(state)) - process_execution_payload(state, block.body.execution_payload, randao_mix, EXECUTION_ENGINE) + process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) # [New in Merge] ``` ### Execution payload processing #### `process_execution_payload` +*Note:* This function depends on `process_randao` function call as it retrieves the most recent randao mix from the `state`. Implementations that are considering parallel processing of execution payload with respect to beacon chain state transition function should work around this dependency. + ```python -def process_execution_payload(state: BeaconState, - payload: ExecutionPayload, - randao_mix: Bytes32, - execution_engine: ExecutionEngine) -> None: +def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None: # Verify consistency of the parent hash, block number and random if is_merge_complete(state): assert payload.parent_hash == state.latest_execution_payload_header.block_hash assert payload.block_number == state.latest_execution_payload_header.block_number + uint64(1) - assert payload.random == randao_mix + assert payload.random == get_randao_mix(state, get_current_epoch(state)) # Verify timestamp assert payload.timestamp == compute_timestamp_at_slot(state, state.slot) # Verify the execution payload is valid @@ -241,7 +238,6 @@ def process_execution_payload(state: BeaconState, def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, eth1_timestamp: uint64, deposits: Sequence[Deposit]) -> BeaconState: - randao_seed = eth1_block_hash fork = Fork( previous_version=GENESIS_FORK_VERSION, current_version=MERGE_FORK_VERSION, # [Modified in Merge] @@ -252,7 +248,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, fork=fork, eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), - randao_mixes=[randao_seed] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy + randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy ) # Process deposits @@ -276,7 +272,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, # [New in Merge] Initialize the execution payload header (with block number set to 0) state.latest_execution_payload_header.block_hash = eth1_block_hash state.latest_execution_payload_header.timestamp = eth1_timestamp - state.latest_execution_payload_header.random = randao_seed + state.latest_execution_payload_header.random = eth1_block_hash return state ``` diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 41fa3117d2..1ef63eaaf1 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,8 +1,4 @@ -def build_empty_execution_payload_with_zeroed_random(spec, state): - return build_empty_execution_payload(spec, state, spec.Bytes32()) - - -def build_empty_execution_payload(spec, state, random): +def build_empty_execution_payload(spec, state, randao_mix=None): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. """ @@ -10,6 +6,9 @@ def build_empty_execution_payload(spec, state, random): timestamp = spec.compute_time_at_slot(state, state.slot) empty_txs = spec.List[spec.Transaction, spec.MAX_TRANSACTIONS_PER_PAYLOAD]() + if randao_mix is None: + randao_mix = spec.get_randao_mix(state, spec.get_current_epoch(state)) + payload = spec.ExecutionPayload( parent_hash=latest.block_hash, coinbase=spec.Bytes20(), @@ -17,7 +16,7 @@ def build_empty_execution_payload(spec, state, random): receipt_root=b"no receipts here" + b"\x00" * 16, # TODO: root of empty MPT may be better. logs_bloom=spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](), # TODO: zeroed logs bloom for empty logs ok? block_number=latest.block_number + 1, - random=random, + random=randao_mix, gas_limit=latest.gas_limit, # retain same limit gas_used=0, # empty block, 0 gas timestamp=timestamp, diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index 4f6c987056..15c69f2dd3 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -1,5 +1,5 @@ from eth2spec.test.helpers.execution_payload import ( - build_empty_execution_payload_with_zeroed_random, + build_empty_execution_payload, get_execution_payload_header, build_state_with_incomplete_transition, build_state_with_complete_transition, @@ -22,7 +22,6 @@ def run_execution_payload_processing(spec, state, execution_payload, valid=True, yield 'execution', {'execution_valid': execution_valid} yield 'execution_payload', execution_payload - randao_mix = spec.Bytes32() called_new_block = False class TestEngine(spec.NoopExecutionEngine): @@ -34,11 +33,11 @@ def on_payload(self, payload) -> bool: if not valid: expect_assertion_error( - lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) + lambda: spec.process_execution_payload(state, execution_payload, TestEngine())) yield 'post', None return - spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine()) + spec.process_execution_payload(state, execution_payload, TestEngine()) # Make sure we called the engine assert called_new_block @@ -56,7 +55,7 @@ def test_success_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -69,7 +68,7 @@ def test_success_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -83,7 +82,7 @@ def test_success_first_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -97,7 +96,7 @@ def test_success_regular_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -112,7 +111,7 @@ def test_bad_execution_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @@ -127,7 +126,7 @@ def test_bad_execution_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @@ -140,7 +139,7 @@ def test_bad_parent_hash_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) execution_payload.parent_hash = spec.Hash32() yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -154,7 +153,7 @@ def test_bad_number_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) execution_payload.block_number = execution_payload.block_number + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -168,7 +167,7 @@ def test_bad_everything_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) execution_payload.parent_hash = spec.Hash32() execution_payload.block_number = execution_payload.block_number + 1 @@ -183,7 +182,7 @@ def test_bad_timestamp_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -197,7 +196,7 @@ def test_bad_timestamp_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload_with_zeroed_random(spec, state) + execution_payload = build_empty_execution_payload(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) From e5c01061af230ad2651097576c5900cb719b1fbd Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 22 Jun 2021 14:26:38 +0600 Subject: [PATCH 7/7] Add couple of cosmetic fixes --- tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 2 +- .../merge/block_processing/test_process_execution_payload.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 1ef63eaaf1..c41a05079d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -51,7 +51,7 @@ def build_state_with_incomplete_transition(spec, state): def build_state_with_complete_transition(spec, state): - pre_state_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + pre_state_payload = build_empty_execution_payload(spec, state) payload_header = get_execution_payload_header(spec, pre_state_payload) return build_state_with_execution_payload_header(spec, state, payload_header) diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index 15c69f2dd3..4c68034d4a 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -32,8 +32,7 @@ def on_payload(self, payload) -> bool: return execution_valid if not valid: - expect_assertion_error( - lambda: spec.process_execution_payload(state, execution_payload, TestEngine())) + expect_assertion_error(lambda: spec.process_execution_payload(state, execution_payload, TestEngine())) yield 'post', None return