Skip to content

Commit

Permalink
Merge pull request #3829 from etan-status/df-elhash
Browse files Browse the repository at this point in the history
Fix EL block hash computation for Deneb
  • Loading branch information
hwwhww authored Jul 5, 2024
2 parents 81f3ea8 + a63bad0 commit 9be0529
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_bad_parent_hash_first_payload(spec, state):

execution_payload = build_empty_execution_payload(spec, state)
execution_payload.parent_hash = b'\x55' * 32
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload)

Expand All @@ -146,7 +146,7 @@ def test_invalid_bad_parent_hash_regular_payload(spec, state):

execution_payload = build_empty_execution_payload(spec, state)
execution_payload.parent_hash = spec.Hash32()
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)

Expand All @@ -156,7 +156,7 @@ def run_bad_prev_randao_test(spec, state):

execution_payload = build_empty_execution_payload(spec, state)
execution_payload.prev_randao = b'\x42' * 32
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)

Expand All @@ -182,7 +182,7 @@ def run_bad_everything_test(spec, state):
execution_payload.parent_hash = spec.Hash32()
execution_payload.prev_randao = spec.Bytes32()
execution_payload.timestamp = 0
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)

Expand Down Expand Up @@ -211,7 +211,7 @@ def run_bad_timestamp_test(spec, state, is_future):
else:
timestamp = execution_payload.timestamp - 1
execution_payload.timestamp = timestamp
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)

Expand Down Expand Up @@ -249,7 +249,7 @@ def run_non_empty_extra_data_test(spec, state):

execution_payload = build_empty_execution_payload(spec, state)
execution_payload.extra_data = b'\x45' * 12
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload)
assert state.latest_execution_payload_header.extra_data == execution_payload.extra_data
Expand Down Expand Up @@ -278,7 +278,7 @@ def run_non_empty_transactions_test(spec, state):
spec.Transaction(b'\x99' * 128)
for _ in range(num_transactions)
]
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload)
assert state.latest_execution_payload_header.transactions_root == execution_payload.transactions.hash_tree_root()
Expand All @@ -304,7 +304,7 @@ def run_zero_length_transaction_test(spec, state):
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.transactions = [spec.Transaction(b'')]
assert len(execution_payload.transactions[0]) == 0
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload)
assert state.latest_execution_payload_header.transactions_root == execution_payload.transactions.hash_tree_root()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_all_valid(spec, state):
def run_func():
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_block.block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)
yield from tick_and_add_block(spec, store, signed_block, test_steps, merge_block=True)
# valid
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_block_lookup_failed(spec, state):
def run_func():
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_block.block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)
yield from tick_and_add_block(spec, store, signed_block, test_steps, valid=False, merge_block=True,
block_not_found=True)
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_too_early_for_merge(spec, state):
def run_func():
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_block.block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)
yield from tick_and_add_block(spec, store, signed_block, test_steps, valid=False, merge_block=True)

Expand Down Expand Up @@ -174,7 +174,7 @@ def test_too_late_for_merge(spec, state):
def run_func():
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_block.block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)
yield from tick_and_add_block(spec, store, signed_block, test_steps, valid=False, merge_block=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_from_syncing_to_invalid(spec, state):
block_hashes[f'chain_a_{i - 1}'] if i != 0 else block_hashes['block_0']
)
block.body.execution_payload.extra_data = spec.hash(bytes(f'chain_a_{i}', 'UTF-8'))
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
block_hashes[f'chain_a_{i}'] = block.body.execution_payload.block_hash

signed_block = state_transition_and_sign_block(spec, state, block)
Expand All @@ -82,7 +82,7 @@ def test_from_syncing_to_invalid(spec, state):
block_hashes[f'chain_b_{i - 1}'] if i != 0 else block_hashes['block_0']
)
block.body.execution_payload.extra_data = spec.hash(bytes(f'chain_b_{i}', 'UTF-8'))
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
block_hashes[f'chain_b_{i}'] = block.body.execution_payload.block_hash

signed_block = state_transition_with_full_block(spec, state, True, True, block=block)
Expand All @@ -95,7 +95,7 @@ def test_from_syncing_to_invalid(spec, state):
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = signed_blocks_b[-1].message.body.execution_payload.block_hash
block.body.execution_payload.extra_data = spec.hash(bytes(f'chain_b_{i}', 'UTF-8'))
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
block_hashes['chain_b_3'] = block.body.execution_payload.block_hash

# Ensure that no duplicate block hashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_validate_merge_block_success(spec, state):
pow_chain.head().total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block)


Expand All @@ -81,7 +81,7 @@ def test_validate_merge_block_fail_parent_block_lookup(spec, state):
pow_chain.head().total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block, valid=False)


Expand All @@ -93,7 +93,7 @@ def test_validate_merge_block_fail_after_terminal(spec, state):
pow_chain.head().total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY + uint256(1)
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block, valid=False)


Expand All @@ -110,7 +110,7 @@ def test_validate_merge_block_tbh_override_success(spec, state):
pow_chain.head().block_hash = TERMINAL_BLOCK_HASH
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block)


Expand All @@ -126,7 +126,7 @@ def test_validate_merge_block_fail_parent_hash_is_not_tbh(spec, state):
pow_chain.head().total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block, valid=False)


Expand All @@ -143,7 +143,7 @@ def test_validate_merge_block_terminal_block_hash_fail_activation_not_reached(sp
pow_chain.head().block_hash = TERMINAL_BLOCK_HASH
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block, valid=False)


Expand All @@ -159,5 +159,5 @@ def test_validate_merge_block_fail_activation_not_reached_parent_hash_is_not_tbh
pow_chain.head().total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.parent_hash = pow_chain.head().block_hash
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
run_validate_merge_block(spec, pow_chain, block, valid=False)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_invalid_bad_parent_hash_first_payload(spec, state):

execution_payload = build_empty_execution_payload(spec, state)
execution_payload.parent_hash = b'\x55' * 32
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload)
execution_payload.block_hash = compute_el_block_hash(spec, execution_payload, state)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Loading

0 comments on commit 9be0529

Please sign in to comment.