From 210ec89b0b1c0d3b1849ff335936b5b42999a957 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 15 Feb 2019 12:21:19 +1100 Subject: [PATCH] Replace `ssz_encode` with `int_to_bytes32` Only in the relevant places I can think of.. I might have missed some. --- eth2/block_producer/Cargo.toml | 7 ++++--- eth2/block_producer/src/lib.rs | 4 ++-- eth2/state_processing/Cargo.toml | 1 + eth2/state_processing/src/block_processable.rs | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/eth2/block_producer/Cargo.toml b/eth2/block_producer/Cargo.toml index 86dde92f7..15d1343cc 100644 --- a/eth2/block_producer/Cargo.toml +++ b/eth2/block_producer/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Paul Hauner "] edition = "2018" [dependencies] -slot_clock = { path = "../../eth2/utils/slot_clock" } -ssz = { path = "../../eth2/utils/ssz" } -types = { path = "../../eth2/types" } +int_to_bytes = { path = "../utils/int_to_bytes" } +slot_clock = { path = "../utils/slot_clock" } +ssz = { path = "../utils/ssz" } +types = { path = "../types" } diff --git a/eth2/block_producer/src/lib.rs b/eth2/block_producer/src/lib.rs index f6a0fd6df..7b15eb4e9 100644 --- a/eth2/block_producer/src/lib.rs +++ b/eth2/block_producer/src/lib.rs @@ -1,8 +1,8 @@ pub mod test_utils; mod traits; +use int_to_bytes::int_to_bytes32; use slot_clock::SlotClock; -use ssz::ssz_encode; use std::sync::Arc; use types::{BeaconBlock, ChainSpec, Slot}; @@ -132,7 +132,7 @@ impl BlockProducer Result { let randao_reveal = { // TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`. - let message = ssz_encode(&slot.epoch(self.spec.epoch_length)); + let message = int_to_bytes32(slot.epoch(self.spec.epoch_length).as_u64()); match self.signer.sign_randao_reveal(&message) { None => return Ok(PollOutcome::SignerRejection(slot)), diff --git a/eth2/state_processing/Cargo.toml b/eth2/state_processing/Cargo.toml index 683475f47..b6b0ea57c 100644 --- a/eth2/state_processing/Cargo.toml +++ b/eth2/state_processing/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] hashing = { path = "../utils/hashing" } +int_to_bytes = { path = "../utils/int_to_bytes" } integer-sqrt = "0.1" log = "0.4" ssz = { path = "../utils/ssz" } diff --git a/eth2/state_processing/src/block_processable.rs b/eth2/state_processing/src/block_processable.rs index f043a723d..368460116 100644 --- a/eth2/state_processing/src/block_processable.rs +++ b/eth2/state_processing/src/block_processable.rs @@ -1,5 +1,6 @@ use crate::SlotProcessingError; use hashing::hash; +use int_to_bytes::int_to_bytes32; use log::debug; use ssz::{ssz_encode, TreeHash}; use types::{ @@ -110,7 +111,7 @@ fn per_block_processing_signature_optional( ensure!( bls_verify( &block_proposer.pubkey, - &ssz_encode(&state.current_epoch(spec)), + &int_to_bytes32(state.current_epoch(spec).as_u64()), &block.randao_reveal, get_domain(&state.fork, state.current_epoch(spec), DOMAIN_RANDAO) ),