From d1bc2f03acc9cff67dcecdd5945aa9c15e14f582 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 30 Jun 2019 13:00:22 -0500 Subject: [PATCH] remove 'int' types from spec typehints. replace with uint64 --- specs/core/0_beacon-chain.md | 16 ++++++++-------- specs/core/0_fork-choice.md | 4 ++-- specs/core/1_custody-game.md | 6 +++--- specs/core/1_shard-data-chains.md | 8 ++++---- specs/validator/0_beacon-chain-validator.md | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7bc0c5377..fb388e438 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -541,7 +541,7 @@ class BeaconState(Container): #### `integer_squareroot` ```python -def integer_squareroot(n: int) -> int: +def integer_squareroot(n: uint64) -> int: """ Return the largest integer ``x`` such that ``x**2 <= n``. """ @@ -564,7 +564,7 @@ def xor(bytes1: Bytes32, bytes2: Bytes32) -> Bytes32: ``` ```python -def int_to_bytes(integer: int, length: int) -> bytes: +def int_to_bytes(integer: uint64, length: uint64) -> bytes: """ Return the ``length``-byte serialization of ``integer``. """ @@ -647,7 +647,7 @@ def is_slashable_attestation_data(data_1: AttestationData, data_2: AttestationDa #### `is_valid_merkle_branch` ```python -def is_valid_merkle_branch(leaf: Hash, branch: Sequence[Hash], depth: int, index: int, root: Hash) -> bool: +def is_valid_merkle_branch(leaf: Hash, branch: Sequence[Hash], depth: uint64, index: uint64, root: Hash) -> bool: """ Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and ``branch``. """ @@ -665,7 +665,7 @@ def is_valid_merkle_branch(leaf: Hash, branch: Sequence[Hash], depth: int, index #### `shuffle_index` ```python -def shuffle_index(index: ValidatorIndex, index_count: int, seed: Hash) -> ValidatorIndex: +def shuffle_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> ValidatorIndex: """ Return the shuffled validator index corresponding to ``seed`` (and ``index_count``). """ @@ -691,8 +691,8 @@ def shuffle_index(index: ValidatorIndex, index_count: int, seed: Hash) -> Valida ```python def compute_committee(indices: Sequence[ValidatorIndex], seed: Hash, - index: int, - count: int) -> Sequence[ValidatorIndex]: + index: uint64, + count: uint64) -> Sequence[ValidatorIndex]: """ Return the committee corresponding to ``indices``, ``seed``, ``index``, and committee ``count``. """ @@ -767,7 +767,7 @@ def delayed_activation_exit_epoch(epoch: Epoch) -> Epoch: #### `bls_domain` ```python -def bls_domain(domain_type: int, fork_version: bytes=b'\x00' * 4) -> int: +def bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: """ Return the BLS domain for the ``domain_type`` and ``fork_version``. """ @@ -997,7 +997,7 @@ def get_total_active_balance(state: BeaconState) -> Gwei: #### `get_domain` ```python -def get_domain(state: BeaconState, domain_type: int, message_epoch: Epoch=None) -> int: +def get_domain(state: BeaconState, domain_type: uint64, message_epoch: Epoch=None) -> int: """ Return the signature domain (fork version concatenated with domain type) of a message. """ diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 64afb3f6b..a45d79fbe 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -69,7 +69,7 @@ class LatestMessage(object): ```python @dataclass class Store(object): - time: int + time: uint64 justified_checkpoint: Checkpoint finalized_checkpoint: Checkpoint blocks: Dict[Hash, BeaconBlock] = field(default_factory=dict) @@ -141,7 +141,7 @@ def get_head(store: Store) -> Hash: #### `on_tick` ```python -def on_tick(store: Store, time: int) -> None: +def on_tick(store: Store, time: uint64) -> None: store.time = time ``` diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index 5e8be7b39..54a1ca34b 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -259,7 +259,7 @@ class BeaconBlockBody(Container): ### `ceillog2` ```python -def ceillog2(x: int) -> int: +def ceillog2(x: uint64) -> int: return x.bit_length() ``` @@ -275,7 +275,7 @@ def get_custody_chunk_count(crosslink: Crosslink) -> int: ### `get_bit` ```python -def get_bit(serialization: bytes, i: int) -> int: +def get_bit(serialization: bytes, i: uint64) -> int: """ Extract the bit in ``serialization`` at position ``i``. """ @@ -304,7 +304,7 @@ def get_chunk_bits_root(chunk_bits: bytes) -> Bytes32: ### `get_randao_epoch_for_custody_period` ```python -def get_randao_epoch_for_custody_period(period: int, validator_index: ValidatorIndex) -> Epoch: +def get_randao_epoch_for_custody_period(period: uint64, validator_index: ValidatorIndex) -> Epoch: next_period_start = (period + 1) * EPOCHS_PER_CUSTODY_PERIOD - validator_index % EPOCHS_PER_CUSTODY_PERIOD return Epoch(next_period_start + CUSTODY_PERIOD_TO_RANDAO_PADDING) ``` diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 82843b7a6..fd0e41b4f 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -132,8 +132,8 @@ class ShardBlockHeader(Container): def get_period_committee(state: BeaconState, epoch: Epoch, shard: Shard, - index: int, - count: int) -> Sequence[ValidatorIndex]: + index: uint64, + count: uint64) -> Sequence[ValidatorIndex]: """ Return committee for a period. Used to construct persistent committees. """ @@ -248,7 +248,7 @@ def verify_shard_attestation_signature(state: BeaconState, ```python def compute_crosslink_data_root(blocks: Sequence[ShardBlock]) -> Bytes32: - def is_power_of_two(value: int) -> bool: + def is_power_of_two(value: uint64) -> bool: return (value > 0) and (value & (value - 1) == 0) def pad_to_power_of_2(values: MutableSequence[bytes]) -> Sequence[bytes]: @@ -259,7 +259,7 @@ def compute_crosslink_data_root(blocks: Sequence[ShardBlock]) -> Bytes32: def hash_tree_root_of_bytes(data: bytes) -> bytes: return hash_tree_root([data[i:i + 32] for i in range(0, len(data), 32)]) - def zpad(data: bytes, length: int) -> bytes: + def zpad(data: bytes, length: uint64) -> bytes: return data + b'\x00' * (length - len(data)) return hash( diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index f4a83b833..0b6857a72 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -223,7 +223,7 @@ epoch_signature = bls_sign( The `block.eth1_data` field is for block proposers to vote on recent Eth 1.0 data. This recent data contains an Eth 1.0 block hash as well as the associated deposit root (as calculated by the `get_hash_tree_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth 1.0 block. If over half of the block proposers in the current Eth 1.0 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. -Let `get_eth1_data(distance: int) -> Eth1Data` be the (subjective) function that returns the Eth 1.0 data at distance `distance` relative to the Eth 1.0 head at the start of the current Eth 1.0 voting period. Let `previous_eth1_distance` be the distance relative to the Eth 1.0 block corresponding to `state.eth1_data.block_hash` at the start of the current Eth 1.0 voting period. An honest block proposer sets `block.eth1_data = get_eth1_vote(state, previous_eth1_distance)` where: +Let `get_eth1_data(distance: uint64) -> Eth1Data` be the (subjective) function that returns the Eth 1.0 data at distance `distance` relative to the Eth 1.0 head at the start of the current Eth 1.0 voting period. Let `previous_eth1_distance` be the distance relative to the Eth 1.0 block corresponding to `state.eth1_data.block_hash` at the start of the current Eth 1.0 voting period. An honest block proposer sets `block.eth1_data = get_eth1_vote(state, previous_eth1_distance)` where: ```python def get_eth1_vote(state: BeaconState, previous_eth1_distance: uint64) -> Eth1Data: