From 9b5e18b61c22e3f3356468cc0ba2191d46aba1c3 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 20:51:10 +0100 Subject: [PATCH 01/12] Last minute cleanups --- scripts/build_spec.py | 6 +- specs/core/0_beacon-chain.md | 58 +++++++++---------- specs/core/0_deposit-contract.md | 2 +- specs/validator/0_beacon-chain-validator.md | 2 +- .../pyspec/eth2spec/utils/ssz/ssz_typing.py | 3 +- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index fe66a72d5..f0c849e85 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -26,7 +26,7 @@ from eth2spec.utils.ssz.ssz_impl import ( ) from eth2spec.utils.ssz.ssz_typing import ( bit, boolean, Container, List, Vector, uint64, - Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, + Bytes1, Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, ) from eth2spec.utils.bls import ( bls_aggregate_pubkeys, @@ -53,7 +53,7 @@ from eth2spec.utils.ssz.ssz_impl import ( ) from eth2spec.utils.ssz.ssz_typing import ( bit, boolean, Container, List, Vector, Bytes, uint64, - Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, + Bytes1, Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector, ) from eth2spec.utils.bls import ( bls_aggregate_pubkeys, @@ -175,7 +175,7 @@ def combine_constants(old_constants: Dict[str, str], new_constants: Dict[str, st ignored_dependencies = [ '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', 'bytes' # to be removed after updating spec doc ] diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 68915177c..b0857b213 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -161,6 +161,7 @@ The following values are (non-configurable) constants used throughout the specif | `BASE_REWARDS_PER_EPOCH` | `5` | | `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) | | `SECONDS_PER_DAY` | `86400` | +| `JUSTIFICATION_BITS_LENGTH` | `4` | ## Configuration @@ -176,10 +177,9 @@ The following values are (non-configurable) constants used throughout the specif | `MIN_PER_EPOCH_CHURN_LIMIT` | `2**2` (= 4) | | `CHURN_LIMIT_QUOTIENT` | `2**16` (= 65,536) | | `SHUFFLE_ROUND_COUNT` | `90` | +| `ENDIANNESS` | `'little'` | | `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) | | `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.) @@ -202,28 +202,26 @@ The following values are (non-configurable) constants used throughout the specif ### Time parameters -| Name | Value | Unit | Duration | +| Name | Value | Duration | | - | - | :-: | :-: | -| `MIN_ATTESTATION_INCLUSION_DELAY` | `2**0` (= 1) | slots | 6 seconds | -| `SLOTS_PER_EPOCH` | `2**6` (= 64) | slots | 6.4 minutes | -| `MIN_SEED_LOOKAHEAD` | `2**0` (= 1) | epochs | 6.4 minutes | -| `ACTIVATION_EXIT_DELAY` | `2**2` (= 4) | epochs | 25.6 minutes | -| `SLOTS_PER_ETH1_VOTING_PERIOD` | `2**10` (= 1,024) | slots | ~1.7 hours | -| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | slots | ~13 hours | -| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | epochs | ~27 hours | -| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | epochs | 9 days | -| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours | -| `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`. +| `MIN_ATTESTATION_INCLUSION_DELAY` | `Slot(2**0)` (= 1) | 6 seconds | +| `SLOTS_PER_EPOCH` | `Slot(2**6)` (= 64) | 6.4 minutes | +| `MIN_SEED_LOOKAHEAD` | `Epoch(2**0)` (= 1) | 6.4 minutes | +| `ACTIVATION_EXIT_DELAY` | `Epoch(2**2)` (= 4) | 25.6 minutes | +| `SLOTS_PER_ETH1_VOTING_PERIOD` | `Slot(2**10)` (= 1,024) | ~1.7 hours | +| `SLOTS_PER_HISTORICAL_ROOT` | `Slot(2**13)` (= 8,192) | ~13 hours | +| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `Epoch(2**8)` (= 256) | ~27 hours | +| `PERSISTENT_COMMITTEE_PERIOD` | `Epoch(2**11)` (= 2,048) | 9 days | +| `MAX_EPOCHS_PER_CROSSLINK` | `Epoch(2**6)` (= 64) | ~7 hours | +| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `Epoch(2**2)` (= 4) | 25.6 minutes | ### State list lengths -| Name | Value | Unit | Duration | +| Name | Value | Duration | | - | - | :-: | :-: | -| `EPOCHS_PER_HISTORICAL_VECTOR` | `2**16` (= 65,536) | epochs | ~0.8 years | -| `EPOCHS_PER_SLASHINGS_VECTOR` | `2**13` (= 8,192) | epochs | ~36 days | -| `HISTORICAL_ROOTS_LIMIT` | `2**24` (= 16,777,216) | historical roots | ~26,131 years | +| `EPOCHS_PER_HISTORICAL_VECTOR` | `Epoch(2**16)` (= 65,536) | ~0.8 years | +| `EPOCHS_PER_SLASHINGS_VECTOR` | `Epoch(2**13)` (= 8,192) | ~36 days | +| `HISTORICAL_ROOTS_LIMIT` | `2**24` (= 16,777,216) | ~26,131 years | | `VALIDATOR_REGISTRY_LIMIT` | `2**40` (= 1,099,511,627,776) | validator spots | | ### Rewards and penalties @@ -541,7 +539,7 @@ class BeaconState(Container): #### `integer_squareroot` ```python -def integer_squareroot(n: uint64) -> int: +def integer_squareroot(n: uint64) -> uint64: """ Return the largest integer ``x`` such that ``x**2 <= n``. """ @@ -564,17 +562,17 @@ def xor(bytes1: Bytes32, bytes2: Bytes32) -> Bytes32: ``` ```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` ```python -def bytes_to_int(data: bytes) -> int: +def bytes_to_int(data: bytes) -> uint64: """ Return the integer deserialization of ``data``. """ @@ -767,7 +765,7 @@ def compute_activation_exit_epoch(epoch: Epoch) -> Epoch: #### `bls_domain` ```python -def bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: +def bls_domain(domain_type: uint64, fork_version: Version=Version()) -> int: """ Return the BLS domain for the ``domain_type`` and ``fork_version``. """ @@ -841,7 +839,7 @@ def get_active_validator_indices(state: BeaconState, epoch: Epoch) -> Sequence[V #### `get_validator_churn_limit` ```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. """ @@ -865,7 +863,7 @@ def get_seed(state: BeaconState, epoch: Epoch) -> Hash: #### `get_committee_count` ```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``. """ @@ -910,7 +908,7 @@ def get_start_shard(state: BeaconState, epoch: Epoch) -> Shard: #### `get_shard_delta` ```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``. """ @@ -1675,8 +1673,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: amount = deposit.data.amount validator_pubkeys = [v.pubkey for v in state.validators] if pubkey not in validator_pubkeys: - # Verify the deposit signature (proof of possession) for new validators. - # Note: The deposit contract does not check signatures. + # Verify the deposit signature (proof of possession) for new validators + # Note: The deposit contract does not check signatures # Note: Deposits are valid across forks, hence the deposit domain is retrieved directly from `bls_domain` if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, bls_domain(DOMAIN_DEPOSIT)): return diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index 0efc15f25..7dee6a998 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -48,7 +48,7 @@ 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: -* `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 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. diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 0b6857a72..66abe5e2e 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -86,7 +86,7 @@ Validator public keys are [G1 points](../bls_signature.md#g1-points) on the [BLS A secondary withdrawal private key, `withdrawal_privkey`, must also be securely generated along with the resultant `withdrawal_pubkey`. This `withdrawal_privkey` does not have to be available for signing during the normal lifetime of a validator and can live in "cold storage". 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:]`. ### Submit deposit diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index d87a22399..cec43fc6d 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -495,7 +495,8 @@ class BytesN(BaseBytes): return True -# Helpers for common BytesN types. +# Helpers for common BytesN types +Bytes1: BytesType = BytesN[1] Bytes4: BytesType = BytesN[4] Bytes32: BytesType = BytesN[32] Bytes48: BytesType = BytesN[48] From e4a225ba68f08b73a1ccab2ec572cacd467a78ed Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 20:51:44 +0100 Subject: [PATCH 02/12] BLS_WITHDRAWAL_PREFIX a Bytes1 --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b0857b213..81b02c9ab 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -198,7 +198,7 @@ The following values are (non-configurable) constants used throughout the specif | - | - | | `GENESIS_SLOT` | `Slot(0)` | | `GENESIS_EPOCH` | `Epoch(0)` | -| `BLS_WITHDRAWAL_PREFIX` | `0` | +| `BLS_WITHDRAWAL_PREFIX` | `Bytes1()` | ### Time parameters From f1931c030fe4d5cb712b6c075d86b199627c8e21 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 20:56:55 +0100 Subject: [PATCH 03/12] Fix --- specs/core/0_beacon-chain.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 81b02c9ab..bcd0737c3 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1734,10 +1734,7 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None: state.balances[transfer.sender] >= transfer.amount + transfer.fee + MAX_EFFECTIVE_BALANCE ) # Verify that the pubkey is valid - assert ( - state.validators[transfer.sender].withdrawal_credentials == - int_to_bytes(BLS_WITHDRAWAL_PREFIX, length=1) + hash(transfer.pubkey)[1:] - ) + assert state.validators[transfer.sender].withdrawal_credentials == BLS_WITHDRAWAL_PREFIX + hash(transfer.pubkey)[1:] # Verify that the signature is valid assert bls_verify(transfer.pubkey, signing_root(transfer), transfer.signature, get_domain(state, DOMAIN_TRANSFER)) # Process the transfer From cf59c303f022a01db5ffe7e2149259a7541e455f Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 22:50:01 +0100 Subject: [PATCH 04/12] Remove index_count --- specs/core/0_beacon-chain.md | 1 - 1 file changed, 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index bcd0737c3..8a90bc2f4 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -668,7 +668,6 @@ def shuffle_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> Val Return the shuffled validator index corresponding to ``seed`` (and ``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) # See the 'generalized domain' algorithm on page 3 From 9df17f54941c10baca7599270aa034565705eb53 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 22:58:02 +0100 Subject: [PATCH 05/12] Explitcit zero byte --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 8a90bc2f4..71566baab 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -198,7 +198,7 @@ The following values are (non-configurable) constants used throughout the specif | - | - | | `GENESIS_SLOT` | `Slot(0)` | | `GENESIS_EPOCH` | `Epoch(0)` | -| `BLS_WITHDRAWAL_PREFIX` | `Bytes1()` | +| `BLS_WITHDRAWAL_PREFIX` | `Bytes1(b'\x00')` | ### Time parameters From 5398281a1fdc084f2851de3bb4a1f872e85471b3 Mon Sep 17 00:00:00 2001 From: protolambda Date: Mon, 1 Jul 2019 00:20:31 +0200 Subject: [PATCH 06/12] fix typed constants in spec func puller --- scripts/function_puller.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/function_puller.py b/scripts/function_puller.py index 36dd5b81f..26671bafc 100644 --- a/scripts/function_puller.py +++ b/scripts/function_puller.py @@ -74,15 +74,14 @@ 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'): + is_constant_def = True + if row[0][0] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_': + is_constant_def = False + for c in row[0]: + if c not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789': + is_constant_def = False + if is_constant_def: + constants[row[0]] = row[1].replace('**TBD**', '0x1234567890123456789012345678901234567890') + elif row[1].startswith('uint') or row[1].startswith('Bytes'): custom_types[row[0]] = row[1] - else: - eligible = True - if row[0][0] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_': - eligible = False - for c in row[0]: - if c not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789': - eligible = False - if eligible: - constants[row[0]] = row[1].replace('**TBD**', '0x1234567890123456789012345678901234567890') return functions, custom_types, constants, ssz_objects, inserts From 393c583d06a7f0d7e34135276506ac4551cc2636 Mon Sep 17 00:00:00 2001 From: protolambda Date: Mon, 1 Jul 2019 00:21:19 +0200 Subject: [PATCH 07/12] move endianness to be a constant --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 71566baab..c8e1b22b7 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -162,6 +162,7 @@ The following values are (non-configurable) constants used throughout the specif | `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) | | `SECONDS_PER_DAY` | `86400` | | `JUSTIFICATION_BITS_LENGTH` | `4` | +| `ENDIANNESS` | `'little'` | ## Configuration @@ -177,7 +178,6 @@ The following values are (non-configurable) constants used throughout the specif | `MIN_PER_EPOCH_CHURN_LIMIT` | `2**2` (= 4) | | `CHURN_LIMIT_QUOTIENT` | `2**16` (= 65,536) | | `SHUFFLE_ROUND_COUNT` | `90` | -| `ENDIANNESS` | `'little'` | | `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) | | `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) | From fdd1fd5b2c598298d20e56653174c5f5f1ef2f3a Mon Sep 17 00:00:00 2001 From: protolambda Date: Mon, 1 Jul 2019 00:26:46 +0200 Subject: [PATCH 08/12] make config values reflect the withdrawal prefix is a byte --- configs/constant_presets/mainnet.yaml | 2 +- configs/constant_presets/minimal.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/constant_presets/mainnet.yaml b/configs/constant_presets/mainnet.yaml index 629badcee..6ce6ec7f7 100644 --- a/configs/constant_presets/mainnet.yaml +++ b/configs/constant_presets/mainnet.yaml @@ -44,7 +44,7 @@ EFFECTIVE_BALANCE_INCREMENT: 1000000000 GENESIS_FORK_VERSION: 0x00000000 # 0, GENESIS_EPOCH is derived from this constant GENESIS_SLOT: 0 -BLS_WITHDRAWAL_PREFIX: 0 +BLS_WITHDRAWAL_PREFIX: 0x00 # Time parameters diff --git a/configs/constant_presets/minimal.yaml b/configs/constant_presets/minimal.yaml index 1d0ad015d..fd9684a0c 100644 --- a/configs/constant_presets/minimal.yaml +++ b/configs/constant_presets/minimal.yaml @@ -43,7 +43,7 @@ EFFECTIVE_BALANCE_INCREMENT: 1000000000 GENESIS_FORK_VERSION: 0x00000000 # 0, GENESIS_EPOCH is derived from this constant GENESIS_SLOT: 0 -BLS_WITHDRAWAL_PREFIX: 0 +BLS_WITHDRAWAL_PREFIX: 0x00 # Time parameters From b7e87338127901755ebe6977f526fa76dcd2b00b Mon Sep 17 00:00:00 2001 From: protolambda Date: Mon, 1 Jul 2019 00:36:24 +0200 Subject: [PATCH 09/12] fix usage of bls withdrawal byte in tests --- test_libs/pyspec/eth2spec/test/helpers/deposits.py | 4 ++-- test_libs/pyspec/eth2spec/test/helpers/genesis.py | 2 +- test_libs/pyspec/eth2spec/test/helpers/transfers.py | 2 +- .../test/phase_0/block_processing/test_process_deposit.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/helpers/deposits.py b/test_libs/pyspec/eth2spec/test/helpers/deposits.py index 4f099be9d..fccba9aa2 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/deposits.py +++ b/test_libs/pyspec/eth2spec/test/helpers/deposits.py @@ -62,7 +62,7 @@ def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False pubkey = pubkeys[validator_index] privkey = privkeys[validator_index] # 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( spec, 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 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( spec, diff --git a/test_libs/pyspec/eth2spec/test/helpers/genesis.py b/test_libs/pyspec/eth2spec/test/helpers/genesis.py index a5a816977..1589b6ae8 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/genesis.py +++ b/test_libs/pyspec/eth2spec/test/helpers/genesis.py @@ -6,7 +6,7 @@ from eth2spec.utils.ssz.ssz_typing import List def build_mock_validator(spec, i: int, balance: int): pubkey = pubkeys[i] # 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( pubkey=pubkeys[i], withdrawal_credentials=withdrawal_credentials, diff --git a/test_libs/pyspec/eth2spec/test/helpers/transfers.py b/test_libs/pyspec/eth2spec/test/helpers/transfers.py index fa01a3088..3d3b0f4e3 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/transfers.py +++ b/test_libs/pyspec/eth2spec/test/helpers/transfers.py @@ -34,7 +34,7 @@ def get_valid_transfer(spec, state, slot=None, sender_index=None, # ensure withdrawal_credentials reproducible 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 diff --git a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_deposit.py b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_deposit.py index 54a284a6e..3dbbeedf0 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_deposit.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_deposit.py @@ -131,7 +131,7 @@ def test_invalid_sig_top_up(spec, state): def test_invalid_withdrawal_credentials_top_up(spec, state): validator_index = 0 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( spec, state, From 8da447f607a1f08e85942142fa8d1d54f81a7da1 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 1 Jul 2019 09:07:33 +0800 Subject: [PATCH 10/12] Revert "5 slots is a `Slot`" --- specs/core/0_beacon-chain.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 82599be8d..b05b263c0 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -205,16 +205,16 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | Duration | | - | - | :-: | :-: | -| `MIN_ATTESTATION_INCLUSION_DELAY` | `Slot(2**0)` (= 1) | 6 seconds | -| `SLOTS_PER_EPOCH` | `Slot(2**6)` (= 64) | 6.4 minutes | -| `MIN_SEED_LOOKAHEAD` | `Epoch(2**0)` (= 1) | 6.4 minutes | -| `ACTIVATION_EXIT_DELAY` | `Epoch(2**2)` (= 4) | 25.6 minutes | -| `SLOTS_PER_ETH1_VOTING_PERIOD` | `Slot(2**10)` (= 1,024) | ~1.7 hours | -| `SLOTS_PER_HISTORICAL_ROOT` | `Slot(2**13)` (= 8,192) | ~13 hours | -| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `Epoch(2**8)` (= 256) | ~27 hours | -| `PERSISTENT_COMMITTEE_PERIOD` | `Epoch(2**11)` (= 2,048) | 9 days | -| `MAX_EPOCHS_PER_CROSSLINK` | `Epoch(2**6)` (= 64) | ~7 hours | -| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `Epoch(2**2)` (= 4) | 25.6 minutes | +| `MIN_ATTESTATION_INCLUSION_DELAY` | `2**0` (= 1) | 6 seconds | +| `SLOTS_PER_EPOCH` | `2**6` (= 64) | 6.4 minutes | +| `MIN_SEED_LOOKAHEAD` | `2**0` (= 1) | 6.4 minutes | +| `ACTIVATION_EXIT_DELAY` | `2**2` (= 4) | 25.6 minutes | +| `SLOTS_PER_ETH1_VOTING_PERIOD` | `2**10` (= 1,024) | ~1.7 hours | +| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | ~13 hours | +| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | ~27 hours | +| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | 9 days | +| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | ~7 hours | +| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | 25.6 minutes | ### State list lengths From e061972eee18ea870855cd3ba7d64c1e4e992b0b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 1 Jul 2019 09:17:03 +0800 Subject: [PATCH 11/12] Revert State list lengths --- specs/core/0_beacon-chain.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b05b263c0..daa8d335c 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -218,12 +218,12 @@ The following values are (non-configurable) constants used throughout the specif ### State list lengths -| Name | Value | Duration | +| Name | Value | Unit | Duration | | - | - | :-: | :-: | -| `EPOCHS_PER_HISTORICAL_VECTOR` | `Epoch(2**16)` (= 65,536) | ~0.8 years | -| `EPOCHS_PER_SLASHINGS_VECTOR` | `Epoch(2**13)` (= 8,192) | ~36 days | -| `HISTORICAL_ROOTS_LIMIT` | `2**24` (= 16,777,216) | ~26,131 years | -| `VALIDATOR_REGISTRY_LIMIT` | `2**40` (= 1,099,511,627,776) | validator spots | | +| `EPOCHS_PER_HISTORICAL_VECTOR` | `2**16` (= 65,536) | epochs | ~0.8 years | +| `EPOCHS_PER_SLASHINGS_VECTOR` | `2**13` (= 8,192) | epochs | ~36 days | +| `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 | ### Rewards and penalties From 476dbdb15364bb89e3ff7a82eaf5d941a5fdcfa5 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 30 Jun 2019 22:13:41 -0500 Subject: [PATCH 12/12] add time param back tp units --- specs/core/0_beacon-chain.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index a05a21b5d..e7ea49f4c 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -205,18 +205,18 @@ The following values are (non-configurable) constants used throughout the specif ### Time parameters -| Name | Value | Duration | +| Name | Value | Unit | Duration | | - | - | :-: | :-: | -| `MIN_ATTESTATION_INCLUSION_DELAY` | `2**0` (= 1) | 6 seconds | -| `SLOTS_PER_EPOCH` | `2**6` (= 64) | 6.4 minutes | -| `MIN_SEED_LOOKAHEAD` | `2**0` (= 1) | 6.4 minutes | -| `ACTIVATION_EXIT_DELAY` | `2**2` (= 4) | 25.6 minutes | -| `SLOTS_PER_ETH1_VOTING_PERIOD` | `2**10` (= 1,024) | ~1.7 hours | -| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | ~13 hours | -| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | ~27 hours | -| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | 9 days | -| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | ~7 hours | -| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | 25.6 minutes | +| `MIN_ATTESTATION_INCLUSION_DELAY` | `2**0` (= 1) | slots | 6 seconds | +| `SLOTS_PER_EPOCH` | `2**6` (= 64) | slots | 6.4 minutes | +| `MIN_SEED_LOOKAHEAD` | `2**0` (= 1) | epochs | 6.4 minutes | +| `ACTIVATION_EXIT_DELAY` | `2**2` (= 4) | epochs | 25.6 minutes | +| `SLOTS_PER_ETH1_VOTING_PERIOD` | `2**10` (= 1,024) | slots | ~1.7 hours | +| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | slots | ~13 hours | +| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | epochs | ~27 hours | +| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | epochs | 9 days | +| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours | +| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | epochs | 25.6 minutes | ### State list lengths