diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 4a9fb8a5f..4150bf26b 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -249,15 +249,17 @@ The above function is accessed through the `EXECUTION_ENGINE` module which insta ### Block processing +*Note*: The call to the `process_execution_payload` must happen before the call to the `process_randao` as the former depends on the `randao_mix` computed with the reveal of the previous block. + ```python def process_block(state: BeaconState, block: BeaconBlock) -> None: process_block_header(state, block) + if is_execution_enabled(state, block.body): + process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) # [New in Merge] process_randao(state, block.body) process_eth1_data(state, block.body) process_operations(state, block.body) process_sync_aggregate(state, block.body.sync_aggregate) - if is_execution_enabled(state, block.body): - process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) # [New in Merge] ``` ### Execution payload processing @@ -287,8 +289,6 @@ def is_valid_gas_limit(payload: ExecutionPayload, parent: ExecutionPayloadHeader #### `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, execution_engine: ExecutionEngine) -> None: # Verify consistency of the parent hash, block number, base fee per gas and gas limit diff --git a/specs/merge/validator.md b/specs/merge/validator.md index efeeca061..b7a2860fd 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -75,23 +75,16 @@ def get_pow_block_at_total_difficulty(total_difficulty: uint256, pow_chain: Sequ return None -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_timestamp_at_slot(state, state.slot) - randao_mix = compute_randao_mix(state, randao_reveal) + randao_mix = get_randao_mix(state, get_current_epoch(state)) return execution_engine.assemble_block(parent_hash, timestamp, randao_mix) def get_execution_payload(state: BeaconState, transition_store: TransitionStore, - randao_reveal: BLSSignature, execution_engine: ExecutionEngine, pow_chain: Sequence[PowBlock]) -> ExecutionPayload: if not is_merge_complete(state): @@ -101,9 +94,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, terminal_pow_block.block_hash, randao_reveal, execution_engine) + return produce_execution_payload(state, terminal_pow_block.block_hash, execution_engine) # Post-merge, normal payload parent_hash = state.latest_execution_payload_header.block_hash - return produce_execution_payload(state, parent_hash, randao_reveal, execution_engine) + return produce_execution_payload(state, parent_hash, execution_engine) ``` diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index f54394275..2c8e8f20b 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -552,12 +552,12 @@ def compute_committee_index_from_shard(state: BeaconState, slot: Slot, shard: Sh ```python def process_block(state: BeaconState, block: BeaconBlock) -> None: process_block_header(state, block) + # is_execution_enabled is omitted, execution is enabled by default. + process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) process_randao(state, block.body) process_eth1_data(state, block.body) process_operations(state, block.body) # [Modified in Sharding] process_sync_aggregate(state, block.body.sync_aggregate) - # is_execution_enabled is omitted, execution is enabled by default. - process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) ``` #### Operations diff --git a/tests/core/pyspec/eth2spec/test/helpers/block.py b/tests/core/pyspec/eth2spec/test/helpers/block.py index b8f7c4bcb..78b90b165 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/block.py +++ b/tests/core/pyspec/eth2spec/test/helpers/block.py @@ -99,8 +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 = spec.compute_randao_mix(state, empty_block.body.randao_reveal) - empty_block.body.execution_payload = build_empty_execution_payload(spec, state, randao_mix) + empty_block.body.execution_payload = build_empty_execution_payload(spec, state) return empty_block diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py index 6866a86ae..8ff6bd731 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py @@ -143,6 +143,9 @@ def process_and_sign_block_without_header_validations(spec, state, block): state_root=spec.Bytes32(), body_root=block.body.hash_tree_root(), ) + if is_post_merge(spec): + if spec.is_execution_enabled(state, block.body): + spec.process_execution_payload(state, block.body.execution_payload, spec.EXECUTION_ENGINE) # Perform rest of process_block transitions spec.process_randao(state, block.body) @@ -150,9 +153,6 @@ def process_and_sign_block_without_header_validations(spec, state, block): spec.process_operations(state, block.body) if is_post_altair(spec): spec.process_sync_aggregate(state, block.body.sync_aggregate) - if is_post_merge(spec): - if spec.is_execution_enabled(state, block.body): - spec.process_execution_payload(state, block.body.execution_payload, spec.EXECUTION_ENGINE) # Insert post-state rot block.state_root = state.hash_tree_root() @@ -196,8 +196,7 @@ def test_parent_from_same_slot(spec, state): child_block.parent_root = state.latest_block_header.hash_tree_root() if is_post_merge(spec): - randao_mix = spec.compute_randao_mix(state, child_block.body.randao_reveal) - child_block.body.execution_payload = build_empty_execution_payload(spec, state, randao_mix) + child_block.body.execution_payload = build_empty_execution_payload(spec, state) # Show that normal path through transition fails failed_state = state.copy()