Update instances of int_to_bytes

This commit is contained in:
Justin Drake 2019-05-07 10:57:41 +01:00
parent b1520ea967
commit 22b06d581d
5 changed files with 7 additions and 11 deletions

View File

@ -15,15 +15,11 @@ from typing import (
from eth2spec.utils.minimal_ssz import *
from eth2spec.utils.bls_stub import *
""")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))
code_lines.append("""
# stub, will get overwritten by real var
SLOTS_PER_EPOCH = 64
def int_to_bytes(integer: int, length: int) -> bytes:
return integer.to_bytes(length, 'little')
Slot = NewType('Slot', int) # uint64
Epoch = NewType('Epoch', int) # uint64

View File

@ -195,7 +195,7 @@ These configurations are updated for releases, but may be out of sync during `de
| `GENESIS_EPOCH` | `0` |
| `FAR_FUTURE_EPOCH` | `2**64 - 1` |
| `ZERO_HASH` | `int_to_bytes(0, length=32)` |
| `BLS_WITHDRAWAL_PREFIX_BYTE` | `int_to_bytes(0, length=1)` |
| `BLS_WITHDRAWAL_PREFIX` | `0` |
### Time parameters
@ -1840,7 +1840,7 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
# Verify that the pubkey is valid
assert (
state.validator_registry[transfer.sender].withdrawal_credentials ==
BLS_WITHDRAWAL_PREFIX_BYTE + hash(transfer.pubkey)[1:]
int_to_bytes(BLS_WITHDRAWAL_PREFIX, length=1) + 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))

View File

@ -180,7 +180,7 @@ def get_shard_proposer_index(state: BeaconState,
slot: Slot) -> ValidatorIndex:
# Randomly shift persistent committee
persistent_committee = get_persistent_committee(state, shard, slot)
seed = hash(state.current_shuffling_seed + int_to_bytes8(shard) + int_to_bytes8(slot))
seed = hash(state.current_shuffling_seed + int_to_bytes(shard, length=8) + int_to_bytes(slot, length=8))
random_index = bytes_to_int(seed[0:8]) % len(persistent_committee)
persistent_committee = persistent_committee[random_index:] + persistent_committee[:random_index]

View File

@ -146,7 +146,7 @@ def compute_committee(header: BeaconBlockHeader,
]
def get_switchover_epoch(index):
return (
bytes_to_int(hash(validator_memory.earlier_period_data.seed + int_to_bytes3(index))[0:8]) %
bytes_to_int(hash(validator_memory.earlier_period_data.seed + int_to_bytes(index, length=3))[0:8]) %
PERSISTENT_COMMITTEE_PERIOD
)

View File

@ -15,7 +15,7 @@ def shuffling_case(seed: spec.Bytes32, count: int):
@to_tuple
def shuffling_test_cases():
for seed in [spec.hash(spec.int_to_bytes4(seed_init_value)) for seed_init_value in range(30)]:
for seed in [spec.hash(spec.int_to_bytes(seed_init_value, length=4)) for seed_init_value in range(30)]:
for count in [0, 1, 2, 3, 5, 10, 33, 100, 1000]:
yield shuffling_case(seed, count)