mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-26 01:05:15 +00:00
Add proofs to validate_blobs_and_kzg_commitments
This commit is contained in:
parent
5e74c51411
commit
29b5309f7d
@ -44,7 +44,7 @@ Note: This API is *unstable*. `get_blobs_and_kzg_commitments` and `get_payload`
|
|||||||
Implementers may also retrieve blobs individually per transaction.
|
Implementers may also retrieve blobs individually per transaction.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_blobs_and_kzg_commitments(payload_id: PayloadId) -> Tuple[Sequence[BLSFieldElement], Sequence[KZGCommitment]]:
|
def get_blobs_and_kzg_commitments(payload_id: PayloadId) -> Tuple[Sequence[BLSFieldElement], Sequence[KZGCommitment], Sequence[KZGProof]]:
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
@ -66,13 +66,14 @@ use the `payload_id` to retrieve `blobs` and `blob_kzg_commitments` via `get_blo
|
|||||||
```python
|
```python
|
||||||
def validate_blobs_and_kzg_commitments(execution_payload: ExecutionPayload,
|
def validate_blobs_and_kzg_commitments(execution_payload: ExecutionPayload,
|
||||||
blobs: Sequence[Blob],
|
blobs: Sequence[Blob],
|
||||||
blob_kzg_commitments: Sequence[KZGCommitment]) -> None:
|
blob_kzg_commitments: Sequence[KZGCommitment],
|
||||||
|
blob_kzg_proofs: Sequence[KZGProof]) -> None:
|
||||||
# Optionally sanity-check that the KZG commitments match the versioned hashes in the transactions
|
# Optionally sanity-check that the KZG commitments match the versioned hashes in the transactions
|
||||||
assert verify_kzg_commitments_against_transactions(execution_payload.transactions, blob_kzg_commitments)
|
assert verify_kzg_commitments_against_transactions(execution_payload.transactions, blob_kzg_commitments)
|
||||||
|
|
||||||
# Optionally sanity-check that the KZG commitments match the blobs (as produced by the execution engine)
|
# Optionally sanity-check that the KZG commitments match the blobs (as produced by the execution engine)
|
||||||
assert len(blob_kzg_commitments) == len(blobs)
|
assert len(blob_kzg_commitments) == len(blobs) == len(blob_kzg_proofs)
|
||||||
assert all(blob_to_kzg_commitment(blob) == commitment for blob, commitment in zip(blobs, blob_kzg_commitments))
|
assert verify_blob_kzg_proof_batch(blobs, blob_kzg_commitments, blob_kzg_proofs)
|
||||||
```
|
```
|
||||||
|
|
||||||
3. If valid, set `block.body.blob_kzg_commitments = blob_kzg_commitments`.
|
3. If valid, set `block.body.blob_kzg_commitments = blob_kzg_commitments`.
|
||||||
|
@ -53,14 +53,15 @@ def test_validate_blobs_and_kzg_commitments(spec, state):
|
|||||||
block.body.blob_kzg_commitments = blob_kzg_commitments
|
block.body.blob_kzg_commitments = blob_kzg_commitments
|
||||||
block.body.execution_payload.transactions = [opaque_tx]
|
block.body.execution_payload.transactions = [opaque_tx]
|
||||||
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
|
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)
|
||||||
# state_transition_and_sign_block(spec, state, block)
|
|
||||||
|
|
||||||
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
||||||
blobs = [sidecar.blob for sidecar in blob_sidecars]
|
blobs = [sidecar.blob for sidecar in blob_sidecars]
|
||||||
|
proofs = [sidecar.kzg_proof for sidecar in blob_sidecars]
|
||||||
|
|
||||||
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
||||||
blobs,
|
blobs,
|
||||||
blob_kzg_commitments)
|
blob_kzg_commitments,
|
||||||
|
proofs)
|
||||||
|
|
||||||
|
|
||||||
@with_deneb_and_later
|
@with_deneb_and_later
|
||||||
@ -79,11 +80,39 @@ def test_validate_blobs_and_kzg_commitments_missing_blob(spec, state):
|
|||||||
|
|
||||||
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
||||||
blobs = [sidecar.blob for sidecar in blob_sidecars][:-1]
|
blobs = [sidecar.blob for sidecar in blob_sidecars][:-1]
|
||||||
|
proofs = [sidecar.kzg_proof for sidecar in blob_sidecars]
|
||||||
|
|
||||||
expect_assertion_error(lambda:
|
expect_assertion_error(lambda:
|
||||||
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
||||||
blobs,
|
blobs,
|
||||||
blob_kzg_commitments)
|
blob_kzg_commitments,
|
||||||
|
proofs)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_deneb_and_later
|
||||||
|
@spec_state_test
|
||||||
|
def test_validate_blobs_and_kzg_commitments_missing_proof(spec, state):
|
||||||
|
"""
|
||||||
|
Test `validate_blobs_and_kzg_commitments`
|
||||||
|
"""
|
||||||
|
blob_count = 4
|
||||||
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
opaque_tx, blobs, blob_kzg_commitments = get_sample_opaque_tx(spec, blob_count=blob_count)
|
||||||
|
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)
|
||||||
|
# state_transition_and_sign_block(spec, state, block)
|
||||||
|
|
||||||
|
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
||||||
|
blobs = [sidecar.blob for sidecar in blob_sidecars]
|
||||||
|
proofs = [sidecar.kzg_proof for sidecar in blob_sidecars][:-1]
|
||||||
|
|
||||||
|
expect_assertion_error(lambda:
|
||||||
|
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
||||||
|
blobs,
|
||||||
|
blob_kzg_commitments,
|
||||||
|
proofs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -103,11 +132,13 @@ def test_validate_blobs_and_kzg_commitments_incorrect_blob(spec, state):
|
|||||||
|
|
||||||
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
blob_sidecars = spec.get_blob_sidecars(block, blobs)
|
||||||
blobs = [sidecar.blob for sidecar in blob_sidecars]
|
blobs = [sidecar.blob for sidecar in blob_sidecars]
|
||||||
|
proofs = [sidecar.kzg_proof for sidecar in blob_sidecars]
|
||||||
|
|
||||||
blobs[1] = spec.Blob(blobs[1][:13] + bytes([(blobs[1][13] + 1) % 256]) + blobs[1][14:])
|
blobs[1] = spec.Blob(blobs[1][:13] + bytes([(blobs[1][13] + 1) % 256]) + blobs[1][14:])
|
||||||
|
|
||||||
expect_assertion_error(lambda:
|
expect_assertion_error(lambda:
|
||||||
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
spec.validate_blobs_and_kzg_commitments(block.body.execution_payload,
|
||||||
blobs,
|
blobs,
|
||||||
blob_kzg_commitments)
|
blob_kzg_commitments,
|
||||||
|
proofs)
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user