Add `test_zeroed_commitment`
This commit is contained in:
parent
f7352d18cf
commit
847553783b
|
@ -150,3 +150,23 @@ def test_incorrect_block_hash(spec, state):
|
||||||
|
|
||||||
yield 'blocks', [signed_block]
|
yield 'blocks', [signed_block]
|
||||||
yield 'post', state
|
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
|
||||||
|
|
|
@ -50,12 +50,9 @@ class SignedBlobTransaction(Container):
|
||||||
signature: ECDSASignature
|
signature: ECDSASignature
|
||||||
|
|
||||||
|
|
||||||
def get_sample_blob(spec, rng=None):
|
def get_sample_blob(spec, rng=random.Random(5566), is_valid_blob=True):
|
||||||
if rng is None:
|
|
||||||
rng = random.Random(5566)
|
|
||||||
|
|
||||||
values = [
|
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)
|
for _ in range(spec.FIELD_ELEMENTS_PER_BLOB)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -98,15 +95,19 @@ def get_poly_in_both_forms(spec, rng=None):
|
||||||
return coeffs, evals
|
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 = []
|
blobs = []
|
||||||
blob_kzg_commitments = []
|
blob_kzg_commitments = []
|
||||||
blob_kzg_proofs = []
|
blob_kzg_proofs = []
|
||||||
blob_versioned_hashes = []
|
blob_versioned_hashes = []
|
||||||
for _ in range(blob_count):
|
for _ in range(blob_count):
|
||||||
blob = get_sample_blob(spec, rng)
|
blob = get_sample_blob(spec, rng, is_valid_blob=is_valid_blob)
|
||||||
blob_commitment = spec.KZGCommitment(spec.blob_to_kzg_commitment(blob))
|
if is_valid_blob:
|
||||||
blob_kzg_proof = spec.compute_blob_kzg_proof(blob, blob_commitment)
|
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)
|
blob_versioned_hash = spec.kzg_commitment_to_versioned_hash(blob_commitment)
|
||||||
blobs.append(blob)
|
blobs.append(blob)
|
||||||
blob_kzg_commitments.append(blob_commitment)
|
blob_kzg_commitments.append(blob_commitment)
|
||||||
|
|
Loading…
Reference in New Issue