Handle BLSPubkey and BLSSignature

This commit is contained in:
Hsiao-Wei Wang 2019-06-15 17:23:44 -04:00
parent 00a68e28b5
commit b772b03847
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
3 changed files with 20 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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