diff --git a/Cargo.lock b/Cargo.lock index eeb01529c20..106b7adddfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -502,7 +502,7 @@ dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1063,7 +1063,7 @@ dependencies = [ "rlp_derive 0.1.0", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "stats 0.1.0", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1361,7 +1361,6 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-util-mem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1369,6 +1368,7 @@ dependencies = [ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1405,7 +1405,7 @@ dependencies = [ "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3041,9 +3041,10 @@ dependencies = [ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "time-utils 0.1.0", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3099,7 +3100,7 @@ dependencies = [ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3113,7 +3114,7 @@ dependencies = [ "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3279,7 +3280,7 @@ dependencies = [ "hamming 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "primal-bit 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "primal-estimate 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3875,11 +3876,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.5" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "socket2" @@ -4333,7 +4331,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4716,6 +4714,25 @@ dependencies = [ "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "zeroize" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54eb1d8fe354e5fc611daf4f2ea97dd45a765f4f1e4512306ec183ae2e8f20c9" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" @@ -5023,7 +5040,7 @@ dependencies = [ "checksum slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6dbdd334bd28d328dad1c41b0ea662517883d8880d8533895ef96c8003dec9c4" "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" -"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" +"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -5114,3 +5131,5 @@ dependencies = [ "checksum xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a66b7c2281ebde13cf4391d70d4c7e5946c3c25e72a7b859ca8f677dcd0b0c61" "checksum xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c1cb601d29fe2c2ac60a2b2e5e293994d87a1f6fa9687a31a15270f909be9c2" "checksum xmltree 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff8eaee9d17062850f1e6163b509947969242990ee59a35801af437abe041e70" +"checksum zeroize 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e2ea4afc22e9497e26b42bf047083c30f7e3ca566f3bcd7187f83d18b327043" +"checksum zeroize_derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afd1469e4bbca3b96606d26ba6e9bd6d3aed3b1299c82b92ec94377d22d78dbc" diff --git a/accounts/ethkey/Cargo.toml b/accounts/ethkey/Cargo.toml index a66a74de05a..9c01fa74f58 100644 --- a/accounts/ethkey/Cargo.toml +++ b/accounts/ethkey/Cargo.toml @@ -11,7 +11,6 @@ eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" } ethereum-types = "0.6.0" lazy_static = "1.0" log = "0.4" -parity-util-mem = "0.1" parity-wordlist = "1.2" quick-error = "1.2.2" rand = "0.6" @@ -19,3 +18,4 @@ rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" tiny-keccak = "1.4" +zeroize = "0.9.1" diff --git a/accounts/ethkey/src/lib.rs b/accounts/ethkey/src/lib.rs index 2312f2bcd31..4f55f056d07 100644 --- a/accounts/ethkey/src/lib.rs +++ b/accounts/ethkey/src/lib.rs @@ -19,7 +19,6 @@ extern crate edit_distance; extern crate parity_crypto; extern crate ethereum_types; -extern crate parity_util_mem; extern crate parity_wordlist; #[macro_use] extern crate quick_error; @@ -28,6 +27,7 @@ extern crate rustc_hex; extern crate secp256k1; extern crate serde; extern crate tiny_keccak; +extern crate zeroize; #[macro_use] extern crate lazy_static; diff --git a/accounts/ethkey/src/secret.rs b/accounts/ethkey/src/secret.rs index 25136ee8330..c850fa70ee8 100644 --- a/accounts/ethkey/src/secret.rs +++ b/accounts/ethkey/src/secret.rs @@ -21,17 +21,23 @@ use rustc_hex::ToHex; use secp256k1::constants::{SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE}; use secp256k1::key; use ethereum_types::H256; -use parity_util_mem::Memzero; +use zeroize::Zeroize; use {Error, SECP256K1}; #[derive(Clone, PartialEq, Eq)] pub struct Secret { - inner: Memzero, + inner: H256, +} + +impl Drop for Secret { + fn drop(&mut self) { + self.inner.0.zeroize() + } } impl ToHex for Secret { fn to_hex(&self) -> String { - format!("{:x}", *self.inner) + format!("{:x}", self.inner) } } @@ -61,12 +67,12 @@ impl Secret { } let mut h = H256::zero(); h.as_bytes_mut().copy_from_slice(&key[0..32]); - Some(Secret { inner: Memzero::from(h) }) + Some(Secret { inner: h }) } /// Creates zero key, which is invalid for crypto operations, but valid for math operation. pub fn zero() -> Self { - Secret { inner: Memzero::from(H256::zero()) } + Secret { inner: H256::zero() } } /// Imports and validates the key. @@ -214,7 +220,7 @@ impl FromStr for Secret { impl From<[u8; 32]> for Secret { fn from(k: [u8; 32]) -> Self { - Secret { inner: Memzero::from(H256(k)) } + Secret { inner: H256(k) } } } diff --git a/ethcore/res/instant_seal.json b/ethcore/res/instant_seal.json index 3ec998f0e5c..0a46f07ff67 100644 --- a/ethcore/res/instant_seal.json +++ b/ethcore/res/instant_seal.json @@ -24,6 +24,9 @@ "eip211Transition": "0x0", "eip214Transition": "0x0", "eip658Transition": "0x0", + "eip145Transition": "0x0", + "eip1014Transition": "0x0", + "eip1052Transition": "0x0", "wasmActivationTransition": "0x0" }, "genesis": { diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 2aa6cfddea7..6094f69949f 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -16,7 +16,6 @@ use std::cmp; use std::collections::{HashSet, BTreeMap, VecDeque}; -use std::str::FromStr; use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::sync::{Arc, Weak}; use std::time::{Instant, Duration}; @@ -753,7 +752,7 @@ impl Client { let importer = Importer::new(&config, engine.clone(), message_channel.clone(), miner)?; - let registrar_address = engine.additional_params().get("registrar").and_then(|s| Address::from_str(s).ok()); + let registrar_address = engine.machine().params().registrar; if let Some(ref addr) = registrar_address { trace!(target: "client", "Found registrar at {}", addr); } @@ -1982,10 +1981,6 @@ impl BlockChainClient for Client { self.importer.block_queue.clear(); } - fn additional_params(&self) -> BTreeMap { - self.engine.additional_params().into_iter().collect() - } - fn logs(&self, filter: Filter) -> Result, BlockId> { let chain = self.chain.read(); diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index cefa2a193b9..9eb1b14eb8f 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -841,10 +841,6 @@ impl BlockChainClient for TestBlockChainClient { fn clear_queue(&self) { } - fn additional_params(&self) -> BTreeMap { - Default::default() - } - fn filter_traces(&self, _filter: TraceFilter) -> Option> { self.traces.read().clone() } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 6f1bd595e90..ff4b778f4a8 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -296,9 +296,6 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra /// Clear block queue and abort all import activity. fn clear_queue(&self); - /// Get the registrar address, if it exists. - fn additional_params(&self) -> BTreeMap; - /// Returns logs matching given filter. If one of the filtering block cannot be found, returns the block id that caused the error. fn logs(&self, filter: Filter) -> Result, BlockId>; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 9edd5814a4b..c550f74c2b0 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -38,7 +38,7 @@ pub use types::engines::ForkChoice; pub use types::engines::epoch::{self, Transition as EpochTransition}; use std::sync::{Weak, Arc}; -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::{fmt, error}; use builtin::Builtin; @@ -543,11 +543,6 @@ pub trait Engine: Sync + Send { self.machine().verify_transaction_basic(t, header) } - /// Additional information. - fn additional_params(&self) -> HashMap { - self.machine().additional_params() - } - /// Performs pre-validation of RLP decoded transaction before other processing fn decode_transaction(&self, transaction: &[u8]) -> Result { self.machine().decode_transaction(transaction) diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index 10f3078c6b8..51d4e3f8278 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -16,7 +16,7 @@ //! Ethereum-like state machine definition. -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::cmp; use std::sync::Arc; @@ -385,13 +385,6 @@ impl Machine { Ok(()) } - /// Additional params. - pub fn additional_params(&self) -> HashMap { - hash_map![ - "registrar".to_owned() => format!("{:x}", self.params.registrar) - ] - } - /// Performs pre-validation of RLP decoded transaction before other processing pub fn decode_transaction(&self, transaction: &[u8]) -> Result { let rlp = Rlp::new(&transaction); diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 9b8c20ea59b..7a409f52188 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -138,7 +138,7 @@ pub struct CommonParams { /// Gas limit bound divisor (how much gas limit can change per block) pub gas_limit_bound_divisor: U256, /// Registrar contract address. - pub registrar: Address, + pub registrar: Option
, /// Node permission managing contract address. pub node_permission_contract: Option
, /// Maximum contract code size that can be deployed. @@ -315,7 +315,7 @@ impl From for CommonParams { nonce_cap_increment: p.nonce_cap_increment.map_or(64, Into::into), remove_dust_contracts: p.remove_dust_contracts.unwrap_or(false), gas_limit_bound_divisor: p.gas_limit_bound_divisor.into(), - registrar: p.registrar.map_or_else(Address::zero, Into::into), + registrar: p.registrar.map(Into::into), node_permission_contract: p.node_permission_contract.map(Into::into), max_code_size: p.max_code_size.map_or(u64::max_value(), Into::into), max_transaction_size: p.max_transaction_size.map_or(MAX_TRANSACTION_SIZE, Into::into), diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 62e2465d4ac..4f26823aea6 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -2678,7 +2678,7 @@ mod tests { state.kill_account(&a); let diff = state.diff_from(original).unwrap(); - let diff_map = diff.get(); + let diff_map = diff.raw; assert_eq!(diff_map.len(), 1); assert!(diff_map.get(&a).is_some()); assert_eq!(diff_map.get(&a), @@ -2709,7 +2709,7 @@ mod tests { state.set_storage(&a, BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(100u64))).unwrap(); let diff = state.diff_from(original).unwrap(); - let diff_map = diff.get(); + let diff_map = diff.raw; assert_eq!(diff_map.len(), 1); assert!(diff_map.get(&a).is_some()); assert_eq!(diff_map.get(&a), diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 6edd16dba9c..093c55a9137 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -69,11 +69,8 @@ fn should_return_registrar() { Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ).unwrap(); - let params = client.additional_params(); - let address = ¶ms["registrar"]; - - assert_eq!(address.len(), 40); - assert!(U256::from_str(address).is_ok()); + let address = client.registrar_address(); + assert_eq!(address, Some("52dff57a8a1532e6afb3dc07e2af58bb9eb05b3d".parse().unwrap())); } #[test] diff --git a/ethcore/types/src/account_diff.rs b/ethcore/types/src/account_diff.rs index 90ee73305d2..b9ff991565d 100644 --- a/ethcore/types/src/account_diff.rs +++ b/ethcore/types/src/account_diff.rs @@ -16,12 +16,9 @@ //! Diff between two accounts. -use std::cmp::*; -use std::fmt; use std::collections::BTreeMap; -use std::convert::TryFrom; -use ethereum_types::{BigEndianHash as _, H256, U256}; use bytes::Bytes; +use ethereum_types::{H256, U256}; #[derive(Debug, PartialEq, Eq, Clone)] /// Diff type for specifying a change (or not). @@ -46,14 +43,13 @@ impl Diff { } } - /// Get the before value, if there is one. - pub fn pre(&self) -> Option<&T> { match *self { Diff::Died(ref x) | Diff::Changed(ref x, _) => Some(x), _ => None } } - - /// Get the after value, if there is one. - pub fn post(&self) -> Option<&T> { match *self { Diff::Born(ref x) | Diff::Changed(_, ref x) => Some(x), _ => None } } - /// Determine whether there was a change or not. - pub fn is_same(&self) -> bool { match *self { Diff::Same => true, _ => false }} + pub fn is_same(&self) -> bool { + match *self { + Diff::Same => true, + _ => false + } + } } #[derive(Debug, PartialEq, Eq, Clone)] @@ -62,83 +58,9 @@ pub struct AccountDiff { /// Change in balance, allowed to be `Diff::Same`. pub balance: Diff, /// Change in nonce, allowed to be `Diff::Same`. - pub nonce: Diff, // Allowed to be Same + pub nonce: Diff, /// Change in code, allowed to be `Diff::Same`. - pub code: Diff, // Allowed to be Same + pub code: Diff, /// Change in storage, values are not allowed to be `Diff::Same`. pub storage: BTreeMap>, } - -#[derive(Debug, PartialEq, Eq, Clone)] -/// Change in existance type. -// TODO: include other types of change. -pub enum Existance { - /// Item came into existance. - Born, - /// Item stayed in existance. - Alive, - /// Item went out of existance. - Died, -} - -impl fmt::Display for Existance { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Existance::Born => write!(f, "+++")?, - Existance::Alive => write!(f, "***")?, - Existance::Died => write!(f, "XXX")?, - } - Ok(()) - } -} - -impl AccountDiff { - /// Get `Existance` projection. - pub fn existance(&self) -> Existance { - match self.balance { - Diff::Born(_) => Existance::Born, - Diff::Died(_) => Existance::Died, - _ => Existance::Alive, - } - } -} - -// TODO: refactor into something nicer. -fn interpreted_hash(u: &H256) -> String { - let uint = u.into_uint(); - if let Ok(n) = u64::try_from(uint) { - format!("{} = {:#x}", n, n) - } else { - format!("#{}", u) - } -} - -impl fmt::Display for AccountDiff { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use bytes::ToPretty; - - match self.nonce { - Diff::Born(ref x) => write!(f, " non {}", x)?, - Diff::Changed(ref pre, ref post) => write!(f, "#{} ({} {} {})", post, pre, if pre > post {"-"} else {"+"}, *max(pre, post) - * min(pre, post))?, - _ => {}, - } - match self.balance { - Diff::Born(ref x) => write!(f, " bal {}", x)?, - Diff::Changed(ref pre, ref post) => write!(f, "${} ({} {} {})", post, pre, if pre > post {"-"} else {"+"}, *max(pre, post) - *min(pre, post))?, - _ => {}, - } - if let Diff::Born(ref x) = self.code { - write!(f, " code {}", x.pretty())?; - } - write!(f, "\n")?; - for (k, dv) in &self.storage { - match *dv { - Diff::Born(ref v) => write!(f, " + {} => {}\n", interpreted_hash(k), interpreted_hash(v))?, - Diff::Changed(ref pre, ref post) => write!(f, " * {} => {} (was {})\n", interpreted_hash(k), interpreted_hash(post), interpreted_hash(pre))?, - Diff::Died(_) => write!(f, " X {}\n", interpreted_hash(k))?, - _ => {}, - } - } - Ok(()) - } -} diff --git a/ethcore/types/src/state_diff.rs b/ethcore/types/src/state_diff.rs index 5605719f015..21a10027f69 100644 --- a/ethcore/types/src/state_diff.rs +++ b/ethcore/types/src/state_diff.rs @@ -16,11 +16,9 @@ //! State diff module. -use std::fmt; -use std::ops::*; use std::collections::BTreeMap; +use account_diff::AccountDiff; use ethereum_types::Address; -use account_diff::*; /// Expression for the delta between two system states. Encoded the /// delta of every altered account. @@ -29,27 +27,3 @@ pub struct StateDiff { /// Raw diff key-value pub raw: BTreeMap } - -impl StateDiff { - /// Get the actual data. - pub fn get(&self) -> &BTreeMap { - &self.raw - } -} - -impl fmt::Display for StateDiff { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - for (add, acc) in &self.raw { - write!(f, "{} {}: {}", acc.existance(), add, acc)?; - } - Ok(()) - } -} - -impl Deref for StateDiff { - type Target = BTreeMap; - - fn deref(&self) -> &Self::Target { - &self.raw - } -} diff --git a/ethcore/types/src/verification_queue_info.rs b/ethcore/types/src/verification_queue_info.rs index a855fee6a17..b89cfe20c0d 100644 --- a/ethcore/types/src/verification_queue_info.rs +++ b/ethcore/types/src/verification_queue_info.rs @@ -37,9 +37,6 @@ impl VerificationQueueInfo { /// The total size of the queues. pub fn total_queue_size(&self) -> usize { self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size } - /// The size of the unverified and verifying queues. - pub fn incomplete_queue_size(&self) -> usize { self.unverified_queue_size + self.verifying_queue_size } - /// Indicates that queue is full pub fn is_full(&self) -> bool { self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size > self.max_queue_size || diff --git a/parity/configuration.rs b/parity/configuration.rs index 2a807e99b07..541637fd411 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -933,13 +933,13 @@ impl Configuration { } fn snapshot_config(&self) -> Result { - let conf = SnapshotConfiguration { - no_periodic: self.args.flag_no_periodic_snapshot, - processing_threads: match self.args.arg_snapshot_threads { - Some(threads) if threads > 0 => threads, - _ => ::std::cmp::max(1, num_cpus::get_physical() / 2), - }, - }; + let mut conf = SnapshotConfiguration::default(); + conf.no_periodic = self.args.flag_no_periodic_snapshot; + if let Some(threads) = self.args.arg_snapshot_threads { + if threads > 0 { + conf.processing_threads = threads; + } + } Ok(conf) } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 06ad7b43b28..21fe836b1fd 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -163,12 +163,7 @@ where } fn registry_address(&self) -> Result> { - let reg = self.light_dispatch.client.engine().params().registrar; - if reg == Default::default() { - Ok(None) - } else { - Ok(Some(reg)) - } + Ok(self.light_dispatch.client.engine().params().registrar) } fn rpc_settings(&self) -> Result { diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 1d5556f4381..e040ed52b92 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -16,11 +16,10 @@ //! Parity-specific rpc implementation. use std::sync::Arc; -use std::str::FromStr; use std::collections::BTreeMap; use crypto::DEFAULT_MAC; -use ethereum_types::{Address, H64, H160, H256, H512, U64, U256}; +use ethereum_types::{H64, H160, H256, H512, U64, U256}; use ethcore::client::{BlockChainClient, StateClient, Call}; use ethcore::miner::{self, MinerService, FilterOptions}; use ethcore::snapshot::{SnapshotService, RestorationStatus}; @@ -165,12 +164,7 @@ impl Parity for ParityClient where } fn registry_address(&self) -> Result> { - Ok( - self.client - .additional_params() - .get("registrar") - .and_then(|s| Address::from_str(s).ok()) - ) + Ok(self.client.registrar_address()) } fn rpc_settings(&self) -> Result { diff --git a/whisper/Cargo.toml b/whisper/Cargo.toml index 46351acc58a..e373b740f8c 100644 --- a/whisper/Cargo.toml +++ b/whisper/Cargo.toml @@ -30,3 +30,4 @@ time-utils = { path = "../util/time-utils" } jsonrpc-core = "10.0.1" jsonrpc-derive = "10.0.2" jsonrpc-pubsub = "10.0.1" +zeroize = "0.9.1" diff --git a/whisper/src/lib.rs b/whisper/src/lib.rs index 7ff7794b77a..550124d13cf 100644 --- a/whisper/src/lib.rs +++ b/whisper/src/lib.rs @@ -35,6 +35,7 @@ extern crate serde; extern crate slab; extern crate smallvec; extern crate tiny_keccak; +extern crate zeroize; extern crate jsonrpc_core; extern crate jsonrpc_derive; diff --git a/whisper/src/rpc/crypto.rs b/whisper/src/rpc/crypto.rs index 3f26e0350a0..ad2b59e2183 100644 --- a/whisper/src/rpc/crypto.rs +++ b/whisper/src/rpc/crypto.rs @@ -20,7 +20,7 @@ use aes_gcm::{Encryptor, Decryptor}; use ethkey::crypto::ecies; use ethereum_types::H256; use ethkey::{self, Public, Secret}; -use parity_util_mem::Memzero; +use zeroize::Zeroizing; /// Length of AES key pub const AES_KEY_LEN: usize = 32; @@ -37,7 +37,7 @@ enum AesEncode { } enum EncryptionInner { - AES(Memzero<[u8; AES_KEY_LEN]>, [u8; AES_NONCE_LEN], AesEncode), + AES(Zeroizing<[u8; AES_KEY_LEN]>, [u8; AES_NONCE_LEN], AesEncode), ECIES(Public), } @@ -59,7 +59,7 @@ impl EncryptionInstance { /// /// If generating nonces with a secure RNG, limit uses such that /// the chance of collision is negligible. - pub fn aes(key: Memzero<[u8; AES_KEY_LEN]>, nonce: [u8; AES_NONCE_LEN]) -> Self { + pub fn aes(key: Zeroizing<[u8; AES_KEY_LEN]>, nonce: [u8; AES_NONCE_LEN]) -> Self { EncryptionInstance(EncryptionInner::AES(key, nonce, AesEncode::AppendedNonce)) } @@ -67,7 +67,7 @@ impl EncryptionInstance { /// /// Key reuse here is extremely dangerous. It should be randomly generated /// with a secure RNG. - pub fn broadcast(key: Memzero<[u8; AES_KEY_LEN]>, topics: Vec) -> Self { + pub fn broadcast(key: Zeroizing<[u8; AES_KEY_LEN]>, topics: Vec) -> Self { EncryptionInstance(EncryptionInner::AES(key, BROADCAST_IV, AesEncode::OnTopics(topics))) } @@ -111,7 +111,7 @@ fn xor(a: &mut [u8; 32], b: &[u8; 32]) { } enum AesExtract { - AppendedNonce(Memzero<[u8; AES_KEY_LEN]>), // extract appended nonce. + AppendedNonce(Zeroizing<[u8; AES_KEY_LEN]>), // extract appended nonce. OnTopics(usize, usize, H256), // number of topics, index we know, topic we know. } @@ -132,7 +132,7 @@ impl DecryptionInstance { } /// 256-bit AES GCM decryption with appended nonce. - pub fn aes(key: Memzero<[u8; AES_KEY_LEN]>) -> Self { + pub fn aes(key: Zeroizing<[u8; AES_KEY_LEN]>) -> Self { DecryptionInstance(DecryptionInner::AES(AesExtract::AppendedNonce(key))) } @@ -167,7 +167,7 @@ impl DecryptionInstance { } let mut salted_topic = H256::zero(); salted_topic.as_bytes_mut().copy_from_slice(&ciphertext[(known_index * 32)..][..32]); - let key = Memzero::from((salted_topic ^ known_topic).0); + let key = Zeroizing::new((salted_topic ^ known_topic).0); let offset = num_topics * 32; Decryptor::aes_256_gcm(&*key).ok()? .decrypt(&BROADCAST_IV, Vec::from(&ciphertext[offset..])) @@ -187,6 +187,7 @@ impl DecryptionInstance { mod tests { use super::*; use rand::{Rng, rngs::OsRng}; + use std::ops::Deref; #[test] @@ -217,9 +218,9 @@ mod tests { fn encrypt_symmetric() { let mut rng = OsRng::new().unwrap(); let mut test_message = move |message: &[u8]| { - let key = Memzero::from(rng.gen::<[u8; 32]>()); + let key = Zeroizing::new(rng.gen::<[u8; 32]>()); - let instance = EncryptionInstance::aes(key.clone(), rng.gen()); + let instance = EncryptionInstance::aes(Zeroizing::new(*key.deref()), rng.gen()); let ciphertext = instance.encrypt(message).unwrap(); if !message.is_empty() { @@ -245,7 +246,7 @@ mod tests { let all_topics = (0..5).map(|_| H256::random_using(&mut rng)).collect::>(); let known_idx = 2; let known_topic = all_topics[2]; - let key = Memzero::from(rng.gen::<[u8; 32]>()); + let key = Zeroizing::new(rng.gen::<[u8; 32]>()); let instance = EncryptionInstance::broadcast(key, all_topics); let ciphertext = instance.encrypt(message).unwrap(); diff --git a/whisper/src/rpc/key_store.rs b/whisper/src/rpc/key_store.rs index 3f84e59ad3a..4d18157880e 100644 --- a/whisper/src/rpc/key_store.rs +++ b/whisper/src/rpc/key_store.rs @@ -23,7 +23,8 @@ use std::collections::HashMap; use ethereum_types::H256; use ethkey::{KeyPair, Public, Secret}; -use parity_util_mem::Memzero; +use zeroize::Zeroizing; +use std::ops::Deref; use rand::{Rng, rngs::OsRng}; use rpc::crypto::{AES_KEY_LEN, EncryptionInstance, DecryptionInstance}; @@ -35,7 +36,7 @@ pub enum Key { /// and signing. Asymmetric(KeyPair), /// AES-256 GCM mode. Suitable for encryption, decryption, but not signing. - Symmetric(Memzero<[u8; AES_KEY_LEN]>), + Symmetric(Zeroizing<[u8; AES_KEY_LEN]>), } impl Key { @@ -49,7 +50,7 @@ impl Key { /// Generate a random symmetric key with the given cryptographic RNG. pub fn new_symmetric(rng: &mut OsRng) -> Self { - Key::Symmetric(Memzero::from(rng.gen::<[u8; 32]>())) + Key::Symmetric(Zeroizing::new(rng.gen::<[u8; 32]>())) } /// From secret asymmetric key. Fails if secret is invalid. @@ -59,7 +60,7 @@ impl Key { /// From raw symmetric key. pub fn from_raw_symmetric(key: [u8; AES_KEY_LEN]) -> Self { - Key::Symmetric(Memzero::from(key)) + Key::Symmetric(Zeroizing::new(key)) } /// Get a handle to the public key if this is an asymmetric key. @@ -138,7 +139,7 @@ impl KeyStore { .map_err(|_| "could not create encryption instance for id"), Key::Symmetric(ref key) => OsRng::new() - .map(|mut rng| EncryptionInstance::aes(key.clone(), rng.gen())) + .map(|mut rng| EncryptionInstance::aes(Zeroizing::new(*key.deref()), rng.gen())) .map_err(|_| "unable to get secure randomness") }) } @@ -149,7 +150,7 @@ impl KeyStore { self.get(id).map(|key| match *key { Key::Asymmetric(ref pair) => DecryptionInstance::ecies(pair.secret().clone()) .expect("all keys stored are valid; qed"), - Key::Symmetric(ref key) => DecryptionInstance::aes(key.clone()), + Key::Symmetric(ref key) => DecryptionInstance::aes(Zeroizing::new(*key.deref())), }) } diff --git a/whisper/src/rpc/mod.rs b/whisper/src/rpc/mod.rs index 61cd14d4b9b..57ec4c6c4f7 100644 --- a/whisper/src/rpc/mod.rs +++ b/whisper/src/rpc/mod.rs @@ -28,7 +28,7 @@ use jsonrpc_derive::rpc; use jsonrpc_pubsub::{Session, PubSubMetadata, SubscriptionId, typed::Subscriber}; use ethereum_types::H256; -use parity_util_mem::Memzero; +use zeroize::Zeroizing; use parking_lot::RwLock; use self::filter::Filter; @@ -284,7 +284,7 @@ impl Whisper for WhisperClien let mut rng = OsRng::new() .map_err(|_| whisper_error("unable to acquire secure randomness"))?; - let key = Memzero::from(rng.gen::<[u8; 32]>()); + let key = Zeroizing::new(rng.gen::<[u8; 32]>()); if req.topics.is_empty() { return Err(whisper_error("must supply at least one topic for broadcast message")); }