Semantic fork versions and signature domains

Fix #706
This commit is contained in:
Justin 2019-03-08 09:57:09 +01:00 committed by GitHub
parent 8e08e742dc
commit 1f147486fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 12 deletions

View File

@ -268,12 +268,12 @@ Code snippets appearing in `this style` are to be interpreted as Python code.
| Name | Value | | Name | Value |
| - | - | | - | - |
| `DOMAIN_BEACON_BLOCK` | `0` | | `DOMAIN_BEACON_BLOCK` | `int_to_bytes4(0)` |
| `DOMAIN_RANDAO` | `1` | | `DOMAIN_RANDAO` | `int_to_bytes4(1)` |
| `DOMAIN_ATTESTATION` | `2` | | `DOMAIN_ATTESTATION` | `int_to_bytes4(2)` |
| `DOMAIN_DEPOSIT` | `3` | | `DOMAIN_DEPOSIT` | `int_to_bytes4(3)` |
| `DOMAIN_VOLUNTARY_EXIT` | `4` | | `DOMAIN_VOLUNTARY_EXIT` | `int_to_bytes4(4)` |
| `DOMAIN_TRANSFER` | `5` | | `DOMAIN_TRANSFER` | `int_to_bytes4(5)` |
## Data structures ## Data structures
@ -288,9 +288,9 @@ The types are defined topologically to aid in facilitating an executable version
```python ```python
{ {
# Previous fork version # Previous fork version
'previous_version': 'uint64', 'previous_version': 'bytes4',
# Current fork version # Current fork version
'current_version': 'uint64', 'current_version': 'bytes4',
# Fork epoch number # Fork epoch number
'epoch': 'uint64', 'epoch': 'uint64',
} }
@ -1107,7 +1107,7 @@ def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> G
```python ```python
def get_fork_version(fork: Fork, def get_fork_version(fork: Fork,
epoch: Epoch) -> int: epoch: Epoch) -> bytes8:
""" """
Return the fork version of the given ``epoch``. Return the fork version of the given ``epoch``.
""" """
@ -1122,12 +1122,11 @@ def get_fork_version(fork: Fork,
```python ```python
def get_domain(fork: Fork, def get_domain(fork: Fork,
epoch: Epoch, epoch: Epoch,
domain_type: int) -> int: domain_type: bytes4) -> bytes8:
""" """
Get the domain number that represents the fork meta and signature domain. Get the domain number that represents the fork meta and signature domain.
""" """
fork_version = get_fork_version(fork, epoch) return get_fork_version(fork, epoch) + domain_type
return fork_version * 2**32 + domain_type
``` ```
### `get_bitfield_bit` ### `get_bitfield_bit`