Merge pull request #3356 from ethereum/deneb-tests

Add `test_zeroed_commitment` test case
This commit is contained in:
Hsiao-Wei Wang 2023-05-16 21:25:40 +08:00 committed by GitHub
commit fe9c1a8cbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 9 deletions

View File

@ -150,3 +150,23 @@ def test_incorrect_block_hash(spec, state):
yield 'blocks', [signed_block]
yield 'post', state
@with_deneb_and_later
@spec_state_test
def test_zeroed_commitment(spec, state):
"""
The blob is invalid, but the commitment is in correct form.
"""
yield 'pre', state
block = build_empty_block_for_next_slot(spec, state)
opaque_tx, _, blob_kzg_commitments, _ = get_sample_opaque_tx(spec, blob_count=1, is_valid_blob=False)
assert all(commitment == b'\x00' * 48 for commitment in blob_kzg_commitments)
block.body.blob_kzg_commitments = blob_kzg_commitments
block.body.execution_payload.transactions = [opaque_tx]
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)
yield 'blocks', [signed_block]
yield 'post', state

View File

@ -50,12 +50,9 @@ class SignedBlobTransaction(Container):
signature: ECDSASignature
def get_sample_blob(spec, rng=None):
if rng is None:
rng = random.Random(5566)
def get_sample_blob(spec, rng=random.Random(5566), is_valid_blob=True):
values = [
rng.randint(0, spec.BLS_MODULUS - 1)
rng.randint(0, spec.BLS_MODULUS - 1) if is_valid_blob else spec.BLS_MODULUS
for _ in range(spec.FIELD_ELEMENTS_PER_BLOB)
]
@ -98,15 +95,19 @@ def get_poly_in_both_forms(spec, rng=None):
return coeffs, evals
def get_sample_opaque_tx(spec, blob_count=1, rng=None):
def get_sample_opaque_tx(spec, blob_count=1, rng=random.Random(5566), is_valid_blob=True):
blobs = []
blob_kzg_commitments = []
blob_kzg_proofs = []
blob_versioned_hashes = []
for _ in range(blob_count):
blob = get_sample_blob(spec, rng)
blob_commitment = spec.KZGCommitment(spec.blob_to_kzg_commitment(blob))
blob_kzg_proof = spec.compute_blob_kzg_proof(blob, blob_commitment)
blob = get_sample_blob(spec, rng, is_valid_blob=is_valid_blob)
if is_valid_blob:
blob_commitment = spec.KZGCommitment(spec.blob_to_kzg_commitment(blob))
blob_kzg_proof = spec.compute_blob_kzg_proof(blob, blob_commitment)
else:
blob_commitment = spec.KZGCommitment()
blob_kzg_proof = spec.KZGProof()
blob_versioned_hash = spec.kzg_commitment_to_versioned_hash(blob_commitment)
blobs.append(blob)
blob_kzg_commitments.append(blob_commitment)