mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 23:49:54 +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)
|
# 2**2 (= 4)
|
||||||
MAX_PAYLOAD_ATTESTATIONS: 4
|
MAX_PAYLOAD_ATTESTATIONS: 4
|
||||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732: 13
|
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732: 13
|
||||||
KZG_GENERALIZED_INDEX_PREFIX: 486
|
|
||||||
|
@ -7,4 +7,3 @@ PTC_SIZE: 2
|
|||||||
# 2**2 (= 4)
|
# 2**2 (= 4)
|
||||||
MAX_PAYLOAD_ATTESTATIONS: 4
|
MAX_PAYLOAD_ATTESTATIONS: 4
|
||||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732: 13
|
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
|
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
|
@classmethod
|
||||||
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
||||||
return {
|
return {
|
||||||
@ -20,8 +30,6 @@ from eth2spec.electra import {preset_name} as electra
|
|||||||
'MAX_PAYLOAD_ATTESTATIONS': spec_object.preset_vars['MAX_PAYLOAD_ATTESTATIONS'].value,
|
'MAX_PAYLOAD_ATTESTATIONS': spec_object.preset_vars['MAX_PAYLOAD_ATTESTATIONS'].value,
|
||||||
'KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732':
|
'KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732':
|
||||||
spec_object.preset_vars['KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732'].value,
|
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
|
@classmethod
|
||||||
|
@ -73,6 +73,10 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock,
|
|||||||
sidecars: List[BlobSidecar] = []
|
sidecars: List[BlobSidecar] = []
|
||||||
for index, blob in enumerate(blobs):
|
for index, blob in enumerate(blobs):
|
||||||
proof = compute_merkle_proof(
|
proof = compute_merkle_proof(
|
||||||
|
blob_kzg_commitments,
|
||||||
|
get_generalized_index(List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK], index),
|
||||||
|
)
|
||||||
|
proof += compute_merkle_proof(
|
||||||
block.body,
|
block.body,
|
||||||
get_generalized_index(
|
get_generalized_index(
|
||||||
BeaconBlockBody,
|
BeaconBlockBody,
|
||||||
@ -81,10 +85,6 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock,
|
|||||||
"blob_kzg_commitments_root",
|
"blob_kzg_commitments_root",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
proof += compute_merkle_proof(
|
|
||||||
blob_kzg_commitments,
|
|
||||||
get_generalized_index(List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK], index),
|
|
||||||
)
|
|
||||||
sidecars.append(
|
sidecars.append(
|
||||||
BlobSidecar(
|
BlobSidecar(
|
||||||
index=index,
|
index=index,
|
||||||
|
@ -36,7 +36,6 @@ This document contains the consensus-layer networking specification for EIP7732.
|
|||||||
| Name | Value | Description |
|
| 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_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
|
### Containers
|
||||||
@ -63,8 +62,17 @@ class BlobSidecar(Container):
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
def verify_blob_sidecar_inclusion_proof(blob_sidecar: BlobSidecar) -> bool:
|
def verify_blob_sidecar_inclusion_proof(blob_sidecar: BlobSidecar) -> bool:
|
||||||
# hardcoded here because the block does not include the commitments but only their root.
|
inner_gindex = get_generalized_index(
|
||||||
gindex = GeneralizedIndex(KZG_GENERALIZED_INDEX_PREFIX + blob_sidecar.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(
|
return is_valid_merkle_branch(
|
||||||
leaf=blob_sidecar.kzg_commitment.hash_tree_root(),
|
leaf=blob_sidecar.kzg_commitment.hash_tree_root(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user