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

Executable EIP-4844 specs #2901

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9811b94
Trying to include EIP-4844 specs to pyspec
hwwhww May 24, 2022
af7898e
WIP. Add kzg.py
hwwhww May 24, 2022
238464d
Rename `SHARDING_FORK_VERSION` to `SHARDING_FORK_VERSION` and fix tests
hwwhww May 31, 2022
29b27b3
Add `test-eip4844` CI job
hwwhww May 31, 2022
15fe4c9
Fix lint
hwwhww May 31, 2022
edb3894
Merge branch 'dev' into eip4844-exe
hwwhww Jun 20, 2022
7324b90
PR feedback from @asn-d6
hwwhww Jun 20, 2022
1a3929d
Merge branch 'dev' into eip4844-exe
hwwhww Jun 29, 2022
60fdcac
Fix bugs and include all EIP-4844 files to executable scope
hwwhww Jun 29, 2022
b8cbfe5
To avoid confusion with SSZ vector, rename `vector_lincomb` -> `matri…
hwwhww Jun 30, 2022
33829dd
Fix eip4844 state transition functions
hwwhww Jul 1, 2022
79b4d77
Add validator unittest to check `verify_blobs_sidecar`.
hwwhww Jul 1, 2022
13d7c06
Fix `matrix_lincomb`: add int() casting to avoid SSZ overflow/underflow
hwwhww Jul 4, 2022
41c5646
Fix `is_data_available` return value
hwwhww Jul 4, 2022
23afa60
Add KZGProof generation helpers to validator.md and polynomial-commit…
hwwhww Jul 4, 2022
f16ca66
Function arguments clean up. Add a link of proto's explainer.
hwwhww Jul 5, 2022
0f17a95
Fix typo `compute_kzg_single` -> `compute_kzg_proof`
hwwhww Jul 5, 2022
71bb4bf
Remove redundant `BLS_MODULUS`
hwwhww Jul 5, 2022
36cdab5
Fix test
hwwhww Jul 5, 2022
ec7f607
Renaming KZGCommitment object `kzg` -> `commitment`
hwwhww Jul 6, 2022
247850a
Use full name `kzg_commitment` instead of `commitment`
hwwhww Jul 6, 2022
418b93d
Change evaluation point variable from `x` to `z` in poly functions
asn-d6 Jul 11, 2022
57d12d8
Compute KZG proof directly from evaluation form
asn-d6 Jul 8, 2022
d4af93d
Fix ToC
hwwhww Jul 13, 2022
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
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,19 @@ jobs:
command: make citest fork=capella
- store_test_results:
path: tests/core/pyspec/test-reports

test-eip4844:
docker:
- image: circleci/python:3.8
working_directory: ~/specs-repo
steps:
- restore_cache:
key: v3-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_pyspec_cached_venv
- run:
name: Run py-tests
command: make citest fork=eip4844
- store_test_results:
path: tests/core/pyspec/test-reports
table_of_contents:
docker:
- image: circleci/node:10.16.3
Expand Down Expand Up @@ -260,6 +272,9 @@ workflows:
- test-capella:
requires:
- install_pyspec_test
- test-eip4844:
requires:
- install_pyspec_test
- table_of_contents
- codespell
- lint:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tests/core/pyspec/eth2spec/phase0/
tests/core/pyspec/eth2spec/altair/
tests/core/pyspec/eth2spec/bellatrix/
tests/core/pyspec/eth2spec/capella/
tests/core/pyspec/eth2spec/eip4844/

# coverage reports
.htmlcov
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ codespell:
lint: pyspec
. venv/bin/activate; cd $(PY_SPEC_DIR); \
flake8 --config $(LINTER_CONFIG_FILE) ./eth2spec \
&& pylint --disable=all --enable unused-argument ./eth2spec/phase0 ./eth2spec/altair ./eth2spec/bellatrix \
&& pylint --disable=all --enable unused-argument ./eth2spec/phase0 ./eth2spec/altair ./eth2spec/bellatrix ./eth2spec/capella \
&& mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.altair -p eth2spec.bellatrix -p eth2spec.capella

lint_generators: pyspec
Expand Down
6 changes: 3 additions & 3 deletions configs/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ BELLATRIX_FORK_EPOCH: 18446744073709551615
# Capella
CAPELLA_FORK_VERSION: 0x03000000
CAPELLA_FORK_EPOCH: 18446744073709551615
# Sharding
SHARDING_FORK_VERSION: 0x04000000
SHARDING_FORK_EPOCH: 18446744073709551615
# EIP4844
EIP4844_FORK_VERSION: 0x04000000
EIP4844_FORK_EPOCH: 18446744073709551615



Expand Down
6 changes: 3 additions & 3 deletions configs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ BELLATRIX_FORK_EPOCH: 18446744073709551615
# Capella
CAPELLA_FORK_VERSION: 0x03000001
CAPELLA_FORK_EPOCH: 18446744073709551615
# Sharding
SHARDING_FORK_VERSION: 0x04000001
SHARDING_FORK_EPOCH: 18446744073709551615
# EIP4844
EIP4844_FORK_VERSION: 0x04000001
EIP4844_FORK_EPOCH: 18446744073709551615


# Time parameters
Expand Down
8 changes: 8 additions & 0 deletions presets/mainnet/eip4844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mainnet preset - Phase0

# Misc
# ---------------------------------------------------------------
# `uint64(4096)`
FIELD_ELEMENTS_PER_BLOB: 4096
# `uint64(2**4)` (= 16)
MAX_BLOBS_PER_BLOCK: 16
8 changes: 8 additions & 0 deletions presets/minimal/eip4844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Minimal preset - Phase0

# Misc
# ---------------------------------------------------------------
# [customized]
FIELD_ELEMENTS_PER_BLOB: 4
# `uint64(2**4)` (= 16)
MAX_BLOBS_PER_BLOCK: 16
79 changes: 67 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def installPackage(package: str):
ALTAIR = 'altair'
BELLATRIX = 'bellatrix'
CAPELLA = 'capella'
EIP4844 = 'eip4844'


# The helper functions that are used when defining constants
Expand Down Expand Up @@ -208,6 +209,9 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str]) ->
elif source.startswith("class"):
class_name, parent_class = _get_class_info_from_source(source)
# check consistency with spec
if class_name != current_name:
print('class_name', class_name, 'current_name', current_name)

assert class_name == current_name
if parent_class:
assert parent_class == "Container"
Expand All @@ -230,7 +234,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str]) ->

if not _is_constant_id(name):
# Check for short type declarations
if value.startswith(("uint", "Bytes", "ByteList", "Union")):
if value.startswith(("uint", "Bytes", "ByteList", "Union", "Vector", "List")):
custom_types[name] = value
continue

Expand Down Expand Up @@ -304,7 +308,7 @@ def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:

@classmethod
@abstractmethod
def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]: # TODO
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]: # TODO
"""
The constants that are required for custom types.
"""
Expand Down Expand Up @@ -432,7 +436,7 @@ def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
return {}

@classmethod
def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]:
def hardcoded_custom_type_dep_constants(cls, spec_object) -> Dict[str, str]:
return {}

@classmethod
Expand Down Expand Up @@ -547,11 +551,11 @@ def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> ExecutionPayloa


@classmethod
def hardcoded_custom_type_dep_constants(cls) -> str:
def hardcoded_custom_type_dep_constants(cls, spec_object) -> str:
constants = {
'MAX_BYTES_PER_TRANSACTION': 'uint64(2**30)',
'MAX_BYTES_PER_TRANSACTION': spec_object.preset_vars['MAX_BYTES_PER_TRANSACTION'].value,
}
return {**super().hardcoded_custom_type_dep_constants(), **constants}
return {**super().hardcoded_custom_type_dep_constants(spec_object), **constants}


#
Expand All @@ -567,14 +571,57 @@ def imports(cls, preset_name: str):
'''


#
# EIP4844SpecBuilder
#
class EIP4844SpecBuilder(BellatrixSpecBuilder):
fork: str = EIP4844

@classmethod
def imports(cls, preset_name: str):
return super().imports(preset_name) + f'''
from eth2spec.utils import kzg
from eth2spec.bellatrix import {preset_name} as bellatrix
'''

@classmethod
def sundry_functions(cls) -> str:
return super().sundry_functions() + '''
# TODO: for mainnet, load pre-generated trusted setup file to reduce building time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a py_ecc-based insecure trusted setup you might want to use for this purpose: https://github.com/asn-d6/kzgverify/blob/playground/trusted_setup.py (and corresponding json files on same directory)

# TESTING_FIELD_ELEMENTS_PER_BLOB is hardcoded copy from minimal presets
TESTING_FIELD_ELEMENTS_PER_BLOB = 4
TESTING_SECRET = 1337
TESTING_KZG_SETUP_G1 = kzg.generate_setup(bls.G1, TESTING_SECRET, TESTING_FIELD_ELEMENTS_PER_BLOB)
TESTING_KZG_SETUP_G2 = kzg.generate_setup(bls.G2, TESTING_SECRET, TESTING_FIELD_ELEMENTS_PER_BLOB)
TESTING_KZG_SETUP_LAGRANGE = kzg.get_lagrange(TESTING_KZG_SETUP_G1)

KZG_SETUP_G1 = [bls.G1_to_bytes48(p) for p in TESTING_KZG_SETUP_G1]
KZG_SETUP_G2 = [bls.G2_to_bytes96(p) for p in TESTING_KZG_SETUP_G2]
KZG_SETUP_LAGRANGE = TESTING_KZG_SETUP_LAGRANGE
ROOTS_OF_UNITY = kzg.compute_roots_of_unity(TESTING_FIELD_ELEMENTS_PER_BLOB)


def retrieve_blobs_sidecar(slot: Slot, beacon_block_root: Root) -> BlobsSidecar:
pass'''

@classmethod
def hardcoded_custom_type_dep_constants(cls, spec_object) -> str:
constants = {
'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,
}
return {**super().hardcoded_custom_type_dep_constants(spec_object), **constants}



spec_builders = {
builder.fork: builder
for builder in (Phase0SpecBuilder, AltairSpecBuilder, BellatrixSpecBuilder, CapellaSpecBuilder)
for builder in (Phase0SpecBuilder, AltairSpecBuilder, BellatrixSpecBuilder, CapellaSpecBuilder, EIP4844SpecBuilder)
}


def is_spec_defined_type(value: str) -> bool:
return value.startswith('ByteList') or value.startswith('Union')
return value.startswith(('ByteList', 'Union', 'Vector', 'List'))


def objects_to_spec(preset_name: str,
Expand Down Expand Up @@ -652,7 +699,7 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
ordered_class_objects_spec = '\n\n\n'.join(ordered_class_objects.values())
ssz_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, builder.hardcoded_ssz_dep_constants()[x]), builder.hardcoded_ssz_dep_constants()))
ssz_dep_constants_verification = '\n'.join(map(lambda x: 'assert %s == %s' % (x, spec_object.ssz_dep_constants[x]), builder.hardcoded_ssz_dep_constants()))
custom_type_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, builder.hardcoded_custom_type_dep_constants()[x]), builder.hardcoded_custom_type_dep_constants()))
custom_type_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, builder.hardcoded_custom_type_dep_constants(spec_object)[x]), builder.hardcoded_custom_type_dep_constants(spec_object)))
spec = (
builder.imports(preset_name)
+ builder.preparations()
Expand Down Expand Up @@ -869,14 +916,14 @@ def finalize_options(self):
if len(self.md_doc_paths) == 0:
print("no paths were specified, using default markdown file paths for pyspec"
" build (spec fork: %s)" % self.spec_fork)
if self.spec_fork in (PHASE0, ALTAIR, BELLATRIX, CAPELLA):
if self.spec_fork in (PHASE0, ALTAIR, BELLATRIX, CAPELLA, EIP4844):
self.md_doc_paths = """
specs/phase0/beacon-chain.md
specs/phase0/fork-choice.md
specs/phase0/validator.md
specs/phase0/weak-subjectivity.md
"""
if self.spec_fork in (ALTAIR, BELLATRIX, CAPELLA):
if self.spec_fork in (ALTAIR, BELLATRIX, CAPELLA, EIP4844):
self.md_doc_paths += """
specs/altair/beacon-chain.md
specs/altair/bls.md
Expand All @@ -885,7 +932,7 @@ def finalize_options(self):
specs/altair/p2p-interface.md
specs/altair/sync-protocol.md
"""
if self.spec_fork in (BELLATRIX, CAPELLA):
if self.spec_fork in (BELLATRIX, CAPELLA, EIP4844):
self.md_doc_paths += """
specs/bellatrix/beacon-chain.md
specs/bellatrix/fork.md
Expand All @@ -901,6 +948,14 @@ def finalize_options(self):
specs/capella/validator.md
specs/capella/p2p-interface.md
"""
if self.spec_fork == EIP4844:
self.md_doc_paths += """
specs/eip4844/beacon-chain.md
specs/eip4844/fork.md
specs/eip4844/polynomial-commitments.md
specs/eip4844/p2p-interface.md
specs/eip4844/validator.md
"""
if len(self.md_doc_paths) == 0:
raise Exception('no markdown files specified, and spec fork "%s" is unknown', self.spec_fork)

Expand Down
Loading