Skip to content

Commit 313a64e

Browse files
authored
Merge pull request ethereum#3748 from ethereum/fix-get_custody_columns
Fix `get_custody_columns`
2 parents 1a5671d + c9e0e6d commit 313a64e

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

specs/_features/eip7594/das-core.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,19 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
106106
assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT
107107

108108
subnet_ids: List[uint64] = []
109-
i = 0
109+
current_id = uint256(node_id)
110110
while len(subnet_ids) < custody_subnet_count:
111-
if node_id == UINT256_MAX:
112-
node_id = NodeID(0)
113-
114111
subnet_id = (
115-
bytes_to_uint64(hash(uint_to_bytes(uint256(node_id + i)))[0:8])
112+
bytes_to_uint64(hash(uint_to_bytes(uint256(current_id)))[0:8])
116113
% DATA_COLUMN_SIDECAR_SUBNET_COUNT
117114
)
118115
if subnet_id not in subnet_ids:
119116
subnet_ids.append(subnet_id)
120-
i += 1
117+
if current_id == UINT256_MAX:
118+
# Overflow prevention
119+
current_id = NodeID(0)
120+
current_id += 1
121+
121122
assert len(subnet_ids) == len(set(subnet_ids))
122123

123124
columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT

tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py

+19
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ def test_get_custody_columns__max_node_id_max_custody_subnet_count(spec):
6565
)
6666

6767

68+
@with_eip7594_and_later
69+
@spec_test
70+
@single_phase
71+
def test_get_custody_columns__max_node_id_max_custody_subnet_count_minus_1(spec):
72+
rng = random.Random(1111)
73+
yield from _run_get_custody_columns(
74+
spec, rng, node_id=2**256 - 2,
75+
custody_subnet_count=spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT,
76+
)
77+
78+
79+
@with_eip7594_and_later
80+
@spec_test
81+
@single_phase
82+
def test_get_custody_columns__short_node_id(spec):
83+
rng = random.Random(1111)
84+
yield from _run_get_custody_columns(spec, rng, node_id=1048576, custody_subnet_count=1)
85+
86+
6887
@with_eip7594_and_later
6988
@spec_test
7089
@single_phase

tests/formats/networking/get_custody_columns.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```yaml
1010
description: string -- optional: description of test case, purely for debugging purposes.
11-
node_id: int -- argument: the NodeId input.
11+
node_id: int -- argument: the NodeID input.
1212
custody_subnet_count: int -- argument: the count of custody subnets.
1313
result: list of int -- output: the list of resulting column indices.
1414
```

0 commit comments

Comments
 (0)