From 64a9455f872657120aea60ed553f187c2508c377 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 9 Jul 2018 12:00:58 +1000 Subject: [PATCH] Add blake2s hash type --- Cargo.toml | 2 ++ src/state/block.rs | 9 ++++----- src/utils/mod.rs | 2 ++ src/utils/types.rs | 6 ++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index de3915531..eddc347bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ authors = ["Paul Hauner "] [dependencies] ethereum-types = "" rand = "" +blake2 = "^0.7.1" +crypto-mac = "^0.6.2" bls = { git = "https://github.com/sigp/bls" } rlp = { path = "parity/util/rlp" } diff --git a/src/state/block.rs b/src/state/block.rs index 758a48262..5bfb82972 100644 --- a/src/state/block.rs +++ b/src/state/block.rs @@ -1,4 +1,4 @@ -use super::utils::types::{ Sha256Digest, Bitfield }; +use super::utils::types::{ Sha256Digest, Bitfield, Blake2sDigest }; use super::utils::bls::{ Signature, AggregateSignature, Keypair, PublicKey }; use super::aggregate_vote::AggregateVote; use super::rlp::{ RlpStream, Encodable } ; @@ -11,15 +11,14 @@ pub struct Block { pub attestation_aggregate_sig: AggregateSignature, pub shard_aggregate_votes: Vec, pub main_chain_ref: Sha256Digest, - pub state_hash: Sha256Digest, + pub state_hash: Blake2sDigest, pub sig: Option -} - +} impl Block { pub fn new(parent_hash: Sha256Digest, randao_reveal: Sha256Digest, main_chain_ref: Sha256Digest, - state_hash: Sha256Digest) -> Block { + state_hash: Blake2sDigest) -> Block { Block { parent_hash: parent_hash, skip_count: 0, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 28e55d869..51c03db67 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,6 @@ extern crate ethereum_types; +extern crate blake2; +extern crate crypto_mac; pub mod types; pub mod bls; diff --git a/src/utils/types.rs b/src/utils/types.rs index 894e56db6..285c354bd 100644 --- a/src/utils/types.rs +++ b/src/utils/types.rs @@ -1,6 +1,12 @@ use super::ethereum_types::{ H256, H160 }; +pub use super::blake2::Blake2s; + +// TODO: presently the compiler accepts these two types +// as interchangable. This is somewhat loose typing, +// which is bad. Make the compiler think they're incompatible. pub type Sha256Digest = H256; +pub type Blake2sDigest = H256; pub type Address = H160;