From 1f486c1b32f8b1b502270e8e5621d222dc5fb158 Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Wed, 15 Sep 2021 18:47:44 -0500 Subject: [PATCH 1/6] fixed client-settings.md link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5a898d37..9e5d7dc42 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The merge is still actively in development. The exact specification has not been * [Merge fork](specs/merge/fork.md) * [Fork Choice changes](specs/merge/fork-choice.md) * [Validator additions](specs/merge/validator.md) - * [Client settings](specs/merge/client_settings.md) + * [Client settings](specs/merge/client-settings.md) ### Sharding From c2084ad5b010de955a2b58430134678fb8e738df Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 17 Sep 2021 18:23:21 +0600 Subject: [PATCH 2/6] Bring on extra_data field --- specs/merge/beacon-chain.md | 4 ++++ tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index ed12d3eb6..a2a37e215 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -64,6 +64,7 @@ This patch adds transaction execution to the beacon chain as part of the Merge f | `BYTES_PER_LOGS_BLOOM` | `uint64(2**8)` (= 256) | | `GAS_LIMIT_DENOMINATOR` | `uint64(2**10)` (= 1,024) | | `MIN_GAS_LIMIT` | `uint64(5000)` (= 5,000) | +| `MAX_EXTRA_DATA_BYTES` | `2**5` (= 32) | ## Configuration @@ -159,6 +160,7 @@ class ExecutionPayload(Container): gas_limit: uint64 gas_used: uint64 timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] base_fee_per_gas: Bytes32 # base fee introduced in EIP-1559, little-endian serialized # Extra payload fields block_hash: Hash32 # Hash of execution block @@ -180,6 +182,7 @@ class ExecutionPayloadHeader(Container): gas_limit: uint64 gas_used: uint64 timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] base_fee_per_gas: Bytes32 # Extra payload fields block_hash: Hash32 # Hash of execution block @@ -310,6 +313,7 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe gas_limit=payload.gas_limit, gas_used=payload.gas_used, timestamp=payload.timestamp, + extra_data=payload.extra_data, base_fee_per_gas=payload.base_fee_per_gas, block_hash=payload.block_hash, transactions_root=hash_tree_root(payload.transactions), diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 43be965a5..6126346a9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -20,6 +20,7 @@ def build_empty_execution_payload(spec, state, randao_mix=None): gas_limit=latest.gas_limit, # retain same limit gas_used=0, # empty block, 0 gas timestamp=timestamp, + extra_data=spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](), base_fee_per_gas=latest.base_fee_per_gas, # retain same base_fee block_hash=spec.Hash32(), transactions=empty_txs, @@ -42,6 +43,7 @@ def get_execution_payload_header(spec, execution_payload): gas_limit=execution_payload.gas_limit, gas_used=execution_payload.gas_used, timestamp=execution_payload.timestamp, + extra_data=execution_payload.extra_data, base_fee_per_gas=execution_payload.base_fee_per_gas, block_hash=execution_payload.block_hash, transactions_root=spec.hash_tree_root(execution_payload.transactions) From 3ef13561e68ee3522e481a587cf3ad3b702849e0 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 17 Sep 2021 11:00:32 -0600 Subject: [PATCH 3/6] ensure random is validated for all payloads including transition --- specs/merge/beacon-chain.md | 6 ++-- .../test_process_execution_payload.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index a2a37e215..4a9fb8a5f 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -291,12 +291,14 @@ def is_valid_gas_limit(payload: ExecutionPayload, parent: ExecutionPayloadHeader ```python def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None: - # Verify consistency of the parent hash, block number, random, base fee per gas and gas limit + # Verify consistency of the parent hash, block number, base fee per gas and gas limit + # with respect to the previous execution payload header 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 == get_randao_mix(state, get_current_epoch(state)) assert is_valid_gas_limit(payload, state.latest_execution_payload_header) + # Verify random + 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 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 4c68034d4..9c5ed6712 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 @@ -144,6 +144,34 @@ def test_bad_parent_hash_regular_payload(spec, state): yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) +@with_merge_and_later +@spec_state_test +def test_bad_random_first_payload(spec, state): + # pre-state + state = build_state_with_incomplete_transition(spec, state) + next_slot(spec, state) + + # execution payload + execution_payload = build_empty_execution_payload(spec, state) + execution_payload.random = b'\x42' * 32 + + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + + +@with_merge_and_later +@spec_state_test +def test_bad_random_regular_payload(spec, state): + # pre-state + state = build_state_with_complete_transition(spec, state) + next_slot(spec, state) + + # execution payload + execution_payload = build_empty_execution_payload(spec, state) + execution_payload.random = b'\x04' * 32 + + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + + @with_merge_and_later @spec_state_test def test_bad_number_regular_payload(spec, state): From cb9e65ab85602661d9625af002247f772453581b Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 17 Sep 2021 18:23:21 +0600 Subject: [PATCH 4/6] Bring on extra_data field --- specs/merge/beacon-chain.md | 4 ++++ tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 03bf01155..4f89908fd 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -65,6 +65,7 @@ This patch adds transaction execution to the beacon chain as part of the Merge f | `BYTES_PER_LOGS_BLOOM` | `uint64(2**8)` (= 256) | | `GAS_LIMIT_DENOMINATOR` | `uint64(2**10)` (= 1,024) | | `MIN_GAS_LIMIT` | `uint64(5000)` (= 5,000) | +| `MAX_EXTRA_DATA_BYTES` | `2**5` (= 32) | ## Configuration @@ -166,6 +167,7 @@ class ExecutionPayload(Container): gas_limit: uint64 gas_used: uint64 timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] base_fee_per_gas: Bytes32 # base fee introduced in EIP-1559, little-endian serialized # Extra payload fields block_hash: Hash32 # Hash of execution block @@ -187,6 +189,7 @@ class ExecutionPayloadHeader(Container): gas_limit: uint64 gas_used: uint64 timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] base_fee_per_gas: Bytes32 # Extra payload fields block_hash: Hash32 # Hash of execution block @@ -317,6 +320,7 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe gas_limit=payload.gas_limit, gas_used=payload.gas_used, timestamp=payload.timestamp, + extra_data=payload.extra_data, base_fee_per_gas=payload.base_fee_per_gas, block_hash=payload.block_hash, transactions_root=hash_tree_root(payload.transactions), diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 43be965a5..6126346a9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -20,6 +20,7 @@ def build_empty_execution_payload(spec, state, randao_mix=None): gas_limit=latest.gas_limit, # retain same limit gas_used=0, # empty block, 0 gas timestamp=timestamp, + extra_data=spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](), base_fee_per_gas=latest.base_fee_per_gas, # retain same base_fee block_hash=spec.Hash32(), transactions=empty_txs, @@ -42,6 +43,7 @@ def get_execution_payload_header(spec, execution_payload): gas_limit=execution_payload.gas_limit, gas_used=execution_payload.gas_used, timestamp=execution_payload.timestamp, + extra_data=execution_payload.extra_data, base_fee_per_gas=execution_payload.base_fee_per_gas, block_hash=execution_payload.block_hash, transactions_root=spec.hash_tree_root(execution_payload.transactions) From 731bcad3175f36d1d99d1343b49e0584cae1ad8e Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Wed, 15 Sep 2021 18:47:44 -0500 Subject: [PATCH 5/6] fixed client-settings.md link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5a898d37..9e5d7dc42 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The merge is still actively in development. The exact specification has not been * [Merge fork](specs/merge/fork.md) * [Fork Choice changes](specs/merge/fork-choice.md) * [Validator additions](specs/merge/validator.md) - * [Client settings](specs/merge/client_settings.md) + * [Client settings](specs/merge/client-settings.md) ### Sharding From e2af59c8cd5557de68d0dd890f04e337cd58e7d3 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 17 Sep 2021 11:00:32 -0600 Subject: [PATCH 6/6] ensure random is validated for all payloads including transition --- specs/merge/beacon-chain.md | 6 ++-- .../test_process_execution_payload.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 4f89908fd..39f457252 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -298,12 +298,14 @@ def is_valid_gas_limit(payload: ExecutionPayload, parent: ExecutionPayloadHeader ```python def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None: - # Verify consistency of the parent hash, block number, random, base fee per gas and gas limit + # Verify consistency of the parent hash, block number, base fee per gas and gas limit + # with respect to the previous execution payload header 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 == get_randao_mix(state, get_current_epoch(state)) assert is_valid_gas_limit(payload, state.latest_execution_payload_header) + # Verify random + 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 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 4c68034d4..9c5ed6712 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 @@ -144,6 +144,34 @@ def test_bad_parent_hash_regular_payload(spec, state): yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) +@with_merge_and_later +@spec_state_test +def test_bad_random_first_payload(spec, state): + # pre-state + state = build_state_with_incomplete_transition(spec, state) + next_slot(spec, state) + + # execution payload + execution_payload = build_empty_execution_payload(spec, state) + execution_payload.random = b'\x42' * 32 + + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + + +@with_merge_and_later +@spec_state_test +def test_bad_random_regular_payload(spec, state): + # pre-state + state = build_state_with_complete_transition(spec, state) + next_slot(spec, state) + + # execution payload + execution_payload = build_empty_execution_payload(spec, state) + execution_payload.random = b'\x04' * 32 + + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) + + @with_merge_and_later @spec_state_test def test_bad_number_regular_payload(spec, state):