Skip to content

Commit e12b9ab

Browse files
EIP-7732: Refactor Beacon chain state transition function (#3898)
1 parent cb99c5f commit e12b9ab

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

specs/_features/eip7732/beacon-chain.md

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
- [Modified `process_operations`](#modified-process_operations)
5151
- [Payload Attestations](#payload-attestations)
5252
- [`process_payload_attestation`](#process_payload_attestation)
53-
- [Modified `process_execution_payload`](#modified-process_execution_payload)
54-
- [New `verify_execution_payload_envelope_signature`](#new-verify_execution_payload_envelope_signature)
5553
- [Modified `is_merge_transition_complete`](#modified-is_merge_transition_complete)
5654
- [Modified `validate_merge_block`](#modified-validate_merge_block)
55+
- [Execution payload processing](#execution-payload-processing)
56+
- [New `verify_execution_payload_envelope_signature`](#new-verify_execution_payload_envelope_signature)
57+
- [New `process_execution_payload`](#new-process_execution_payload)
5758

5859
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5960
<!-- /TOC -->
@@ -429,7 +430,8 @@ The post-state corresponding to a pre-state `state` and a signed execution paylo
429430
def process_block(state: BeaconState, block: BeaconBlock) -> None:
430431
process_block_header(state, block)
431432
process_withdrawals(state) # [Modified in EIP-7732]
432-
process_execution_payload_header(state, block) # [Modified in EIP-7732, removed process_execution_payload]
433+
# Removed `process_execution_payload` in EIP-7732
434+
process_execution_payload_header(state, block) # [New in EIP-7732]
433435
process_randao(state, block.body)
434436
process_eth1_data(state, block.body)
435437
process_operations(state, block.body) # [Modified in EIP-7732]
@@ -597,9 +599,51 @@ def process_payload_attestation(state: BeaconState, payload_attestation: Payload
597599
increase_balance(state, proposer_index, proposer_reward)
598600
```
599601

600-
#### Modified `process_execution_payload`
602+
#### Modified `is_merge_transition_complete`
603+
604+
`is_merge_transition_complete` is modified only for testing purposes to add the blob kzg commitments root for an empty list
605+
606+
```python
607+
def is_merge_transition_complete(state: BeaconState) -> bool:
608+
header = ExecutionPayloadHeader()
609+
kzgs = List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]()
610+
header.blob_kzg_commitments_root = kzgs.hash_tree_root()
611+
612+
return state.latest_execution_payload_header != header
613+
```
601614

602-
##### New `verify_execution_payload_envelope_signature`
615+
#### Modified `validate_merge_block`
616+
`validate_merge_block` is modified to use the new `signed_execution_payload_header` message in the Beacon Block Body
617+
618+
```python
619+
def validate_merge_block(block: BeaconBlock) -> None:
620+
"""
621+
Check the parent PoW block of execution payload is a valid terminal PoW block.
622+
623+
Note: Unavailable PoW block(s) may later become available,
624+
and a client software MAY delay a call to ``validate_merge_block``
625+
until the PoW block(s) become available.
626+
"""
627+
if TERMINAL_BLOCK_HASH != Hash32():
628+
# If `TERMINAL_BLOCK_HASH` is used as an override, the activation epoch must be reached.
629+
assert compute_epoch_at_slot(block.slot) >= TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH
630+
assert block.body.signed_execution_payload_header.message.parent_block_hash == TERMINAL_BLOCK_HASH
631+
return
632+
633+
# Modified in EIP-7732
634+
pow_block = get_pow_block(block.body.signed_execution_payload_header.message.parent_block_hash)
635+
# Check if `pow_block` is available
636+
assert pow_block is not None
637+
pow_parent = get_pow_block(pow_block.parent_hash)
638+
# Check if `pow_parent` is available
639+
assert pow_parent is not None
640+
# Check if `pow_block` is a valid terminal PoW block
641+
assert is_valid_terminal_pow_block(pow_block, pow_parent)
642+
```
643+
644+
### Execution payload processing
645+
646+
#### New `verify_execution_payload_envelope_signature`
603647

604648
```python
605649
def verify_execution_payload_envelope_signature(
@@ -609,6 +653,8 @@ def verify_execution_payload_envelope_signature(
609653
return bls.Verify(builder.pubkey, signing_root, signed_envelope.signature)
610654
```
611655

656+
#### New `process_execution_payload`
657+
612658
*Note*: `process_execution_payload` is now an independent check in state transition. It is called when importing a signed execution payload proposed by the builder of the current slot.
613659

614660
```python
@@ -679,45 +725,3 @@ def process_execution_payload(state: BeaconState,
679725
if verify:
680726
assert envelope.state_root == hash_tree_root(state)
681727
```
682-
683-
#### Modified `is_merge_transition_complete`
684-
685-
`is_merge_transition_complete` is modified only for testing purposes to add the blob kzg commitments root for an empty list
686-
687-
```python
688-
def is_merge_transition_complete(state: BeaconState) -> bool:
689-
header = ExecutionPayloadHeader()
690-
kzgs = List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]()
691-
header.blob_kzg_commitments_root = kzgs.hash_tree_root()
692-
693-
return state.latest_execution_payload_header != header
694-
```
695-
696-
#### Modified `validate_merge_block`
697-
`validate_merge_block` is modified to use the new `signed_execution_payload_header` message in the Beacon Block Body
698-
699-
```python
700-
def validate_merge_block(block: BeaconBlock) -> None:
701-
"""
702-
Check the parent PoW block of execution payload is a valid terminal PoW block.
703-
704-
Note: Unavailable PoW block(s) may later become available,
705-
and a client software MAY delay a call to ``validate_merge_block``
706-
until the PoW block(s) become available.
707-
"""
708-
if TERMINAL_BLOCK_HASH != Hash32():
709-
# If `TERMINAL_BLOCK_HASH` is used as an override, the activation epoch must be reached.
710-
assert compute_epoch_at_slot(block.slot) >= TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH
711-
assert block.body.signed_execution_payload_header.message.parent_block_hash == TERMINAL_BLOCK_HASH
712-
return
713-
714-
# Modified in EIP-7732
715-
pow_block = get_pow_block(block.body.signed_execution_payload_header.message.parent_block_hash)
716-
# Check if `pow_block` is available
717-
assert pow_block is not None
718-
pow_parent = get_pow_block(pow_block.parent_hash)
719-
# Check if `pow_parent` is available
720-
assert pow_parent is not None
721-
# Check if `pow_block` is a valid terminal PoW block
722-
assert is_valid_terminal_pow_block(pow_block, pow_parent)
723-
```

0 commit comments

Comments
 (0)