diff --git a/Cargo.lock b/Cargo.lock index 6b6ab1bb6d980..14ab7f229bb92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2574,7 +2574,6 @@ dependencies = [ "substrate-runtime-version 0.1.0", "substrate-serializer 0.1.0", "substrate-state-machine 0.1.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "triehash 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2619,6 +2618,7 @@ dependencies = [ "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-primitives 0.1.0", "subtle 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2710,7 +2710,6 @@ dependencies = [ "substrate-codec-derive 0.1.0", "substrate-runtime-std 0.1.0", "substrate-serializer 0.1.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/demo/api/src/lib.rs b/demo/api/src/lib.rs index fbcba1cf9acee..f83a6d228d3c9 100644 --- a/demo/api/src/lib.rs +++ b/demo/api/src/lib.rs @@ -33,7 +33,7 @@ use primitives::{ AccountId, Block, BlockId, Hash, Index, InherentData, SessionKey, Timestamp, UncheckedExtrinsic, }; -use substrate_primitives::{KeccakHasher, RlpCodec}; +use substrate_primitives::{Blake2Hasher, RlpCodec}; /// Build new blocks. pub trait BlockBuilder { @@ -81,10 +81,10 @@ pub trait Api { fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result>; } -impl BlockBuilder for ClientBlockBuilder +impl BlockBuilder for ClientBlockBuilder where - B: Backend, - E: CallExecutor+ Clone, + B: Backend, + E: CallExecutor+ Clone, { fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> { self.push(extrinsic).map_err(Into::into) @@ -98,10 +98,10 @@ where impl Api for Client where - B: Backend, - E: CallExecutor + Clone, + B: Backend, + E: CallExecutor + Clone, { - type BlockBuilder = ClientBlockBuilder; + type BlockBuilder = ClientBlockBuilder; fn session_keys(&self, at: &BlockId) -> Result> { Ok(self.authorities_at(at)?) diff --git a/demo/executor/src/lib.rs b/demo/executor/src/lib.rs index 19f0764f4bdf1..83f64f35169fd 100644 --- a/demo/executor/src/lib.rs +++ b/demo/executor/src/lib.rs @@ -51,7 +51,7 @@ mod tests { use keyring::Keyring; use runtime_support::{Hashable, StorageValue, StorageMap}; use state_machine::{CodeExecutor, TestExternalities}; - use primitives::{twox_128, KeccakHasher}; + use primitives::{twox_128, Blake2Hasher}; use demo_primitives::{Hash, BlockNumber, AccountId}; use runtime_primitives::traits::Header as HeaderT; use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult}; @@ -117,7 +117,7 @@ mod tests { #[test] fn panic_execution_with_foreign_code_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], @@ -137,7 +137,7 @@ mod tests { #[test] fn bad_extrinsic_with_native_equivalent_code_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], @@ -157,7 +157,7 @@ mod tests { #[test] fn successful_execution_with_native_equivalent_code_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -181,7 +181,7 @@ mod tests { #[test] fn successful_execution_with_foreign_code_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -203,7 +203,7 @@ mod tests { }); } - fn new_test_ext() -> TestExternalities { + fn new_test_ext() -> TestExternalities { use keyring::Keyring::*; let three = [3u8; 32].into(); GenesisConfig { @@ -244,7 +244,7 @@ mod tests { use triehash::ordered_trie_root; let extrinsics = extrinsics.into_iter().map(sign).collect::>(); - let extrinsics_root = ordered_trie_root::(extrinsics.iter().map(Encode::encode)).0.into(); + let extrinsics_root = ordered_trie_root::(extrinsics.iter().map(Encode::encode)).0.into(); let header = Header { parent_hash, @@ -262,7 +262,7 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("efdd1840ae46b687fc59fc730892d412a0fb051ef120f9e6dfcf1c416d0fc2cb").into(), + hex!("c2fcc528c92b3c958b0e0914f26e05f151903ed43c87f29b20f9c8f0450d7484").into(), vec![ CheckedExtrinsic { signed: None, @@ -282,7 +282,7 @@ mod tests { construct_block( 2, block1().1, - hex!("e360ad4a43929e521fd41cdabf8d772eb39f9cbf71fe95bada685e24bd3bbbbb").into(), + hex!("62e5879f10338fa6136161c60ae0ffc35936f7b8c3fdb38095ddd0e044309762").into(), vec![ CheckedExtrinsic { signed: None, @@ -307,7 +307,7 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("989ebec4920fe4a99edcd3766eee35a31de92dff20427920ae68d15471afba9a").into(), + hex!("789b19bc7beaa83ae70412f65ad0ac02435fd79e0226ba3394865a052e56fbd8").into(), vec![ CheckedExtrinsic { signed: None, @@ -478,7 +478,7 @@ mod tests { #[test] fn panic_execution_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], @@ -499,7 +499,7 @@ mod tests { #[test] fn successful_execution_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], diff --git a/demo/runtime/wasm/Cargo.lock b/demo/runtime/wasm/Cargo.lock index ec034f0999f74..89017d1a91d4d 100644 --- a/demo/runtime/wasm/Cargo.lock +++ b/demo/runtime/wasm/Cargo.lock @@ -609,7 +609,6 @@ dependencies = [ "substrate-codec 0.1.0", "substrate-codec-derive 0.1.0", "substrate-runtime-std 0.1.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm index 4d61fd65ab6b3..0561462684fe8 100644 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm differ diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm index 41e8d9f5542a4..d0cf943ec482f 100755 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm differ diff --git a/demo/service/src/lib.rs b/demo/service/src/lib.rs index 14cd91d643acf..3f761b7542bc4 100644 --- a/demo/service/src/lib.rs +++ b/demo/service/src/lib.rs @@ -49,7 +49,7 @@ use client::Client; use demo_network::{Protocol as DemoProtocol, consensus::ConsensusNetwork}; use tokio::runtime::TaskExecutor; use service::FactoryFullConfiguration; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; pub use service::{Roles, PruningMode, ExtrinsicPoolOptions, ErrorKind, Error, ComponentBlock, LightComponents, FullComponents}; @@ -66,9 +66,9 @@ pub trait Components: service::Components { /// Demo API. type Api: 'static + Api + Send + Sync; /// Client backend. - type Backend: 'static + client::backend::Backend; + type Backend: 'static + client::backend::Backend; /// Client executor. - type Executor: 'static + client::CallExecutor + Send + Sync; + type Executor: 'static + client::CallExecutor + Send + Sync; } impl Components for service::LightComponents { diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index c4911e7d9c6d8..acbd935ce8c32 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -55,7 +55,7 @@ use hashdb::Hasher; use kvdb::{KeyValueDB, DBTransaction}; use memorydb::MemoryDB; use parking_lot::RwLock; -use primitives::{H256, AuthorityId, KeccakHasher, RlpCodec}; +use primitives::{H256, AuthorityId, Blake2Hasher, RlpCodec}; use runtime_primitives::generic::BlockId; use runtime_primitives::bft::Justification; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hash, HashFor, NumberFor, Zero}; @@ -71,7 +71,7 @@ pub use state_db::PruningMode; const FINALIZATION_WINDOW: u64 = 32; /// DB-backed patricia trie state, transaction type is an overlay of changes to commit. -pub type DbState = state_machine::TrieBackend; +pub type DbState = state_machine::TrieBackend; /// Database settings. pub struct DatabaseSettings { @@ -92,7 +92,7 @@ pub fn new_client( ) -> Result, client::LocalCallExecutor, E>, Block>, client::error::Error> where Block: BlockT, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, { let backend = Arc::new(Backend::new(settings, FINALIZATION_WINDOW)?); @@ -234,8 +234,8 @@ pub struct BlockImportOperation { pending_block: Option>, } -impl client::backend::BlockImportOperation -for BlockImportOperation +impl client::backend::BlockImportOperation +for BlockImportOperation where Block: BlockT, { type State = DbState; @@ -259,7 +259,7 @@ where Block: BlockT, // currently authorities are not cached on full nodes } - fn update_storage(&mut self, update: MemoryDB) -> Result<(), client::error::Error> { + fn update_storage(&mut self, update: MemoryDB) -> Result<(), client::error::Error> { self.updates = update; Ok(()) } @@ -277,7 +277,7 @@ struct StorageDb { pub state_db: StateDb, } -impl state_machine::Storage for StorageDb { +impl state_machine::Storage for StorageDb { fn get(&self, key: &H256) -> Result, String> { self.state_db.get(&key.0.into(), self).map(|r| r.map(|v| DBValue::from_slice(&v))) .map_err(|e| format!("Database backend error: {:?}", e)) @@ -351,8 +351,8 @@ fn apply_state_commit(transaction: &mut DBTransaction, commit: state_db::CommitS } } -impl client::backend::Backend for Backend where Block: BlockT { - type BlockImportOperation = BlockImportOperation; +impl client::backend::Backend for Backend where Block: BlockT { + type BlockImportOperation = BlockImportOperation; type Blockchain = BlockchainDb; type State = DbState; @@ -476,7 +476,7 @@ impl client::backend::Backend for Backend< } } -impl client::backend::LocalBackend for Backend +impl client::backend::LocalBackend for Backend where Block: BlockT {} #[cfg(test)] diff --git a/substrate/client/db/src/light.rs b/substrate/client/db/src/light.rs index 0c21bb59d36b7..9b82aec1f3087 100644 --- a/substrate/client/db/src/light.rs +++ b/substrate/client/db/src/light.rs @@ -27,7 +27,7 @@ use client::cht; use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult}; use client::light::blockchain::Storage as LightBlockchainStorage; use codec::{Decode, Encode}; -use primitives::{AuthorityId, H256, KeccakHasher}; +use primitives::{AuthorityId, H256, Blake2Hasher}; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash, HashFor, Zero, One, As, NumberFor}; @@ -203,7 +203,7 @@ impl LightBlockchainStorage for LightStorage // build new CHT if required if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) { let new_cht_start: NumberFor = cht::start_number(cht::SIZE, new_cht_number); - let new_cht_root: Option = cht::compute_root::( + let new_cht_root: Option = cht::compute_root::( cht::SIZE, new_cht_number, (new_cht_start.as_()..) .map(|num| self.hash(As::sa(num)).unwrap_or_default())); diff --git a/substrate/client/src/block_builder.rs b/substrate/client/src/block_builder.rs index 30216f4157f27..0d78f30cc413b 100644 --- a/substrate/client/src/block_builder.rs +++ b/substrate/client/src/block_builder.rs @@ -24,7 +24,7 @@ use runtime_primitives::generic::BlockId; use {backend, error, Client, CallExecutor}; use runtime_primitives::{ApplyResult, ApplyOutcome}; use patricia_trie::NodeCodec; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use hashdb::Hasher; use rlp::Encodable; @@ -45,10 +45,10 @@ where changes: state_machine::OverlayedChanges, } -impl BlockBuilder +impl BlockBuilder where - B: backend::Backend, - E: CallExecutor + Clone, + B: backend::Backend, + E: CallExecutor + Clone, Block: BlockT, { /// Create a new instance of builder from the given client, building on the latest block. diff --git a/substrate/client/src/call_executor.rs b/substrate/client/src/call_executor.rs index cbb0830615160..d78025574185a 100644 --- a/substrate/client/src/call_executor.rs +++ b/substrate/client/src/call_executor.rs @@ -25,7 +25,7 @@ use patricia_trie::NodeCodec; use hashdb::Hasher; use rlp::Encodable; use codec::Decode; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use backend; use error; @@ -115,10 +115,10 @@ impl Clone for LocalCallExecutor where E: Clone { } } -impl CallExecutor for LocalCallExecutor +impl CallExecutor for LocalCallExecutor where - B: backend::LocalBackend, - E: CodeExecutor + RuntimeInfo, + B: backend::LocalBackend, + E: CodeExecutor + RuntimeInfo, Block: BlockT, { type Error = E::Error; @@ -157,7 +157,7 @@ where } fn call_at_state< - S: state_machine::Backend, + S: state_machine::Backend, F: FnOnce(Result, Self::Error>, Result, Self::Error>) -> Result, Self::Error>, >(&self, state: &S, @@ -176,7 +176,7 @@ where ).map_err(Into::into) } - fn prove_at_state>(&self, + fn prove_at_state>(&self, state: S, changes: &mut OverlayedChanges, method: &str, diff --git a/substrate/client/src/cht.rs b/substrate/client/src/cht.rs index c407cee6f5711..2f2f38523b179 100644 --- a/substrate/client/src/cht.rs +++ b/substrate/client/src/cht.rs @@ -213,7 +213,7 @@ pub fn decode_cht_value>(value: &[u8]) -> Option { #[cfg(test)] mod tests { - use primitives::{KeccakHasher, RlpCodec}; + use primitives::{Blake2Hasher, RlpCodec}; use test_client::runtime::Header; use super::*; @@ -257,18 +257,18 @@ mod tests { #[test] fn compute_root_works() { - assert!(compute_root::(SIZE, 42, vec![Some(1.into()); SIZE as usize]).is_some()); + assert!(compute_root::(SIZE, 42, vec![Some(1.into()); SIZE as usize]).is_some()); } #[test] fn build_proof_fails_when_querying_wrong_block() { - assert!(build_proof::( + assert!(build_proof::( SIZE, 0, (SIZE * 1000) as u64, vec![Some(1.into()); SIZE as usize]).is_none()); } #[test] fn build_proof_works() { - assert!(build_proof::( + assert!(build_proof::( SIZE, 0, (SIZE / 2) as u64, vec![Some(1.into()); SIZE as usize]).is_some()); } } diff --git a/substrate/client/src/client.rs b/substrate/client/src/client.rs index 963d165b1f51b..9246e61ec85d9 100644 --- a/substrate/client/src/client.rs +++ b/substrate/client/src/client.rs @@ -24,7 +24,7 @@ use runtime_primitives::{bft::Justification, generic::{BlockId, SignedBlock, Blo use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, As, NumberFor}; use runtime_primitives::BuildStorage; use runtime_support::metadata::JSONMetadataDecodable; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use primitives::storage::{StorageKey, StorageData}; use codec::{Encode, Decode}; use state_machine::{ @@ -165,9 +165,9 @@ impl JustifiedHeader { pub fn new_in_mem( executor: E, genesis_storage: S, -) -> error::Result, LocalCallExecutor, E>, Block>> +) -> error::Result, LocalCallExecutor, E>, Block>> where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, Block: BlockT, { @@ -177,8 +177,8 @@ pub fn new_in_mem( } impl Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { /// Creates new Substrate Client with given blockchain and code executor. @@ -303,7 +303,7 @@ impl Client where let cht_num = cht::block_to_cht_number(cht_size, block_num).ok_or_else(proof_error)?; let cht_start = cht::start_number(cht_size, cht_num); let headers = (cht_start.as_()..).map(|num| self.block_hash(As::sa(num)).unwrap_or_default()); - let proof = cht::build_proof::(cht_size, cht_num, block_num, headers) + let proof = cht::build_proof::(cht_size, cht_num, block_num, headers) .ok_or_else(proof_error)?; Ok((header, proof)) } @@ -326,14 +326,14 @@ impl Client where } /// Create a new block, built on the head of the chain. - pub fn new_block(&self) -> error::Result> + pub fn new_block(&self) -> error::Result> where E: Clone { block_builder::BlockBuilder::new(self) } /// Create a new block, built on top of `parent`. - pub fn new_block_at(&self, parent: &BlockId) -> error::Result> + pub fn new_block_at(&self, parent: &BlockId) -> error::Result> where E: Clone { block_builder::BlockBuilder::at_block(parent, &self) @@ -595,8 +595,8 @@ impl Client where impl bft::BlockImport for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn import_block( @@ -618,8 +618,8 @@ impl bft::BlockImport for Client impl bft::Authorities for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn authorities(&self, at: &BlockId) -> Result, bft::Error> { @@ -641,7 +641,7 @@ impl bft::Authorities for Client impl BlockchainEvents for Client where - E: CallExecutor, + E: CallExecutor, Block: BlockT, { /// Get block import event stream. @@ -659,8 +659,8 @@ where impl ChainHead for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn best_block_header(&self) -> error::Result<::Header> { @@ -670,8 +670,8 @@ where impl BlockBody for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn block_body(&self, id: &BlockId) -> error::Result::Extrinsic>>> { diff --git a/substrate/client/src/genesis.rs b/substrate/client/src/genesis.rs index d3f0278e3f0f4..93b8244fec534 100644 --- a/substrate/client/src/genesis.rs +++ b/substrate/client/src/genesis.rs @@ -51,7 +51,7 @@ mod tests { use test_client::runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; use test_client::runtime::{Hash, Transfer, Block, BlockNumber, Header, Digest, Extrinsic}; use ed25519::{Public, Pair}; - use primitives::{KeccakHasher, RlpCodec}; + use primitives::{Blake2Hasher, RlpCodec}; native_executor_instance!(Executor, test_client::runtime::api::dispatch, test_client::runtime::VERSION, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")); @@ -59,7 +59,7 @@ mod tests { NativeExecutionDispatch::new() } - fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec) -> (Vec, Hash) { + fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec) -> (Vec, Hash) { use triehash::ordered_trie_root; let transactions = txs.into_iter().map(|tx| { @@ -69,7 +69,7 @@ mod tests { Extrinsic { transfer: tx, signature } }).collect::>(); - let extrinsics_root = ordered_trie_root::(transactions.iter().map(Encode::encode)).into(); + let extrinsics_root = ordered_trie_root::(transactions.iter().map(Encode::encode)).into(); println!("root before: {:?}", extrinsics_root); let mut header = Header { @@ -116,7 +116,7 @@ mod tests { (vec![].and(&Block { header, extrinsics: transactions }), hash) } - fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec, Hash) { + fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec, Hash) { construct_block( backend, 1, diff --git a/substrate/client/src/light/fetcher.rs b/substrate/client/src/light/fetcher.rs index 89416a2beee8d..02090a4bc6076 100644 --- a/substrate/client/src/light/fetcher.rs +++ b/substrate/client/src/light/fetcher.rs @@ -187,7 +187,7 @@ pub mod tests { use in_mem::{Blockchain as InMemoryBlockchain}; use light::fetcher::{Fetcher, FetchChecker, LightDataChecker, RemoteCallRequest, RemoteHeaderRequest}; - use primitives::{KeccakHasher, RlpCodec}; + use primitives::{Blake2Hasher, RlpCodec}; use runtime_primitives::generic::BlockId; use state_machine::Backend; use super::*; @@ -213,7 +213,7 @@ pub mod tests { } fn prepare_for_read_proof_check() -> ( - LightDataChecker, KeccakHasher, RlpCodec>, + LightDataChecker, Blake2Hasher, RlpCodec>, Header, Vec>, usize) { // prepare remote client @@ -236,7 +236,7 @@ pub mod tests { } fn prepare_for_header_proof_check(insert_cht: bool) -> ( - LightDataChecker, KeccakHasher, RlpCodec>, + LightDataChecker, Blake2Hasher, RlpCodec>, Hash, Header, Vec>) { // prepare remote client @@ -254,7 +254,7 @@ pub mod tests { // check remote read proof locally let local_storage = InMemoryBlockchain::::new(); - let local_cht_root = cht::compute_root::(4, 0, local_headers_hashes.into_iter()).unwrap(); + let local_cht_root = cht::compute_root::(4, 0, local_headers_hashes.into_iter()).unwrap(); if insert_cht { local_storage.insert_cht_root(1, local_cht_root); } diff --git a/substrate/client/src/light/mod.rs b/substrate/client/src/light/mod.rs index e722daab78d22..d16814ae2fca5 100644 --- a/substrate/client/src/light/mod.rs +++ b/substrate/client/src/light/mod.rs @@ -23,7 +23,7 @@ pub mod fetcher; use std::sync::Arc; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use runtime_primitives::BuildStorage; use runtime_primitives::traits::Block as BlockT; use state_machine::{CodeExecutor, ExecutionStrategy}; @@ -53,7 +53,7 @@ pub fn new_light( backend: Arc>, fetcher: Arc, genesis_storage: GS, -) -> ClientResult, RemoteCallExecutor, F, KeccakHasher, RlpCodec>, B>> +) -> ClientResult, RemoteCallExecutor, F, Blake2Hasher, RlpCodec>, B>> where B: BlockT, S: BlockchainStorage, diff --git a/substrate/executor/Cargo.toml b/substrate/executor/Cargo.toml index 4d1c61d5e5715..0c4e658740517 100644 --- a/substrate/executor/Cargo.toml +++ b/substrate/executor/Cargo.toml @@ -22,7 +22,6 @@ lazy_static = "1.0" parking_lot = "*" log = "0.3" hashdb = "0.2.1" -tiny-keccak = "1.4" [dev-dependencies] assert_matches = "1.1" diff --git a/substrate/executor/src/lib.rs b/substrate/executor/src/lib.rs index cee6107fdd562..7898411be47d4 100644 --- a/substrate/executor/src/lib.rs +++ b/substrate/executor/src/lib.rs @@ -45,7 +45,6 @@ extern crate triehash; extern crate parking_lot; extern crate twox_hash; extern crate hashdb; -extern crate tiny_keccak; #[macro_use] extern crate log; @@ -78,7 +77,7 @@ pub use native_executor::{with_native_environment, NativeExecutor, NativeExecuti pub use state_machine::Externalities; pub use runtime_version::RuntimeVersion; pub use codec::Codec; -use primitives::KeccakHasher; +use primitives::Blake2Hasher; /// Provides runtime information. pub trait RuntimeInfo { @@ -86,7 +85,7 @@ pub trait RuntimeInfo { const NATIVE_VERSION: Option; /// Extract RuntimeVersion of given :code block - fn runtime_version> ( + fn runtime_version> ( &self, ext: &mut E, heap_pages: usize, diff --git a/substrate/executor/src/native_executor.rs b/substrate/executor/src/native_executor.rs index 32cd44de973c8..bc928364a607a 100644 --- a/substrate/executor/src/native_executor.rs +++ b/substrate/executor/src/native_executor.rs @@ -24,7 +24,7 @@ use codec::Decode; use primitives::hashing::blake2_256; use parking_lot::{Mutex, MutexGuard}; use RuntimeInfo; -use primitives::KeccakHasher; +use primitives::Blake2Hasher; // For the internal Runtime Cache: // Is it compatible enough to run this natively or do we need to fall back on the WasmModule @@ -51,7 +51,7 @@ fn gen_cache_key(code: &[u8]) -> [u8; 32] { /// fetch a runtime version from the cache or if there is no cached version yet, create /// the runtime version entry for `code`, determines whether `Compatibility::IsCompatible` /// can be used by comparing returned RuntimeVersion to `ref_version` -fn fetch_cached_runtime_version<'a, E: Externalities>( +fn fetch_cached_runtime_version<'a, E: Externalities>( wasm_executor: &WasmExecutor, cache: &'a mut MutexGuard, ext: &mut E, @@ -90,7 +90,7 @@ fn safe_call(f: F) -> Result /// Set up the externalities and safe calling environment to execute calls to a native runtime. /// /// If the inner closure panics, it will be caught and return an error. -pub fn with_native_environment(ext: &mut Externalities, f: F) -> Result +pub fn with_native_environment(ext: &mut Externalities, f: F) -> Result where F: ::std::panic::UnwindSafe + FnOnce() -> U { ::runtime_io::with_externalities(ext, move || safe_call(f)) @@ -104,7 +104,7 @@ pub trait NativeExecutionDispatch: Send + Sync { /// Dispatch a method and input data to be executed natively. Returns `Some` result or `None` /// if the `method` is unknown. Panics if there's an unrecoverable error. // fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; - fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; + fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; /// Get native runtime version. const VERSION: RuntimeVersion; @@ -147,7 +147,7 @@ impl Clone for NativeExecutor { impl RuntimeInfo for NativeExecutor { const NATIVE_VERSION: Option = Some(D::VERSION); - fn runtime_version>( + fn runtime_version>( &self, ext: &mut E, heap_pages: usize, @@ -157,10 +157,10 @@ impl RuntimeInfo for NativeExecutor { } } -impl CodeExecutor for NativeExecutor { +impl CodeExecutor for NativeExecutor { type Error = Error; - fn call>( + fn call>( &self, ext: &mut E, heap_pages: usize, @@ -203,7 +203,7 @@ macro_rules! native_executor_instance { }; (IMPL $name:ident, $dispatcher:path, $version:path, $code:expr) => { // TODO: this is not so great – I think I should go back to have dispatch take a type param and modify this macro to accept a type param and then pass it in from the test-client instead - use primitives::KeccakHasher as _KeccakHasher; + use primitives::Blake2Hasher as _Blake2Hasher; impl $crate::NativeExecutionDispatch for $name { const VERSION: $crate::RuntimeVersion = $version; fn native_equivalent() -> &'static [u8] { @@ -211,7 +211,7 @@ macro_rules! native_executor_instance { // get a proper build script, this must be strictly adhered to or things will go wrong. $code } - fn dispatch(ext: &mut $crate::Externalities<_KeccakHasher>, method: &str, data: &[u8]) -> $crate::error::Result> { + fn dispatch(ext: &mut $crate::Externalities<_Blake2Hasher>, method: &str, data: &[u8]) -> $crate::error::Result> { $crate::with_native_environment(ext, move || $dispatcher(method, data))? .ok_or_else(|| $crate::error::ErrorKind::MethodNotFound(method.to_owned()).into()) } diff --git a/substrate/executor/src/wasm_executor.rs b/substrate/executor/src/wasm_executor.rs index 45d0aad97313f..50488ac285087 100644 --- a/substrate/executor/src/wasm_executor.rs +++ b/substrate/executor/src/wasm_executor.rs @@ -30,10 +30,9 @@ use wasm_utils::UserError; use primitives::{blake2_256, twox_128, twox_256}; use primitives::hexdisplay::HexDisplay; use primitives::sandbox as sandbox_primitives; -use primitives::KeccakHasher; +use primitives::Blake2Hasher; use triehash::ordered_trie_root; use sandbox; -use tiny_keccak::keccak256; struct Heap { @@ -75,7 +74,7 @@ macro_rules! debug_trace { ( $( $x:tt )* ) => () } -struct FunctionExecutor<'e, E: Externalities + 'e> { +struct FunctionExecutor<'e, E: Externalities + 'e> { sandbox_store: sandbox::Store, heap: Heap, memory: MemoryRef, @@ -84,7 +83,7 @@ struct FunctionExecutor<'e, E: Externalities + 'e> { hash_lookup: HashMap, Vec>, } -impl<'e, E: Externalities> FunctionExecutor<'e, E> { +impl<'e, E: Externalities> FunctionExecutor<'e, E> { fn new(m: MemoryRef, heap_pages: usize, t: Option, e: &'e mut E) -> Result { Ok(FunctionExecutor { sandbox_store: sandbox::Store::new(), @@ -97,7 +96,7 @@ impl<'e, E: Externalities> FunctionExecutor<'e, E> { } } -impl<'e, E: Externalities> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> { +impl<'e, E: Externalities> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> { fn store(&self) -> &sandbox::Store { &self.sandbox_store } @@ -293,7 +292,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.memory.set(result, r.as_ref()).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_root"))?; Ok(()) }, - ext_keccak_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => { + ext_blake2_256_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => { let values = (0..lens_len) .map(|i| this.memory.read_primitive(lens_data + i * 4)) .collect::<::std::result::Result, UserError>>()? @@ -301,11 +300,11 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, .scan(0u32, |acc, v| { let o = *acc; *acc += v; Some((o, v)) }) .map(|(offset, len)| this.memory.get(values_data + offset, len as usize) - .map_err(|_| UserError("Invalid attempt to get memory in ext_keccak_enumerated_trie_root")) + .map_err(|_| UserError("Invalid attempt to get memory in ext_blake2_256_enumerated_trie_root")) ) .collect::<::std::result::Result, UserError>>()?; - let r = ordered_trie_root::(values.into_iter()); - this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_keccak_enumerated_trie_root"))?; + let r = ordered_trie_root::(values.into_iter()); + this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_blake2_256_enumerated_trie_root"))?; Ok(()) }, ext_chain_id() -> u64 => { @@ -353,15 +352,6 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_blake2_256"))?; Ok(()) }, - ext_keccak256(data: *const u8, len: u32, out: *mut u8) => { - let result = if len == 0 { - keccak256(&[0u8; 0]) - } else { - keccak256(&this.memory.get(data, len as usize).map_err(|_| UserError("Invalid attempt to get data in ext_keccak256"))?) - }; - this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_keccak256"))?; - Ok(()) - }, ext_ed25519_verify(msg_data: *const u8, msg_len: u32, sig_data: *const u8, pubkey_data: *const u8) -> u32 => { let mut sig = [0u8; 64]; this.memory.get_into(sig_data, &mut sig[..]).map_err(|_| UserError("Invalid attempt to get signature in ext_ed25519_verify"))?; @@ -396,25 +386,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.sandbox_store.instance_teardown(instance_idx)?; Ok(()) }, - ext_sandbox_invoke(instance_idx: u32, export_ptr: *const u8, export_len: usize, state: usize) -> u32 => { - trace!(target: "runtime-sandbox", "invoke, instance_idx={}", instance_idx); - let export = this.memory.get(export_ptr, export_len as usize) - .map_err(|_| UserError("Sandbox error")) - .and_then(|b| - String::from_utf8(b) - .map_err(|_| UserError("Sandbox error")) - )?; - - let instance = this.sandbox_store.instance(instance_idx)?; - let result = instance.invoke(&export, &[], this, state); - match result { - Ok(None) => Ok(sandbox_primitives::ERR_OK), - Ok(_) => unimplemented!(), - Err(_) => Ok(sandbox_primitives::ERR_EXECUTION), - } - }, - // TODO: Remove the old 'ext_sandbox_invoke' and rename this to it. - ext_sandbox_invoke_poc2(instance_idx: u32, export_ptr: *const u8, export_len: usize, args_ptr: *const u8, args_len: usize, return_val_ptr: *const u8, return_val_len: usize, state: usize) -> u32 => { + ext_sandbox_invoke(instance_idx: u32, export_ptr: *const u8, export_len: usize, args_ptr: *const u8, args_len: usize, return_val_ptr: *const u8, return_val_len: usize, state: usize) -> u32 => { use codec::{Decode, Encode}; trace!(target: "runtime-sandbox", "invoke, instance_idx={}", instance_idx); @@ -490,7 +462,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.sandbox_store.memory_teardown(memory_idx)?; Ok(()) }, - => <'e, E: Externalities + 'e> + => <'e, E: Externalities + 'e> ); /// Wasm rust executor for contracts. @@ -509,7 +481,7 @@ impl WasmExecutor { /// Call a given method in the given code. /// This should be used for tests only. - pub fn call>( + pub fn call>( &self, ext: &mut E, heap_pages: usize, @@ -522,7 +494,7 @@ impl WasmExecutor { } /// Call a given method in the given wasm-module runtime. - pub fn call_in_wasm_module>( + pub fn call_in_wasm_module>( &self, ext: &mut E, heap_pages: usize, @@ -740,7 +712,7 @@ mod tests { let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm"); assert_eq!( WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_enumerated_trie_root", &[]).unwrap(), - ordered_trie_root::(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.encode() + ordered_trie_root::(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.encode() ); } diff --git a/substrate/executor/wasm/src/lib.rs b/substrate/executor/wasm/src/lib.rs index bb692607e74e2..3046fd1f166ca 100644 --- a/substrate/executor/wasm/src/lib.rs +++ b/substrate/executor/wasm/src/lib.rs @@ -56,7 +56,7 @@ impl_stubs!( [ed25519_verify(&sig, &msg[..], &pubkey) as u8].to_vec() }, test_enumerated_trie_root NO_DECODE => |_| { - enumerated_trie_root::(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).to_vec() + enumerated_trie_root::(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).to_vec() }, test_sandbox NO_DECODE => |code: &[u8]| { let ok = execute_sandboxed(code, &[]).is_ok(); diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm index 5ba90adfc02f1..9feda33fa2347 100644 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm differ diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm index 1d92150f3827c..2e44e7cbb6624 100755 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm differ diff --git a/substrate/keystore/Cargo.toml b/substrate/keystore/Cargo.toml index d307bd77569af..eb1da7e02061b 100644 --- a/substrate/keystore/Cargo.toml +++ b/substrate/keystore/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] +substrate-primitives = { path = "../primitives" } parity-crypto = { version = "0.1", default_features = false } ed25519 = { path = "../ed25519" } error-chain = "0.12" diff --git a/substrate/keystore/src/lib.rs b/substrate/keystore/src/lib.rs index af261a35109b3..5686e637371b7 100644 --- a/substrate/keystore/src/lib.rs +++ b/substrate/keystore/src/lib.rs @@ -18,6 +18,7 @@ //! Keystore (and session key management) for ed25519 based chains like Polkadot. // end::description[] +extern crate substrate_primitives; extern crate parity_crypto as crypto; extern crate subtle; extern crate ed25519; @@ -40,7 +41,7 @@ use std::path::PathBuf; use std::fs::{self, File}; use std::io::{self, Write}; -use crypto::Keccak256; +use substrate_primitives::hashing::blake2_256; use ed25519::{Pair, Public, PKCS_LEN}; pub use crypto::KEY_ITERATIONS; @@ -96,8 +97,8 @@ impl EncryptedKey { crypto::aes::encrypt_128_ctr(&derived_left_bits, &iv, plain, &mut *ciphertext) .expect("input lengths of key and iv are both 16; qed"); - // KECCAK(DK[16..31] ++ ), where DK[16..31] - derived_right_bits - let mac = crypto::derive_mac(&derived_right_bits, &*ciphertext).keccak256(); + // Blake2_256(DK[16..31] ++ ), where DK[16..31] - derived_right_bits + let mac = blake2_256(&crypto::derive_mac(&derived_right_bits, &*ciphertext)); EncryptedKey { salt, @@ -112,7 +113,7 @@ impl EncryptedKey { let (derived_left_bits, derived_right_bits) = crypto::derive_key_iterations(password.as_bytes(), &self.salt, self.iterations); - let mac = crypto::derive_mac(&derived_right_bits, &self.ciphertext).keccak256(); + let mac = blake2_256(&crypto::derive_mac(&derived_right_bits, &self.ciphertext)); if subtle::slices_equal(&mac[..], &self.mac[..]) != 1 { return Err(ErrorKind::InvalidPassword.into()); diff --git a/substrate/network/src/chain.rs b/substrate/network/src/chain.rs index 52a9960fbdc02..704e32d55d117 100644 --- a/substrate/network/src/chain.rs +++ b/substrate/network/src/chain.rs @@ -21,7 +21,7 @@ use client::error::Error; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT}; use runtime_primitives::generic::BlockId; use runtime_primitives::bft::Justification; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; /// Local client abstraction for the network. pub trait Client: Send + Sync { @@ -57,8 +57,8 @@ pub trait Client: Send + Sync { } impl Client for SubstrateClient where - B: client::backend::Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, { fn import(&self, origin: BlockOrigin, header: Block::Header, justification: Justification, body: Option>) -> Result { diff --git a/substrate/network/src/test/mod.rs b/substrate/network/src/test/mod.rs index cdb51649d8a30..7a78dd28fc01b 100644 --- a/substrate/network/src/test/mod.rs +++ b/substrate/network/src/test/mod.rs @@ -26,7 +26,7 @@ use runtime_primitives::traits::Block as BlockT; use runtime_primitives::generic::BlockId; use io::SyncIo; use protocol::{Context, Protocol}; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use config::ProtocolConfig; use service::TransactionPool; use network_libp2p::{NodeIndex, SessionInfo, Severity}; @@ -174,7 +174,7 @@ impl Peer { } fn generate_blocks(&self, count: usize, mut edit_block: F) - where F: FnMut(&mut BlockBuilder) + where F: FnMut(&mut BlockBuilder) { for _ in 0 .. count { let mut builder = self.client.new_block().unwrap(); diff --git a/substrate/primitives/Cargo.toml b/substrate/primitives/Cargo.toml index 9ccd33ad6617e..206bb24c5626a 100644 --- a/substrate/primitives/Cargo.toml +++ b/substrate/primitives/Cargo.toml @@ -23,8 +23,6 @@ patricia-trie = { version = "0.2.1", optional = true } plain_hasher = { version = "0.2", default_features = false } blake2-rfc = { version = "0.2.18", optional = true } -# Switch back to Blake after PoC-3 is out and remove this -tiny-keccak = { version = "1.4", optional = true } [dev-dependencies] substrate-serializer = { path = "../serializer" } @@ -45,7 +43,6 @@ std = [ "rustc-hex/std", "twox-hash", "blake2-rfc", - "tiny-keccak", "serde_derive", "byteorder/std", "patricia-trie", diff --git a/substrate/primitives/src/hasher.rs b/substrate/primitives/src/hasher.rs index 7cc00a917e743..d4dd39b855498 100644 --- a/substrate/primitives/src/hasher.rs +++ b/substrate/primitives/src/hasher.rs @@ -20,69 +20,34 @@ use hashdb::Hasher; use plain_hasher::PlainHasher; use hash::H256; -// Use this when switching to Blake2 after PoC-3 -// pub mod blake { -// use super::{Hasher, PlainHasher, H256}; -// #[cfg(feature = "std")] -// use hashing::blake2_256; - -// #[cfg(not(feature = "std"))] -// extern "C" { -// fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8); -// } -// #[cfg(not(feature = "std"))] -// fn blake2_256(data: &[u8]) -> [u8; 32] { -// let mut result: [u8; 32] = Default::default(); -// unsafe { -// ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); -// } -// result -// } - -// /// Concrete implementation of Hasher using Blake2b 256-bit hashes -// #[derive(Debug)] -// pub struct BlakeHasher; - -// impl Hasher for BlakeHasher { -// type Out = H256; -// type StdHasher = PlainHasher; -// const LENGTH:usize = 32; -// fn hash(x: &[u8]) -> Self::Out { -// blake2_256(x).into() -// } -// } -// } - -pub mod keccak { +pub mod blake2 { use super::{Hasher, PlainHasher, H256}; - #[cfg(feature = "std")] - use tiny_keccak::keccak256; + use hashing::blake2_256; #[cfg(not(feature = "std"))] extern "C" { - fn ext_keccak256(data: *const u8, len: u32, out: *mut u8); + fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8); } - #[cfg(not(feature = "std"))] - fn keccak256(data: &[u8]) -> [u8; 32] { + fn blake2_256(data: &[u8]) -> [u8; 32] { let mut result: [u8; 32] = Default::default(); unsafe { - ext_keccak256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); } result } - /// Concrete implementation of Hasher using Keccak 256-bit hashes + /// Concrete implementation of Hasher using Blake2b 256-bit hashes #[derive(Debug)] - pub struct KeccakHasher; + pub struct Blake2Hasher; - impl Hasher for KeccakHasher { + impl Hasher for Blake2Hasher { type Out = H256; type StdHasher = PlainHasher; - const LENGTH : usize = 32; + const LENGTH:usize = 32; fn hash(x: &[u8]) -> Self::Out { - keccak256(x).into() + blake2_256(x).into() } } } diff --git a/substrate/primitives/src/lib.rs b/substrate/primitives/src/lib.rs index 7ea3a035c1faf..5fddf350d811f 100644 --- a/substrate/primitives/src/lib.rs +++ b/substrate/primitives/src/lib.rs @@ -45,9 +45,6 @@ extern crate twox_hash; #[cfg(feature = "std")] extern crate blake2_rfc; -// Switch back to Blake after PoC-3 is out -#[cfg(feature = "std")] -extern crate tiny_keccak; #[cfg(feature = "std")] #[macro_use] @@ -114,7 +111,7 @@ pub use authority_id::AuthorityId; // Switch back to Blake after PoC-3 is out // pub use self::hasher::blake::BlakeHasher; -pub use self::hasher::keccak::KeccakHasher; +pub use self::hasher::blake2::Blake2Hasher; #[cfg(feature = "std")] pub use self::rlp_codec::RlpCodec; diff --git a/substrate/primitives/src/rlp_codec.rs b/substrate/primitives/src/rlp_codec.rs index 0c5f30b371a48..bf1ae978b3d12 100644 --- a/substrate/primitives/src/rlp_codec.rs +++ b/substrate/primitives/src/rlp_codec.rs @@ -23,23 +23,17 @@ use core::marker::PhantomData; use patricia_trie::{NibbleSlice, NodeCodec, node::Node, ChildReference}; use hash::H256; -// When switching to Blake2, use this instead: -// use BlakeHasher; -use KeccakHasher; +use Blake2Hasher; /// Concrete implementation of a `NodeCodec` with Rlp encoding, generic over the `Hasher` pub struct RlpNodeCodec {mark: PhantomData} -/// Convenience type for a Keccak/Rlp flavoured NodeCodec -pub type RlpCodec = RlpNodeCodec; -// When switching to Blake2, use this instead: -// pub type RlpCodec = RlpNodeCodec; +/// Convenience type for a Blake2_256/Rlp flavoured NodeCodec +pub type RlpCodec = RlpNodeCodec; -impl NodeCodec for RlpCodec { +impl NodeCodec for RlpCodec { type Error = DecoderError; - // When switching to Blake2, use this null node - // const HASHED_NULL_NODE : H256 = H256( [0x45, 0xb0, 0xcf, 0xc2, 0x20, 0xce, 0xec, 0x5b, 0x7c, 0x1c, 0x62, 0xc4, 0xd4, 0x19, 0x3d, 0x38, 0xe4, 0xeb, 0xa4, 0x8e, 0x88, 0x15, 0x72, 0x9c, 0xe7, 0x5f, 0x9c, 0xa, 0xb0, 0xe4, 0xc1, 0xc0] ); - const HASHED_NULL_NODE : H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21] ); + const HASHED_NULL_NODE : H256 = H256( [0x45, 0xb0, 0xcf, 0xc2, 0x20, 0xce, 0xec, 0x5b, 0x7c, 0x1c, 0x62, 0xc4, 0xd4, 0x19, 0x3d, 0x38, 0xe4, 0xeb, 0xa4, 0x8e, 0x88, 0x15, 0x72, 0x9c, 0xe7, 0x5f, 0x9c, 0xa, 0xb0, 0xe4, 0xc1, 0xc0] ); fn decode(data: &[u8]) -> ::std::result::Result { let r = Rlp::new(data); match r.prototype()? { @@ -66,9 +60,9 @@ impl NodeCodec for RlpCodec { _ => Err(DecoderError::Custom("Rlp is not valid.")) } } - fn try_decode_hash(data: &[u8]) -> Option<::Out> { + fn try_decode_hash(data: &[u8]) -> Option<::Out> { let r = Rlp::new(data); - if r.is_data() && r.size() == KeccakHasher::LENGTH { + if r.is_data() && r.size() == Blake2Hasher::LENGTH { Some(r.as_val().expect("Hash is the correct size; qed")) } else { None @@ -90,7 +84,7 @@ impl NodeCodec for RlpCodec { stream.drain() } - fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> ElasticArray1024 { + fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> ElasticArray1024 { let mut stream = RlpStream::new_list(2); stream.append(&partial); match child_ref { @@ -104,7 +98,7 @@ impl NodeCodec for RlpCodec { } fn branch_node(children: I, value: Option>) -> ElasticArray1024 - where I: IntoIterator::Out>>> + where I: IntoIterator::Out>>> { let mut stream = RlpStream::new_list(17); for child_ref in children { diff --git a/substrate/rpc/src/author/mod.rs b/substrate/rpc/src/author/mod.rs index 08a46ad34bd80..5ba5140c5ee52 100644 --- a/substrate/rpc/src/author/mod.rs +++ b/substrate/rpc/src/author/mod.rs @@ -32,7 +32,7 @@ use extrinsic_pool::{ }; use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; -use primitives::{Bytes, KeccakHasher, RlpCodec}; +use primitives::{Bytes, Blake2Hasher, RlpCodec}; use rpc::futures::{Sink, Stream, Future}; use runtime_primitives::{generic, traits}; use subscriptions::Subscriptions; @@ -100,8 +100,8 @@ impl Author where } impl AuthorApi, ExtrinsicFor

, AllExtrinsics

> for Author where - B: client::backend::Backend<

::Block, KeccakHasher, RlpCodec> + Send + Sync + 'static, - E: client::CallExecutor<

::Block, KeccakHasher, RlpCodec> + Send + Sync + 'static, + B: client::backend::Backend<

::Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static, + E: client::CallExecutor<

::Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static, P: PoolChainApi + Sync + Send + 'static, P::Error: 'static, { diff --git a/substrate/rpc/src/chain/mod.rs b/substrate/rpc/src/chain/mod.rs index 7866ae3ef2cd7..86551e04847d0 100644 --- a/substrate/rpc/src/chain/mod.rs +++ b/substrate/rpc/src/chain/mod.rs @@ -27,7 +27,7 @@ use runtime_primitives::generic::{BlockId, SignedBlock}; use runtime_primitives::traits::{Block as BlockT, Header, NumberFor}; use runtime_version::RuntimeVersion; use tokio::runtime::TaskExecutor; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use subscriptions::Subscriptions; @@ -92,8 +92,8 @@ impl Chain { impl Chain where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, { fn unwrap_or_best(&self, hash: Trailing) -> Result { Ok(match hash.into() { @@ -105,8 +105,8 @@ impl Chain where impl ChainApi, Block::Extrinsic> for Chain where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, { type Metadata = ::metadata::Metadata; diff --git a/substrate/rpc/src/chain/tests.rs b/substrate/rpc/src/chain/tests.rs index 0be58b2b4be8b..def410532cd25 100644 --- a/substrate/rpc/src/chain/tests.rs +++ b/substrate/rpc/src/chain/tests.rs @@ -36,7 +36,7 @@ fn should_return_header() { parent_hash: 0.into(), number: 0, state_root: x.state_root.clone(), - extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(), + extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(), digest: Default::default(), } ); @@ -47,7 +47,7 @@ fn should_return_header() { parent_hash: 0.into(), number: 0, state_root: x.state_root.clone(), - extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(), + extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(), digest: Default::default(), } ); @@ -86,7 +86,7 @@ fn should_return_a_block() { parent_hash: api.client.genesis_hash(), number: 1, state_root: x.block.header.state_root.clone(), - extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(), + extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(), digest: Default::default(), }, extrinsics: vec![], @@ -100,7 +100,7 @@ fn should_return_a_block() { parent_hash: api.client.genesis_hash(), number: 1, state_root: x.block.header.state_root.clone(), - extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(), + extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(), digest: Default::default(), }, extrinsics: vec![], diff --git a/substrate/rpc/src/state/mod.rs b/substrate/rpc/src/state/mod.rs index 56772786babdc..e335310af74aa 100644 --- a/substrate/rpc/src/state/mod.rs +++ b/substrate/rpc/src/state/mod.rs @@ -27,7 +27,7 @@ use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; use primitives::hexdisplay::HexDisplay; use primitives::storage::{StorageKey, StorageData, StorageChangeSet}; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; use rpc::Result as RpcResult; use rpc::futures::{stream, Future, Sink, Stream}; use runtime_primitives::generic::BlockId; @@ -107,8 +107,8 @@ impl State { impl State where Block: BlockT, - B: client::backend::Backend, - E: CallExecutor, + B: client::backend::Backend, + E: CallExecutor, { fn unwrap_or_best(&self, hash: Trailing) -> Result { ::helpers::unwrap_or_else(|| Ok(self.client.info()?.chain.best_hash), hash) @@ -117,8 +117,8 @@ impl State where impl StateApi for State where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, { type Metadata = ::metadata::Metadata; diff --git a/substrate/runtime-io/with_std.rs b/substrate/runtime-io/with_std.rs index 954c4fad1521e..c1d85d914ebef 100644 --- a/substrate/runtime-io/with_std.rs +++ b/substrate/runtime-io/with_std.rs @@ -31,7 +31,7 @@ pub extern crate substrate_codec as codec; // re-export hashing functions. pub use primitives::{blake2_256, twox_128, twox_256}; -pub use primitives::KeccakHasher; +pub use primitives::Blake2Hasher; // Switch to this after PoC-3 // pub use primitives::BlakeHasher; pub use substrate_state_machine::{Externalities, TestExternalities}; @@ -42,7 +42,7 @@ use rlp::Encodable; // TODO: use the real error, not NoError. -environmental!(ext: trait Externalities); +environmental!(ext: trait Externalities); /// Get `key` from storage and return a `Vec`, empty if there's a problem. pub fn storage(key: &[u8]) -> Option> { @@ -145,7 +145,7 @@ pub fn ed25519_verify>(sig: &[u8; 64], msg: &[u8], pubkey: P) -> /// Execute the given closure with global function available whose functionality routes into the /// externalities `ext`. Forwards the value that the closure returns. // NOTE: need a concrete hasher here due to limitations of the `environmental!` macro, otherwise a type param would have been fine I think. -pub fn with_externalities R>(ext: &mut Externalities, f: F) -> R { +pub fn with_externalities R>(ext: &mut Externalities, f: F) -> R { ext::using(ext, f) } @@ -211,7 +211,7 @@ mod std_tests { #[test] fn storage_works() { - let mut t = TestExternalities::::new(); + let mut t = TestExternalities::::new(); assert!(with_externalities(&mut t, || { assert_eq!(storage(b"hello"), None); set_storage(b"hello", b"world"); @@ -232,7 +232,7 @@ mod std_tests { #[test] fn read_storage_works() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ b":test".to_vec() => b"\x0b\0\0\0Hello world".to_vec() ]; @@ -248,7 +248,7 @@ mod std_tests { #[test] fn clear_prefix_works() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ b":a".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), b":abcd".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), b":abc".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), diff --git a/substrate/runtime-io/without_std.rs b/substrate/runtime-io/without_std.rs index 130e7b1555eb7..34c4191e97e22 100644 --- a/substrate/runtime-io/without_std.rs +++ b/substrate/runtime-io/without_std.rs @@ -27,7 +27,7 @@ pub extern crate substrate_codec as codec; use core::intrinsics; use rstd::vec::Vec; use hashdb::Hasher; -use primitives::KeccakHasher; +use primitives::Blake2Hasher; pub use rstd::{mem, slice}; #[panic_handler] @@ -64,7 +64,7 @@ extern "C" { fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8; fn ext_get_storage_into(key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32, value_offset: u32) -> u32; fn ext_storage_root(result: *mut u8); - fn ext_keccak_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8); + fn ext_blake2_256_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8); fn ext_chain_id() -> u64; fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8); fn ext_twox_128(data: *const u8, len: u32, out: *mut u8); @@ -77,14 +77,14 @@ pub trait ExternTrieCrypto { fn enumerated_trie_root(values: &[&[u8]]) -> [u8; 32]; } -// Ensures we use a Keccak-flavoured Hasher when calling into native -impl ExternTrieCrypto for KeccakHasher { +// Ensures we use a Blake2_256-flavoured Hasher when calling into native +impl ExternTrieCrypto for Blake2Hasher { fn enumerated_trie_root(values: &[&[u8]]) -> [u8; 32] { let lengths = values.iter().map(|v| (v.len() as u32).to_le()).collect::>(); let values = values.iter().fold(Vec::new(), |mut acc, sl| { acc.extend_from_slice(sl); acc }); let mut result: [u8; 32] = Default::default(); unsafe { - ext_keccak_enumerated_trie_root( + ext_blake2_256_enumerated_trie_root( values.as_ptr(), lengths.as_ptr(), lengths.len() as u32, diff --git a/substrate/runtime-sandbox/without_std.rs b/substrate/runtime-sandbox/without_std.rs index 9efa282ebc290..f7feb466a090b 100755 --- a/substrate/runtime-sandbox/without_std.rs +++ b/substrate/runtime-sandbox/without_std.rs @@ -57,8 +57,7 @@ mod ffi { imports_len: usize, state: usize, ) -> u32; - // TODO: Rename it back to 'ext_sandbox_invoke'. - pub fn ext_sandbox_invoke_poc2( + pub fn ext_sandbox_invoke( instance_idx: u32, export_ptr: *const u8, export_len: usize, @@ -272,7 +271,7 @@ impl Instance { let mut return_val = vec![0u8; sandbox_primitives::ReturnValue::ENCODED_MAX_SIZE]; let result = unsafe { - ffi::ext_sandbox_invoke_poc2( + ffi::ext_sandbox_invoke( self.instance_idx, name.as_ptr(), name.len(), diff --git a/substrate/runtime-support/src/storage/mod.rs b/substrate/runtime-support/src/storage/mod.rs index cb8f61659e232..7b5665bf9bca8 100644 --- a/substrate/runtime-support/src/storage/mod.rs +++ b/substrate/runtime-support/src/storage/mod.rs @@ -40,22 +40,6 @@ impl<'a> Input for IncrementalInput<'a> { } } -// TODO: only introduce this wrapper for types where it makes sense, ideally have it within the module declaration. - -struct AppendZeroes<'a, I: Input + 'a> { - input: &'a mut I, -} - -impl<'a, I: Input + 'a> Input for AppendZeroes<'a, I> { - fn read(&mut self, into: &mut [u8]) -> usize { - let r = self.input.read(into); - for z in &mut into[r..] { - *z = 0; - }; - into.len() - } -} - /// Return the value of the item in storage under `key`, or `None` if there is no explicit entry. pub fn get(key: &[u8]) -> Option { let key = twox_128(key); @@ -64,7 +48,7 @@ pub fn get(key: &[u8]) -> Option { key: &key[..], pos: 0, }; - Decode::decode(&mut AppendZeroes { input: &mut input } ).expect("storage is not null, therefore must be a valid type") + Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type") }) } diff --git a/substrate/runtime/balances/src/genesis_config.rs b/substrate/runtime/balances/src/genesis_config.rs index 30331b24645a8..1b88353c632e3 100644 --- a/substrate/runtime/balances/src/genesis_config.rs +++ b/substrate/runtime/balances/src/genesis_config.rs @@ -23,7 +23,7 @@ use rstd::prelude::*; use codec::Encode; use runtime_support::{StorageValue, StorageMap}; use primitives::traits::{Zero, As}; -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; use {runtime_io, primitives}; use super::{Trait, ENUM_SET_SIZE, EnumSet, NextEnumSet, CreationFee, TransferFee, ReclaimRebate, ExistentialDeposit, TransactionByteFee, TransactionBaseFee, TotalIssuance, @@ -60,7 +60,7 @@ impl primitives::BuildStorage for GenesisConfig { fn build_storage(self) -> ::std::result::Result, Vec>, String> { let total_issuance: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n); - let mut r: runtime_io::TestExternalities = map![ + let mut r: runtime_io::TestExternalities = map![ Self::hash(>::key()).to_vec() => T::AccountIndex::sa(self.balances.len() / ENUM_SET_SIZE).encode(), Self::hash(>::key()).to_vec() => self.transaction_base_fee.encode(), Self::hash(>::key()).to_vec() => self.transaction_byte_fee.encode(), diff --git a/substrate/runtime/balances/src/mock.rs b/substrate/runtime/balances/src/mock.rs index 99204b91d121d..d85a27715819d 100644 --- a/substrate/runtime/balances/src/mock.rs +++ b/substrate/runtime/balances/src/mock.rs @@ -20,7 +20,7 @@ use primitives::BuildStorage; use primitives::testing::{Digest, Header}; -use substrate_primitives::{H256, KeccakHasher}; +use substrate_primitives::{H256, Blake2Hasher}; use runtime_io; use {GenesisConfig, Module, Trait, system}; @@ -50,7 +50,7 @@ impl Trait for Runtime { type Event = (); } -pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities { +pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); let balance_factor = if ext_deposit > 0 { 256 diff --git a/substrate/runtime/consensus/src/lib.rs b/substrate/runtime/consensus/src/lib.rs index 852b93bcdfc23..07ff10d0714b6 100644 --- a/substrate/runtime/consensus/src/lib.rs +++ b/substrate/runtime/consensus/src/lib.rs @@ -51,7 +51,7 @@ use primitives::bft::MisbehaviorReport; use system::{ensure_signed, ensure_inherent, ensure_root}; #[cfg(any(feature = "std", test))] -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; #[cfg(any(feature = "std", test))] use std::collections::HashMap; @@ -257,7 +257,7 @@ impl primitives::BuildStorage for GenesisConfig fn build_storage(self) -> ::std::result::Result, Vec>, String> { use codec::{Encode, KeyedVec}; let auth_count = self.authorities.len() as u32; - let mut r: runtime_io::TestExternalities = self.authorities.into_iter().enumerate().map(|(i, v)| + let mut r: runtime_io::TestExternalities = self.authorities.into_iter().enumerate().map(|(i, v)| ((i as u32).to_keyed_vec(AUTHORITY_AT), v.encode()) ).collect(); r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode()); diff --git a/substrate/runtime/contract/src/genesis_config.rs b/substrate/runtime/contract/src/genesis_config.rs index dc2019d882400..2d9a50573a672 100644 --- a/substrate/runtime/contract/src/genesis_config.rs +++ b/substrate/runtime/contract/src/genesis_config.rs @@ -25,7 +25,7 @@ use runtime_io::{self, twox_128}; use runtime_support::StorageValue; use codec::Encode; use std::collections::HashMap; -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -41,7 +41,7 @@ pub struct GenesisConfig { impl runtime_primitives::BuildStorage for GenesisConfig { fn build_storage(self) -> ::std::result::Result, Vec>, String> { - let r: runtime_io::TestExternalities = map![ + let r: runtime_io::TestExternalities = map![ twox_128(>::key()).to_vec() => self.contract_fee.encode(), twox_128(>::key()).to_vec() => self.call_base_fee.encode(), twox_128(>::key()).to_vec() => self.create_base_fee.encode(), diff --git a/substrate/runtime/contract/src/tests.rs b/substrate/runtime/contract/src/tests.rs index 4456bf1972c6b..17f5a4d88aac9 100644 --- a/substrate/runtime/contract/src/tests.rs +++ b/substrate/runtime/contract/src/tests.rs @@ -20,7 +20,7 @@ use runtime_primitives::testing::{Digest, H256, Header}; use runtime_primitives::traits::{BlakeTwo256}; use runtime_primitives::BuildStorage; use runtime_support::StorageMap; -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; use wabt; use { runtime_io, balances, system, CodeOf, ContractAddressFor, @@ -93,7 +93,7 @@ impl ExtBuilder { self.block_gas_limit = block_gas_limit; self } - fn build(self) -> runtime_io::TestExternalities { + fn build(self) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default() .build_storage() .unwrap(); diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index 7d9407b57d8a5..1c0883877fcba 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -133,7 +133,7 @@ mod tests { pub use primitives::BuildStorage; pub use primitives::traits::{BlakeTwo256}; pub use primitives::testing::{Digest, Header}; - pub use substrate_primitives::KeccakHasher; + pub use substrate_primitives::Blake2Hasher; pub use {seats, motions, voting}; impl_outer_origin! { @@ -192,7 +192,7 @@ mod tests { type Event = Event; } - pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities { + pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(balances::GenesisConfig::{ balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], diff --git a/substrate/runtime/council/src/seats.rs b/substrate/runtime/council/src/seats.rs index b98a655fbddd1..294035a25a941 100644 --- a/substrate/runtime/council/src/seats.rs +++ b/substrate/runtime/council/src/seats.rs @@ -628,7 +628,7 @@ mod tests { }); } - fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities { + fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities { let mut t = new_test_ext(false); with_externalities(&mut t, || { >::put(vec![0, 0, 1]); diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index cd540d5ed35aa..12f2e7e7aa402 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -374,7 +374,7 @@ impl primitives::BuildStorage for GenesisConfig mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::{H256, KeccakHasher}; + use substrate_primitives::{H256, Blake2Hasher}; use primitives::BuildStorage; use primitives::traits::{BlakeTwo256}; use primitives::testing::{Digest, Header}; @@ -416,7 +416,7 @@ mod tests { type Event = (); } - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(balances::GenesisConfig::{ balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], diff --git a/substrate/runtime/example/src/lib.rs b/substrate/runtime/example/src/lib.rs index fee47239ae899..8247106e38466 100644 --- a/substrate/runtime/example/src/lib.rs +++ b/substrate/runtime/example/src/lib.rs @@ -331,7 +331,7 @@ mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::{H256, KeccakHasher}; + use substrate_primitives::{H256, Blake2Hasher}; use runtime_primitives::BuildStorage; use runtime_primitives::traits::{BlakeTwo256}; @@ -373,7 +373,7 @@ mod tests { // This function basically just builds a genesis storage key/value store according to // our desired mockup. - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); // We use default for brevity, but you can configure as desired if needed. t.extend(balances::GenesisConfig::::default().build_storage().unwrap()); diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index 060e0c32e99e6..9b7e736f6d934 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -217,7 +217,7 @@ mod tests { use super::*; use balances::Call; use runtime_io::with_externalities; - use substrate_primitives::{H256, KeccakHasher}; + use substrate_primitives::{H256, Blake2Hasher}; use primitives::BuildStorage; use primitives::traits::{Header as HeaderT, BlakeTwo256, Lookup}; use primitives::testing::{Digest, Header, Block}; @@ -290,7 +290,7 @@ mod tests { }); } - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(balances::GenesisConfig::::default().build_storage().unwrap()); t.into() @@ -303,11 +303,8 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, - // Blake - // state_root: hex!("02532989c613369596025dfcfc821339fc9861987003924913a5a1382f87034a").into(), - // Keccak - state_root: hex!("14a253cb1c5f38beeec8bee962a941b2ba0773b7593564fbe62b9c3a46784df5").into(), - extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), + state_root: hex!("d1d3da2b1efb1a6ef740b8cdef52e4cf3c6dade6f8a360969fd7ef0034c53b54").into(), + extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(), digest: Digest { logs: vec![], }, }, extrinsics: vec![], @@ -324,7 +321,7 @@ mod tests { parent_hash: [69u8; 32].into(), number: 1, state_root: [0u8; 32].into(), - extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), + extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(), digest: Digest { logs: vec![], }, }, extrinsics: vec![], @@ -340,7 +337,7 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, - state_root: hex!("14a253cb1c5f38beeec8bee962a941b2ba0773b7593564fbe62b9c3a46784df5").into(), + state_root: hex!("d1d3da2b1efb1a6ef740b8cdef52e4cf3c6dade6f8a360969fd7ef0034c53b54").into(), extrinsics_root: [0u8; 32].into(), digest: Digest { logs: vec![], }, }, diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 66d523fe4c291..32aa47a16f95a 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -22,7 +22,7 @@ use runtime_io; #[cfg(feature = "std")] use std::fmt::{Debug, Display}; #[cfg(feature = "std")] use serde::{Serialize, de::DeserializeOwned}; use substrate_primitives; -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; use codec::{Codec, Encode}; pub use integer_sqrt::IntegerSquareRoot; pub use num_traits::{Zero, One, Bounded}; @@ -257,20 +257,20 @@ impl Hash for BlakeTwo256 { runtime_io::blake2_256(s).into() } fn enumerated_trie_root(items: &[&[u8]]) -> Self::Output { - runtime_io::enumerated_trie_root::(items).into() + runtime_io::enumerated_trie_root::(items).into() } fn trie_root< I: IntoIterator, A: AsRef<[u8]> + Ord, B: AsRef<[u8]> >(input: I) -> Self::Output { - runtime_io::trie_root::(input).into() + runtime_io::trie_root::(input).into() } fn ordered_trie_root< I: IntoIterator, A: AsRef<[u8]> >(input: I) -> Self::Output { - runtime_io::ordered_trie_root::(input).into() + runtime_io::ordered_trie_root::(input).into() } fn storage_root() -> Self::Output { runtime_io::storage_root().into() diff --git a/substrate/runtime/session/src/lib.rs b/substrate/runtime/session/src/lib.rs index ccbb9a9890d50..007dd43729f7c 100644 --- a/substrate/runtime/session/src/lib.rs +++ b/substrate/runtime/session/src/lib.rs @@ -286,7 +286,7 @@ impl primitives::BuildStorage for GenesisConfig mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::{H256, KeccakHasher}; + use substrate_primitives::{H256, Blake2Hasher}; use primitives::BuildStorage; use primitives::traits::{Identity, BlakeTwo256}; use primitives::testing::{Digest, Header}; @@ -328,7 +328,7 @@ mod tests { type Consensus = consensus::Module; type Session = Module; - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(consensus::GenesisConfig::{ code: vec![], diff --git a/substrate/runtime/staking/src/genesis_config.rs b/substrate/runtime/staking/src/genesis_config.rs index 38be260dfbed1..e2b50ca1229ad 100644 --- a/substrate/runtime/staking/src/genesis_config.rs +++ b/substrate/runtime/staking/src/genesis_config.rs @@ -23,7 +23,7 @@ use rstd::prelude::*; use codec::Encode; use runtime_support::StorageValue; use primitives::traits::As; -use substrate_primitives::KeccakHasher; +use substrate_primitives::Blake2Hasher; use {runtime_io, primitives}; use super::{Trait, Intentions, CurrentEra, OfflineSlashGrace, MinimumValidatorCount, BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, OfflineSlash}; @@ -61,7 +61,7 @@ impl Default for GenesisConfig { impl primitives::BuildStorage for GenesisConfig { fn build_storage(self) -> ::std::result::Result, Vec>, String> { - let r: runtime_io::TestExternalities = map![ + let r: runtime_io::TestExternalities = map![ Self::hash(>::key()).to_vec() => self.intentions.encode(), Self::hash(>::key()).to_vec() => self.sessions_per_era.encode(), Self::hash(>::key()).to_vec() => self.validator_count.encode(), diff --git a/substrate/runtime/staking/src/mock.rs b/substrate/runtime/staking/src/mock.rs index 4fbc64419a8ce..7dda4fe7ebec4 100644 --- a/substrate/runtime/staking/src/mock.rs +++ b/substrate/runtime/staking/src/mock.rs @@ -21,7 +21,7 @@ use primitives::BuildStorage; use primitives::traits::{Identity}; use primitives::testing::{Digest, Header}; -use substrate_primitives::{H256, KeccakHasher}; +use substrate_primitives::{H256, Blake2Hasher}; use runtime_io; use {GenesisConfig, Module, Trait, consensus, session, system, timestamp, balances}; @@ -70,7 +70,7 @@ impl Trait for Test { type Event = (); } -pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities { +pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); let balance_factor = if ext_deposit > 0 { 256 diff --git a/substrate/runtime/system/src/lib.rs b/substrate/runtime/system/src/lib.rs index 1df27352bb606..ae8ceff6a6047 100644 --- a/substrate/runtime/system/src/lib.rs +++ b/substrate/runtime/system/src/lib.rs @@ -55,7 +55,7 @@ use rstd::marker::PhantomData; use codec::Encode; #[cfg(any(feature = "std", test))] -use runtime_io::{twox_128, TestExternalities, KeccakHasher}; +use runtime_io::{twox_128, TestExternalities, Blake2Hasher}; /// Compute the extrinsics root of a list of extrinsics. pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { @@ -261,7 +261,7 @@ impl Module { /// Get the basic externalities for this module, useful for tests. #[cfg(any(feature = "std", test))] - pub fn externalities() -> TestExternalities { + pub fn externalities() -> TestExternalities { map![ twox_128(&>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(), // TODO: replace with Hash::default().encode twox_128(>::key()).to_vec() => T::BlockNumber::one().encode(), @@ -395,7 +395,7 @@ mod tests { - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { GenesisConfig::::default().build_storage().unwrap().into() } diff --git a/substrate/runtime/treasury/src/lib.rs b/substrate/runtime/treasury/src/lib.rs index 0aac4c3f9d1e6..1edf33a563066 100644 --- a/substrate/runtime/treasury/src/lib.rs +++ b/substrate/runtime/treasury/src/lib.rs @@ -335,7 +335,7 @@ mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::{H256, KeccakHasher}; + use substrate_primitives::{H256, Blake2Hasher}; use runtime_primitives::BuildStorage; use runtime_primitives::traits::{BlakeTwo256}; use runtime_primitives::testing::{Digest, Header}; @@ -372,7 +372,7 @@ mod tests { type Balances = balances::Module; type Treasury = Module; - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(balances::GenesisConfig::{ balances: vec![(0, 100), (1, 99), (2, 1)], diff --git a/substrate/service/src/components.rs b/substrate/service/src/components.rs index 9f3e19bc14e1f..38088b905069d 100644 --- a/substrate/service/src/components.rs +++ b/substrate/service/src/components.rs @@ -29,7 +29,7 @@ use substrate_executor::{NativeExecutor, NativeExecutionDispatch}; use extrinsic_pool::{self, Options as ExtrinsicPoolOptions, Pool as ExtrinsicPool}; use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, BuildStorage}; use config::Configuration; -use primitives::{KeccakHasher, RlpCodec, H256}; +use primitives::{Blake2Hasher, RlpCodec, H256}; // Type aliases. // These exist mainly to avoid typing `::Foo` all over the code. @@ -65,7 +65,7 @@ pub type LightExecutor = client::light::call_executor::RemoteCallExecutor< network::OnDemand<::Block, NetworkService> >, network::OnDemand<::Block, NetworkService>, - KeccakHasher, + Blake2Hasher, RlpCodec, >; @@ -153,9 +153,9 @@ pub trait Components: 'static { /// Associated service factory. type Factory: ServiceFactory; /// Client backend. - type Backend: 'static + client::backend::Backend, KeccakHasher, RlpCodec>; + type Backend: 'static + client::backend::Backend, Blake2Hasher, RlpCodec>; /// Client executor. - type Executor: 'static + client::CallExecutor, KeccakHasher, RlpCodec> + Send + Sync; + type Executor: 'static + client::CallExecutor, Blake2Hasher, RlpCodec> + Send + Sync; /// Extrinsic pool type. type ExtrinsicPoolApi: 'static + extrinsic_pool::ChainApi::ExtrinsicHash, Block=FactoryBlock>; @@ -241,7 +241,7 @@ impl Components for LightComponents }; let db_storage = client_db::light::LightStorage::new(db_settings)?; let light_blockchain = client::light::new_light_blockchain(db_storage); - let fetch_checker = Arc::new(client::light::new_fetch_checker::<_, KeccakHasher, RlpCodec>(executor)); + let fetch_checker = Arc::new(client::light::new_fetch_checker::<_, Blake2Hasher, RlpCodec>(executor)); let fetcher = Arc::new(network::OnDemand::new(fetch_checker)); let client_backend = client::light::new_light_backend(light_blockchain, fetcher.clone()); let client = client::light::new_light(client_backend, fetcher.clone(), &config.chain_spec)?; diff --git a/substrate/state-machine/src/lib.rs b/substrate/state-machine/src/lib.rs index fc3f52c5dcb5c..7dab6e6af6375 100644 --- a/substrate/state-machine/src/lib.rs +++ b/substrate/state-machine/src/lib.rs @@ -484,7 +484,7 @@ mod tests { use super::*; use super::backend::InMemory; use super::ext::Ext; - use primitives::{KeccakHasher, RlpCodec, H256}; + use primitives::{Blake2Hasher, RlpCodec, H256}; struct DummyCodeExecutor { native_available: bool, @@ -557,7 +557,7 @@ mod tests { b"dogglesworth".to_vec() => b"catXXX".to_vec(), b"doug".to_vec() => b"notadog".to_vec() ]; - let backend = InMemory::::from(initial); + let backend = InMemory::::from(initial); let mut overlay = OverlayedChanges { committed: map![ b"dog".to_vec() => Some(b"puppy".to_vec()), @@ -570,10 +570,7 @@ mod tests { ], }; let mut ext = Ext::new(&mut overlay, &backend); - // Blake - // const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); - // Keccak - const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"); + const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); assert_eq!(ext.storage_root(), H256(ROOT)); } @@ -630,7 +627,7 @@ mod tests { &mut Default::default(), &executor, "test", &[]).unwrap(); // check proof locally - let (local_result, _) = execution_proof_check::(remote_root, remote_proof, + let (local_result, _) = execution_proof_check::(remote_root, remote_proof, &mut Default::default(), &executor, "test", &[]).unwrap(); // check that both results are correct @@ -646,7 +643,7 @@ mod tests { b"abc".to_vec() => b"2".to_vec(), b"bbb".to_vec() => b"3".to_vec() ]; - let backend = InMemory::::from(initial).try_into_trie_backend().unwrap(); + let backend = InMemory::::from(initial).try_into_trie_backend().unwrap(); let mut overlay = OverlayedChanges { committed: map![ b"aba".to_vec() => Some(b"1312".to_vec()), @@ -685,8 +682,8 @@ mod tests { let remote_root = remote_backend.storage_root(::std::iter::empty()).0; let remote_proof = prove_read(remote_backend, b"value2").unwrap().1; // check proof locally - let local_result1 = read_proof_check::(remote_root, remote_proof.clone(), b"value2").unwrap(); - let local_result2 = read_proof_check::(remote_root, remote_proof.clone(), &[0xff]).is_ok(); + let local_result1 = read_proof_check::(remote_root, remote_proof.clone(), b"value2").unwrap(); + let local_result2 = read_proof_check::(remote_root, remote_proof.clone(), &[0xff]).is_ok(); // check that results are correct assert_eq!(local_result1, Some(vec![24])); assert_eq!(local_result2, false); diff --git a/substrate/state-machine/src/proving_backend.rs b/substrate/state-machine/src/proving_backend.rs index db8d142452eba..25a2f49c75a34 100644 --- a/substrate/state-machine/src/proving_backend.rs +++ b/substrate/state-machine/src/proving_backend.rs @@ -123,9 +123,9 @@ mod tests { use backend::{InMemory}; use trie_backend::tests::test_trie; use super::*; - use primitives::{KeccakHasher, RlpCodec}; + use primitives::{Blake2Hasher, RlpCodec}; - fn test_proving() -> ProvingBackend { + fn test_proving() -> ProvingBackend { ProvingBackend::new(test_trie()) } @@ -143,7 +143,7 @@ mod tests { #[test] fn proof_is_invalid_when_does_not_contains_root() { - assert!(create_proof_check_backend::(1.into(), vec![]).is_err()); + assert!(create_proof_check_backend::(1.into(), vec![]).is_err()); } #[test] @@ -162,7 +162,7 @@ mod tests { #[test] fn proof_recorded_and_checked() { let contents = (0..64).map(|i| (vec![i], Some(vec![i]))).collect::>(); - let in_memory = InMemory::::default(); + let in_memory = InMemory::::default(); let in_memory = in_memory.update(contents); let in_memory_root = in_memory.storage_root(::std::iter::empty()).0; (0..64).for_each(|i| assert_eq!(in_memory.storage(&[i]).unwrap().unwrap(), vec![i])); @@ -177,7 +177,7 @@ mod tests { let proof = proving.extract_proof(); - let proof_check = create_proof_check_backend::(in_memory_root.into(), proof).unwrap(); + let proof_check = create_proof_check_backend::(in_memory_root.into(), proof).unwrap(); assert_eq!(proof_check.storage(&[42]).unwrap().unwrap(), vec![42]); } } diff --git a/substrate/state-machine/src/testing.rs b/substrate/state-machine/src/testing.rs index 955cb77464b4e..bcb02f6bb06e0 100644 --- a/substrate/state-machine/src/testing.rs +++ b/substrate/state-machine/src/testing.rs @@ -104,18 +104,15 @@ impl Externalities for TestExternalities where H::Out: Ord + En #[cfg(test)] mod tests { use super::*; - use primitives::{KeccakHasher, H256}; + use primitives::{Blake2Hasher, H256}; #[test] fn commit_should_work() { - let mut ext = TestExternalities::::new(); + let mut ext = TestExternalities::::new(); ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec()); ext.set_storage(b"dog".to_vec(), b"puppy".to_vec()); ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec()); - // Blake - // const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); - // Keccak - const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"); + const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); assert_eq!(ext.storage_root(), H256(ROOT)); } } diff --git a/substrate/state-machine/src/trie_backend.rs b/substrate/state-machine/src/trie_backend.rs index 066f74b77d06a..565cc5387f486 100644 --- a/substrate/state-machine/src/trie_backend.rs +++ b/substrate/state-machine/src/trie_backend.rs @@ -280,11 +280,11 @@ impl TrieBackendStorage { pub mod tests { use super::*; use std::collections::HashSet; - use primitives::{KeccakHasher, RlpCodec, H256}; + use primitives::{Blake2Hasher, RlpCodec, H256}; - fn test_db() -> (MemoryDB, H256) { + fn test_db() -> (MemoryDB, H256) { let mut root = H256::default(); - let mut mdb = MemoryDB::::new(); + let mut mdb = MemoryDB::::new(); { let mut trie = TrieDBMut::<_, RlpCodec>::new(&mut mdb, &mut root); trie.insert(b"key", b"value").expect("insert failed"); @@ -298,7 +298,7 @@ pub mod tests { (mdb, root) } - pub(crate) fn test_trie() -> TrieBackend { + pub(crate) fn test_trie() -> TrieBackend { let (mdb, root) = test_db(); TrieBackend::with_memorydb(mdb, root) } @@ -320,7 +320,7 @@ pub mod tests { #[test] fn pairs_are_empty_on_empty_storage() { - let db = TrieBackend::::with_memorydb( + let db = TrieBackend::::with_memorydb( MemoryDB::new(), Default::default() ); diff --git a/substrate/test-client/src/block_builder_ext.rs b/substrate/test-client/src/block_builder_ext.rs index a1894f5fa68f3..4cc0854771a2c 100644 --- a/substrate/test-client/src/block_builder_ext.rs +++ b/substrate/test-client/src/block_builder_ext.rs @@ -22,7 +22,7 @@ use keyring; use runtime; use {Backend, Executor}; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; /// Extension trait for test block builder. pub trait BlockBuilderExt { @@ -30,7 +30,7 @@ pub trait BlockBuilderExt { fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error>; } -impl BlockBuilderExt for client::block_builder::BlockBuilder { +impl BlockBuilderExt for client::block_builder::BlockBuilder { fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> { self.push(sign_tx(transfer)) } diff --git a/substrate/test-client/src/lib.rs b/substrate/test-client/src/lib.rs index 4de63d46a28a0..3aeefed0fafb2 100644 --- a/substrate/test-client/src/lib.rs +++ b/substrate/test-client/src/lib.rs @@ -39,7 +39,7 @@ mod block_builder_ext; pub use client_ext::TestClient; pub use block_builder_ext::BlockBuilderExt; -use primitives::{KeccakHasher, RlpCodec}; +use primitives::{Blake2Hasher, RlpCodec}; mod local_executor { #![allow(missing_docs)] @@ -52,7 +52,7 @@ mod local_executor { pub use local_executor::LocalExecutor; /// Test client database backend. -pub type Backend = client::in_mem::Backend; +pub type Backend = client::in_mem::Backend; /// Test client executor. pub type Executor = client::LocalCallExecutor< diff --git a/substrate/test-runtime/src/system.rs b/substrate/test-runtime/src/system.rs index b57b5f93f9ec8..b60cfa7872c89 100644 --- a/substrate/test-runtime/src/system.rs +++ b/substrate/test-runtime/src/system.rs @@ -24,7 +24,7 @@ use runtime_primitives::traits::{Hash as HashT, BlakeTwo256}; use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult}; use codec::{KeyedVec, Encode}; use super::{AccountId, BlockNumber, Extrinsic, H256 as Hash, Block, Header}; -use primitives::KeccakHasher; +use primitives::Blake2Hasher; const NONCE_OF: &[u8] = b"nonce:"; const BALANCE_OF: &[u8] = b"balance:"; @@ -69,7 +69,7 @@ pub fn execute_block(block: Block) { // check transaction trie root represents the transactions. let txs = block.extrinsics.iter().map(Encode::encode).collect::>(); let txs = txs.iter().map(Vec::as_slice).collect::>(); - let txs_root = enumerated_trie_root::(&txs).into(); + let txs_root = enumerated_trie_root::(&txs).into(); info_expect_equal_hash(&txs_root, &header.extrinsics_root); assert!(txs_root == header.extrinsics_root, "Transaction trie root must be valid."); @@ -96,7 +96,7 @@ pub fn finalise_block() -> Header { let extrinsic_index = ExtrinsicIndex::take(); let txs: Vec<_> = (0..extrinsic_index).map(ExtrinsicData::take).collect(); let txs = txs.iter().map(Vec::as_slice).collect::>(); - let extrinsics_root = enumerated_trie_root::(&txs).into(); + let extrinsics_root = enumerated_trie_root::(&txs).into(); let number = ::take(); let parent_hash = ::take(); @@ -172,9 +172,9 @@ mod tests { use codec::{Joiner, KeyedVec}; use keyring::Keyring; use ::{Header, Digest, Extrinsic, Transfer}; - use primitives::KeccakHasher; + use primitives::Blake2Hasher; - fn new_test_ext() -> TestExternalities { + fn new_test_ext() -> TestExternalities { map![ twox_128(b"latest").to_vec() => vec![69u8; 32], twox_128(b":auth:len").to_vec() => vec![].and(&3u32), @@ -197,11 +197,8 @@ mod tests { let h = Header { parent_hash: [69u8; 32].into(), number: 1, - // Blake - // state_root: hex!("0c22599e15fb5e052c84f79a2aab179ba6bb238218fd86bdd4a74ebcc87adfcd").into(), - // Keccak - state_root: hex!("97dfcd1f8cbf8845fcb544f89332f1a94c1137f7d1b199ef0b0a6ed217015c3e").into(), - extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), + state_root: hex!("0c22599e15fb5e052c84f79a2aab179ba6bb238218fd86bdd4a74ebcc87adfcd").into(), + extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(), digest: Digest { logs: vec![], }, }; @@ -228,11 +225,8 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, - // Blake - // state_root: hex!("0425393fd07e2a806cfd7e990ee91dc92fe6bba34eab2bf45d5be7d67e24d467").into(), - // Keccak - state_root: hex!("0dd8210adaf581464cc68555814a787ed491f8c608d0a0dbbf2208a6d44190b1").into(), - extrinsics_root: hex!("951508f2cc0071500a74765ab0fb2f280fdcdd329d5f989dda675010adee99d6").into(), + state_root: hex!("0425393fd07e2a806cfd7e990ee91dc92fe6bba34eab2bf45d5be7d67e24d467").into(), + extrinsics_root: hex!("83fd59e8fe7cee53d7421713a09fe0abae1aec5f4db94fe5193737b12195f013").into(), digest: Digest { logs: vec![], }, }, extrinsics: vec![ @@ -256,11 +250,8 @@ mod tests { header: Header { parent_hash: b.header.hash(), number: 2, - // Blake - // state_root: hex!("e32dd1d84d9133ca48078d2d83f2b0db19f9d47229ba98bf5ced0e9f86fac2c7").into(), - // Keccak - state_root: hex!("c93f2fd494c386fa32ee76b6198a7ccf5db12c02c3a79755fd2d4646ec2bf8d7").into(), - extrinsics_root: hex!("3563642676d7e042c894eedc579ba2d6eeedf9a6c66d9d557599effc9f674372").into(), + state_root: hex!("e32dd1d84d9133ca48078d2d83f2b0db19f9d47229ba98bf5ced0e9f86fac2c7").into(), + extrinsics_root: hex!("5d2d0a93201744f0df878c33b07da40cd38e24ac2358cc2811ea640835c31b68").into(), digest: Digest { logs: vec![], }, }, extrinsics: vec![ diff --git a/substrate/test-runtime/wasm/Cargo.lock b/substrate/test-runtime/wasm/Cargo.lock index 16fa861ae0012..f42241061f26e 100644 --- a/substrate/test-runtime/wasm/Cargo.lock +++ b/substrate/test-runtime/wasm/Cargo.lock @@ -541,7 +541,6 @@ dependencies = [ "substrate-codec 0.1.0", "substrate-codec-derive 0.1.0", "substrate-runtime-std 0.1.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index ccc4ccc1bbfe2..c917584c7f3d8 100644 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm index 10dd03ccc461a..89a0e6127e8be 100755 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm differ