Skip to content

Commit eb1f9d8

Browse files
authored
Merge pull request #4422 from ethereum/dev
Pull in fixes from dev for v1.6.0-alpha.3 release
2 parents eaef87d + 8cbdc86 commit eb1f9d8

File tree

3 files changed

+66
-41
lines changed

3 files changed

+66
-41
lines changed

tests/core/pyspec/eth2spec/test/fulu/fork_choice/test_on_block.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def get_alt_sidecars(spec, state):
3131
Get alternative sidecars for negative test cases.
3232
"""
3333
rng = Random(4321)
34-
_, _, _, _, alt_sidecars = get_block_with_blob_and_sidecars(spec, state, rng=rng, blob_count=2)
34+
state_copy = state.copy()
35+
_, _, _, _, alt_sidecars = get_block_with_blob_and_sidecars(
36+
spec, state_copy, rng=rng, blob_count=2
37+
)
3538
return alt_sidecars
3639

3740

@@ -55,20 +58,20 @@ def test_on_block_peerdas__ok(spec, state):
5558
assert store.time == current_time
5659

5760
# On receiving a block of `GENESIS_SLOT + 1` slot
58-
_, blobs, blob_kzg_proofs, signed_block, sidecars = get_block_with_blob_and_sidecars(
61+
_, _, _, signed_block, sidecars = get_block_with_blob_and_sidecars(
5962
spec, state, rng=rng, blob_count=2
6063
)
61-
blob_data = BlobData(blobs, blob_kzg_proofs, sidecars)
64+
blob_data = BlobData(sidecars=sidecars)
6265

6366
yield from tick_and_add_block_with_data(spec, store, signed_block, test_steps, blob_data)
6467

6568
assert spec.get_head(store) == signed_block.message.hash_tree_root()
6669

6770
# On receiving a block of next epoch
68-
_, blobs, blob_kzg_proofs, signed_block, sidecars = get_block_with_blob_and_sidecars(
71+
_, _, _, signed_block, sidecars = get_block_with_blob_and_sidecars(
6972
spec, state, rng=rng, blob_count=2
7073
)
71-
blob_data = BlobData(blobs, blob_kzg_proofs, sidecars)
74+
blob_data = BlobData(sidecars=sidecars)
7275

7376
yield from tick_and_add_block_with_data(spec, store, signed_block, test_steps, blob_data)
7477

@@ -93,11 +96,11 @@ def run_on_block_peerdas_invalid_test(spec, state, fn):
9396
on_tick_and_append_step(spec, store, current_time, test_steps)
9497
assert store.time == current_time
9598

96-
_, blobs, blob_kzg_proofs, signed_block, sidecars = get_block_with_blob_and_sidecars(
99+
_, _, _, signed_block, sidecars = get_block_with_blob_and_sidecars(
97100
spec, state, rng=rng, blob_count=2
98101
)
99102
sidecars = fn(sidecars)
100-
blob_data = BlobData(blobs, blob_kzg_proofs, [])
103+
blob_data = BlobData(sidecars=sidecars)
101104

102105
yield from tick_and_add_block_with_data(
103106
spec, store, signed_block, test_steps, blob_data, valid=False
@@ -148,7 +151,7 @@ def invalid_index(sidecars):
148151
sidecars[0].index = 128 # Invalid index
149152
return sidecars
150153

151-
run_on_block_peerdas_invalid_test(spec, state, invalid_index)
154+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_index)
152155

153156

154157
@with_fulu_and_later
@@ -162,7 +165,7 @@ def invalid_index(sidecars):
162165
sidecars[0].index = 256 # Invalid index
163166
return sidecars
164167

165-
run_on_block_peerdas_invalid_test(spec, state, invalid_index)
168+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_index)
166169

167170

168171
@with_fulu_and_later
@@ -176,7 +179,7 @@ def invalid_mismatch_len_column(sidecars):
176179
sidecars[0].column = sidecars[0].column[1:]
177180
return sidecars
178181

179-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_column)
182+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_column)
180183

181184

182185
@with_fulu_and_later
@@ -190,7 +193,7 @@ def invalid_mismatch_len_column(sidecars):
190193
sidecars[1].column = sidecars[1].column[1:]
191194
return sidecars
192195

193-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_column)
196+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_column)
194197

195198

196199
@with_fulu_and_later
@@ -204,7 +207,7 @@ def invalid_mismatch_len_kzg_commitments(sidecars):
204207
sidecars[0].kzg_commitments = sidecars[0].kzg_commitments[1:]
205208
return sidecars
206209

207-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_commitments)
210+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_commitments)
208211

209212

210213
@with_fulu_and_later
@@ -218,7 +221,7 @@ def invalid_mismatch_len_kzg_commitments(sidecars):
218221
sidecars[1].kzg_commitments = sidecars[1].kzg_commitments[1:]
219222
return sidecars
220223

221-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_commitments)
224+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_commitments)
222225

223226

224227
@with_fulu_and_later
@@ -232,7 +235,7 @@ def invalid_mismatch_len_kzg_proofs(sidecars):
232235
sidecars[0].kzg_proofs = sidecars[0].kzg_proofs[1:]
233236
return sidecars
234237

235-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_proofs)
238+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_proofs)
236239

237240

238241
@with_fulu_and_later
@@ -246,7 +249,7 @@ def invalid_mismatch_len_kzg_proofs(sidecars):
246249
sidecars[1].kzg_proofs = sidecars[1].kzg_proofs[1:]
247250
return sidecars
248251

249-
run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_proofs)
252+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_mismatch_len_kzg_proofs)
250253

251254

252255
@with_fulu_and_later
@@ -260,7 +263,7 @@ def invalid_wrong_column(sidecars):
260263
sidecars[0].column[0] = flip_one_bit_in_bytes(sidecars[0].column[0], 80)
261264
return sidecars
262265

263-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_column)
266+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_column)
264267

265268

266269
@with_fulu_and_later
@@ -274,7 +277,7 @@ def invalid_wrong_column(sidecars):
274277
sidecars[1].column[1] = flip_one_bit_in_bytes(sidecars[1].column[1], 20)
275278
return sidecars
276279

277-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_column)
280+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_column)
278281

279282

280283
@with_fulu_and_later
@@ -285,11 +288,11 @@ def test_on_block_peerdas__invalid_wrong_commitment_1(spec, state):
285288
"""
286289
alt_sidecars = get_alt_sidecars(spec, state)
287290

288-
def invalid_wrong_commitment(sidecars):
291+
def invalid_wrong_commitment(sidecars, alt_sidecars=alt_sidecars):
289292
sidecars[0].kzg_commitments[0] = alt_sidecars[0].kzg_commitments[0]
290293
return sidecars
291294

292-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_commitment)
295+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_commitment)
293296

294297

295298
@with_fulu_and_later
@@ -300,11 +303,11 @@ def test_on_block_peerdas__invalid_wrong_commitment_2(spec, state):
300303
"""
301304
alt_sidecars = get_alt_sidecars(spec, state)
302305

303-
def invalid_wrong_commitment(sidecars):
306+
def invalid_wrong_commitment(sidecars, alt_sidecars=alt_sidecars):
304307
sidecars[1].kzg_commitments[1] = alt_sidecars[1].kzg_commitments[1]
305308
return sidecars
306309

307-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_commitment)
310+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_commitment)
308311

309312

310313
@with_fulu_and_later
@@ -315,11 +318,11 @@ def test_on_block_peerdas__invalid_wrong_proof_1(spec, state):
315318
"""
316319
alt_sidecars = get_alt_sidecars(spec, state)
317320

318-
def invalid_wrong_proof(sidecars):
321+
def invalid_wrong_proof(sidecars, alt_sidecars=alt_sidecars):
319322
sidecars[0].kzg_proofs[0] = alt_sidecars[0].kzg_proofs[0]
320323
return sidecars
321324

322-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_proof)
325+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_proof)
323326

324327

325328
@with_fulu_and_later
@@ -330,8 +333,8 @@ def test_on_block_peerdas__invalid_wrong_proof_2(spec, state):
330333
"""
331334
alt_sidecars = get_alt_sidecars(spec, state)
332335

333-
def invalid_wrong_proof(sidecars):
336+
def invalid_wrong_proof(sidecars, alt_sidecars=alt_sidecars):
334337
sidecars[1].kzg_proofs[1] = alt_sidecars[1].kzg_proofs[1]
335338
return sidecars
336339

337-
run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_proof)
340+
yield from run_on_block_peerdas_invalid_test(spec, state, invalid_wrong_proof)

tests/core/pyspec/eth2spec/test/helpers/fork_choice.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ class BlobData(NamedTuple):
3030
The return values of ``retrieve_blobs_and_proofs`` helper.
3131
"""
3232

33-
blobs: Sequence[Any]
33+
blobs: Sequence[Any] | None = None
3434
proofs: Sequence[bytes] | None = None
3535
sidecars: Sequence[DataColumnSidecar] | None = None
3636

37+
def is_post_fulu(self):
38+
return self.sidecars is not None and self.blobs is None and self.proofs is None
39+
40+
def is_pre_fulu(self):
41+
return self.blobs is not None and self.proofs is not None and self.sidecars is None
42+
3743

3844
def with_blob_data(spec, blob_data: BlobData, func):
3945
if not is_post_fulu(spec):
@@ -245,7 +251,7 @@ def get_sidecar_file_name(sidecar: DataColumnSidecar) -> str:
245251
"""
246252
Returns the file name for a single sidecar.
247253
"""
248-
return f"sidecar_{encode_hex(sidecar.hash_tree_root())}"
254+
return f"column_{encode_hex(sidecar.hash_tree_root())}"
249255

250256

251257
def on_tick_and_append_step(spec, store, time, test_steps):
@@ -292,25 +298,32 @@ def add_block(
292298

293299
# Check blob_data
294300
if blob_data is not None:
295-
blobs = spec.List[spec.Blob, spec.MAX_BLOB_COMMITMENTS_PER_BLOCK](blob_data.blobs)
296-
blobs_root = blobs.hash_tree_root()
297-
yield get_blobs_file_name(blobs_root=blobs_root), blobs
301+
assert blob_data.is_pre_fulu() or blob_data.is_post_fulu(), "Integrity fail blob_data"
302+
303+
if blob_data.is_pre_fulu():
304+
blobs = spec.List[spec.Blob, spec.MAX_BLOB_COMMITMENTS_PER_BLOCK](blob_data.blobs)
305+
blobs_root = blobs.hash_tree_root()
306+
yield get_blobs_file_name(blobs_root=blobs_root), blobs
298307

299-
if blob_data.sidecars is not None:
308+
if blob_data.is_post_fulu():
300309
for sidecar in blob_data.sidecars:
301310
yield get_sidecar_file_name(sidecar), sidecar
302311

303312
def _append_step(valid=True):
304313
if blob_data is not None:
305-
step = {
306-
"block": get_block_file_name(signed_block),
307-
"blobs": get_blobs_file_name(blobs_root=blobs_root),
308-
"valid": valid,
309-
}
310-
if blob_data.proofs is not None:
311-
step["proofs"] = [encode_hex(proof) for proof in blob_data.proofs]
312-
if blob_data.sidecars is not None:
313-
step["sidecars"] = get_sidecars_file_names(blob_data.sidecars)
314+
if blob_data.is_post_fulu():
315+
step = {
316+
"block": get_block_file_name(signed_block),
317+
"columns": get_sidecars_file_names(blob_data.sidecars),
318+
"valid": valid,
319+
}
320+
if blob_data.is_pre_fulu():
321+
step = {
322+
"block": get_block_file_name(signed_block),
323+
"blobs": get_blobs_file_name(blobs_root=blobs_root),
324+
"proofs": [encode_hex(proof) for proof in blob_data.proofs],
325+
"valid": valid,
326+
}
314327

315328
test_steps.append(step)
316329
else:

tests/formats/fork_choice/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The parameter that is required for executing `on_block(store, block)`.
9292
blobs: string -- optional, the name of the `blobs_<32-byte-root>.ssz_snappy` file.
9393
The blobs file content is a `List[Blob, MAX_BLOB_COMMITMENTS_PER_BLOCK]` SSZ object.
9494
proofs: array of byte48 hex string -- optional, the proofs of blob commitments.
95-
sidecars: string -- optional, array of the names of the `sidecar_<32-byte-root>.ssz_snappy` files.
95+
columns: string -- optional, array of the names of the `column_<32-byte-root>.ssz_snappy` files.
9696
valid: bool -- optional, default to `true`.
9797
If it's `false`, this execution step is expected to be invalid.
9898
}
@@ -105,6 +105,15 @@ the expected values from `retrieve_blobs_and_proofs()` helper inside
105105
`is_data_available()` helper. If these two fields are not provided,
106106
`retrieve_blobs_and_proofs()` returns empty lists.
107107

108+
`columns` is a new field in Fulu EIP-7594. This field indicate the expected
109+
values from `retrieve_column_sidecars` helper inside `is_data_available()`
110+
helper. If this field is an empty array, `retrieve_column_sidecars` should throw
111+
an exception (not enough data sampled). If this field is not provided,
112+
`retrieve_column_sidecars` returns an empty list.
113+
114+
Post-Deneb and pre-Fulu, `columns` should not be present. Post-Fulu `blobs` and
115+
`proofs` should not be present.
116+
108117
After this step, the `store` object may have been updated.
109118

110119
#### `on_merge_block` execution step

0 commit comments

Comments
 (0)