Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob sidecar inclusion proof #3531

Merged
merged 31 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
530efa8
Add blob sidecar inclusion proof
dapplion Oct 27, 2023
e8bccec
remove verify_blob_sidecar_signature
dapplion Oct 27, 2023
29bbdf4
compute KZG_COMMITMENT_INCLUSION_PROOF_DEPTH
dapplion Oct 27, 2023
a4a29a1
List typo
dapplion Oct 27, 2023
3dbe54e
doctoc
dapplion Oct 27, 2023
c2a64a1
pass lint
dapplion Oct 27, 2023
caa79a5
build tree
dapplion Oct 27, 2023
8712451
Update specs/deneb/p2p-interface.md
dapplion Oct 27, 2023
f2649f6
fix unit tests
dapplion Oct 27, 2023
83e5930
doctoc
dapplion Oct 27, 2023
0bf9e75
review PR
dapplion Oct 27, 2023
26516ec
Move `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` to preset and cast `int()`
hwwhww Oct 27, 2023
1657d16
Add `BLOB_KZG_COMMITMENTS_GINDEX` to "Constant". Use pyspec parser tr…
hwwhww Oct 28, 2023
de3b6a2
Fix toc
hwwhww Oct 28, 2023
b7e0b88
Fix test
hwwhww Oct 28, 2023
b018fbc
Remove `BLOB_KZG_COMMITMENTS_GINDEX` from the preset files
hwwhww Oct 28, 2023
ae6a9eb
Fix lint
hwwhww Oct 28, 2023
0e4737e
Add a general `compute_merkle_proof` helper to replace container-spec…
hwwhww Oct 30, 2023
c680212
drop is_valid_merkle_path
dapplion Oct 30, 2023
126e807
Update specs/deneb/p2p-interface.md
dapplion Oct 30, 2023
b803f1c
Update specs/deneb/p2p-interface.md
dapplion Oct 30, 2023
d323f05
drop sidecar alias
dapplion Oct 30, 2023
a124414
Enhance `blob_sidecar_inclusion_proof` tests
hwwhww Oct 30, 2023
51343f5
Fix typing and delete the `signed_sidecar`
hwwhww Oct 30, 2023
1bac25a
Add Merkle proof test
hwwhww Oct 30, 2023
19883ec
Add verify_blob_kzg_proof condition
dapplion Oct 31, 2023
7f63f00
Merge branch 'dev' into blob-p2p-proof
dapplion Oct 31, 2023
4a609ce
rename to kzg_commitment_inclusion_proof
dapplion Nov 1, 2023
71106f1
Remove `BLOB_KZG_COMMITMENTS_GINDEX`
hwwhww Nov 2, 2023
3492c0a
minor refactoring
hwwhww Nov 2, 2023
7118c30
a few cleanups to sidecar gossip conditions
djrtwo Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions specs/deneb/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ The specification of these changes continues in the same format as the network s
| `MAX_REQUEST_BLOB_SIDECARS` | `MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK` | Maximum number of blob sidecars in a single request |
| `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `2**12` (= 4096 epochs, ~18 days) | The minimum epoch range over which a node must serve blob sidecars |
| `BLOB_SIDECAR_SUBNET_COUNT` | `6` | The number of blob sidecar subnets used in the gossipsub protocol. |
| `BLOB_KZG_COMMITMENTS_GINDEX` | `get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')` (= 27) | `blob_kzg_commitments` field gindex on `BeaconBlockBody` container |
hwwhww marked this conversation as resolved.
Show resolved Hide resolved
| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK) # noqa: E501` | Merkle proof for `blob_kzg_commitments` list item |
| `BLOB_KZG_COMMITMENTS_GINDEX` | `2**4 + 11` (= 27) | `blob_kzg_commitments` field gindex on `BeaconBlockBody` container |
dapplion marked this conversation as resolved.
Show resolved Hide resolved
| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `4 + 1 + floorlog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` | Merkle proof for `blob_kzg_commitments` list item |

### Containers

Expand Down
2 changes: 1 addition & 1 deletion specs/deneb/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock,
kzg_proof=blob_kzg_proofs[index],
commitment_inclusion_proof=compute_commitment_inclusion_proof(
dapplion marked this conversation as resolved.
Show resolved Hide resolved
dapplion marked this conversation as resolved.
Show resolved Hide resolved
block.body,
get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments', index),
get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments', index), # type: ignore
),
signed_block_header=signed_block_header,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,15 @@
get_sample_opaque_tx,
)
from eth2spec.test.helpers.block import (
build_empty_block_for_next_slot
build_empty_block_for_next_slot,
sign_block
)
from tests.core.pyspec.eth2spec.utils.ssz.ssz_impl import hash_tree_root


def get_blob_sidecars(spec, signed_block, blobs, blob_kzg_proofs):
block = signed_block.message
block_header = spec.BeaconBlockHeader(
slot=block.slot,
proposer_index=block.proposer_index,
parent_root=block.parent_root,
state_root=block.state_root,
body_root=hash_tree_root(block.body),
)
signed_block_header = spec.SignedBeaconBlockHeader(message=block_header, signature=signed_block.signature)
return [
spec.BlobSidecar(
index=index,
blob=blob,
kzg_commitment=signed_block.message.body.blob_kzg_commitments[index],
kzg_proof=blob_kzg_proofs[index],
commitment_inclusion_proof=compute_commitment_inclusion_proof(
spec,
signed_block.message.body,
index,
),
signed_block_header=signed_block_header,
)
for index, blob in enumerate(blobs)
]


def compute_commitment_inclusion_proof(spec, body, index):
gindex = spec.get_generalized_index(spec.BeaconBlockBody, 'blob_kzg_commitments', index)
return spec.build_proof(body, gindex)


@with_deneb_and_later
@spec_state_test
def test_blob_sidecar_inclusion_proof(spec, state):
def test_blob_sidecar_inclusion_proof_correct(spec, state):
"""
Test `verify_blob_sidecar_inclusion_proof`
"""
Expand All @@ -60,7 +29,8 @@ def test_blob_sidecar_inclusion_proof(spec, state):
block.body.execution_payload.transactions = [opaque_tx]
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)

blob_sidecars = spec.get_blob_sidecars(spec, block, blobs, proofs)
signed_block = sign_block(spec, state, block, proposer_index=0)
blob_sidecars = spec.get_blob_sidecars(signed_block, blobs, proofs)

for blob_sidecar in blob_sidecars:
assert spec.verify_blob_sidecar_inclusion_proof(blob_sidecar)
Expand All @@ -80,7 +50,8 @@ def test_blob_sidecar_inclusion_proof_incorrect(spec, state):
block.body.execution_payload.transactions = [opaque_tx]
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload)

blob_sidecars = spec.get_blob_sidecars(spec, block, blobs, proofs)
signed_block = sign_block(spec, state, block, proposer_index=0)
blob_sidecars = spec.get_blob_sidecars(signed_block, blobs, proofs)

for blob_sidecar in blob_sidecars:
block = blob_sidecar.signed_block_header.message
Expand Down
Loading