From 17dac8cab92d2982d7940966d0de40c5e3283828 Mon Sep 17 00:00:00 2001 From: gajinder Date: Tue, 25 Apr 2023 15:36:48 +0530 Subject: [PATCH 01/10] Update MAX_BLOBS_PER_BLOCK to a higher bound --- presets/mainnet/deneb.yaml | 4 ++-- specs/deneb/beacon-chain.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/presets/mainnet/deneb.yaml b/presets/mainnet/deneb.yaml index ebe33f2d1..7cf41bbf4 100644 --- a/presets/mainnet/deneb.yaml +++ b/presets/mainnet/deneb.yaml @@ -4,5 +4,5 @@ # --------------------------------------------------------------- # `uint64(4096)` FIELD_ELEMENTS_PER_BLOB: 4096 -# `uint64(2**2)` (= 4) -MAX_BLOBS_PER_BLOCK: 4 +# `uint64(2**10)` (= 1024) +MAX_BLOBS_PER_BLOCK: 1024 diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index 359c7fc95..a123f921b 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -68,7 +68,7 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extensi | Name | Value | | - | - | -| `MAX_BLOBS_PER_BLOCK` | `uint64(2**2)` (= 4) | +| `MAX_BLOBS_PER_BLOCK` | `uint64(2**10)` (= 1024) | ## Configuration From 5e43f43df135a576cbdff51fa3aec6d85a08cf24 Mon Sep 17 00:00:00 2001 From: gajinder Date: Fri, 28 Apr 2023 10:55:35 +0530 Subject: [PATCH 02/10] update limit to 4844 friendly 16 blobs --- presets/mainnet/deneb.yaml | 4 ++-- specs/deneb/beacon-chain.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/presets/mainnet/deneb.yaml b/presets/mainnet/deneb.yaml index 7cf41bbf4..d5dafe0d0 100644 --- a/presets/mainnet/deneb.yaml +++ b/presets/mainnet/deneb.yaml @@ -4,5 +4,5 @@ # --------------------------------------------------------------- # `uint64(4096)` FIELD_ELEMENTS_PER_BLOB: 4096 -# `uint64(2**10)` (= 1024) -MAX_BLOBS_PER_BLOCK: 1024 +# `uint64(2**4)` (= 16) +MAX_BLOBS_PER_BLOCK: 16 diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index a123f921b..fc59e3be8 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -68,7 +68,7 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extensi | Name | Value | | - | - | -| `MAX_BLOBS_PER_BLOCK` | `uint64(2**10)` (= 1024) | +| `MAX_BLOBS_PER_BLOCK` | `uint64(2**4)` (= 16) | ## Configuration From 1aad9b5fa0dce3a0043710bd6595646260459fb2 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sat, 6 May 2023 17:19:28 +0530 Subject: [PATCH 03/10] adding a fixed theoretical limit for commitments in a block --- specs/deneb/beacon-chain.md | 4 ++-- specs/deneb/p2p-interface.md | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index fc59e3be8..934a84013 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -68,7 +68,7 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extensi | Name | Value | | - | - | -| `MAX_BLOBS_PER_BLOCK` | `uint64(2**4)` (= 16) | +| `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**10)` (= 1024) | hardfork independent fixed theoretical limit | ## Configuration @@ -96,7 +96,7 @@ class BeaconBlockBody(Container): # Execution execution_payload: ExecutionPayload # [Modified in Deneb] bls_to_execution_changes: List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES] - blob_kzg_commitments: List[KZGCommitment, MAX_BLOBS_PER_BLOCK] # [New in Deneb] + blob_kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK] # [New in Deneb] ``` #### `ExecutionPayload` diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index d67c144b2..514991bb7 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -43,6 +43,7 @@ The specification of these changes continues in the same format as the network s | Name | Value | Description | |------------------------------------------|-----------------------------------|---------------------------------------------------------------------| | `MAX_REQUEST_BLOCKS_DENEB` | `2**7` (= 128) | Maximum number of blocks in a single request | +| `MAX_BLOBS_PER_BLOCK` | `2**4` (= 16) | Maximum number of blobs in a single request, to be always <= `MAX_BLOB_COMMITMENTS_PER_BLOCK` | | `MAX_REQUEST_BLOB_SIDECARS` | `MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK` | Maximum number of blob sidecars in a single request | | `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `2**12` (= 4096 epochs, ~18 days) | The minimum epoch range over which a node must serve blob sidecars | @@ -119,7 +120,7 @@ The *type* of the payload of this topic changes to the (modified) `SignedBeaconB ###### `blob_sidecar_{subnet_id}` -This topic is used to propagate signed blob sidecars, where each blob index maps to some `subnet_id`. +This topic is used to propagate signed blob sidecars, where each blob index maps to some `subnet_id`. However the actual blobs that will be generated by the EL will be limited by `MAX_DATA_GAS_PER_BLOCK // DATA_GAS_PER_BLOB` and will require an EL hardfork to upgrade the limit. The following validations MUST pass before forwarding the `signed_blob_sidecar` on the network, assuming the alias `sidecar = signed_blob_sidecar.message`: From 9f530a7741e220b2c2611452a98e8ee195e6f02c Mon Sep 17 00:00:00 2001 From: gajinder Date: Sun, 7 May 2023 19:52:59 +0530 Subject: [PATCH 04/10] update max commitments per block limit to blobs per tx limit from eip4844 --- specs/deneb/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index 934a84013..971b67f0e 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -68,7 +68,7 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extensi | Name | Value | | - | - | -| `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**10)` (= 1024) | hardfork independent fixed theoretical limit | +| `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**12)` (= 4096) | hardfork independent fixed theoretical limit same as `LIMIT_BLOBS_PER_TX` (see EIP 4844) | ## Configuration From a75292beebdea362b70d65e7ceb3b78ae03d5be4 Mon Sep 17 00:00:00 2001 From: gajinder Date: Thu, 11 May 2023 19:03:43 +0530 Subject: [PATCH 05/10] restore the 4844 max limit to 4 --- presets/mainnet/deneb.yaml | 4 ++-- specs/deneb/p2p-interface.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/presets/mainnet/deneb.yaml b/presets/mainnet/deneb.yaml index d5dafe0d0..ebe33f2d1 100644 --- a/presets/mainnet/deneb.yaml +++ b/presets/mainnet/deneb.yaml @@ -4,5 +4,5 @@ # --------------------------------------------------------------- # `uint64(4096)` FIELD_ELEMENTS_PER_BLOB: 4096 -# `uint64(2**4)` (= 16) -MAX_BLOBS_PER_BLOCK: 16 +# `uint64(2**2)` (= 4) +MAX_BLOBS_PER_BLOCK: 4 diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index 514991bb7..4de7f4a83 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -43,7 +43,7 @@ The specification of these changes continues in the same format as the network s | Name | Value | Description | |------------------------------------------|-----------------------------------|---------------------------------------------------------------------| | `MAX_REQUEST_BLOCKS_DENEB` | `2**7` (= 128) | Maximum number of blocks in a single request | -| `MAX_BLOBS_PER_BLOCK` | `2**4` (= 16) | Maximum number of blobs in a single request, to be always <= `MAX_BLOB_COMMITMENTS_PER_BLOCK` | +| `MAX_BLOBS_PER_BLOCK` | `2**2` (= 4) | Maximum number of blobs in a single request, can never exceed `MAX_BLOB_COMMITMENTS_PER_BLOCK` limit | | `MAX_REQUEST_BLOB_SIDECARS` | `MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK` | Maximum number of blob sidecars in a single request | | `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `2**12` (= 4096 epochs, ~18 days) | The minimum epoch range over which a node must serve blob sidecars | From 8ccc2570d15774b474b2151337304be727750cf1 Mon Sep 17 00:00:00 2001 From: gajinder Date: Sat, 20 May 2023 19:35:22 +0530 Subject: [PATCH 06/10] apply feedback --- specs/deneb/beacon-chain.md | 3 +++ specs/deneb/p2p-interface.md | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index 971b67f0e..1926cc8ce 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -40,6 +40,8 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extension of the Capella upgrade. +The blob transactions are packed into the execution payload by the EL/builder with their corresponding blobs being independently transmitted and are limited by `MAX_DATA_GAS_PER_BLOCK // DATA_GAS_PER_BLOB`. However the CL limit is independently defined by `MAX_BLOBS_PER_BLOCK`. + ## Custom types | Name | SSZ equivalent | Description | @@ -69,6 +71,7 @@ This upgrade adds blobs to the beacon chain as part of Deneb. This is an extensi | Name | Value | | - | - | | `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**12)` (= 4096) | hardfork independent fixed theoretical limit same as `LIMIT_BLOBS_PER_TX` (see EIP 4844) | +| `MAX_BLOBS_PER_BLOCK` | `uint64(2**2)` (= 4) | Maximum number of blobs in a single block limited by `MAX_BLOB_COMMITMENTS_PER_BLOCK` | ## Configuration diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index 4de7f4a83..d67c144b2 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -43,7 +43,6 @@ The specification of these changes continues in the same format as the network s | Name | Value | Description | |------------------------------------------|-----------------------------------|---------------------------------------------------------------------| | `MAX_REQUEST_BLOCKS_DENEB` | `2**7` (= 128) | Maximum number of blocks in a single request | -| `MAX_BLOBS_PER_BLOCK` | `2**2` (= 4) | Maximum number of blobs in a single request, can never exceed `MAX_BLOB_COMMITMENTS_PER_BLOCK` limit | | `MAX_REQUEST_BLOB_SIDECARS` | `MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK` | Maximum number of blob sidecars in a single request | | `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `2**12` (= 4096 epochs, ~18 days) | The minimum epoch range over which a node must serve blob sidecars | @@ -120,7 +119,7 @@ The *type* of the payload of this topic changes to the (modified) `SignedBeaconB ###### `blob_sidecar_{subnet_id}` -This topic is used to propagate signed blob sidecars, where each blob index maps to some `subnet_id`. However the actual blobs that will be generated by the EL will be limited by `MAX_DATA_GAS_PER_BLOCK // DATA_GAS_PER_BLOB` and will require an EL hardfork to upgrade the limit. +This topic is used to propagate signed blob sidecars, where each blob index maps to some `subnet_id`. The following validations MUST pass before forwarding the `signed_blob_sidecar` on the network, assuming the alias `sidecar = signed_blob_sidecar.message`: From 4458645f0cffc65133618690ff97ace401f83f27 Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 22 May 2023 18:41:40 +0530 Subject: [PATCH 07/10] add check --- specs/deneb/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index 1926cc8ce..b2f6b1763 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -254,6 +254,7 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe ```python def process_blob_kzg_commitments(body: BeaconBlockBody) -> None: + assert len(body.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK assert verify_kzg_commitments_against_transactions(body.execution_payload.transactions, body.blob_kzg_commitments) ``` From feb1968e433daa1a4c540d9226a98c6c4f9b238b Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 22 May 2023 18:44:12 +0530 Subject: [PATCH 08/10] add comment --- specs/deneb/beacon-chain.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index b2f6b1763..f492a948c 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -254,7 +254,9 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe ```python def process_blob_kzg_commitments(body: BeaconBlockBody) -> None: + # Verify commitments are under limit assert len(body.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK + # Verify commitments match with corresponding blob transactions assert verify_kzg_commitments_against_transactions(body.execution_payload.transactions, body.blob_kzg_commitments) ``` From f0a4281afdeeea8cc41c85405fb35203cf60463a Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 24 May 2023 16:11:32 +0800 Subject: [PATCH 09/10] Add tests. Add validation in the p2p beacon block gossiping --- presets/mainnet/deneb.yaml | 2 ++ presets/minimal/deneb.yaml | 2 ++ specs/_features/eip6110/beacon-chain.md | 2 ++ specs/deneb/p2p-interface.md | 5 +++++ .../test_process_execution_payload.py | 13 ++++++++++++ .../eth2spec/test/deneb/sanity/test_blocks.py | 20 +++++++++++++++---- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/presets/mainnet/deneb.yaml b/presets/mainnet/deneb.yaml index ebe33f2d1..10c5025ed 100644 --- a/presets/mainnet/deneb.yaml +++ b/presets/mainnet/deneb.yaml @@ -4,5 +4,7 @@ # --------------------------------------------------------------- # `uint64(4096)` FIELD_ELEMENTS_PER_BLOB: 4096 +# `uint64(2**12)` (= 4096) +MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096 # `uint64(2**2)` (= 4) MAX_BLOBS_PER_BLOCK: 4 diff --git a/presets/minimal/deneb.yaml b/presets/minimal/deneb.yaml index e51b5587d..91120f9da 100644 --- a/presets/minimal/deneb.yaml +++ b/presets/minimal/deneb.yaml @@ -4,5 +4,7 @@ # --------------------------------------------------------------- # [customized] FIELD_ELEMENTS_PER_BLOB: 4 +# [customized] +MAX_BLOB_COMMITMENTS_PER_BLOCK: 16 # `uint64(2**2)` (= 4) MAX_BLOBS_PER_BLOCK: 4 diff --git a/specs/_features/eip6110/beacon-chain.md b/specs/_features/eip6110/beacon-chain.md index 5f6fd99cf..e1384fdae 100644 --- a/specs/_features/eip6110/beacon-chain.md +++ b/specs/_features/eip6110/beacon-chain.md @@ -244,6 +244,8 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi assert payload.prev_randao == get_randao_mix(state, get_current_epoch(state)) # Verify timestamp assert payload.timestamp == compute_timestamp_at_slot(state, state.slot) + # Verify commitments are under limit + assert len(body.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK # Verify the execution payload is valid versioned_hashes = [kzg_commitment_to_versioned_hash(commitment) for commitment in body.blob_kzg_commitments] assert execution_engine.verify_and_notify_new_payload( diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index d67c144b2..2d6454737 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -117,6 +117,11 @@ Deneb introduces new global topics for blob sidecars. The *type* of the payload of this topic changes to the (modified) `SignedBeaconBlock` found in deneb. +New validation: + +- _[REJECT]_ The length of KZG commitments is less than or equal to the limitation defined in Consensus Layer -- + i.e. validate that `len(body.signed_beacon_block.message.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK` + ###### `blob_sidecar_{subnet_id}` This topic is used to propagate signed blob sidecars, where each blob index maps to some `subnet_id`. diff --git a/tests/core/pyspec/eth2spec/test/deneb/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/deneb/block_processing/test_process_execution_payload.py index df59385ab..988070278 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/deneb/block_processing/test_process_execution_payload.py @@ -190,3 +190,16 @@ def test_invalid_correct_input__execution_invalid(spec, state): yield from run_execution_payload_processing(spec, state, execution_payload, blob_kzg_commitments, valid=False, execution_valid=False) + + +@with_deneb_and_later +@spec_state_test +def test_invalid_exceed_max_blobs_per_block(spec, state): + execution_payload = build_empty_execution_payload(spec, state) + + opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx(spec, blob_count=spec.MAX_BLOBS_PER_BLOCK + 1) + + execution_payload.transactions = [opaque_tx] + execution_payload.block_hash = compute_el_block_hash(spec, execution_payload) + + yield from run_execution_payload_processing(spec, state, execution_payload, blob_kzg_commitments, valid=False) diff --git a/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py index 36caacd3f..13a042b9f 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/deneb/sanity/test_blocks.py @@ -16,7 +16,7 @@ from eth2spec.test.helpers.sharding import ( ) -def run_block_with_blobs(spec, state, blob_count, excess_data_gas=1): +def run_block_with_blobs(spec, state, blob_count, excess_data_gas=1, valid=True): yield 'pre', state block = build_empty_block_for_next_slot(spec, state) @@ -25,10 +25,16 @@ def run_block_with_blobs(spec, state, blob_count, excess_data_gas=1): block.body.execution_payload.transactions = [opaque_tx] block.body.execution_payload.excess_data_gas = excess_data_gas block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) - signed_block = state_transition_and_sign_block(spec, state, block) + + print(len(block.body.blob_kzg_commitments)) + + if valid: + signed_block = state_transition_and_sign_block(spec, state, block) + else: + signed_block = state_transition_and_sign_block(spec, state, block, expect_fail=True) yield 'blocks', [signed_block] - yield 'post', state + yield 'post', state if valid else None @with_deneb_and_later @@ -45,5 +51,11 @@ def test_one_blob(spec, state): @with_deneb_and_later @spec_state_test -def test_max_blobs(spec, state): +def test_max_blobs_per_block(spec, state): yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK) + + +@with_deneb_and_later +@spec_state_test +def test_invalid_exceed_max_blobs_per_block(spec, state): + yield from run_block_with_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK + 1, valid=False) From e9cc8dcc051ccff90916547027e6088b55083da5 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 24 May 2023 16:32:39 +0800 Subject: [PATCH 10/10] PR feedback of Danny + verify `MAX_BLOBS_PER_BLOCK` size in unittest --- specs/deneb/beacon-chain.md | 2 +- .../test/deneb/unittests/test_config_invariants.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/core/pyspec/eth2spec/test/deneb/unittests/test_config_invariants.py diff --git a/specs/deneb/beacon-chain.md b/specs/deneb/beacon-chain.md index c8b79f919..cd02d2494 100644 --- a/specs/deneb/beacon-chain.md +++ b/specs/deneb/beacon-chain.md @@ -73,7 +73,7 @@ The blob transactions are packed into the execution payload by the EL/builder wi | Name | Value | | - | - | -| `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**12)` (= 4096) | hardfork independent fixed theoretical limit same as `LIMIT_BLOBS_PER_TX` (see EIP 4844) | +| `MAX_BLOB_COMMITMENTS_PER_BLOCK` | `uint64(2**12)` (= 4096) | hardfork independent fixed theoretical limit same as `LIMIT_BLOBS_PER_TX` (see EIP 4844) | | `MAX_BLOBS_PER_BLOCK` | `uint64(2**2)` (= 4) | Maximum number of blobs in a single block limited by `MAX_BLOB_COMMITMENTS_PER_BLOCK` | ## Configuration diff --git a/tests/core/pyspec/eth2spec/test/deneb/unittests/test_config_invariants.py b/tests/core/pyspec/eth2spec/test/deneb/unittests/test_config_invariants.py new file mode 100644 index 000000000..13a54225e --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/deneb/unittests/test_config_invariants.py @@ -0,0 +1,12 @@ +from eth2spec.test.context import ( + single_phase, + spec_test, + with_deneb_and_later, +) + + +@with_deneb_and_later +@spec_test +@single_phase +def test_length(spec): + assert spec.MAX_BLOBS_PER_BLOCK < spec.MAX_BLOB_COMMITMENTS_PER_BLOCK