From 23e3f4defe5cd10aa239094768fc9489a126a9ea Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:30:04 +0800 Subject: [PATCH] Rename `bytes1(x)`, `bytes2(x)`... function to `int_to_bytes1(x)`, `int_to_bytes2(x)`... --- specs/core/0_beacon-chain.md | 14 +++++++------- specs/core/1_shard-data-chains.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 2757d89a7..92c300b0d 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -75,7 +75,7 @@ - [`get_beacon_proposer_index`](#get_beacon_proposer_index) - [`merkle_root`](#merkle_root) - [`get_attestation_participants`](#get_attestation_participants) - - [`bytes1`, `bytes2`, ...](#bytes1-bytes2-) + - [`int_to_bytes1`, `int_to_bytes2`, ...](#int_to_bytes1-int_to_bytes2-) - [`get_effective_balance`](#get_effective_balance) - [`get_fork_version`](#get_fork_version) - [`get_domain`](#get_domain) @@ -190,9 +190,9 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted | `GENESIS_SLOT` | `0` | | `GENESIS_START_SHARD` | `0` | | `FAR_FUTURE_SLOT` | `2**64 - 1` | -| `ZERO_HASH` | `bytes32(0)` | -| `EMPTY_SIGNATURE` | `[bytes48(0), bytes48(0)]` | -| `BLS_WITHDRAWAL_PREFIX_BYTE` | `bytes1(0)` | +| `ZERO_HASH` | `int_to_bytes32(0)` | +| `EMPTY_SIGNATURE` | `[int_to_bytes48(0), int_to_bytes48(0)]` | +| `BLS_WITHDRAWAL_PREFIX_BYTE` | `int_to_bytes1(0)` | ### Time parameters @@ -894,7 +894,7 @@ def get_shuffling(seed: Hash32, committees_per_slot = get_committee_count_per_slot(len(active_validator_indices)) # Shuffle - seed = xor(seed, bytes32(slot)) + seed = xor(seed, int_to_bytes32(slot)) shuffled_active_validator_indices = shuffle(active_validator_indices, seed) # Split the shuffled list into epoch_length * committees_per_slot pieces @@ -1046,9 +1046,9 @@ def get_attestation_participants(state: BeaconState, return participants ``` -#### `bytes1`, `bytes2`, ... +#### `int_to_bytes1`, `int_to_bytes2`, ... -`bytes1(x): return x.to_bytes(1, 'big')`, `bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32. +`int_to_bytes1(x): return x.to_bytes(1, 'big')`, `int_to_bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32. #### `get_effective_balance` diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 973a0d332..cabe2934e 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -70,7 +70,7 @@ To validate a block header on shard `shard_id`, compute as follows: * Verify that `beacon_chain_ref` is the hash of a block in the beacon chain with slot less than or equal to `slot`. Verify that `beacon_chain_ref` is equal to or a descendant of the `beacon_chain_ref` specified in the `ShardBlock` pointed to by `parent_root`. * Let `state` be the state of the beacon chain block referred to by `beacon_chain_ref`. Let `validators` be `[validators[i] for i in state.current_persistent_committees[shard_id]]`. * Assert `len(participation_bitfield) == ceil_div8(len(validators))` -* Let `proposer_index = hash(state.randao_mix + bytes8(shard_id) + bytes8(slot)) % len(validators)`. Let `msg` be the block but with the `block.signature` set to `[0, 0]`. Verify that `BLSVerify(pub=validators[proposer_index].pubkey, msg=hash(msg), sig=block.signature, domain=get_domain(state, slot, SHARD_PROPOSER_DOMAIN))` passes. +* Let `proposer_index = hash(state.randao_mix + int_to_bytes8(shard_id) + int_to_bytes8(slot)) % len(validators)`. Let `msg` be the block but with the `block.signature` set to `[0, 0]`. Verify that `BLSVerify(pub=validators[proposer_index].pubkey, msg=hash(msg), sig=block.signature, domain=get_domain(state, slot, SHARD_PROPOSER_DOMAIN))` passes. * Generate the `group_public_key` by adding the public keys of all the validators for whom the corresponding position in the bitfield is set to 1. Verify that `BLSVerify(pub=group_public_key, msg=parent_root, sig=block.aggregate_signature, domain=get_domain(state, slot, SHARD_ATTESTER_DOMAIN))` passes. ### Block Merklization helper