Add `BLOB_KZG_COMMITMENTS_GINDEX` to "Constant". Use pyspec parser trick to add assertion in pyspec
This commit is contained in:
parent
26516ec3e9
commit
1657d16afd
|
@ -8,5 +8,7 @@ FIELD_ELEMENTS_PER_BLOB: 4096
|
|||
MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096
|
||||
# `uint64(6)`
|
||||
MAX_BLOBS_PER_BLOCK: 6
|
||||
# `4 + 1 + floorlog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17
|
||||
# `get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')` = 27
|
||||
BLOB_KZG_COMMITMENTS_GINDEX: 27
|
||||
# `floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17
|
||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 17
|
||||
|
|
|
@ -8,5 +8,7 @@ FIELD_ELEMENTS_PER_BLOB: 4096
|
|||
MAX_BLOB_COMMITMENTS_PER_BLOCK: 16
|
||||
# `uint64(6)`
|
||||
MAX_BLOBS_PER_BLOCK: 6
|
||||
# [customized] `4 + 1 + floorlog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9
|
||||
# `get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')` = 27
|
||||
BLOB_KZG_COMMITMENTS_GINDEX: 27
|
||||
# [customized] `floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9
|
||||
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9
|
||||
|
|
|
@ -111,8 +111,9 @@ def objects_to_spec(preset_name: str,
|
|||
return out
|
||||
|
||||
# Merge all constant objects
|
||||
hardcoded_ssz_dep_constants = reduce(lambda obj, builder: {**obj, **builder.hardcoded_ssz_dep_constants()}, builders, {})
|
||||
hardcoded_ssz_dep_constants = reduce(lambda obj, builder: {**obj, **builder.hardcoded_ssz_dep_constants()}, builders, {})
|
||||
hardcoded_custom_type_dep_constants = reduce(lambda obj, builder: {**obj, **builder.hardcoded_custom_type_dep_constants(spec_object)}, builders, {})
|
||||
hardcoded_func_dep_presets = reduce(lambda obj, builder: {**obj, **builder.hardcoded_func_dep_presets(spec_object)}, builders, {})
|
||||
# Concatenate all strings
|
||||
imports = reduce(lambda txt, builder: (txt + "\n\n" + builder.imports(preset_name) ).strip("\n"), builders, "")
|
||||
preparations = reduce(lambda txt, builder: (txt + "\n\n" + builder.preparations() ).strip("\n"), builders, "")
|
||||
|
@ -126,6 +127,7 @@ def objects_to_spec(preset_name: str,
|
|||
ssz_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, hardcoded_ssz_dep_constants[x]), hardcoded_ssz_dep_constants))
|
||||
ssz_dep_constants_verification = '\n'.join(map(lambda x: 'assert %s == %s' % (x, spec_object.ssz_dep_constants[x]), hardcoded_ssz_dep_constants))
|
||||
custom_type_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, hardcoded_custom_type_dep_constants[x]), hardcoded_custom_type_dep_constants))
|
||||
func_dep_presets_verification = '\n'.join(map(lambda x: 'assert %s == %s # noqa: E501' % (x, spec_object.func_dep_presets[x]), hardcoded_func_dep_presets))
|
||||
spec_strs = [
|
||||
imports,
|
||||
preparations,
|
||||
|
@ -147,6 +149,7 @@ def objects_to_spec(preset_name: str,
|
|||
# Since some constants are hardcoded in setup.py, the following assertions verify that the hardcoded constants are
|
||||
# as same as the spec definition.
|
||||
ssz_dep_constants_verification,
|
||||
func_dep_presets_verification,
|
||||
]
|
||||
return "\n\n\n".join([str.strip("\n") for str in spec_strs if str]) + "\n"
|
||||
|
||||
|
@ -223,6 +226,7 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
|
|||
preset_vars = combine_dicts(spec0.preset_vars, spec1.preset_vars)
|
||||
config_vars = combine_dicts(spec0.config_vars, spec1.config_vars)
|
||||
ssz_dep_constants = combine_dicts(spec0.ssz_dep_constants, spec1.ssz_dep_constants)
|
||||
func_dep_presets = combine_dicts(spec0.func_dep_presets, spec1.func_dep_presets)
|
||||
ssz_objects = combine_ssz_objects(spec0.ssz_objects, spec1.ssz_objects, custom_types)
|
||||
dataclasses = combine_dicts(spec0.dataclasses, spec1.dataclasses)
|
||||
return SpecObject(
|
||||
|
@ -233,6 +237,7 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
|
|||
preset_vars=preset_vars,
|
||||
config_vars=config_vars,
|
||||
ssz_dep_constants=ssz_dep_constants,
|
||||
func_dep_presets=func_dep_presets,
|
||||
ssz_objects=ssz_objects,
|
||||
dataclasses=dataclasses,
|
||||
)
|
||||
|
|
|
@ -47,6 +47,10 @@ class BaseSpecBuilder(ABC):
|
|||
"""
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def hardcoded_func_dep_presets(cls, spec_object) -> Dict[str, str]:
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
|
||||
return functions
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from typing import Dict
|
||||
from .base import BaseSpecBuilder
|
||||
from ..constants import DENEB
|
||||
|
||||
|
@ -68,10 +69,22 @@ EXECUTION_ENGINE = NoopExecutionEngine()"""
|
|||
|
||||
|
||||
@classmethod
|
||||
def hardcoded_custom_type_dep_constants(cls, spec_object) -> str:
|
||||
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
|
||||
return {
|
||||
'BYTES_PER_FIELD_ELEMENT': spec_object.constant_vars['BYTES_PER_FIELD_ELEMENT'].value,
|
||||
'FIELD_ELEMENTS_PER_BLOB': spec_object.preset_vars['FIELD_ELEMENTS_PER_BLOB'].value,
|
||||
'MAX_BLOBS_PER_BLOCK': spec_object.preset_vars['MAX_BLOBS_PER_BLOCK'].value,
|
||||
'MAX_BLOB_COMMITMENTS_PER_BLOCK': spec_object.preset_vars['MAX_BLOB_COMMITMENTS_PER_BLOCK'].value,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
|
||||
return {
|
||||
'BLOB_KZG_COMMITMENTS_GINDEX': 'GeneralizedIndex(27)',
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def hardcoded_func_dep_presets(cls, spec_object) -> Dict[str, str]:
|
||||
return {
|
||||
'KZG_COMMITMENT_INCLUSION_PROOF_DEPTH': spec_object.preset_vars['KZG_COMMITMENT_INCLUSION_PROOF_DEPTH'].value,
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class SpecObject(NamedTuple):
|
|||
preset_vars: Dict[str, VariableDefinition]
|
||||
config_vars: Dict[str, VariableDefinition]
|
||||
ssz_dep_constants: Dict[str, str] # the constants that depend on ssz_objects
|
||||
func_dep_presets: Dict[str, str] # the constants that depend on functions
|
||||
ssz_objects: Dict[str, str]
|
||||
dataclasses: Dict[str, str]
|
||||
|
||||
|
|
15
setup.py
15
setup.py
|
@ -162,6 +162,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
|||
preset_vars: Dict[str, VariableDefinition] = {}
|
||||
config_vars: Dict[str, VariableDefinition] = {}
|
||||
ssz_dep_constants: Dict[str, str] = {}
|
||||
func_dep_presets: Dict[str, str] = {}
|
||||
ssz_objects: Dict[str, str] = {}
|
||||
dataclasses: Dict[str, str] = {}
|
||||
custom_types: Dict[str, str] = {}
|
||||
|
@ -214,6 +215,16 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
|||
|
||||
value_cell = cells[1]
|
||||
value = value_cell.children[0].children
|
||||
|
||||
description = None
|
||||
if len(cells) >= 3:
|
||||
description_cell = cells[2]
|
||||
if len(description_cell.children) > 0:
|
||||
description = description_cell.children[0].children
|
||||
if isinstance(description, list):
|
||||
# marko parses `**X**` as a list containing a X
|
||||
description = description[0].children
|
||||
|
||||
if isinstance(value, list):
|
||||
# marko parses `**X**` as a list containing a X
|
||||
value = value[0].children
|
||||
|
@ -228,6 +239,9 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
|||
ssz_dep_constants[name] = value
|
||||
continue
|
||||
|
||||
if description is not None and description.startswith("<!-- predefined -->"):
|
||||
func_dep_presets[name] = value
|
||||
|
||||
value_def = _parse_value(name, value)
|
||||
if name in preset:
|
||||
preset_vars[name] = VariableDefinition(value_def.type_name, preset[name], value_def.comment, None)
|
||||
|
@ -256,6 +270,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
|||
preset_vars=preset_vars,
|
||||
config_vars=config_vars,
|
||||
ssz_dep_constants=ssz_dep_constants,
|
||||
func_dep_presets=func_dep_presets,
|
||||
ssz_objects=ssz_objects,
|
||||
dataclasses=dataclasses,
|
||||
)
|
||||
|
|
|
@ -40,13 +40,21 @@ The specification of these changes continues in the same format as the network s
|
|||
|
||||
## Modifications in Deneb
|
||||
|
||||
### Constant
|
||||
|
||||
*[New in Deneb:EIP4844]*
|
||||
|
||||
| Name | Value | Description |
|
||||
|------------------------------------------|-----------------------------------|---------------------------------------------------------------------|
|
||||
| `BLOB_KZG_COMMITMENTS_GINDEX` | `get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')` (= 27) | `blob_kzg_commitments` field gindex on `BeaconBlockBody` container |
|
||||
|
||||
### Preset
|
||||
|
||||
*[New in Deneb:EIP4844]*
|
||||
|
||||
| Name | Value | Description |
|
||||
|------------------------------------------|-----------------------------------|---------------------------------------------------------------------|
|
||||
| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `int(4 + 1 + floorlog2(MAX_BLOB_COMMITMENTS_PER_BLOCK))` | Merkle proof depth for `blob_kzg_commitments` list item |
|
||||
| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `uint64(floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK))` (= 17) | <!-- predefined --> Merkle proof depth for `blob_kzg_commitments` list item |
|
||||
|
||||
### Configuration
|
||||
|
||||
|
|
Loading…
Reference in New Issue