From b772b03847d90e52b5c0f79df893f416b655fb6f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 15 Jun 2019 17:23:44 -0400 Subject: [PATCH] Handle `BLSPubkey` and `BLSSignature` --- scripts/build_spec.py | 14 ++++++++------ scripts/function_puller.py | 2 +- specs/core/0_beacon-chain.md | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 6bcb04656..8f0048b8f 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -142,8 +142,10 @@ def objects_to_spec(functions: Dict[str, str], '\n\n'.join( [ f"class {key}({value}):\n" - f" def __init__(self, _x: uint64) -> None:\n" + f" def __init__(self, _x: {value}) -> None:\n" f" ...\n" + if value.startswith("uint") + else f"class {key}({value}):\n pass\n" for key, value in custom_types.items() ] ) @@ -185,7 +187,7 @@ def combine_constants(old_constants: Dict[str, str], new_constants: Dict[str, st return old_constants -def dependency_order_ssz_objects(objects: Dict[str, str]) -> None: +def dependency_order_ssz_objects(objects: Dict[str, str], custom_types: Dict[str, str]) -> None: """ Determines which SSZ Object is depenedent on which other and orders them appropriately """ @@ -194,14 +196,14 @@ def dependency_order_ssz_objects(objects: Dict[str, str]) -> None: dependencies = re.findall(r'(: [A-Z][\w[]*)', value) dependencies = map(lambda x: re.sub(r'\W|Vector|List|Container|uint\d+|Bytes\d+|bytes', '', x), dependencies) for dep in dependencies: - if dep in NEW_TYPES or len(dep) == 0: + if dep in custom_types or len(dep) == 0: continue key_list = list(objects.keys()) for item in [dep, key] + key_list[key_list.index(dep)+1:]: objects[item] = objects.pop(item) -def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str]) -> Dict[str, str]: +def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str], custom_types) -> Dict[str, str]: """ Takes in old spec and new spec ssz objects, combines them, and returns the newer versions of the objects in dependency order. @@ -213,7 +215,7 @@ def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str] # remove leading variable name value = re.sub(r'^class [\w]*\(Container\):\n', '', value) old_objects[key] = old_objects.get(key, '') + value - dependency_order_ssz_objects(old_objects) + dependency_order_ssz_objects(old_objects, custom_types) return old_objects @@ -230,7 +232,7 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject: functions = combine_functions(functions0, functions1) custom_types = combine_constants(custom_types0, custom_types1) constants = combine_constants(constants0, constants1) - ssz_objects = combine_ssz_objects(ssz_objects0, ssz_objects1) + ssz_objects = combine_ssz_objects(ssz_objects0, ssz_objects1, custom_types) inserts = combine_inserts(inserts0, inserts1) return functions, custom_types, constants, ssz_objects, inserts diff --git a/scripts/function_puller.py b/scripts/function_puller.py index 4ad9eef57..0fd2fa476 100644 --- a/scripts/function_puller.py +++ b/scripts/function_puller.py @@ -73,7 +73,7 @@ def get_spec(file_name: str) -> SpecObject: row[i] = row[i].strip().strip('`') if '`' in row[i]: row[i] = row[i][:row[i].find('`')] - if row[1].startswith('uint') or row[1].startswith('bytes'): + if row[1].startswith('uint') or row[1].startswith('Bytes'): custom_types[row[0]] = row[1] else: eligible = True diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 8baba6928..a45da2872 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -294,7 +294,7 @@ class Fork(Container): ```python class Validator(Container): # BLS public key - pubkey: Bytes48 + pubkey: BLSPubkey # Withdrawal credentials withdrawal_credentials: Bytes32 # Epoch when became eligible for activation @@ -363,7 +363,7 @@ class IndexedAttestation(Container): # Attestation data data: AttestationData # Aggregate signature - signature: Bytes96 + signature: BLSSignature ``` #### `PendingAttestation` @@ -407,13 +407,13 @@ class HistoricalBatch(Container): ```python class DepositData(Container): # BLS pubkey - pubkey: Bytes48 + pubkey: BLSPubkey # Withdrawal credentials withdrawal_credentials: Bytes32 # Amount in Gwei amount: Gwei # Container self-signature - signature: Bytes96 + signature: BLSSignature ``` #### `BeaconBlockHeader` @@ -424,7 +424,7 @@ class BeaconBlockHeader(Container): parent_root: Bytes32 state_root: Bytes32 body_root: Bytes32 - signature: Bytes96 + signature: BLSSignature ``` ### Beacon operations @@ -462,7 +462,7 @@ class Attestation(Container): # Custody bitfield custody_bitfield: bytes # BLS aggregate signature - signature: Bytes96 + signature: BLSSignature ``` #### `Deposit` @@ -484,7 +484,7 @@ class VoluntaryExit(Container): # Index of the exiting validator validator_index: ValidatorIndex # Validator signature - signature: Bytes96 + signature: BLSSignature ``` #### `Transfer` @@ -502,9 +502,9 @@ class Transfer(Container): # Inclusion slot slot: Slot # Sender withdrawal pubkey - pubkey: Bytes48 + pubkey: BLSPubkey # Sender signature - signature: Bytes96 + signature: BLSSignature ``` ### Beacon blocks @@ -513,7 +513,7 @@ class Transfer(Container): ```python class BeaconBlockBody(Container): - randao_reveal: Bytes96 + randao_reveal: BLSSignature eth1_data: Eth1Data graffiti: Bytes32 proposer_slashings: List[ProposerSlashing] @@ -533,7 +533,7 @@ class BeaconBlock(Container): parent_root: Bytes32 state_root: Bytes32 body: BeaconBlockBody - signature: Bytes96 + signature: BLSSignature ``` ### Beacon state