Update ethereum-types to 0.5

This commit is contained in:
Michael Sproul
2019-03-04 17:19:25 +11:00
parent af8b8d519c
commit 6253167cac
19 changed files with 80 additions and 79 deletions

View File

@@ -16,7 +16,7 @@ pub struct Attestation {
impl Attestation {
pub fn canonical_root(&self) -> Hash256 {
Hash256::from(&self.hash_tree_root()[..])
Hash256::from_slice(&self.hash_tree_root()[..])
}
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {

View File

@@ -35,7 +35,7 @@ impl Eq for AttestationData {}
impl AttestationData {
pub fn canonical_root(&self) -> Hash256 {
Hash256::from(&self.hash_tree_root()[..])
Hash256::from_slice(&self.hash_tree_root()[..])
}
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {

View File

@@ -27,8 +27,8 @@ impl AttesterSlashingBuilder {
let shard = 0;
let justified_epoch = Epoch::new(0);
let epoch = Epoch::new(0);
let hash_1 = Hash256::from(&[1][..]);
let hash_2 = Hash256::from(&[2][..]);
let hash_1 = Hash256::from_low_u64_le(1);
let hash_2 = Hash256::from_low_u64_le(2);
let mut slashable_attestation_1 = SlashableAttestation {
validator_indices: validator_indices.to_vec(),

View File

@@ -42,7 +42,7 @@ impl BeaconBlock {
}
pub fn canonical_root(&self) -> Hash256 {
Hash256::from(&self.hash_tree_root()[..])
Hash256::from_slice(&self.hash_tree_root()[..])
}
pub fn proposal_root(&self, spec: &ChainSpec) -> Hash256 {
@@ -57,7 +57,7 @@ impl BeaconBlock {
shard: spec.beacon_chain_shard_number,
block_root: block_without_signature_root,
};
Hash256::from(&proposal.hash_tree_root()[..])
Hash256::from_slice(&proposal.hash_tree_root()[..])
}
}

View File

@@ -3,6 +3,7 @@ use crate::test_utils::TestRandom;
use crate::{validator::StatusFlags, validator_registry::get_active_validator_indices, *};
use bls::verify_proof_of_possession;
use honey_badger_split::SplitExt;
use int_to_bytes::int_to_bytes32;
use log::{debug, error, trace};
use rand::RngCore;
use rayon::prelude::*;
@@ -326,7 +327,7 @@ impl BeaconState {
///
/// Spec v0.2.0
pub fn canonical_root(&self) -> Hash256 {
Hash256::from(&self.hash_tree_root()[..])
Hash256::from_slice(&self.hash_tree_root()[..])
}
/// The epoch corresponding to `self.slot`.
@@ -487,19 +488,20 @@ impl BeaconState {
let mut input = self
.get_randao_mix(epoch, spec)
.ok_or_else(|| Error::InsufficientRandaoMixes)?
.as_bytes()
.to_vec();
input.append(
&mut self
.get_active_index_root(epoch, spec)
.ok_or_else(|| Error::InsufficientIndexRoots)?
.as_bytes()
.to_vec(),
);
// TODO: ensure `Hash256::from(u64)` == `int_to_bytes32`.
input.append(&mut Hash256::from(epoch.as_u64()).to_vec());
input.append(&mut int_to_bytes32(epoch.as_u64()));
Ok(Hash256::from(&hash(&input[..])[..]))
Ok(Hash256::from_slice(&hash(&input[..])[..]))
}
/// Returns the crosslink committees for some slot.
@@ -1311,7 +1313,7 @@ impl BeaconState {
}
fn hash_tree_root<T: TreeHash>(input: Vec<T>) -> Hash256 {
Hash256::from(&input.hash_tree_root()[..])
Hash256::from_slice(&input.hash_tree_root()[..])
}
impl From<Error> for InclusionError {

View File

@@ -145,8 +145,8 @@ impl BeaconStateBuilder {
state.previous_calculation_epoch = epoch - 1;
state.current_calculation_epoch = epoch;
state.previous_epoch_seed = Hash256::from(&b"previous_seed"[..]);
state.current_epoch_seed = Hash256::from(&b"current_seed"[..]);
state.previous_epoch_seed = Hash256::from([0x01; 32]);
state.current_epoch_seed = Hash256::from([0x02; 32]);
state.previous_justified_epoch = epoch - 2;
state.justified_epoch = epoch - 1;

View File

@@ -25,13 +25,13 @@ impl ProposerSlashingBuilder {
let proposal_data_1 = ProposalSignedData {
slot,
shard,
block_root: Hash256::from(&[1][..]),
block_root: Hash256::from_low_u64_le(1),
};
let proposal_data_2 = ProposalSignedData {
slot,
shard,
block_root: Hash256::from(&[2][..]),
block_root: Hash256::from_low_u64_le(2),
};
let proposal_signature_1 = {

View File

@@ -6,6 +6,6 @@ impl<T: RngCore> TestRandom<T> for Address {
fn random_for_test(rng: &mut T) -> Self {
let mut key_bytes = vec![0; 20];
rng.fill_bytes(&mut key_bytes);
Address::from(&key_bytes[..])
Address::from_slice(&key_bytes[..])
}
}

View File

@@ -6,6 +6,6 @@ impl<T: RngCore> TestRandom<T> for Hash256 {
fn random_for_test(rng: &mut T) -> Self {
let mut key_bytes = vec![0; 32];
rng.fill_bytes(&mut key_bytes);
Hash256::from(&key_bytes[..])
Hash256::from_slice(&key_bytes[..])
}
}