Merge pull request #1251 from ethereum/last-minute-cleanups-2

#1244 without "5 slots is a `Slot`"
This commit is contained in:
Danny Ryan 2019-06-30 22:22:23 -05:00 committed by GitHub
commit 82d3c4f606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 41 additions and 47 deletions

View File

@ -44,7 +44,7 @@ EFFECTIVE_BALANCE_INCREMENT: 1000000000
GENESIS_FORK_VERSION: 0x00000000 GENESIS_FORK_VERSION: 0x00000000
# 0, GENESIS_EPOCH is derived from this constant # 0, GENESIS_EPOCH is derived from this constant
GENESIS_SLOT: 0 GENESIS_SLOT: 0
BLS_WITHDRAWAL_PREFIX: 0 BLS_WITHDRAWAL_PREFIX: 0x00
# Time parameters # Time parameters

View File

@ -43,7 +43,7 @@ EFFECTIVE_BALANCE_INCREMENT: 1000000000
GENESIS_FORK_VERSION: 0x00000000 GENESIS_FORK_VERSION: 0x00000000
# 0, GENESIS_EPOCH is derived from this constant # 0, GENESIS_EPOCH is derived from this constant
GENESIS_SLOT: 0 GENESIS_SLOT: 0
BLS_WITHDRAWAL_PREFIX: 0 BLS_WITHDRAWAL_PREFIX: 0x00
# Time parameters # Time parameters

View File

@ -25,7 +25,7 @@ from eth2spec.utils.ssz.ssz_impl import (
) )
from eth2spec.utils.ssz.ssz_typing import ( from eth2spec.utils.ssz.ssz_typing import (
bit, boolean, Container, List, Vector, uint64, bit, boolean, Container, List, Vector, uint64,
Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, Bytes1, Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
) )
from eth2spec.utils.bls import ( from eth2spec.utils.bls import (
bls_aggregate_pubkeys, bls_aggregate_pubkeys,
@ -53,7 +53,7 @@ from eth2spec.utils.ssz.ssz_impl import (
) )
from eth2spec.utils.ssz.ssz_typing import ( from eth2spec.utils.ssz.ssz_typing import (
bit, boolean, Container, List, Vector, Bytes, uint64, bit, boolean, Container, List, Vector, Bytes, uint64,
Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, Bytes1, Bytes4, Bytes8, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
) )
from eth2spec.utils.bls import ( from eth2spec.utils.bls import (
bls_aggregate_pubkeys, bls_aggregate_pubkeys,
@ -185,7 +185,7 @@ def combine_constants(old_constants: Dict[str, str], new_constants: Dict[str, st
ignored_dependencies = [ ignored_dependencies = [
'bit', 'boolean', 'Vector', 'List', 'Container', 'Hash', 'BLSPubkey', 'BLSSignature', 'Bytes', 'BytesN' 'bit', 'boolean', 'Vector', 'List', 'Container', 'Hash', 'BLSPubkey', 'BLSSignature', 'Bytes', 'BytesN'
'Bytes4', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector', 'Bytes1', 'Bytes4', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector',
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256', 'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
'bytes' # to be removed after updating spec doc 'bytes' # to be removed after updating spec doc
] ]

View File

@ -74,15 +74,14 @@ def get_spec(file_name: str) -> SpecObject:
row[i] = row[i].strip().strip('`') row[i] = row[i].strip().strip('`')
if '`' in row[i]: if '`' in row[i]:
row[i] = row[i][:row[i].find('`')] row[i] = row[i][:row[i].find('`')]
if row[1].startswith('uint') or row[1].startswith('Bytes'): is_constant_def = True
custom_types[row[0]] = row[1]
else:
eligible = True
if row[0][0] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_': if row[0][0] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_':
eligible = False is_constant_def = False
for c in row[0]: for c in row[0]:
if c not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789': if c not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789':
eligible = False is_constant_def = False
if eligible: if is_constant_def:
constants[row[0]] = row[1].replace('**TBD**', '0x1234567890123456789012345678901234567890') constants[row[0]] = row[1].replace('**TBD**', '0x1234567890123456789012345678901234567890')
elif row[1].startswith('uint') or row[1].startswith('Bytes'):
custom_types[row[0]] = row[1]
return functions, custom_types, constants, ssz_objects, inserts return functions, custom_types, constants, ssz_objects, inserts

View File

@ -19,7 +19,7 @@
- [State list lengths](#state-list-lengths) - [State list lengths](#state-list-lengths)
- [Rewards and penalties](#rewards-and-penalties) - [Rewards and penalties](#rewards-and-penalties)
- [Max operations per block](#max-operations-per-block) - [Max operations per block](#max-operations-per-block)
- [Signature domains](#signature-domains) - [Signature domain types](#signature-domain-types)
- [Containers](#containers) - [Containers](#containers)
- [Misc dependencies](#misc-dependencies) - [Misc dependencies](#misc-dependencies)
- [`Fork`](#fork) - [`Fork`](#fork)
@ -164,6 +164,8 @@ The following values are (non-configurable) constants used throughout the specif
| `BASE_REWARDS_PER_EPOCH` | `5` | | `BASE_REWARDS_PER_EPOCH` | `5` |
| `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) | | `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) |
| `SECONDS_PER_DAY` | `86400` | | `SECONDS_PER_DAY` | `86400` |
| `JUSTIFICATION_BITS_LENGTH` | `4` |
| `ENDIANNESS` | `'little'` |
## Configuration ## Configuration
@ -181,8 +183,6 @@ The following values are (non-configurable) constants used throughout the specif
| `SHUFFLE_ROUND_COUNT` | `90` | | `SHUFFLE_ROUND_COUNT` | `90` |
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) | | `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) |
| `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) | | `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) |
| `JUSTIFICATION_BITS_LENGTH` | `4` |
| `ENDIANNESS` | `'little'` |
- For the safety of crosslinks, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.) - For the safety of crosslinks, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.)
@ -201,7 +201,7 @@ The following values are (non-configurable) constants used throughout the specif
| - | - | | - | - |
| `GENESIS_SLOT` | `Slot(0)` | | `GENESIS_SLOT` | `Slot(0)` |
| `GENESIS_EPOCH` | `Epoch(0)` | | `GENESIS_EPOCH` | `Epoch(0)` |
| `BLS_WITHDRAWAL_PREFIX` | `0` | | `BLS_WITHDRAWAL_PREFIX` | `Bytes1(b'\x00')` |
### Time parameters ### Time parameters
@ -218,8 +218,6 @@ The following values are (non-configurable) constants used throughout the specif
| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours | | `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours |
| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | epochs | 25.6 minutes | | `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | epochs | 25.6 minutes |
- `MAX_EPOCHS_PER_CROSSLINK` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`.
### State list lengths ### State list lengths
| Name | Value | Unit | Duration | | Name | Value | Unit | Duration |
@ -227,7 +225,7 @@ The following values are (non-configurable) constants used throughout the specif
| `EPOCHS_PER_HISTORICAL_VECTOR` | `2**16` (= 65,536) | epochs | ~0.8 years | | `EPOCHS_PER_HISTORICAL_VECTOR` | `2**16` (= 65,536) | epochs | ~0.8 years |
| `EPOCHS_PER_SLASHINGS_VECTOR` | `2**13` (= 8,192) | epochs | ~36 days | | `EPOCHS_PER_SLASHINGS_VECTOR` | `2**13` (= 8,192) | epochs | ~36 days |
| `HISTORICAL_ROOTS_LIMIT` | `2**24` (= 16,777,216) | historical roots | ~26,131 years | | `HISTORICAL_ROOTS_LIMIT` | `2**24` (= 16,777,216) | historical roots | ~26,131 years |
| `VALIDATOR_REGISTRY_LIMIT` | `2**40` (= 1,099,511,627,776) | validator spots | | | `VALIDATOR_REGISTRY_LIMIT` | `2**40` (= 1,099,511,627,776) | validator spots |
### Rewards and penalties ### Rewards and penalties
@ -547,7 +545,7 @@ class BeaconState(Container):
#### `integer_squareroot` #### `integer_squareroot`
```python ```python
def integer_squareroot(n: uint64) -> int: def integer_squareroot(n: uint64) -> uint64:
""" """
Return the largest integer ``x`` such that ``x**2 <= n``. Return the largest integer ``x`` such that ``x**2 <= n``.
""" """
@ -570,17 +568,17 @@ def xor(bytes1: Bytes32, bytes2: Bytes32) -> Bytes32:
``` ```
```python ```python
def int_to_bytes(integer: uint64, length: uint64) -> bytes: def int_to_bytes(n: uint64, length: uint64) -> bytes:
""" """
Return the ``length``-byte serialization of ``integer``. Return the ``length``-byte serialization of ``n``.
""" """
return integer.to_bytes(length, ENDIANNESS) return n.to_bytes(length, ENDIANNESS)
``` ```
#### `bytes_to_int` #### `bytes_to_int`
```python ```python
def bytes_to_int(data: bytes) -> int: def bytes_to_int(data: bytes) -> uint64:
""" """
Return the integer deserialization of ``data``. Return the integer deserialization of ``data``.
""" """
@ -715,7 +713,6 @@ def compute_shuffled_index(index: ValidatorIndex, index_count: uint64, seed: Has
Return the shuffled validator index corresponding to ``seed`` (and ``index_count``). Return the shuffled validator index corresponding to ``seed`` (and ``index_count``).
""" """
assert index < index_count assert index < index_count
assert index_count <= 2**40
# Swap or not (https://link.springer.com/content/pdf/10.1007%2F978-3-642-32009-5_1.pdf) # Swap or not (https://link.springer.com/content/pdf/10.1007%2F978-3-642-32009-5_1.pdf)
# See the 'generalized domain' algorithm on page 3 # See the 'generalized domain' algorithm on page 3
@ -853,7 +850,7 @@ def get_active_validator_indices(state: BeaconState, epoch: Epoch) -> Sequence[V
#### `get_validator_churn_limit` #### `get_validator_churn_limit`
```python ```python
def get_validator_churn_limit(state: BeaconState) -> int: def get_validator_churn_limit(state: BeaconState) -> uint64:
""" """
Return the validator churn limit for the current epoch. Return the validator churn limit for the current epoch.
""" """
@ -876,7 +873,7 @@ def get_seed(state: BeaconState, epoch: Epoch) -> Hash:
#### `get_committee_count` #### `get_committee_count`
```python ```python
def get_committee_count(state: BeaconState, epoch: Epoch) -> int: def get_committee_count(state: BeaconState, epoch: Epoch) -> uint64:
""" """
Return the number of committees at ``epoch``. Return the number of committees at ``epoch``.
""" """
@ -921,7 +918,7 @@ def get_start_shard(state: BeaconState, epoch: Epoch) -> Shard:
#### `get_shard_delta` #### `get_shard_delta`
```python ```python
def get_shard_delta(state: BeaconState, epoch: Epoch) -> int: def get_shard_delta(state: BeaconState, epoch: Epoch) -> uint64:
""" """
Return the number of shards to increment ``state.start_shard`` at ``epoch``. Return the number of shards to increment ``state.start_shard`` at ``epoch``.
""" """
@ -1699,7 +1696,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
if pubkey not in validator_pubkeys: if pubkey not in validator_pubkeys:
# Verify the deposit signature (proof of possession) for new validators. # Verify the deposit signature (proof of possession) for new validators.
# Note: The deposit contract does not check signatures. # Note: The deposit contract does not check signatures.
# Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_domain` # Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_domain`.
domain = compute_domain(DOMAIN_DEPOSIT) domain = compute_domain(DOMAIN_DEPOSIT)
if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, domain): if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, domain):
return return
@ -1759,10 +1756,7 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
state.balances[transfer.sender] >= transfer.amount + transfer.fee + MAX_EFFECTIVE_BALANCE state.balances[transfer.sender] >= transfer.amount + transfer.fee + MAX_EFFECTIVE_BALANCE
) )
# Verify that the pubkey is valid # Verify that the pubkey is valid
assert ( assert state.validators[transfer.sender].withdrawal_credentials == BLS_WITHDRAWAL_PREFIX + hash(transfer.pubkey)[1:]
state.validators[transfer.sender].withdrawal_credentials ==
int_to_bytes(BLS_WITHDRAWAL_PREFIX, length=1) + hash(transfer.pubkey)[1:]
)
# Verify that the signature is valid # Verify that the signature is valid
assert bls_verify(transfer.pubkey, signing_root(transfer), transfer.signature, get_domain(state, DOMAIN_TRANSFER)) assert bls_verify(transfer.pubkey, signing_root(transfer), transfer.signature, get_domain(state, DOMAIN_TRANSFER))
# Process the transfer # Process the transfer

View File

@ -48,8 +48,8 @@ The amount of ETH (rounded down to the closest Gwei) sent to the deposit contrac
One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawing validator balance (e.g. to another validator, or to shards). The first byte of `withdrawal_credentials` is a version number. As of now, the only expected format is as follows: One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawing validator balance (e.g. to another validator, or to shards). The first byte of `withdrawal_credentials` is a version number. As of now, the only expected format is as follows:
- `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE` * `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX`
- `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey * `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey
The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage. The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage.

View File

@ -87,8 +87,8 @@ A secondary withdrawal private key, `withdrawal_privkey`, must also be securely
The validator constructs their `withdrawal_credentials` via the following: The validator constructs their `withdrawal_credentials` via the following:
- Set `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE`. * Set `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX`.
- Set `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]`. * Set `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]`.
### Submit deposit ### Submit deposit

View File

@ -62,7 +62,7 @@ def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False
pubkey = pubkeys[validator_index] pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index] privkey = privkeys[validator_index]
# insecurely use pubkey as withdrawal key if no credentials provided # insecurely use pubkey as withdrawal key if no credentials provided
withdrawal_credentials = spec.int_to_bytes(spec.BLS_WITHDRAWAL_PREFIX, length=1) + spec.hash(pubkey)[1:] withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:]
deposit, root, deposit_data_list = build_deposit( deposit, root, deposit_data_list = build_deposit(
spec, spec,
None, None,
@ -89,7 +89,7 @@ def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_c
# insecurely use pubkey as withdrawal key if no credentials provided # insecurely use pubkey as withdrawal key if no credentials provided
if withdrawal_credentials is None: if withdrawal_credentials is None:
withdrawal_credentials = spec.int_to_bytes(spec.BLS_WITHDRAWAL_PREFIX, length=1) + spec.hash(pubkey)[1:] withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:]
deposit, root, deposit_data_list = build_deposit( deposit, root, deposit_data_list = build_deposit(
spec, spec,

View File

@ -6,7 +6,7 @@ from eth2spec.utils.ssz.ssz_typing import List
def build_mock_validator(spec, i: int, balance: int): def build_mock_validator(spec, i: int, balance: int):
pubkey = pubkeys[i] pubkey = pubkeys[i]
# insecurely use pubkey as withdrawal key as well # insecurely use pubkey as withdrawal key as well
withdrawal_credentials = spec.int_to_bytes(spec.BLS_WITHDRAWAL_PREFIX, length=1) + spec.hash(pubkey)[1:] withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:]
return spec.Validator( return spec.Validator(
pubkey=pubkeys[i], pubkey=pubkeys[i],
withdrawal_credentials=withdrawal_credentials, withdrawal_credentials=withdrawal_credentials,

View File

@ -34,7 +34,7 @@ def get_valid_transfer(spec, state, slot=None, sender_index=None,
# ensure withdrawal_credentials reproducible # ensure withdrawal_credentials reproducible
state.validators[transfer.sender].withdrawal_credentials = ( state.validators[transfer.sender].withdrawal_credentials = (
spec.int_to_bytes(spec.BLS_WITHDRAWAL_PREFIX, length=1) + spec.hash(transfer.pubkey)[1:] spec.BLS_WITHDRAWAL_PREFIX + spec.hash(transfer.pubkey)[1:]
) )
return transfer return transfer

View File

@ -131,7 +131,7 @@ def test_invalid_sig_top_up(spec, state):
def test_invalid_withdrawal_credentials_top_up(spec, state): def test_invalid_withdrawal_credentials_top_up(spec, state):
validator_index = 0 validator_index = 0
amount = spec.MAX_EFFECTIVE_BALANCE // 4 amount = spec.MAX_EFFECTIVE_BALANCE // 4
withdrawal_credentials = spec.int_to_bytes(spec.BLS_WITHDRAWAL_PREFIX, length=1) + spec.hash(b"junk")[1:] withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(b"junk")[1:]
deposit = prepare_state_and_deposit( deposit = prepare_state_and_deposit(
spec, spec,
state, state,

View File

@ -495,7 +495,8 @@ class BytesN(BaseBytes):
return True return True
# Helpers for common BytesN types. # Helpers for common BytesN types
Bytes1: BytesType = BytesN[1]
Bytes4: BytesType = BytesN[4] Bytes4: BytesType = BytesN[4]
Bytes8: BytesType = BytesN[8] Bytes8: BytesType = BytesN[8]
Bytes32: BytesType = BytesN[32] Bytes32: BytesType = BytesN[32]