Skip to content

Commit 13e54dd

Browse files
authored
Limit BlobId to a maximum supported range (#6967)
* Limit `BlobId` to a maximum supported range `BlobId` historically tracked `MAX_BLOBS_PER_BLOCK_ELECTRA` which is no longer correct because the network configuration may assign multiple blobs to the same subnet dynamically since v1.5.0-alpha.4. Instead, restrict it to a specific range, there is no `for x in BlobId` anywhere. * Lint
1 parent ed576c5 commit 13e54dd

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

beacon_chain/spec/datatypes/base.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ type
204204
## blob sidecar - it is distinct from the BlobIndex in particular
205205
##
206206
## The `BlobId` type is constrained to values in the range
207-
## `[0, MAX_BLOBS_PER_BLOCK_ELECTRA)` during initialization.
207+
## `[0, MAX_SUPPORTED_BLOB_SIDECAR_SUBNET_COUNT)` during initialization.
208+
## The network configuration may impose further restrictions on the count!
208209

209210
# BitVector[4] in the spec, ie 4 bits which end up encoded as a byte for
210211
# SSZ / hashing purposes
@@ -612,9 +613,7 @@ template makeLimitedU64*(T: untyped, limit: uint64) =
612613

613614
makeLimitedU64(CommitteeIndex, MAX_COMMITTEES_PER_SLOT)
614615
makeLimitedU64(SubnetId, ATTESTATION_SUBNET_COUNT)
615-
616-
static: doAssert MAX_BLOBS_PER_BLOCK_ELECTRA >= BLOB_SIDECAR_SUBNET_COUNT
617-
makeLimitedU64(BlobId, MAX_BLOBS_PER_BLOCK_ELECTRA)
616+
makeLimitedU64(BlobId, MAX_SUPPORTED_BLOB_SIDECAR_SUBNET_COUNT)
618617

619618
const
620619
validatorIndexLimit = min(uint64(int32.high), VALIDATOR_REGISTRY_LIMIT)

beacon_chain/spec/datatypes/constants.nim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ const
6464
REORG_PARENT_WEIGHT_THRESHOLD*: uint64 = 160
6565
REORG_MAX_EPOCHS_SINCE_FINALIZATION* = Epoch(2)
6666

67-
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/deneb/p2p-interface.md#configuration
68-
BLOB_SIDECAR_SUBNET_COUNT*: uint64 = 6
69-
7067
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#configuration
7168
MAX_REQUEST_BLOCKS* = 1024'u64
7269
RESP_TIMEOUT* = 10'u64
@@ -90,6 +87,3 @@ const
9087
DEPOSIT_REQUEST_TYPE* = 0x00'u8
9188
WITHDRAWAL_REQUEST_TYPE* = 0x01'u8
9289
CONSOLIDATION_REQUEST_TYPE* = 0x02'u8
93-
94-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.0/specs/electra/beacon-chain.md#execution-1
95-
MAX_BLOBS_PER_BLOCK_ELECTRA* = 9'u64

beacon_chain/spec/presets.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const
3131
MESSAGE_DOMAIN_INVALID_SNAPPY*: array[4, byte] = [0x00, 0x00, 0x00, 0x00]
3232
MESSAGE_DOMAIN_VALID_SNAPPY*: array[4, byte] = [0x01, 0x00, 0x00, 0x00]
3333

34+
MAX_SUPPORTED_BLOB_SIDECAR_SUBNET_COUNT*: uint64 = 9
3435
MAX_SUPPORTED_BLOBS_PER_BLOCK*: uint64 = 9 # revisit getShortMap(Blobs) if >9
3536
MAX_SUPPORTED_REQUEST_BLOB_SIDECARS*: uint64 = 1152
3637

@@ -870,10 +871,10 @@ proc readRuntimeConfig*(
870871
checkCompatibility ATTESTATION_SUBNET_PREFIX_BITS
871872

872873
checkCompatibility MAX_REQUEST_BLOCKS_DENEB
873-
checkCompatibility BLOB_SIDECAR_SUBNET_COUNT
874-
checkCompatibility MAX_BLOBS_PER_BLOCK_ELECTRA
875874

876875
for suffix in ["", "_ELECTRA"]:
876+
checkCompatibility MAX_SUPPORTED_BLOB_SIDECAR_SUBNET_COUNT,
877+
"BLOB_SIDECAR_SUBNET_COUNT" & suffix, `<=`
877878
checkCompatibility MAX_SUPPORTED_BLOBS_PER_BLOCK,
878879
"MAX_BLOBS_PER_BLOCK" & suffix, `<=`
879880
checkCompatibility MAX_SUPPORTED_REQUEST_BLOB_SIDECARS,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# beacon_chain
2-
# Copyright (c) 2023 Status Research & Development GmbH
2+
# Copyright (c) 2023-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

8+
{.push raises: [].}
9+
810
# Gnosis preset - Deneb
9-
# https://github.com/gnosischain/specs/blob/1648fc86cef7bc148d74cb21921d2d12ca9442ac/consensus/preset/gnosis/deneb.yaml
11+
# https://github.com/gnosischain/specs/blob/31f87ac73d271762ac35b3649e7639d00c73c66d/consensus/preset/gnosis/deneb.yaml
1012
const
1113
# `uint64(4096)`
1214
FIELD_ELEMENTS_PER_BLOB*: uint64 = 4096
1315
# `uint64(2**12)` (= 4096)
1416
MAX_BLOB_COMMITMENTS_PER_BLOCK*: uint64 = 4096
15-
# `uint64(6)`
16-
MAX_BLOBS_PER_BLOCK*: uint64 = 6
1717
# `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17
1818
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH* = 17
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2023-2024 Status Research & Development GmbH
2+
# Copyright (c) 2023-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -8,13 +8,11 @@
88
{.push raises: [].}
99

1010
# Mainnet preset - Deneb
11-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/presets/mainnet/deneb.yaml
11+
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.2/presets/mainnet/deneb.yaml
1212
const
1313
# `uint64(4096)`
1414
FIELD_ELEMENTS_PER_BLOB*: uint64 = 4096
1515
# `uint64(2**12)` (= 4096)
1616
MAX_BLOB_COMMITMENTS_PER_BLOCK*: uint64 = 4096
17-
# `uint64(6)`
18-
MAX_BLOBS_PER_BLOCK*: uint64 = 6
1917
# `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17
2018
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH* = 17
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2023-2024 Status Research & Development GmbH
2+
# Copyright (c) 2023-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -8,13 +8,11 @@
88
{.push raises: [].}
99

1010
# Minimal preset - Deneb
11-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/presets/minimal/deneb.yaml
11+
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.2/presets/minimal/deneb.yaml
1212
const
1313
# `uint64(4096)`
1414
FIELD_ELEMENTS_PER_BLOB*: uint64 = 4096
1515
# [customized]
1616
MAX_BLOB_COMMITMENTS_PER_BLOCK*: uint64 = 32
17-
# `uint64(6)`
18-
MAX_BLOBS_PER_BLOCK*: uint64 = 6
1917
# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 5 = 10
2018
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH* = 10

0 commit comments

Comments
 (0)