Skip to content

Commit

Permalink
Start to reintroduce types
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia committed Sep 24, 2024
1 parent 21df5b1 commit 1d1e31b
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 84 deletions.
2 changes: 2 additions & 0 deletions pysetup/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
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, "")
classes = reduce(lambda txt, builder: (txt + "\n\n" + builder.classes() ).strip("\n"), builders, "")
preparations = reduce(lambda txt, builder: (txt + "\n\n" + builder.preparations() ).strip("\n"), builders, "")
sundry_functions = reduce(lambda txt, builder: (txt + "\n\n" + builder.sundry_functions() ).strip("\n"), builders, "")
# Keep engine from the most recent fork
Expand All @@ -142,6 +143,7 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
func_dep_presets_verification = '\n'.join(map(lambda x: 'assert %s == %s # noqa: E501' % (x, spec_object.func_dep_presets[x]), filtered_hardcoded_func_dep_presets))
spec_strs = [
imports,
classes,
preparations,
f"fork = \'{fork}\'\n",
# The helper functions that some SSZ containers require. Need to be defined before `custom_type_dep_constants`
Expand Down
7 changes: 7 additions & 0 deletions pysetup/spec_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def imports(cls, preset_name: str) -> str:
"""
return ""

@classmethod
def classes(cls) -> str:
"""
Define special classes.
"""
return ""

@classmethod
def preparations(cls) -> str:
"""
Expand Down
15 changes: 15 additions & 0 deletions pysetup/spec_builders/deneb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ def imports(cls, preset_name: str):
from eth2spec.capella import {preset_name} as capella
'''

@classmethod
def classes(cls):
return f'''
class BLSFieldElement(bls.Scalar):
pass
class Polynomial(list):
def __init__(self, evals: Optional[Sequence[BLSFieldElement]] = None):
if evals is None:
evals = [BLSFieldElement(0)] * 4096
if len(evals) != 4096:
raise ValueError("expected 4096 evals")
super().__init__(evals)
'''

@classmethod
def preparations(cls):
Expand Down
26 changes: 26 additions & 0 deletions pysetup/spec_builders/eip7594.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ def imports(cls, preset_name: str):
'''


@classmethod
def classes(cls):
return f'''
class PolynomialCoeff(list):
def __init__(self, coeffs: Sequence[BLSFieldElement]):
super().__init__(coeffs)
class Coset(list):
def __init__(self, coeffs: Optional[Sequence[BLSFieldElement]] = None):
if coeffs is None:
coeffs = [BLSFieldElement(0)] * 64
if len(coeffs) != 64:
raise ValueError("expected 64 coeffs")
super().__init__(coeffs)
class CosetEvals(list):
def __init__(self, evals: Optional[Sequence[BLSFieldElement]] = None):
if evals is None:
evals = [BLSFieldElement(0)] * 64
if len(evals) != 64:
raise ValueError("expected 64 evals")
super().__init__(evals)
'''

@classmethod
def sundry_functions(cls) -> str:
return """
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def run(self):
RUAMEL_YAML_VERSION,
"lru-dict==1.2.0",
MARKO_VERSION,
"py_arkworks_bls12381==0.3.5",
"py_arkworks_bls12381==0.3.8",
"curdleproofs==0.1.2",
]
)
Loading

0 comments on commit 1d1e31b

Please sign in to comment.