mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
fix Merkle proof generator
This commit is contained in:
parent
93aa7d6bee
commit
9274a66199
@ -7,4 +7,3 @@ PTC_SIZE: 512
|
||||
# 2**2 (= 4)
|
||||
MAX_PAYLOAD_ATTESTATIONS: 4
|
||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732: 13
|
||||
KZG_GENERALIZED_INDEX_PREFIX: 486
|
||||
|
@ -7,4 +7,3 @@ PTC_SIZE: 2
|
||||
# 2**2 (= 4)
|
||||
MAX_PAYLOAD_ATTESTATIONS: 4
|
||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732: 13
|
||||
KZG_GENERALIZED_INDEX_PREFIX: 486
|
||||
|
@ -13,6 +13,16 @@ class EIP7732SpecBuilder(BaseSpecBuilder):
|
||||
from eth2spec.electra import {preset_name} as electra
|
||||
'''
|
||||
|
||||
@classmethod
|
||||
def sundry_functions(cls) -> str:
|
||||
return '''
|
||||
def concat_generalized_indices(*indices: GeneralizedIndex) -> GeneralizedIndex:
|
||||
o = GeneralizedIndex(1)
|
||||
for i in indices:
|
||||
o = GeneralizedIndex(o * bit_floor(i) + (i - bit_floor(i)))
|
||||
return o'''
|
||||
|
||||
|
||||
@classmethod
|
||||
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
||||
return {
|
||||
@ -20,8 +30,6 @@ from eth2spec.electra import {preset_name} as electra
|
||||
'MAX_PAYLOAD_ATTESTATIONS': spec_object.preset_vars['MAX_PAYLOAD_ATTESTATIONS'].value,
|
||||
'KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732':
|
||||
spec_object.preset_vars['KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732'].value,
|
||||
'KZG_GENERALIZED_INDEX_PREFIX':
|
||||
spec_object.preset_vars['KZG_GENERALIZED_INDEX_PREFIX'].value,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -73,6 +73,10 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock,
|
||||
sidecars: List[BlobSidecar] = []
|
||||
for index, blob in enumerate(blobs):
|
||||
proof = compute_merkle_proof(
|
||||
blob_kzg_commitments,
|
||||
get_generalized_index(List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK], index),
|
||||
)
|
||||
proof += compute_merkle_proof(
|
||||
block.body,
|
||||
get_generalized_index(
|
||||
BeaconBlockBody,
|
||||
@ -81,10 +85,6 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock,
|
||||
"blob_kzg_commitments_root",
|
||||
),
|
||||
)
|
||||
proof += compute_merkle_proof(
|
||||
blob_kzg_commitments,
|
||||
get_generalized_index(List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK], index),
|
||||
)
|
||||
sidecars.append(
|
||||
BlobSidecar(
|
||||
index=index,
|
||||
|
@ -36,7 +36,6 @@ This document contains the consensus-layer networking specification for EIP7732.
|
||||
| Name | Value | Description |
|
||||
|------------------------------------------|-----------------------------------|---------------------------------------------------------------------|
|
||||
| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732` | `13` # TODO: Compute it when the spec stabilizes | Merkle proof depth for the `blob_kzg_commitments` list item |
|
||||
| `KZG_GENERALIZED_INDEX_PREFIX` | `486` # TODO: Compute it when the spec stabilizes | Generalized index for the first item in the `blob_kzg_commitments` list |
|
||||
|
||||
|
||||
### Containers
|
||||
@ -63,8 +62,17 @@ class BlobSidecar(Container):
|
||||
|
||||
```python
|
||||
def verify_blob_sidecar_inclusion_proof(blob_sidecar: BlobSidecar) -> bool:
|
||||
# hardcoded here because the block does not include the commitments but only their root.
|
||||
gindex = GeneralizedIndex(KZG_GENERALIZED_INDEX_PREFIX + blob_sidecar.index)
|
||||
inner_gindex = get_generalized_index(
|
||||
List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK],
|
||||
blob_sidecar.index
|
||||
)
|
||||
outer_gindex = get_generalized_index(
|
||||
BeaconBlockBody,
|
||||
"signed_execution_payload_header",
|
||||
"message",
|
||||
"blob_kzg_commitments_root",
|
||||
)
|
||||
gindex = get_subtree_index(concat_generalized_indices(outer_gindex, inner_gindex))
|
||||
|
||||
return is_valid_merkle_branch(
|
||||
leaf=blob_sidecar.kzg_commitment.hash_tree_root(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user