Merge pull request #6423 from paritytech/keccak_fn
replace trait Hashable with fn keccak
This commit is contained in:
commit
47f7366a5c
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -196,7 +196,7 @@ name = "bloomable"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -301,6 +301,7 @@ dependencies = [
|
||||
"bloomable 0.1.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
"rlp_derive 0.1.0",
|
||||
@ -481,10 +482,10 @@ name = "ethash"
|
||||
version = "1.8.0"
|
||||
dependencies = [
|
||||
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha3 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -517,6 +518,7 @@ dependencies = [
|
||||
"evm 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hardware-wallet 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -654,6 +656,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"evm 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -696,6 +699,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"hash 0.1.0",
|
||||
"igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -730,6 +734,7 @@ dependencies = [
|
||||
"ethkey 0.2.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"hyper 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -758,6 +763,7 @@ dependencies = [
|
||||
"ethcore-logger 1.8.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-macros 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-tcp-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -780,6 +786,7 @@ dependencies = [
|
||||
"ethcore-bloom-journal 0.1.0",
|
||||
"ethcore-devtools 1.8.0",
|
||||
"ethcore-logger 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -792,7 +799,6 @@ dependencies = [
|
||||
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha3 0.1.0",
|
||||
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -901,6 +907,7 @@ dependencies = [
|
||||
"ethcore-network 1.8.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"ethkey 0.2.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -923,6 +930,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"evmjit 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1066,6 +1074,16 @@ dependencies = [
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapsize"
|
||||
version = "0.4.0"
|
||||
@ -1851,6 +1869,7 @@ dependencies = [
|
||||
"fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -1898,6 +1917,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -1943,6 +1963,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2010,6 +2031,7 @@ dependencies = [
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -2046,6 +2068,7 @@ version = "1.4.0"
|
||||
dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-ws-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2694,13 +2717,6 @@ name = "sha1"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shell32-sys"
|
||||
version = "0.1.1"
|
||||
@ -3185,6 +3201,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"evmjit 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
|
@ -57,6 +57,7 @@ parity-updater = { path = "updater" }
|
||||
parity-whisper = { path = "whisper" }
|
||||
path = { path = "util/path" }
|
||||
panic_hook = { path = "panic_hook" }
|
||||
hash = { path = "util/hash" }
|
||||
|
||||
parity-dapps = { path = "dapps", optional = true }
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
|
@ -35,6 +35,7 @@ node-health = { path = "./node-health" }
|
||||
parity-hash-fetch = { path = "../hash-fetch" }
|
||||
parity-reactor = { path = "../util/reactor" }
|
||||
parity-ui = { path = "./ui" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
|
||||
|
@ -19,9 +19,9 @@ use std::{fs, fmt};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use fetch::{self, Mime};
|
||||
use hash::keccak_buffer;
|
||||
use util::H256;
|
||||
|
||||
use util::sha3::sha3;
|
||||
use page::{LocalPageEndpoint, PageCache};
|
||||
use handlers::{ContentValidator, ValidatorResponse};
|
||||
use apps::manifest::{MANIFEST_FILENAME, deserialize_manifest, serialize_manifest, Manifest};
|
||||
@ -57,9 +57,9 @@ fn write_response_and_check_hash(
|
||||
file.flush()?;
|
||||
|
||||
// Validate hash
|
||||
// TODO [ToDr] calculate sha3 in-flight while reading the response
|
||||
// TODO [ToDr] calculate keccak in-flight while reading the response
|
||||
let mut file = io::BufReader::new(fs::File::open(&content_path)?);
|
||||
let hash = sha3(&mut file)?;
|
||||
let hash = keccak_buffer(&mut file)?;
|
||||
if id == hash {
|
||||
Ok((file.into_inner(), content_path))
|
||||
} else {
|
||||
|
@ -43,6 +43,7 @@ extern crate parity_dapps_glue as parity_dapps;
|
||||
extern crate parity_hash_fetch as hash_fetch;
|
||||
extern crate parity_reactor;
|
||||
extern crate parity_ui;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -7,10 +7,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
sha3 = { path = "../util/sha3" }
|
||||
hash = { path = "../util/hash" }
|
||||
primal = "0.2.3"
|
||||
parking_lot = "0.4"
|
||||
crunchy = "0.1.0"
|
||||
|
||||
[features]
|
||||
benches = []
|
||||
benches = []
|
||||
|
@ -23,7 +23,7 @@ use primal::is_prime;
|
||||
use std::cell::Cell;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use sha3;
|
||||
use hash;
|
||||
use std::slice;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::io::{self, Read, Write};
|
||||
@ -200,7 +200,7 @@ impl SeedHashCompute {
|
||||
#[inline]
|
||||
pub fn resume_compute_seedhash(mut hash: H256, start_epoch: u64, end_epoch: u64) -> H256 {
|
||||
for _ in start_epoch..end_epoch {
|
||||
unsafe { sha3::sha3_256(hash[..].as_mut_ptr(), 32, hash[..].as_ptr(), 32) };
|
||||
unsafe { hash::keccak_256(hash[..].as_mut_ptr(), 32, hash[..].as_ptr(), 32) };
|
||||
}
|
||||
hash
|
||||
}
|
||||
@ -214,14 +214,14 @@ fn fnv_hash(x: u32, y: u32) -> u32 {
|
||||
return x.wrapping_mul(FNV_PRIME) ^ y;
|
||||
}
|
||||
|
||||
fn sha3_512(input: &[u8], output: &mut [u8]) {
|
||||
unsafe { sha3::sha3_512(output.as_mut_ptr(), output.len(), input.as_ptr(), input.len()) };
|
||||
fn keccak_512(input: &[u8], output: &mut [u8]) {
|
||||
unsafe { hash::keccak_512(output.as_mut_ptr(), output.len(), input.as_ptr(), input.len()) };
|
||||
}
|
||||
|
||||
fn sha3_512_inplace(input: &mut [u8]) {
|
||||
// This is safe since `sha3_*` uses an internal buffer and copies the result to the output. This
|
||||
fn keccak_512_inplace(input: &mut [u8]) {
|
||||
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This
|
||||
// means that we can reuse the input buffer for both input and output.
|
||||
unsafe { sha3::sha3_512(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()) };
|
||||
unsafe { hash::keccak_512(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()) };
|
||||
}
|
||||
|
||||
fn get_cache_size(block_number: u64) -> usize {
|
||||
@ -250,23 +250,23 @@ fn get_data_size(block_number: u64) -> usize {
|
||||
/// Boundary recovered from mix hash
|
||||
pub fn quick_get_difficulty(header_hash: &H256, nonce: u64, mix_hash: &H256) -> H256 {
|
||||
unsafe {
|
||||
// This is safe - the `sha3_512` call below reads the first 40 bytes (which we explicitly set
|
||||
// This is safe - the `keccak_512` call below reads the first 40 bytes (which we explicitly set
|
||||
// with two `copy_nonoverlapping` calls) but writes the first 64, and then we explicitly write
|
||||
// the next 32 bytes before we read the whole thing with `sha3_256`.
|
||||
// the next 32 bytes before we read the whole thing with `keccak_256`.
|
||||
//
|
||||
// This cannot be elided by the compiler as it doesn't know the implementation of
|
||||
// `sha3_512`.
|
||||
// `keccak_512`.
|
||||
let mut buf: [u8; 64 + 32] = mem::uninitialized();
|
||||
|
||||
ptr::copy_nonoverlapping(header_hash.as_ptr(), buf.as_mut_ptr(), 32);
|
||||
ptr::copy_nonoverlapping(mem::transmute(&nonce), buf[32..].as_mut_ptr(), 8);
|
||||
|
||||
sha3::sha3_512(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
|
||||
hash::keccak_512(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
|
||||
ptr::copy_nonoverlapping(mix_hash.as_ptr(), buf[64..].as_mut_ptr(), 32);
|
||||
|
||||
// This is initialized in `sha3_256`
|
||||
// This is initialized in `keccak_256`
|
||||
let mut hash: [u8; 32] = mem::uninitialized();
|
||||
sha3::sha3_256(hash.as_mut_ptr(), hash.len(), buf.as_ptr(), buf.len());
|
||||
hash::keccak_256(hash.as_mut_ptr(), hash.len(), buf.as_ptr(), buf.len());
|
||||
|
||||
hash
|
||||
}
|
||||
@ -320,7 +320,7 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
half_mix: unsafe {
|
||||
// Pack `header_hash` and `nonce` together
|
||||
// We explicitly write the first 40 bytes, leaving the last 24 as uninitialized. Then
|
||||
// `sha3_512` reads the first 40 bytes (4th parameter) and overwrites the entire array,
|
||||
// `keccak_512` reads the first 40 bytes (4th parameter) and overwrites the entire array,
|
||||
// leaving it fully initialized.
|
||||
let mut out: [u8; NODE_BYTES] = mem::uninitialized();
|
||||
|
||||
@ -335,8 +335,8 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
mem::size_of::<u64>(),
|
||||
);
|
||||
|
||||
// compute sha3-512 hash and replicate across mix
|
||||
sha3::sha3_512(
|
||||
// compute keccak-512 hash and replicate across mix
|
||||
hash::keccak_512(
|
||||
out.as_mut_ptr(),
|
||||
NODE_BYTES,
|
||||
out.as_ptr(),
|
||||
@ -427,10 +427,10 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
let value: H256 = unsafe {
|
||||
// We can interpret the buffer as an array of `u8`s, since it's `repr(C)`.
|
||||
let read_ptr: *const u8 = mem::transmute(&buf);
|
||||
// We overwrite the second half since `sha3_256` has an internal buffer and so allows
|
||||
// We overwrite the second half since `keccak_256` has an internal buffer and so allows
|
||||
// overlapping arrays as input.
|
||||
let write_ptr: *mut u8 = mem::transmute(&mut buf.compress_bytes);
|
||||
sha3::sha3_256(
|
||||
hash::keccak_256(
|
||||
write_ptr,
|
||||
buf.compress_bytes.len(),
|
||||
read_ptr,
|
||||
@ -450,7 +450,7 @@ fn calculate_dag_item(node_index: u32, cache: &[Node]) -> Node {
|
||||
let mut ret = cache[node_index as usize % num_parent_nodes].clone();
|
||||
ret.as_words_mut()[0] ^= node_index;
|
||||
|
||||
sha3_512_inplace(&mut ret.bytes);
|
||||
keccak_512_inplace(&mut ret.bytes);
|
||||
|
||||
debug_assert_eq!(NODE_WORDS, 16);
|
||||
for i in 0..ETHASH_DATASET_PARENTS as u32 {
|
||||
@ -467,7 +467,7 @@ fn calculate_dag_item(node_index: u32, cache: &[Node]) -> Node {
|
||||
}
|
||||
}
|
||||
|
||||
sha3_512_inplace(&mut ret.bytes);
|
||||
keccak_512_inplace(&mut ret.bytes);
|
||||
|
||||
ret
|
||||
}
|
||||
@ -485,9 +485,9 @@ fn light_new<T: AsRef<Path>>(cache_dir: T, block_number: u64) -> Light {
|
||||
// Use uninit instead of unnecessarily writing `size_of::<Node>() * num_nodes` 0s
|
||||
nodes.set_len(num_nodes);
|
||||
|
||||
sha3_512(&seedhash[0..32], &mut nodes.get_unchecked_mut(0).bytes);
|
||||
keccak_512(&seedhash[0..32], &mut nodes.get_unchecked_mut(0).bytes);
|
||||
for i in 1..num_nodes {
|
||||
sha3::sha3_512(nodes.get_unchecked_mut(i).bytes.as_mut_ptr(), NODE_BYTES, nodes.get_unchecked(i - 1).bytes.as_ptr(), NODE_BYTES);
|
||||
hash::keccak_512(nodes.get_unchecked_mut(i).bytes.as_mut_ptr(), NODE_BYTES, nodes.get_unchecked(i - 1).bytes.as_ptr(), NODE_BYTES);
|
||||
}
|
||||
|
||||
debug_assert_eq!(NODE_WORDS, 16);
|
||||
@ -504,7 +504,7 @@ fn light_new<T: AsRef<Path>>(cache_dir: T, block_number: u64) -> Light {
|
||||
}
|
||||
}
|
||||
|
||||
sha3_512(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes);
|
||||
keccak_512(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#![cfg_attr(feature = "benches", feature(test))]
|
||||
|
||||
extern crate primal;
|
||||
extern crate sha3;
|
||||
extern crate hash;
|
||||
extern crate parking_lot;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -60,6 +60,7 @@ table = { path = "../util/table" }
|
||||
bloomable = { path = "../util/bloomable" }
|
||||
vm = { path = "vm" }
|
||||
wasm = { path = "wasm" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
||||
[dev-dependencies]
|
||||
native-contracts = { path = "native_contracts", features = ["test_contracts"] }
|
||||
|
@ -18,6 +18,7 @@ vm = { path = "../vm" }
|
||||
parity-wasm = "0.12"
|
||||
ethcore-logger = { path = "../../logger" }
|
||||
wasm-utils = { git = "https://github.com/paritytech/wasm-utils" }
|
||||
hash = { path = "../../util/hash" }
|
||||
|
||||
[dev-dependencies]
|
||||
rustc-hex = "1.0"
|
||||
|
@ -26,6 +26,7 @@ mod shared_cache;
|
||||
use std::marker::PhantomData;
|
||||
use std::{cmp, mem};
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
|
||||
use vm::{
|
||||
self, ActionParams, ActionValue, CallType, MessageCallResult,
|
||||
@ -180,7 +181,7 @@ impl<Cost: CostType> vm::Vm for Interpreter<Cost> {
|
||||
match result {
|
||||
InstructionResult::JumpToPosition(position) => {
|
||||
if valid_jump_destinations.is_none() {
|
||||
let code_hash = params.code_hash.clone().unwrap_or_else(|| code.sha3());
|
||||
let code_hash = params.code_hash.clone().unwrap_or_else(|| keccak(code.as_ref()));
|
||||
valid_jump_destinations = Some(self.cache.jump_destinations(&code_hash, code));
|
||||
}
|
||||
let jump_destinations = valid_jump_destinations.as_ref().expect("jump_destinations are initialized on first jump; qed");
|
||||
@ -464,8 +465,8 @@ impl<Cost: CostType> Interpreter<Cost> {
|
||||
instructions::SHA3 => {
|
||||
let offset = stack.pop_back();
|
||||
let size = stack.pop_back();
|
||||
let sha3 = self.mem.read_slice(offset, size).sha3();
|
||||
stack.push(U256::from(&*sha3));
|
||||
let k = keccak(self.mem.read_slice(offset, size));
|
||||
stack.push(U256::from(&*k));
|
||||
},
|
||||
instructions::SLOAD => {
|
||||
let key = H256::from(&stack.pop_back());
|
||||
@ -880,7 +881,7 @@ mod tests {
|
||||
use rustc_hex::FromHex;
|
||||
use vmtype::VMType;
|
||||
use factory::Factory;
|
||||
use vm::{self, ActionParams, ActionValue};
|
||||
use vm::{ActionParams, ActionValue};
|
||||
use vm::tests::{FakeExt, test_finalize};
|
||||
|
||||
#[test]
|
||||
|
@ -15,9 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::KECCAK_EMPTY;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, Mutex};
|
||||
use util::sha3::*;
|
||||
use util::cache::MemoryLruCache;
|
||||
use bit_set::BitSet;
|
||||
use super::super::instructions;
|
||||
@ -50,7 +50,7 @@ impl SharedCache {
|
||||
|
||||
/// Get jump destinations bitmap for a contract.
|
||||
pub fn jump_destinations(&self, code_hash: &H256, code: &[u8]) -> Arc<BitSet> {
|
||||
if code_hash == &SHA3_EMPTY {
|
||||
if code_hash == &KECCAK_EMPTY {
|
||||
return Self::find_jump_destinations(code);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ extern crate wasm_utils;
|
||||
extern crate ethcore_logger;
|
||||
extern crate heapsize;
|
||||
extern crate vm;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
@ -32,6 +32,7 @@ bincode = "0.8.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
stats = { path = "../../util/stats" }
|
||||
hash = { path = "../../util/hash" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -487,7 +487,7 @@ impl HeaderChain {
|
||||
|
||||
/// Get the genesis hash.
|
||||
pub fn genesis_hash(&self) -> H256 {
|
||||
::util::Hashable::sha3(&self.genesis_header)
|
||||
self.genesis_header.hash()
|
||||
}
|
||||
|
||||
/// Get the best block's data.
|
||||
|
@ -84,6 +84,7 @@ extern crate smallvec;
|
||||
extern crate stats;
|
||||
extern crate time;
|
||||
extern crate vm;
|
||||
extern crate hash;
|
||||
|
||||
#[cfg(feature = "ipc")]
|
||||
extern crate ethcore_ipc as ipc;
|
||||
|
@ -25,13 +25,13 @@ use ethcore::receipt::Receipt;
|
||||
use ethcore::state::{self, ProvedExecution};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use vm::EnvInfo;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||
|
||||
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
|
||||
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use util::{Address, Bytes, DBValue, HashDB, Mutex, H256, U256};
|
||||
use util::memorydb::MemoryDB;
|
||||
use util::sha3::{Hashable, SHA3_NULL_RLP, SHA3_EMPTY, SHA3_EMPTY_LIST_RLP};
|
||||
use util::trie::{Trie, TrieDB, TrieError};
|
||||
|
||||
const SUPPLIED_MATCHES: &'static str = "supplied responses always match produced requests; enforced by `check_response`; qed";
|
||||
@ -276,7 +276,7 @@ impl From<Request> for CheckedRequest {
|
||||
Request::Account(req) => {
|
||||
let net_req = net_request::IncompleteAccountRequest {
|
||||
block_hash: req.header.field(),
|
||||
address_hash: ::util::Hashable::sha3(&req.address).into(),
|
||||
address_hash: ::hash::keccak(&req.address).into(),
|
||||
};
|
||||
CheckedRequest::Account(req, net_req)
|
||||
}
|
||||
@ -366,7 +366,7 @@ impl CheckedRequest {
|
||||
}
|
||||
CheckedRequest::Receipts(ref check, ref req) => {
|
||||
// empty transactions -> no receipts
|
||||
if check.0.as_ref().ok().map_or(false, |hdr| hdr.receipts_root() == SHA3_NULL_RLP) {
|
||||
if check.0.as_ref().ok().map_or(false, |hdr| hdr.receipts_root() == KECCAK_NULL_RLP) {
|
||||
return Some(Response::Receipts(Vec::new()));
|
||||
}
|
||||
|
||||
@ -377,7 +377,7 @@ impl CheckedRequest {
|
||||
CheckedRequest::Body(ref check, ref req) => {
|
||||
// check for empty body.
|
||||
if let Some(hdr) = check.0.as_ref().ok() {
|
||||
if hdr.transactions_root() == SHA3_NULL_RLP && hdr.uncles_hash() == SHA3_EMPTY_LIST_RLP {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP && hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
let mut stream = RlpStream::new_list(3);
|
||||
stream.append_raw(hdr.rlp().as_raw(), 1);
|
||||
stream.begin_list(0);
|
||||
@ -422,7 +422,7 @@ impl CheckedRequest {
|
||||
})
|
||||
}
|
||||
CheckedRequest::Code(_, ref req) => {
|
||||
if req.code_hash.as_ref().map_or(false, |&h| h == SHA3_EMPTY) {
|
||||
if req.code_hash.as_ref().map_or(false, |&h| h == KECCAK_EMPTY) {
|
||||
Some(Response::Code(Vec::new()))
|
||||
} else {
|
||||
None
|
||||
@ -571,8 +571,8 @@ impl net_request::ResponseLike for Response {
|
||||
match *self {
|
||||
Response::HeaderProof((ref hash, _)) => f(0, Output::Hash(*hash)),
|
||||
Response::Account(None) => {
|
||||
f(0, Output::Hash(SHA3_EMPTY)); // code hash
|
||||
f(1, Output::Hash(SHA3_NULL_RLP)); // storage root.
|
||||
f(0, Output::Hash(KECCAK_EMPTY)); // code hash
|
||||
f(1, Output::Hash(KECCAK_NULL_RLP)); // storage root.
|
||||
}
|
||||
Response::Account(Some(ref acc)) => {
|
||||
f(0, Output::Hash(acc.code_hash));
|
||||
@ -688,7 +688,7 @@ impl HeaderByHash {
|
||||
};
|
||||
|
||||
let header = headers.get(0).ok_or(Error::Empty)?;
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
match hash == expected_hash {
|
||||
true => {
|
||||
cache.lock().insert_block_header(hash, header.clone());
|
||||
@ -713,7 +713,7 @@ impl Body {
|
||||
return Err(Error::WrongTrieRoot(header.transactions_root(), tx_root));
|
||||
}
|
||||
|
||||
let uncles_hash = body.rlp().at(1).as_raw().sha3();
|
||||
let uncles_hash = keccak(body.rlp().at(1).as_raw());
|
||||
if uncles_hash != header.uncles_hash() {
|
||||
return Err(Error::WrongHash(header.uncles_hash(), uncles_hash));
|
||||
}
|
||||
@ -768,7 +768,7 @@ impl Account {
|
||||
let mut db = MemoryDB::new();
|
||||
for node in proof { db.insert(&node[..]); }
|
||||
|
||||
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&self.address.sha3()))? {
|
||||
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
|
||||
Some(val) => {
|
||||
let rlp = UntrustedRlp::new(&val);
|
||||
Ok(Some(BasicAccount {
|
||||
@ -800,7 +800,7 @@ impl Code {
|
||||
code_hash: &H256,
|
||||
code: &[u8]
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let found_hash = code.sha3();
|
||||
let found_hash = keccak(code);
|
||||
if &found_hash == code_hash {
|
||||
Ok(code.to_vec())
|
||||
} else {
|
||||
@ -853,6 +853,7 @@ mod tests {
|
||||
use util::{MemoryDB, Address, Mutex, H256};
|
||||
use util::trie::{Trie, TrieMut, SecTrieDB, SecTrieDBMut};
|
||||
use util::trie::recorder::Recorder;
|
||||
use hash::keccak;
|
||||
|
||||
use ethcore::client::{BlockChainClient, TestBlockChainClient, EachBlockWith};
|
||||
use ethcore::header::Header;
|
||||
@ -998,7 +999,7 @@ mod tests {
|
||||
#[test]
|
||||
fn check_code() {
|
||||
let code = vec![1u8; 256];
|
||||
let code_hash = ::util::Hashable::sha3(&code);
|
||||
let code_hash = keccak(&code);
|
||||
let header = Header::new();
|
||||
let req = Code {
|
||||
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! DB backend wrapper for Account trie
|
||||
use std::collections::HashMap;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
use util::*;
|
||||
use rlp::NULL_RLP;
|
||||
|
||||
@ -79,7 +80,7 @@ impl<'db> AccountDB<'db> {
|
||||
/// Create a new AccountDB from an address.
|
||||
#[cfg(test)]
|
||||
pub fn new(db: &'db HashDB, address: &Address) -> Self {
|
||||
Self::from_hash(db, address.sha3())
|
||||
Self::from_hash(db, keccak(address))
|
||||
}
|
||||
|
||||
/// Create a new AcountDB from an address' hash.
|
||||
@ -97,14 +98,14 @@ impl<'db> HashDB for AccountDB<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.db.get(&combine_key(&self.address_hash, key))
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.db.contains(&combine_key(&self.address_hash, key))
|
||||
@ -133,7 +134,7 @@ impl<'db> AccountDBMut<'db> {
|
||||
/// Create a new AccountDB from an address.
|
||||
#[cfg(test)]
|
||||
pub fn new(db: &'db mut HashDB, address: &Address) -> Self {
|
||||
Self::from_hash(db, address.sha3())
|
||||
Self::from_hash(db, keccak(address))
|
||||
}
|
||||
|
||||
/// Create a new AcountDB from an address' hash.
|
||||
@ -156,14 +157,14 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.db.get(&combine_key(&self.address_hash, key))
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.db.contains(&combine_key(&self.address_hash, key))
|
||||
@ -171,16 +172,16 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
|
||||
fn insert(&mut self, value: &[u8]) -> H256 {
|
||||
if value == &NULL_RLP {
|
||||
return SHA3_NULL_RLP.clone();
|
||||
return KECCAK_NULL_RLP.clone();
|
||||
}
|
||||
let k = value.sha3();
|
||||
let k = keccak(value);
|
||||
let ak = combine_key(&self.address_hash, &k);
|
||||
self.db.emplace(ak, DBValue::from_slice(value));
|
||||
k
|
||||
}
|
||||
|
||||
fn emplace(&mut self, key: H256, value: DBValue) {
|
||||
if key == SHA3_NULL_RLP {
|
||||
if key == KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
let key = combine_key(&self.address_hash, &key);
|
||||
@ -188,7 +189,7 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &H256) {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
let key = combine_key(&self.address_hash, key);
|
||||
@ -204,14 +205,14 @@ impl<'db> HashDB for Wrapping<'db> {
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.0.contains(key)
|
||||
@ -238,14 +239,14 @@ impl<'db> HashDB for WrappingMut<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.0.contains(key)
|
||||
@ -253,20 +254,20 @@ impl<'db> HashDB for WrappingMut<'db>{
|
||||
|
||||
fn insert(&mut self, value: &[u8]) -> H256 {
|
||||
if value == &NULL_RLP {
|
||||
return SHA3_NULL_RLP.clone();
|
||||
return KECCAK_NULL_RLP.clone();
|
||||
}
|
||||
self.0.insert(value)
|
||||
}
|
||||
|
||||
fn emplace(&mut self, key: H256, value: DBValue) {
|
||||
if key == SHA3_NULL_RLP {
|
||||
if key == KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
self.0.emplace(key, value)
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &H256) {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
self.0.remove(key)
|
||||
|
@ -19,9 +19,10 @@
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
||||
use util::{Bytes, Address, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP};
|
||||
use util::{Bytes, Address, U256, H256, ordered_trie_root};
|
||||
use util::error::{Mismatch, OutOfBounds};
|
||||
|
||||
use basic_types::{LogBloom, Seal};
|
||||
@ -398,13 +399,13 @@ impl<'x> OpenBlock<'x> {
|
||||
if let Err(e) = s.engine.on_close_block(&mut s.block) {
|
||||
warn!("Encountered error on closing the block: {}", e);
|
||||
}
|
||||
|
||||
|
||||
if let Err(e) = s.block.state.commit() {
|
||||
warn!("Encountered error on state commit: {}", e);
|
||||
}
|
||||
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
||||
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
||||
s.block.header.set_uncles_hash(uncle_bytes.sha3());
|
||||
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
||||
s.block.header.set_state_root(s.block.state.root().clone());
|
||||
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
|
||||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
|
||||
@ -429,14 +430,14 @@ impl<'x> OpenBlock<'x> {
|
||||
if let Err(e) = s.block.state.commit() {
|
||||
warn!("Encountered error on state commit: {}", e);
|
||||
}
|
||||
if s.block.header.transactions_root().is_zero() || s.block.header.transactions_root() == &SHA3_NULL_RLP {
|
||||
if s.block.header.transactions_root().is_zero() || s.block.header.transactions_root() == &KECCAK_NULL_RLP {
|
||||
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
||||
}
|
||||
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
||||
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &SHA3_EMPTY_LIST_RLP {
|
||||
s.block.header.set_uncles_hash(uncle_bytes.sha3());
|
||||
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &KECCAK_EMPTY_LIST_RLP {
|
||||
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
||||
}
|
||||
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &SHA3_NULL_RLP {
|
||||
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &KECCAK_NULL_RLP {
|
||||
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
|
||||
}
|
||||
|
||||
@ -469,7 +470,7 @@ impl<'x> IsBlock for LockedBlock {
|
||||
|
||||
impl ClosedBlock {
|
||||
/// Get the hash of the header without seal arguments.
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_sha3(Seal::Without) }
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_keccak(Seal::Without) }
|
||||
|
||||
/// Turn this into a `LockedBlock`, unable to be reopened again.
|
||||
pub fn lock(self) -> LockedBlock {
|
||||
@ -494,7 +495,7 @@ impl ClosedBlock {
|
||||
|
||||
impl LockedBlock {
|
||||
/// Get the hash of the header without seal arguments.
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_sha3(Seal::Without) }
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_keccak(Seal::Without) }
|
||||
|
||||
/// Provide a valid seal in order to turn this into a `SealedBlock`.
|
||||
///
|
||||
|
@ -512,7 +512,7 @@ impl BlockChain {
|
||||
// we need to insert genesis into the cache
|
||||
let block = BlockView::new(genesis);
|
||||
let header = block.header_view();
|
||||
let hash = block.sha3();
|
||||
let hash = block.hash();
|
||||
|
||||
let details = BlockDetails {
|
||||
number: header.number(),
|
||||
@ -764,7 +764,7 @@ impl BlockChain {
|
||||
pub fn insert_unordered_block(&self, batch: &mut DBTransaction, bytes: &[u8], receipts: Vec<Receipt>, parent_td: Option<U256>, is_best: bool, is_ancient: bool) -> bool {
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known(&hash) {
|
||||
return false;
|
||||
@ -966,7 +966,7 @@ impl BlockChain {
|
||||
// create views onto rlp
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known_child(&header.parent_hash(), &hash) {
|
||||
return ImportRoute::none();
|
||||
@ -1005,7 +1005,7 @@ impl BlockChain {
|
||||
|
||||
/// Get inserted block info which is critical to prepare extras updates.
|
||||
fn block_info(&self, header: &HeaderView) -> BlockInfo {
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
let number = header.number();
|
||||
let parent_hash = header.parent_hash();
|
||||
let parent_details = self.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
|
||||
@ -1466,9 +1466,9 @@ mod tests {
|
||||
#![cfg_attr(feature="dev", allow(similar_names))]
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::hash::*;
|
||||
use util::sha3::Hashable;
|
||||
use receipt::Receipt;
|
||||
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
|
||||
use tests::helpers::*;
|
||||
@ -1518,8 +1518,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -1549,7 +1549,7 @@ mod tests {
|
||||
let mut canon_chain = ChainGenerator::default();
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -1558,7 +1558,7 @@ mod tests {
|
||||
let mut batch = db.transaction();
|
||||
for _ in 0..10 {
|
||||
let block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
block_hashes.push(BlockView::new(&block).header_view().sha3());
|
||||
block_hashes.push(BlockView::new(&block).header_view().hash());
|
||||
bc.insert_block(&mut batch, &block, vec![]);
|
||||
bc.commit();
|
||||
}
|
||||
@ -1607,14 +1607,14 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
[&b4b, &b3b, &b2b].iter().map(|b| BlockView::new(b).header()).collect::<Vec<_>>(),
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().sha3(), 3).unwrap()
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().hash(), 3).unwrap()
|
||||
);
|
||||
|
||||
// TODO: insert block that already includes one of them as an uncle to check it's not allowed.
|
||||
}
|
||||
|
||||
fn secret() -> Secret {
|
||||
"".sha3().into()
|
||||
keccak("").into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1646,8 +1646,8 @@ mod tests {
|
||||
let b2 = fork_chain
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
|
||||
@ -1730,9 +1730,9 @@ mod tests {
|
||||
.with_transaction(t3.clone())
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
let t2_hash = t2.hash();
|
||||
@ -1790,11 +1790,11 @@ mod tests {
|
||||
let b3b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||
let b3a = canon_chain.generate(&mut finalizer).unwrap();
|
||||
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let b1_hash= BlockView::new(&b1).header_view().sha3();
|
||||
let b2_hash= BlockView::new(&b2).header_view().sha3();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().sha3();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let b1_hash= BlockView::new(&b1).header_view().hash();
|
||||
let b2_hash= BlockView::new(&b2).header_view().hash();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().hash();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().hash();
|
||||
|
||||
// b3a is a part of canon chain, whereas b3b is part of sidechain
|
||||
let best_block_hash = b3a_hash.clone();
|
||||
@ -1910,8 +1910,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let db = new_db();
|
||||
|
||||
{
|
||||
@ -2226,9 +2226,9 @@ mod tests {
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let second = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let second_hash = BlockView::new(&second).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let second_hash = BlockView::new(&second).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -2266,7 +2266,7 @@ mod tests {
|
||||
// create a longer fork
|
||||
for i in 0..5 {
|
||||
let canon_block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let hash = BlockView::new(&canon_block).header_view().sha3();
|
||||
let hash = BlockView::new(&canon_block).header_view().hash();
|
||||
|
||||
bc.insert_block(&mut batch, &canon_block, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, i, EpochTransition {
|
||||
@ -2279,7 +2279,7 @@ mod tests {
|
||||
|
||||
assert_eq!(bc.best_block_number(), 5);
|
||||
|
||||
let hash = BlockView::new(&uncle).header_view().sha3();
|
||||
let hash = BlockView::new(&uncle).header_view().hash();
|
||||
bc.insert_block(&mut batch, &uncle, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, 999, EpochTransition {
|
||||
block_hash: hash,
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
use util::hash::H256;
|
||||
use util::bytes::Bytes;
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@ -46,7 +45,7 @@ impl<'a, I> Iterator for Complete<'a, I> where I: Iterator, <I as Iterator>::Ite
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(|item| {
|
||||
let rlp = item.complete(self.finalizer.parent_hash.clone());
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().sha3();
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().hash();
|
||||
rlp
|
||||
})
|
||||
}
|
||||
|
@ -111,7 +111,6 @@ impl Iterator for ChainGenerator {
|
||||
|
||||
mod tests {
|
||||
use util::hash::{H256, H2048};
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
use blockchain::generator::{ChainIterator, ChainGenerator, BlockFinalizer};
|
||||
|
||||
@ -129,7 +128,7 @@ mod tests {
|
||||
let b1_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b1 = BlockView::new(&b1_rlp);
|
||||
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().sha3());
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().hash());
|
||||
assert_eq!(b1.header_view().number(), 1);
|
||||
|
||||
let mut fork_chain = canon_chain.fork(1);
|
||||
@ -137,13 +136,13 @@ mod tests {
|
||||
let b2_rlp_fork = fork_chain.generate(&mut finalizer.fork()).unwrap();
|
||||
let b2_fork = BlockView::new(&b2_rlp_fork);
|
||||
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2_fork.header_view().number(), 2);
|
||||
|
||||
let b2_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b2 = BlockView::new(&b2_rlp);
|
||||
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2.header_view().number(), 2);
|
||||
assert!(b2.header_view().difficulty() > b2_fork.header_view().difficulty());
|
||||
}
|
||||
@ -163,7 +162,7 @@ mod tests {
|
||||
assert_eq!(block0.header_view().parent_hash(), H256::default());
|
||||
|
||||
assert_eq!(block1.header_view().number(), 1);
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().sha3());
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().hash());
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ use crypto::ripemd160::Ripemd160 as Ripemd160Digest;
|
||||
use crypto::digest::Digest;
|
||||
use num::{BigUint, Zero, One};
|
||||
|
||||
use util::{U256, H256, Hashable, BytesRef};
|
||||
use hash::keccak;
|
||||
use util::{U256, H256, BytesRef};
|
||||
use ethkey::{Signature, recover as ec_recover};
|
||||
use ethjson;
|
||||
|
||||
@ -228,7 +229,7 @@ impl Impl for EcRecover {
|
||||
let s = Signature::from_rsv(&r, &s, bit);
|
||||
if s.is_valid() {
|
||||
if let Ok(p) = ec_recover(&s, &hash) {
|
||||
let r = p.sha3();
|
||||
let r = keccak(p);
|
||||
output.write(0, &[0; 12]);
|
||||
output.write(12, &r[12..r.len()]);
|
||||
}
|
||||
@ -572,14 +573,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ecrecover() {
|
||||
/*let k = KeyPair::from_secret(b"test".sha3()).unwrap();
|
||||
let a: Address = From::from(k.public().sha3());
|
||||
println!("Address: {}", a);
|
||||
let m = b"hello world".sha3();
|
||||
println!("Message: {}", m);
|
||||
let s = k.sign(&m).unwrap();
|
||||
println!("Signed: {}", s);*/
|
||||
|
||||
let f = ethereum_builtin("ecrecover");
|
||||
|
||||
let i = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap();
|
||||
|
@ -23,7 +23,8 @@ use time::precise_time_ns;
|
||||
use itertools::Itertools;
|
||||
|
||||
// util
|
||||
use util::{Bytes, PerfTimer, Mutex, RwLock, MutexGuard, Hashable};
|
||||
use hash::keccak;
|
||||
use util::{Bytes, PerfTimer, Mutex, RwLock, MutexGuard};
|
||||
use util::{journaldb, DBValue, TrieFactory, Trie};
|
||||
use util::{U256, H256, Address, H2048};
|
||||
use util::trie::TrieSpec;
|
||||
@ -652,7 +653,7 @@ impl Client {
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
|
||||
assert_eq!(header.hash(), BlockView::new(block_data).header_view().sha3());
|
||||
assert_eq!(header.hash(), BlockView::new(block_data).header_view().hash());
|
||||
|
||||
//let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new));
|
||||
|
||||
@ -1503,7 +1504,7 @@ impl BlockChainClient for Client {
|
||||
};
|
||||
|
||||
let (_, db) = state.drop();
|
||||
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), account.sha3());
|
||||
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), keccak(account));
|
||||
let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) {
|
||||
Ok(trie) => trie,
|
||||
_ => {
|
||||
@ -1591,7 +1592,7 @@ impl BlockChainClient for Client {
|
||||
use verification::queue::kind::BlockLike;
|
||||
use verification::queue::kind::blocks::Unverified;
|
||||
|
||||
// create unverified block here so the `sha3` calculation can be cached.
|
||||
// create unverified block here so the `keccak` calculation can be cached.
|
||||
let unverified = Unverified::new(bytes);
|
||||
|
||||
{
|
||||
@ -1792,7 +1793,7 @@ impl BlockChainClient for Client {
|
||||
let dispatch = move |reg_addr, data| {
|
||||
future::done(self.call_contract(BlockId::Latest, reg_addr, data))
|
||||
};
|
||||
r.get_address(dispatch, name.as_bytes().sha3(), "A".to_string()).wait().ok()
|
||||
r.get_address(dispatch, keccak(name.as_bytes()), "A".to_string()).wait().ok()
|
||||
})
|
||||
.and_then(|a| if a.is_zero() { None } else { Some(a) })
|
||||
}
|
||||
@ -2067,16 +2068,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_return_correct_log_index() {
|
||||
use hash::keccak;
|
||||
use super::transaction_receipt;
|
||||
use ethkey::KeyPair;
|
||||
use log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use receipt::{Receipt, LocalizedReceipt};
|
||||
use transaction::{Transaction, LocalizedTransaction, Action};
|
||||
use util::Hashable;
|
||||
use tests::helpers::TestEngine;
|
||||
|
||||
// given
|
||||
let key = KeyPair::from_secret_slice(&"test".sha3()).unwrap();
|
||||
let key = KeyPair::from_secret_slice(&keccak("test")).unwrap();
|
||||
let secret = key.secret();
|
||||
let engine = TestEngine::new(0);
|
||||
|
||||
|
@ -22,6 +22,7 @@ use std::collections::{HashMap, BTreeMap};
|
||||
use std::mem;
|
||||
use itertools::Itertools;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use ethkey::{Generator, Random};
|
||||
@ -241,7 +242,7 @@ impl TestBlockChainClient {
|
||||
uncle_header.set_parent_hash(self.last_hash.read().clone());
|
||||
uncle_header.set_number(n as BlockNumber);
|
||||
uncles.append(&uncle_header);
|
||||
header.set_uncles_hash(uncles.as_raw().sha3());
|
||||
header.set_uncles_hash(keccak(uncles.as_raw()));
|
||||
uncles
|
||||
},
|
||||
_ => RlpStream::new_list(0)
|
||||
|
@ -28,8 +28,9 @@ use header::{BlockNumber, Header as FullHeader};
|
||||
use transaction::UnverifiedTransaction;
|
||||
use views;
|
||||
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{Address, Hashable, H256, H2048, U256};
|
||||
use util::{Address, H256, H2048, U256};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// Owning header view.
|
||||
@ -65,7 +66,7 @@ impl Header {
|
||||
// forwarders to borrowed view.
|
||||
impl Header {
|
||||
/// Returns the header hash.
|
||||
pub fn hash(&self) -> H256 { self.sha3() }
|
||||
pub fn hash(&self) -> H256 { keccak(&self.0) }
|
||||
|
||||
/// Returns the parent hash.
|
||||
pub fn parent_hash(&self) -> H256 { self.view().parent_hash() }
|
||||
@ -110,12 +111,6 @@ impl Header {
|
||||
pub fn seal(&self) -> Vec<Vec<u8>> { self.view().seal() }
|
||||
}
|
||||
|
||||
impl Hashable for Header {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.0.sha3()
|
||||
}
|
||||
}
|
||||
|
||||
/// Owning block body view.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
@ -219,7 +214,7 @@ impl Block {
|
||||
// forwarders to borrowed header view.
|
||||
impl Block {
|
||||
/// Returns the header hash.
|
||||
pub fn hash(&self) -> H256 { self.header_view().sha3() }
|
||||
pub fn hash(&self) -> H256 { self.header_view().hash() }
|
||||
|
||||
/// Returns the parent hash.
|
||||
pub fn parent_hash(&self) -> H256 { self.header_view().parent_hash() }
|
||||
|
@ -830,6 +830,7 @@ impl Engine for AuthorityRound {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::Header;
|
||||
use error::{Error, BlockError};
|
||||
@ -884,8 +885,8 @@ mod tests {
|
||||
#[test]
|
||||
fn generates_seal_and_does_not_double_propose() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr1 = tap.insert_account("1".sha3().into(), "1").unwrap();
|
||||
let addr2 = tap.insert_account("2".sha3().into(), "2").unwrap();
|
||||
let addr1 = tap.insert_account(keccak("1").into(), "1").unwrap();
|
||||
let addr2 = tap.insert_account(keccak("2").into(), "2").unwrap();
|
||||
|
||||
let spec = Spec::new_test_round();
|
||||
let engine = &*spec.engine;
|
||||
@ -916,7 +917,7 @@ mod tests {
|
||||
#[test]
|
||||
fn proposer_switching() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
|
||||
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
|
||||
@ -941,7 +942,7 @@ mod tests {
|
||||
#[test]
|
||||
fn rejects_future_block() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
|
||||
@ -967,7 +968,7 @@ mod tests {
|
||||
#[test]
|
||||
fn rejects_step_backwards() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&4usize).into_vec()]);
|
||||
|
@ -252,6 +252,7 @@ impl Engine for BasicAuthority {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use block::*;
|
||||
use error::{BlockError, Error};
|
||||
@ -308,7 +309,7 @@ mod tests {
|
||||
#[test]
|
||||
fn can_generate_seal() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("").into(), "").unwrap();
|
||||
|
||||
let spec = new_test_authority();
|
||||
let engine = &*spec.engine;
|
||||
@ -326,7 +327,7 @@ mod tests {
|
||||
#[test]
|
||||
fn seals_internally() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let authority = tap.insert_account("".sha3().into(), "").unwrap();
|
||||
let authority = tap.insert_account(keccak("").into(), "").unwrap();
|
||||
|
||||
let engine = new_test_authority().engine;
|
||||
assert!(!engine.seals_internally().unwrap());
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Tendermint message handling.
|
||||
|
||||
use std::cmp;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use super::{Height, View, BlockHash, Step};
|
||||
use error::Error;
|
||||
@ -99,7 +100,7 @@ impl ConsensusMessage {
|
||||
pub fn verify(&self) -> Result<Address, Error> {
|
||||
let full_rlp = ::rlp::encode(self);
|
||||
let block_info = Rlp::new(&full_rlp).at(1);
|
||||
let public_key = recover(&self.signature.into(), &block_info.as_raw().sha3())?;
|
||||
let public_key = recover(&self.signature.into(), &keccak(block_info.as_raw()))?;
|
||||
Ok(public_to_address(&public_key))
|
||||
}
|
||||
}
|
||||
@ -194,12 +195,13 @@ pub fn message_full_rlp(signature: &H520, vote_info: &Bytes) -> Bytes {
|
||||
}
|
||||
|
||||
pub fn message_hash(vote_step: VoteStep, block_hash: H256) -> H256 {
|
||||
message_info_rlp(&vote_step, Some(block_hash)).sha3()
|
||||
keccak(message_info_rlp(&vote_step, Some(block_hash)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use account_provider::AccountProvider;
|
||||
@ -228,7 +230,7 @@ mod tests {
|
||||
view: 123,
|
||||
step: Step::Precommit,
|
||||
},
|
||||
block_hash: Some("1".sha3())
|
||||
block_hash: Some(keccak("1")),
|
||||
};
|
||||
let raw_rlp = ::rlp::encode(&message).into_vec();
|
||||
let rlp = Rlp::new(&raw_rlp);
|
||||
@ -251,12 +253,12 @@ mod tests {
|
||||
#[test]
|
||||
fn generate_and_verify() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
tap.unlock_account_permanently(addr, "0".into()).unwrap();
|
||||
|
||||
let mi = message_info_rlp(&VoteStep::new(123, 2, Step::Precommit), Some(H256::default()));
|
||||
|
||||
let raw_rlp = message_full_rlp(&tap.sign(addr, None, mi.sha3()).unwrap().into(), &mi);
|
||||
let raw_rlp = message_full_rlp(&tap.sign(addr, None, keccak(&mi)).unwrap().into(), &mi);
|
||||
|
||||
let rlp = UntrustedRlp::new(&raw_rlp);
|
||||
let message: ConsensusMessage = rlp.as_val().unwrap();
|
||||
|
@ -28,6 +28,7 @@ mod params;
|
||||
use std::sync::{Weak, Arc};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||
use std::collections::{HashSet, BTreeMap, HashMap};
|
||||
use hash::keccak;
|
||||
use std::cmp;
|
||||
use util::*;
|
||||
use client::{Client, EngineClient};
|
||||
@ -213,7 +214,7 @@ impl Tendermint {
|
||||
let r = self.view.load(AtomicOrdering::SeqCst);
|
||||
let s = *self.step.read();
|
||||
let vote_info = message_info_rlp(&VoteStep::new(h, r, s), block_hash);
|
||||
match (self.signer.read().address(), self.sign(vote_info.sha3()).map(Into::into)) {
|
||||
match (self.signer.read().address(), self.sign(keccak(&vote_info)).map(Into::into)) {
|
||||
(Some(validator), Ok(signature)) => {
|
||||
let message_rlp = message_full_rlp(&signature, &vote_info);
|
||||
let message = ConsensusMessage::new(signature, h, r, s, block_hash);
|
||||
@ -498,7 +499,7 @@ impl Engine for Tendermint {
|
||||
let view = self.view.load(AtomicOrdering::SeqCst);
|
||||
let bh = Some(header.bare_hash());
|
||||
let vote_info = message_info_rlp(&VoteStep::new(height, view, Step::Propose), bh.clone());
|
||||
if let Ok(signature) = self.sign(vote_info.sha3()).map(Into::into) {
|
||||
if let Ok(signature) = self.sign(keccak(&vote_info)).map(Into::into) {
|
||||
// Insert Propose vote.
|
||||
debug!(target: "engine", "Submitting proposal {} at height {} view {}.", header.bare_hash(), height, view);
|
||||
self.votes.vote(ConsensusMessage::new(signature, height, view, Step::Propose, bh), author);
|
||||
@ -522,7 +523,7 @@ impl Engine for Tendermint {
|
||||
let rlp = UntrustedRlp::new(rlp);
|
||||
let message: ConsensusMessage = rlp.as_val()?;
|
||||
if !self.votes.is_old_or_known(&message) {
|
||||
let sender = public_to_address(&recover(&message.signature.into(), &rlp.at(1)?.as_raw().sha3())?);
|
||||
let sender = public_to_address(&recover(&message.signature.into(), &keccak(rlp.at(1)?.as_raw()))?);
|
||||
if !self.is_authority(&sender) {
|
||||
return Err(EngineError::NotAuthorized(sender).into());
|
||||
}
|
||||
@ -798,7 +799,7 @@ mod tests {
|
||||
|
||||
fn vote<F>(engine: &Engine, signer: F, height: usize, view: usize, step: Step, block_hash: Option<H256>) -> Bytes where F: FnOnce(H256) -> Result<H520, ::account_provider::SignError> {
|
||||
let mi = message_info_rlp(&VoteStep::new(height, view, step), block_hash);
|
||||
let m = message_full_rlp(&signer(mi.sha3()).unwrap().into(), &mi);
|
||||
let m = message_full_rlp(&signer(keccak(&mi)).unwrap().into(), &mi);
|
||||
engine.handle_message(&m).unwrap();
|
||||
m
|
||||
}
|
||||
@ -806,7 +807,7 @@ mod tests {
|
||||
fn proposal_seal(tap: &Arc<AccountProvider>, header: &Header, view: View) -> Vec<Bytes> {
|
||||
let author = header.author();
|
||||
let vote_info = message_info_rlp(&VoteStep::new(header.number() as Height, view, Step::Propose), Some(header.bare_hash()));
|
||||
let signature = tap.sign(*author, None, vote_info.sha3()).unwrap();
|
||||
let signature = tap.sign(*author, None, keccak(vote_info)).unwrap();
|
||||
vec![
|
||||
::rlp::encode(&view).into_vec(),
|
||||
::rlp::encode(&H520::from(signature)).into_vec(),
|
||||
@ -815,7 +816,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn insert_and_unlock(tap: &Arc<AccountProvider>, acc: &str) -> Address {
|
||||
let addr = tap.insert_account(acc.sha3().into(), acc).unwrap();
|
||||
let addr = tap.insert_account(keccak(acc).into(), acc).unwrap();
|
||||
tap.unlock_account_permanently(addr, acc.into()).unwrap();
|
||||
addr
|
||||
}
|
||||
@ -922,7 +923,7 @@ mod tests {
|
||||
let mut seal = proposal_seal(&tap, &header, 0);
|
||||
|
||||
let vote_info = message_info_rlp(&VoteStep::new(2, 0, Step::Precommit), Some(header.bare_hash()));
|
||||
let signature1 = tap.sign(proposer, None, vote_info.sha3()).unwrap();
|
||||
let signature1 = tap.sign(proposer, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[1] = ::rlp::NULL_RLP.to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec();
|
||||
@ -935,7 +936,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let voter = insert_and_unlock(&tap, "0");
|
||||
let signature0 = tap.sign(voter, None, vote_info.sha3()).unwrap();
|
||||
let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).into_vec();
|
||||
header.set_seal(seal.clone());
|
||||
@ -943,7 +944,7 @@ mod tests {
|
||||
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
|
||||
|
||||
let bad_voter = insert_and_unlock(&tap, "101");
|
||||
let bad_signature = tap.sign(bad_voter, None, vote_info.sha3()).unwrap();
|
||||
let bad_signature = tap.sign(bad_voter, None, keccak(vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec();
|
||||
header.set_seal(seal);
|
||||
@ -1076,10 +1077,10 @@ mod tests {
|
||||
let mut seal = proposal_seal(&tap, &header, 0);
|
||||
|
||||
let vote_info = message_info_rlp(&VoteStep::new(2, 0, Step::Precommit), Some(header.bare_hash()));
|
||||
let signature1 = tap.sign(proposer, None, vote_info.sha3()).unwrap();
|
||||
let signature1 = tap.sign(proposer, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
let voter = insert_and_unlock(&tap, "0");
|
||||
let signature0 = tap.sign(voter, None, vote_info.sha3()).unwrap();
|
||||
let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[1] = ::rlp::NULL_RLP.to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec();
|
||||
@ -1116,7 +1117,7 @@ mod tests {
|
||||
assert!(epoch_verifier.verify_light(&header).is_ok());
|
||||
|
||||
let bad_voter = insert_and_unlock(&tap, "101");
|
||||
let bad_signature = tap.sign(bad_voter, None, vote_info.sha3()).unwrap();
|
||||
let bad_signature = tap.sign(bad_voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec();
|
||||
header.set_seal(seal);
|
||||
|
@ -128,6 +128,7 @@ impl ValidatorSet for ValidatorContract {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::encode;
|
||||
use spec::Spec;
|
||||
@ -153,7 +154,7 @@ mod tests {
|
||||
#[test]
|
||||
fn reports_validators() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, Some(tap.clone()));
|
||||
client.engine().register_client(Arc::downgrade(&client));
|
||||
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
|
||||
|
@ -144,6 +144,7 @@ impl ValidatorSet for Multi {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::collections::BTreeMap;
|
||||
use hash::keccak;
|
||||
use account_provider::AccountProvider;
|
||||
use client::{BlockChainClient, EngineClient};
|
||||
use engines::EpochChange;
|
||||
@ -163,9 +164,9 @@ mod tests {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let s0: Secret = "0".sha3().into();
|
||||
let s0: Secret = keccak("0").into();
|
||||
let v0 = tap.insert_account(s0.clone(), "").unwrap();
|
||||
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_multi, Some(tap));
|
||||
client.engine().register_client(Arc::downgrade(&client));
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::sync::{Weak, Arc};
|
||||
use futures::Future;
|
||||
use native_contracts::ValidatorSet as Provider;
|
||||
use hash::keccak;
|
||||
|
||||
use util::*;
|
||||
use util::cache::MemoryLruCache;
|
||||
@ -41,7 +42,7 @@ const MEMOIZE_CAPACITY: usize = 500;
|
||||
const EVENT_NAME: &'static [u8] = &*b"InitiateChange(bytes32,address[])";
|
||||
|
||||
lazy_static! {
|
||||
static ref EVENT_NAME_HASH: H256 = EVENT_NAME.sha3();
|
||||
static ref EVENT_NAME_HASH: H256 = keccak(EVENT_NAME);
|
||||
}
|
||||
|
||||
/// The validator contract should have the following interface:
|
||||
@ -424,6 +425,7 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use types::ids::BlockId;
|
||||
use spec::Spec;
|
||||
@ -449,9 +451,9 @@ mod tests {
|
||||
#[test]
|
||||
fn knows_validators() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let s0: Secret = "1".sha3().into();
|
||||
let s0: Secret = keccak("1").into();
|
||||
let v0 = tap.insert_account(s0.clone(), "").unwrap();
|
||||
let v1 = tap.insert_account("0".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("0").into(), "").unwrap();
|
||||
let chain_id = Spec::new_validator_safe_contract().chain_id();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, Some(tap));
|
||||
client.engine().register_client(Arc::downgrade(&client));
|
||||
|
@ -206,6 +206,7 @@ impl <M: Message + Default + Encodable + Debug> VoteCollector<M> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use super::*;
|
||||
@ -251,7 +252,7 @@ mod tests {
|
||||
#[test]
|
||||
fn seal_retrieval() {
|
||||
let collector = VoteCollector::default();
|
||||
let bh = Some("1".sha3());
|
||||
let bh = Some(keccak("1"));
|
||||
let mut signatures = Vec::new();
|
||||
for _ in 0..5 {
|
||||
signatures.push(H520::random());
|
||||
@ -263,9 +264,9 @@ mod tests {
|
||||
// Good proposal
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), bh.clone());
|
||||
// Wrong block proposal.
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), Some("0".sha3()));
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), Some(keccak("0")));
|
||||
// Wrong block commit.
|
||||
random_vote(&collector, signatures[3].clone(), commit_round.clone(), Some("0".sha3()));
|
||||
random_vote(&collector, signatures[3].clone(), commit_round.clone(), Some(keccak("0")));
|
||||
// Wrong round.
|
||||
random_vote(&collector, signatures[0].clone(), 6, bh.clone());
|
||||
// Wrong round.
|
||||
@ -291,22 +292,22 @@ mod tests {
|
||||
let round1 = 1;
|
||||
let round3 = 3;
|
||||
// good 1
|
||||
random_vote(&collector, H520::random(), round1, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 0, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 0, Some(keccak("0")));
|
||||
// good 3
|
||||
random_vote(&collector, H520::random(), round3, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 2, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), round3, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 2, Some(keccak("0")));
|
||||
// good prevote
|
||||
random_vote(&collector, H520::random(), round1, Some("1".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("1")));
|
||||
// good prevote
|
||||
let same_sig = H520::random();
|
||||
random_vote(&collector, same_sig.clone(), round1, Some("1".sha3()));
|
||||
random_vote(&collector, same_sig, round1, Some("1".sha3()));
|
||||
random_vote(&collector, same_sig.clone(), round1, Some(keccak("1")));
|
||||
random_vote(&collector, same_sig, round1, Some(keccak("1")));
|
||||
// good precommit
|
||||
random_vote(&collector, H520::random(), round3, Some("1".sha3()));
|
||||
random_vote(&collector, H520::random(), round3, Some(keccak("1")));
|
||||
// good prevote
|
||||
random_vote(&collector, H520::random(), round1, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 4, Some("2".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 4, Some(keccak("2")));
|
||||
|
||||
assert_eq!(collector.count_round_votes(&round1), 4);
|
||||
assert_eq!(collector.count_round_votes(&round3), 2);
|
||||
@ -314,7 +315,7 @@ mod tests {
|
||||
let message = TestMessage {
|
||||
signature: H520::default(),
|
||||
step: round1,
|
||||
block_hash: Some("1".sha3())
|
||||
block_hash: Some(keccak("1"))
|
||||
};
|
||||
assert_eq!(collector.count_aligned_votes(&message), 2);
|
||||
}
|
||||
@ -325,11 +326,11 @@ mod tests {
|
||||
let vote = |round, hash| {
|
||||
random_vote(&collector, H520::random(), round, hash);
|
||||
};
|
||||
vote(6, Some("0".sha3()));
|
||||
vote(3, Some("0".sha3()));
|
||||
vote(7, Some("0".sha3()));
|
||||
vote(8, Some("1".sha3()));
|
||||
vote(1, Some("1".sha3()));
|
||||
vote(6, Some(keccak("0")));
|
||||
vote(3, Some(keccak("0")));
|
||||
vote(7, Some(keccak("0")));
|
||||
vote(8, Some(keccak("1")));
|
||||
vote(1, Some(keccak("1")));
|
||||
|
||||
collector.throw_out_old(&7);
|
||||
assert_eq!(collector.len(), 2);
|
||||
@ -340,9 +341,9 @@ mod tests {
|
||||
let collector = VoteCollector::default();
|
||||
let round = 3;
|
||||
// Vote is inserted fine.
|
||||
assert!(full_vote(&collector, H520::random(), round, Some("0".sha3()), &Address::default()));
|
||||
assert!(full_vote(&collector, H520::random(), round, Some(keccak("0")), &Address::default()));
|
||||
// Returns the double voting address.
|
||||
assert!(!full_vote(&collector, H520::random(), round, Some("1".sha3()), &Address::default()));
|
||||
assert!(!full_vote(&collector, H520::random(), round, Some(keccak("1")), &Address::default()));
|
||||
assert_eq!(collector.count_round_votes(&round), 1);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use std::path::Path;
|
||||
use std::cmp;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_EMPTY_LIST_RLP};
|
||||
use ethash::{quick_get_difficulty, slow_get_seedhash, EthashManager};
|
||||
use util::*;
|
||||
use block::*;
|
||||
@ -481,7 +482,7 @@ impl Ethash {
|
||||
panic!("Can't calculate genesis block difficulty");
|
||||
}
|
||||
|
||||
let parent_has_uncles = parent.uncles_hash() != &sha3::SHA3_EMPTY_LIST_RLP;
|
||||
let parent_has_uncles = parent.uncles_hash() != &KECCAK_EMPTY_LIST_RLP;
|
||||
|
||||
let min_difficulty = self.ethash_params.minimum_difficulty;
|
||||
|
||||
|
@ -119,7 +119,7 @@ mod tests {
|
||||
|
||||
assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".into());
|
||||
let genesis = morden.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into());
|
||||
|
||||
let _ = morden.engine;
|
||||
}
|
||||
@ -130,7 +130,7 @@ mod tests {
|
||||
|
||||
assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".into());
|
||||
let genesis = frontier.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".into());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".into());
|
||||
|
||||
let _ = frontier.engine;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Transaction Execution environment.
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use state::{Backend as StateBackend, State, Substate, CleanupMode};
|
||||
use engines::Engine;
|
||||
@ -47,20 +48,20 @@ pub fn contract_address(address_scheme: CreateContractAddress, sender: &Address,
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(sender);
|
||||
stream.append(nonce);
|
||||
(From::from(stream.as_raw().sha3()), None)
|
||||
(From::from(keccak(stream.as_raw())), None)
|
||||
},
|
||||
CreateContractAddress::FromCodeHash => {
|
||||
let code_hash = code.sha3();
|
||||
let code_hash = keccak(code);
|
||||
let mut buffer = [0xffu8; 20 + 32];
|
||||
&mut buffer[20..].copy_from_slice(&code_hash[..]);
|
||||
(From::from((&buffer[..]).sha3()), Some(code_hash))
|
||||
(From::from(keccak(&buffer[..])), Some(code_hash))
|
||||
},
|
||||
CreateContractAddress::FromSenderAndCodeHash => {
|
||||
let code_hash = code.sha3();
|
||||
let code_hash = keccak(code);
|
||||
let mut buffer = [0u8; 20 + 32];
|
||||
&mut buffer[..20].copy_from_slice(&sender[..]);
|
||||
&mut buffer[20..].copy_from_slice(&code_hash[..]);
|
||||
(From::from((&buffer[..]).sha3()), Some(code_hash))
|
||||
(From::from(keccak(&buffer[..])), Some(code_hash))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1307,8 +1308,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
evm_test!{test_sha3: test_sha3_jit, test_sha3_int}
|
||||
fn test_sha3(factory: Factory) {
|
||||
evm_test!{test_keccak: test_keccak_jit, test_keccak_int}
|
||||
fn test_keccak(factory: Factory) {
|
||||
let code = "6064640fffffffff20600055".from_hex().unwrap();
|
||||
|
||||
let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
use std::cmp;
|
||||
use std::cell::RefCell;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::*;
|
||||
use basic_types::{LogBloom, ZERO_LOGBLOOM};
|
||||
@ -101,12 +102,12 @@ impl Default for Header {
|
||||
number: 0,
|
||||
author: Address::default(),
|
||||
|
||||
transactions_root: SHA3_NULL_RLP,
|
||||
uncles_hash: SHA3_EMPTY_LIST_RLP,
|
||||
transactions_root: KECCAK_NULL_RLP,
|
||||
uncles_hash: KECCAK_EMPTY_LIST_RLP,
|
||||
extra_data: vec![],
|
||||
|
||||
state_root: SHA3_NULL_RLP,
|
||||
receipts_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
receipts_root: KECCAK_NULL_RLP,
|
||||
log_bloom: ZERO_LOGBLOOM.clone(),
|
||||
gas_used: U256::default(),
|
||||
gas_limit: U256::default(),
|
||||
@ -195,13 +196,13 @@ impl Header {
|
||||
/// Set the seal field of the header.
|
||||
pub fn set_seal(&mut self, a: Vec<Bytes>) { self.seal = a; self.note_dirty(); }
|
||||
|
||||
/// Get the hash of this header (sha3 of the RLP).
|
||||
/// Get the hash of this header (keccak of the RLP).
|
||||
pub fn hash(&self) -> H256 {
|
||||
let mut hash = self.hash.borrow_mut();
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
let h = self.rlp_sha3(Seal::With);
|
||||
let h = self.rlp_keccak(Seal::With);
|
||||
*hash = Some(h.clone());
|
||||
h
|
||||
}
|
||||
@ -214,7 +215,7 @@ impl Header {
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
let h = self.rlp_sha3(Seal::Without);
|
||||
let h = self.rlp_keccak(Seal::Without);
|
||||
*hash = Some(h.clone());
|
||||
h
|
||||
}
|
||||
@ -258,8 +259,8 @@ impl Header {
|
||||
s.out()
|
||||
}
|
||||
|
||||
/// Get the SHA3 (Keccak) of this header, optionally `with_seal`.
|
||||
pub fn rlp_sha3(&self, with_seal: Seal) -> H256 { self.rlp(with_seal).sha3() }
|
||||
/// Get the KECCAK (Keccak) of this header, optionally `with_seal`.
|
||||
pub fn rlp_keccak(&self, with_seal: Seal) -> H256 { keccak(self.rlp(with_seal)) }
|
||||
}
|
||||
|
||||
impl Decodable for Header {
|
||||
@ -279,7 +280,7 @@ impl Decodable for Header {
|
||||
timestamp: cmp::min(r.val_at::<U256>(11)?, u64::max_value().into()).as_u64(),
|
||||
extra_data: r.val_at(12)?,
|
||||
seal: vec![],
|
||||
hash: RefCell::new(Some(r.as_raw().sha3())),
|
||||
hash: RefCell::new(Some(keccak(r.as_raw()))),
|
||||
bare_hash: RefCell::new(None),
|
||||
};
|
||||
|
||||
|
@ -101,6 +101,7 @@ extern crate num;
|
||||
extern crate price_info;
|
||||
extern crate rand;
|
||||
extern crate rlp;
|
||||
extern crate hash;
|
||||
extern crate heapsize;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -23,14 +23,14 @@ use util::Bytes;
|
||||
use util::{Address, H256};
|
||||
use util::kvdb::Database;
|
||||
use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress};
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rlp::{decode, Rlp, RlpStream};
|
||||
|
||||
// attempt to migrate a key, value pair. None if migration not possible.
|
||||
fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
|
||||
let val_hash = val.sha3();
|
||||
let val_hash = keccak(val);
|
||||
|
||||
if key_h != val_hash {
|
||||
// this is a key which has been xor'd with an address.
|
||||
@ -43,7 +43,7 @@ fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let address_hash = Address::from(address).sha3();
|
||||
let address_hash = keccak(Address::from(address));
|
||||
|
||||
// create the xor'd key in place.
|
||||
key_h.copy_from_slice(&*val_hash);
|
||||
|
@ -24,7 +24,8 @@ use transient_hashmap::TransientHashMap;
|
||||
use miner::{TransactionQueue, TransactionQueueDetailsProvider, TransactionImportResult, TransactionOrigin};
|
||||
use miner::transaction_queue::QueuingInstant;
|
||||
use error::{Error, TransactionError};
|
||||
use util::{U256, H256, Address, Hashable};
|
||||
use util::{U256, H256, Address};
|
||||
use hash::keccak;
|
||||
|
||||
type Count = u16;
|
||||
|
||||
@ -103,7 +104,7 @@ impl BanningTransactionQueue {
|
||||
|
||||
// Check code
|
||||
if let Action::Create = transaction.action {
|
||||
let code_hash = transaction.data.sha3();
|
||||
let code_hash = keccak(&transaction.data);
|
||||
let count = self.codes_bans.direct().get(&code_hash).cloned().unwrap_or(0);
|
||||
if count > threshold {
|
||||
debug!(target: "txqueue", "Ignoring transaction {:?} because code is banned.", transaction.hash());
|
||||
@ -131,7 +132,7 @@ impl BanningTransactionQueue {
|
||||
self.ban_recipient(recipient)
|
||||
},
|
||||
Action::Create => {
|
||||
self.ban_codehash(transaction.data.sha3())
|
||||
self.ban_codehash(keccak(&transaction.data))
|
||||
},
|
||||
};
|
||||
sender_banned || recipient_or_code_banned
|
||||
@ -210,13 +211,14 @@ impl DerefMut for BanningTransactionQueue {
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::{BanningTransactionQueue, Threshold};
|
||||
use ethkey::{Random, Generator};
|
||||
use transaction::{Transaction, SignedTransaction, Action};
|
||||
use error::{Error, TransactionError};
|
||||
use client::TransactionImportResult;
|
||||
use miner::{TransactionQueue, TransactionOrigin};
|
||||
use util::{U256, Address, Hashable};
|
||||
use util::{U256, Address};
|
||||
use miner::transaction_queue::test::DummyTransactionDetailsProvider;
|
||||
|
||||
fn queue() -> BanningTransactionQueue {
|
||||
@ -310,7 +312,7 @@ mod tests {
|
||||
fn should_not_accept_transactions_with_banned_code() {
|
||||
// given
|
||||
let tx = transaction(Action::Create);
|
||||
let codehash = tx.data.sha3();
|
||||
let codehash = keccak(&tx.data);
|
||||
let mut txq = queue();
|
||||
// Banlist once (threshold not reached)
|
||||
let banlist1 = txq.ban_codehash(codehash);
|
||||
|
@ -1235,6 +1235,7 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::super::{MinerService, PrioritizationStrategy};
|
||||
use super::*;
|
||||
use block::IsBlock;
|
||||
@ -1418,7 +1419,7 @@ mod tests {
|
||||
fn should_fail_setting_engine_signer_on_pow() {
|
||||
let spec = Spec::new_pow_test_spec;
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(spec, Some(tap.clone()));
|
||||
assert!(match client.miner().set_engine_signer(addr, "".into()) { Err(AccountError::InappropriateChain) => true, _ => false })
|
||||
}
|
||||
@ -1427,7 +1428,7 @@ mod tests {
|
||||
fn should_fail_setting_engine_signer_without_account_provider() {
|
||||
let spec = Spec::new_instant;
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(spec, None);
|
||||
assert!(match client.miner().set_engine_signer(addr, "".into()) { Err(AccountError::NotFound) => true, _ => false });
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
use std::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use itertools::Itertools;
|
||||
use hash::{keccak};
|
||||
use util::*;
|
||||
use state::Account;
|
||||
use ethjson;
|
||||
@ -61,7 +62,7 @@ impl PodAccount {
|
||||
stream.append(&self.nonce);
|
||||
stream.append(&self.balance);
|
||||
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), rlp::encode(&U256::from(&**v)).to_vec())).collect()));
|
||||
stream.append(&self.code.as_ref().unwrap_or(&vec![]).sha3());
|
||||
stream.append(&keccak(&self.code.as_ref().unwrap_or(&vec![])));
|
||||
stream.out()
|
||||
}
|
||||
|
||||
@ -117,7 +118,7 @@ impl fmt::Display for PodAccount {
|
||||
self.balance,
|
||||
self.nonce,
|
||||
self.code.as_ref().map_or(0, |c| c.len()),
|
||||
self.code.as_ref().map_or_else(H256::new, |c| c.sha3()),
|
||||
self.code.as_ref().map_or_else(H256::new, |c| keccak(c)),
|
||||
self.storage.len(),
|
||||
)
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use basic_account::BasicAccount;
|
||||
use snapshot::Error;
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
|
||||
|
||||
use util::{U256, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{U256, H256, Bytes, HashDB};
|
||||
use util::trie::{TrieDB, Trie};
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
|
||||
@ -30,8 +31,8 @@ use std::collections::HashSet;
|
||||
const ACC_EMPTY: BasicAccount = BasicAccount {
|
||||
nonce: U256([0, 0, 0, 0]),
|
||||
balance: U256([0, 0, 0, 0]),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
};
|
||||
|
||||
// whether an encoded account has code and how it is referred to.
|
||||
@ -78,7 +79,7 @@ pub fn to_fat_rlps(account_hash: &H256, acc: &BasicAccount, acct_db: &AccountDB,
|
||||
.append(&acc.balance);
|
||||
|
||||
// [has_code, code_hash].
|
||||
if acc.code_hash == SHA3_EMPTY {
|
||||
if acc.code_hash == KECCAK_EMPTY {
|
||||
account_stream.append(&CodeState::Empty.raw()).append_empty_data();
|
||||
} else if used_code.contains(&acc.code_hash) {
|
||||
account_stream.append(&CodeState::Hash.raw()).append(&acc.code_hash);
|
||||
@ -164,7 +165,7 @@ pub fn from_fat_rlp(
|
||||
|
||||
// load the code if it exists.
|
||||
let (code_hash, new_code) = match code_state {
|
||||
CodeState::Empty => (SHA3_EMPTY, None),
|
||||
CodeState::Empty => (KECCAK_EMPTY, None),
|
||||
CodeState::Inline => {
|
||||
let code: Bytes = rlp.val_at(3)?;
|
||||
let code_hash = acct_db.insert(&code);
|
||||
@ -210,8 +211,8 @@ mod tests {
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use snapshot::tests::helpers::fill_storage;
|
||||
|
||||
use util::sha3::{SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{Address, H256, HashDB, DBValue, Hashable};
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
use util::{Address, H256, HashDB, DBValue};
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
use std::collections::HashSet;
|
||||
@ -226,14 +227,14 @@ mod tests {
|
||||
let account = BasicAccount {
|
||||
nonce: 50.into(),
|
||||
balance: 123456789.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlps = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlps[0]).at(1).unwrap();
|
||||
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
|
||||
}
|
||||
@ -245,20 +246,20 @@ mod tests {
|
||||
|
||||
let account = {
|
||||
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||
BasicAccount {
|
||||
nonce: 25.into(),
|
||||
balance: 987654321.into(),
|
||||
storage_root: root,
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
}
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlp = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlp[0]).at(1).unwrap();
|
||||
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
|
||||
}
|
||||
@ -270,21 +271,21 @@ mod tests {
|
||||
|
||||
let account = {
|
||||
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||
BasicAccount {
|
||||
nonce: 25.into(),
|
||||
balance: 987654321.into(),
|
||||
storage_root: root,
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
}
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlps = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), 500, 1000).unwrap();
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), 500, 1000).unwrap();
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
let mut restored_account = None;
|
||||
for rlp in fat_rlps {
|
||||
let fat_rlp = UntrustedRlp::new(&rlp).at(1).unwrap();
|
||||
@ -314,21 +315,21 @@ mod tests {
|
||||
let account1 = BasicAccount {
|
||||
nonce: 50.into(),
|
||||
balance: 123456789.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: code_hash,
|
||||
};
|
||||
|
||||
let account2 = BasicAccount {
|
||||
nonce: 400.into(),
|
||||
balance: 98765432123456789usize.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: code_hash,
|
||||
};
|
||||
|
||||
let mut used_code = HashSet::new();
|
||||
|
||||
let fat_rlp1 = to_fat_rlps(&addr1.sha3(), &account1, &AccountDB::new(db.as_hashdb(), &addr1), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp2 = to_fat_rlps(&addr2.sha3(), &account2, &AccountDB::new(db.as_hashdb(), &addr2), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::new(db.as_hashdb(), &addr1), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::new(db.as_hashdb(), &addr2), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
assert_eq!(used_code.len(), 1);
|
||||
|
||||
let fat_rlp1 = UntrustedRlp::new(&fat_rlp1[0]).at(1).unwrap();
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
use block::Block;
|
||||
use header::Header;
|
||||
use hash::keccak;
|
||||
|
||||
use views::BlockView;
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp};
|
||||
use util::{Bytes, Hashable, H256};
|
||||
use util::{Bytes, H256};
|
||||
use util::triehash::ordered_trie_root;
|
||||
|
||||
const HEADER_FIELDS: usize = 8;
|
||||
@ -111,7 +112,7 @@ impl AbridgedBlock {
|
||||
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append_list(&uncles);
|
||||
header.set_uncles_hash(uncles_rlp.as_raw().sha3());
|
||||
header.set_uncles_hash(keccak(uncles_rlp.as_raw()));
|
||||
|
||||
let mut seal_fields = Vec::new();
|
||||
for i in (HEADER_FIELDS + BLOCK_FIELDS)..rlp.item_count()? {
|
||||
|
@ -342,7 +342,7 @@ impl SnapshotReader for LooseReader {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use devtools::RandomTempPath;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
|
||||
use snapshot::ManifestData;
|
||||
use super::{SnapshotWriter, SnapshotReader, PackedWriter, PackedReader, LooseWriter, LooseReader, SNAPSHOT_VERSION};
|
||||
@ -359,24 +359,24 @@ mod tests {
|
||||
let mut block_hashes = Vec::new();
|
||||
|
||||
for chunk in STATE_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
state_hashes.push(hash.clone());
|
||||
writer.write_state_chunk(hash, chunk).unwrap();
|
||||
}
|
||||
|
||||
for chunk in BLOCK_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
block_hashes.push(hash.clone());
|
||||
writer.write_block_chunk(chunk.sha3(), chunk).unwrap();
|
||||
writer.write_block_chunk(keccak(&chunk), chunk).unwrap();
|
||||
}
|
||||
|
||||
let manifest = ManifestData {
|
||||
version: SNAPSHOT_VERSION,
|
||||
state_hashes: state_hashes,
|
||||
block_hashes: block_hashes,
|
||||
state_root: b"notarealroot".sha3(),
|
||||
state_root: keccak(b"notarealroot"),
|
||||
block_number: 12345678987654321,
|
||||
block_hash: b"notarealblock".sha3(),
|
||||
block_hash: keccak(b"notarealblock"),
|
||||
};
|
||||
|
||||
writer.finish(manifest.clone()).unwrap();
|
||||
@ -398,24 +398,24 @@ mod tests {
|
||||
let mut block_hashes = Vec::new();
|
||||
|
||||
for chunk in STATE_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
state_hashes.push(hash.clone());
|
||||
writer.write_state_chunk(hash, chunk).unwrap();
|
||||
}
|
||||
|
||||
for chunk in BLOCK_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
block_hashes.push(hash.clone());
|
||||
writer.write_block_chunk(chunk.sha3(), chunk).unwrap();
|
||||
writer.write_block_chunk(keccak(&chunk), chunk).unwrap();
|
||||
}
|
||||
|
||||
let manifest = ManifestData {
|
||||
version: SNAPSHOT_VERSION,
|
||||
state_hashes: state_hashes,
|
||||
block_hashes: block_hashes,
|
||||
state_root: b"notarealroot".sha3(),
|
||||
state_root: keccak(b"notarealroot"),
|
||||
block_number: 12345678987654321,
|
||||
block_hash: b"notarealblock".sha3(),
|
||||
block_hash: keccak(b"notarealblock)"),
|
||||
};
|
||||
|
||||
writer.finish(manifest.clone()).unwrap();
|
||||
|
@ -22,6 +22,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY};
|
||||
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
@ -29,13 +30,12 @@ use engines::Engine;
|
||||
use header::Header;
|
||||
use ids::BlockId;
|
||||
|
||||
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256};
|
||||
use util::{Bytes, HashDB, DBValue, snappy, U256};
|
||||
use util::Mutex;
|
||||
use util::hash::{H256};
|
||||
use util::journaldb::{self, Algorithm, JournalDB};
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use bloom_journal::Bloom;
|
||||
|
||||
@ -183,7 +183,7 @@ pub fn chunk_secondary<'a>(mut chunker: Box<SnapshotComponents>, chain: &'a Bloc
|
||||
let mut chunk_sink = |raw_data: &[u8]| {
|
||||
let compressed_size = snappy::compress_into(raw_data, &mut snappy_buffer);
|
||||
let compressed = &snappy_buffer[..compressed_size];
|
||||
let hash = compressed.sha3();
|
||||
let hash = keccak(&compressed);
|
||||
let size = compressed.len();
|
||||
|
||||
writer.lock().write_block_chunk(hash, compressed)?;
|
||||
@ -240,7 +240,7 @@ impl<'a> StateChunker<'a> {
|
||||
|
||||
let compressed_size = snappy::compress_into(&raw_data, &mut self.snappy_buffer);
|
||||
let compressed = &self.snappy_buffer[..compressed_size];
|
||||
let hash = compressed.sha3();
|
||||
let hash = keccak(&compressed);
|
||||
|
||||
self.writer.lock().write_state_chunk(hash, compressed)?;
|
||||
trace!(target: "snapshot", "wrote state chunk. size: {}, uncompressed size: {}", compressed_size, raw_data.len());
|
||||
@ -318,7 +318,7 @@ impl StateRebuilder {
|
||||
pub fn new(db: Arc<KeyValueDB>, pruning: Algorithm) -> Self {
|
||||
StateRebuilder {
|
||||
db: journaldb::new(db.clone(), pruning, ::db::COL_STATE),
|
||||
state_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
known_code: HashMap::new(),
|
||||
missing_code: HashMap::new(),
|
||||
bloom: StateDB::load_bloom(&*db),
|
||||
@ -362,7 +362,7 @@ impl StateRebuilder {
|
||||
|
||||
// batch trie writes
|
||||
{
|
||||
let mut account_trie = if self.state_root != SHA3_NULL_RLP {
|
||||
let mut account_trie = if self.state_root != KECCAK_NULL_RLP {
|
||||
TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root)?
|
||||
} else {
|
||||
TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root)
|
||||
@ -443,7 +443,7 @@ fn rebuild_accounts(
|
||||
// new inline code
|
||||
Some(code) => status.new_code.push((code_hash, code, hash)),
|
||||
None => {
|
||||
if code_hash != ::util::SHA3_EMPTY {
|
||||
if code_hash != KECCAK_EMPTY {
|
||||
// see if this code has already been included inline
|
||||
match known_code.get(&code_hash) {
|
||||
Some(&first_with) => {
|
||||
|
@ -18,6 +18,7 @@
|
||||
//! which can be queried before and after a full snapshot/restore cycle.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_NULL_RLP};
|
||||
|
||||
use account_db::AccountDBMut;
|
||||
use basic_account::BasicAccount;
|
||||
@ -36,7 +37,6 @@ use util::hashdb::HashDB;
|
||||
use util::journaldb;
|
||||
use util::trie::{Alphabet, StandardMap, SecTrieDBMut, TrieMut, ValueMode};
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
|
||||
// the proportion of accounts we will alter each tick.
|
||||
const ACCOUNT_CHURN: f32 = 0.01;
|
||||
@ -51,7 +51,7 @@ impl StateProducer {
|
||||
/// Create a new `StateProducer`.
|
||||
pub fn new() -> Self {
|
||||
StateProducer {
|
||||
state_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
storage_seed: H256::zero(),
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
|
||||
count: 100,
|
||||
};
|
||||
{
|
||||
let mut trie = if *root == SHA3_NULL_RLP {
|
||||
let mut trie = if *root == KECCAK_NULL_RLP {
|
||||
SecTrieDBMut::new(&mut db, root)
|
||||
} else {
|
||||
SecTrieDBMut::from_existing(&mut db, root).unwrap()
|
||||
|
@ -30,7 +30,7 @@ use spec::Spec;
|
||||
use tests::helpers;
|
||||
use transaction::{Transaction, Action, SignedTransaction};
|
||||
|
||||
use util::{Address, Hashable};
|
||||
use util::Address;
|
||||
use util::kvdb;
|
||||
|
||||
const PASS: &'static str = "";
|
||||
@ -38,14 +38,14 @@ const TRANSITION_BLOCK_1: usize = 2; // block at which the contract becomes acti
|
||||
const TRANSITION_BLOCK_2: usize = 10; // block at which the second contract activates.
|
||||
|
||||
macro_rules! secret {
|
||||
($e: expr) => { Secret::from_slice(&$e.sha3()) }
|
||||
($e: expr) => { Secret::from_slice(&$crate::hash::keccak($e)) }
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
// contract addresses.
|
||||
static ref CONTRACT_ADDR_1: Address = Address::from_str("0000000000000000000000000000000000000005").unwrap();
|
||||
static ref CONTRACT_ADDR_2: Address = Address::from_str("0000000000000000000000000000000000000006").unwrap();
|
||||
// secret: `sha3(1)`, and initial validator.
|
||||
// secret: `keccak(1)`, and initial validator.
|
||||
static ref RICH_ADDR: Address = Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap();
|
||||
// rich address' secret.
|
||||
static ref RICH_SECRET: Secret = secret!("1");
|
||||
@ -53,7 +53,7 @@ lazy_static! {
|
||||
|
||||
|
||||
/// Contract code used here: https://gist.github.com/anonymous/2a43783647e0f0dfcc359bd6fd81d6d9
|
||||
/// Account with secrets "1".sha3() is initially the validator.
|
||||
/// Account with secrets keccak("1") is initially the validator.
|
||||
/// Transitions to the contract at block 2, initially same validator set.
|
||||
/// Create a new Spec with AuthorityRound which uses a contract at address 5 to determine the current validators using `getValidators`.
|
||||
/// `native_contracts::test_contracts::ValidatorSet` provides a native wrapper for the ABi.
|
||||
|
@ -71,7 +71,7 @@ fn chunk_and_restore(amount: u64) {
|
||||
version: 2,
|
||||
state_hashes: Vec::new(),
|
||||
block_hashes: block_hashes,
|
||||
state_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
state_root: ::hash::KECCAK_NULL_RLP,
|
||||
block_number: amount,
|
||||
block_hash: best_hash,
|
||||
};
|
||||
@ -134,7 +134,7 @@ fn checks_flag() {
|
||||
version: 2,
|
||||
state_hashes: Vec::new(),
|
||||
block_hashes: Vec::new(),
|
||||
state_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
state_root: ::hash::KECCAK_NULL_RLP,
|
||||
block_number: 102,
|
||||
block_hash: H256::default(),
|
||||
};
|
||||
|
@ -32,10 +32,9 @@ use util::memorydb::MemoryDB;
|
||||
use util::Mutex;
|
||||
use devtools::RandomTempPath;
|
||||
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
|
||||
#[test]
|
||||
fn snap_and_restore() {
|
||||
@ -98,7 +97,7 @@ fn snap_and_restore() {
|
||||
fn get_code_from_prev_chunk() {
|
||||
use std::collections::HashSet;
|
||||
use rlp::RlpStream;
|
||||
use util::{HashDB, H256, U256, Hashable};
|
||||
use util::{HashDB, H256, U256};
|
||||
|
||||
use account_db::{AccountDBMut, AccountDB};
|
||||
|
||||
@ -107,8 +106,8 @@ fn get_code_from_prev_chunk() {
|
||||
let mut acc_stream = RlpStream::new_list(4);
|
||||
acc_stream.append(&U256::default())
|
||||
.append(&U256::default())
|
||||
.append(&SHA3_NULL_RLP)
|
||||
.append(&code.sha3());
|
||||
.append(&KECCAK_NULL_RLP)
|
||||
.append(&keccak(code));
|
||||
|
||||
let (h1, h2) = (H256::random(), H256::random());
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use util::{Address, H256, U256};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use hash::KECCAK_NULL_RLP;
|
||||
use ethjson;
|
||||
use super::seal::Seal;
|
||||
|
||||
@ -54,8 +54,8 @@ impl From<ethjson::spec::Genesis> for Genesis {
|
||||
timestamp: g.timestamp.map_or(0, Into::into),
|
||||
parent_hash: g.parent_hash.map_or_else(H256::zero, Into::into),
|
||||
gas_limit: g.gas_limit.into(),
|
||||
transactions_root: g.transactions_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
|
||||
receipts_root: g.receipts_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
|
||||
transactions_root: g.transactions_root.map_or_else(|| KECCAK_NULL_RLP.clone(), Into::into),
|
||||
receipts_root: g.receipts_root.map_or_else(|| KECCAK_NULL_RLP.clone(), Into::into),
|
||||
state_root: g.state_root.map(Into::into),
|
||||
gas_used: g.gas_used.map_or_else(U256::zero, Into::into),
|
||||
extra_data: g.extra_data.map_or_else(Vec::new, Into::into),
|
||||
|
@ -21,6 +21,7 @@ use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
use super::genesis::Genesis;
|
||||
use super::seal::Generic as GenericSeal;
|
||||
|
||||
@ -203,9 +204,9 @@ pub struct Spec {
|
||||
pub gas_used: U256,
|
||||
/// The genesis block's timestamp field.
|
||||
pub timestamp: u64,
|
||||
/// Transactions root of the genesis block. Should be SHA3_NULL_RLP.
|
||||
/// Transactions root of the genesis block. Should be KECCAK_NULL_RLP.
|
||||
pub transactions_root: H256,
|
||||
/// Receipts root of the genesis block. Should be SHA3_NULL_RLP.
|
||||
/// Receipts root of the genesis block. Should be KECCAK_NULL_RLP.
|
||||
pub receipts_root: H256,
|
||||
/// The genesis block's extra data field.
|
||||
pub extra_data: Bytes,
|
||||
@ -287,7 +288,7 @@ impl Spec {
|
||||
|
||||
// given a pre-constructor state, run all the given constructors and produce a new state and state root.
|
||||
fn run_constructors<T: Backend>(&self, factories: &Factories, mut db: T) -> Result<T, Error> {
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
|
||||
// basic accounts in spec.
|
||||
{
|
||||
@ -301,7 +302,7 @@ impl Spec {
|
||||
for (address, account) in self.genesis_state.get().iter() {
|
||||
db.note_non_null_account(address);
|
||||
account.insert_additional(
|
||||
&mut *factories.accountdb.create(db.as_hashdb_mut(), address.sha3()),
|
||||
&mut *factories.accountdb.create(db.as_hashdb_mut(), keccak(address)),
|
||||
&factories.trie
|
||||
);
|
||||
}
|
||||
@ -333,7 +334,7 @@ impl Spec {
|
||||
trace!(target: "spec", " .. root before = {}", state.root());
|
||||
let params = ActionParams {
|
||||
code_address: address.clone(),
|
||||
code_hash: Some(constructor.sha3()),
|
||||
code_hash: Some(keccak(constructor)),
|
||||
address: address.clone(),
|
||||
sender: from.clone(),
|
||||
origin: from.clone(),
|
||||
@ -399,7 +400,7 @@ impl Spec {
|
||||
header.set_number(0);
|
||||
header.set_author(self.author.clone());
|
||||
header.set_transactions_root(self.transactions_root.clone());
|
||||
header.set_uncles_hash(RlpStream::new_list(0).out().sha3());
|
||||
header.set_uncles_hash(keccak(RlpStream::new_list(0).out()));
|
||||
header.set_extra_data(self.extra_data.clone());
|
||||
header.set_state_root(self.state_root());
|
||||
header.set_receipts_root(self.receipts_root.clone());
|
||||
@ -486,7 +487,7 @@ impl Spec {
|
||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close.
|
||||
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
|
||||
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is sha3('').
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is keccak('').
|
||||
pub fn new_null() -> Spec { load_bundled!("null") }
|
||||
|
||||
/// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1.
|
||||
@ -496,15 +497,15 @@ impl Spec {
|
||||
pub fn new_instant() -> Spec { load_bundled!("instant_seal") }
|
||||
|
||||
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not requiring work).
|
||||
/// Accounts with secrets "0".sha3() and "1".sha3() are the validators.
|
||||
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
||||
pub fn new_test_round() -> Self { load_bundled!("authority_round") }
|
||||
|
||||
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring work).
|
||||
/// Account "0".sha3() and "1".sha3() are a authorities.
|
||||
/// Account keccak("0") and keccak("1") are a authorities.
|
||||
pub fn new_test_tendermint() -> Self { load_bundled!("tendermint") }
|
||||
|
||||
/// TestList.sol used in both specs: https://github.com/paritytech/contracts/pull/30/files
|
||||
/// Accounts with secrets "0".sha3() and "1".sha3() are initially the validators.
|
||||
/// Accounts with secrets keccak("0") and keccak("1") are initially the validators.
|
||||
/// Create a new Spec with BasicAuthority which uses a contract at address 5 to determine the current validators using `getValidators`.
|
||||
/// Second validator can be removed with "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added back in using "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".
|
||||
pub fn new_validator_safe_contract() -> Self { load_bundled!("validator_safe_contract") }
|
||||
@ -515,7 +516,7 @@ impl Spec {
|
||||
pub fn new_validator_contract() -> Self { load_bundled!("validator_contract") }
|
||||
|
||||
/// Create a new Spec with BasicAuthority which uses multiple validator sets changing with height.
|
||||
/// Account with secrets "0".sha3() is the validator for block 1 and with "1".sha3() onwards.
|
||||
/// Account with secrets keccak("0") is the validator for block 1 and with keccak("1") onwards.
|
||||
pub fn new_validator_multi() -> Self { load_bundled!("validator_multi") }
|
||||
|
||||
/// Create a new spec for a PoW chain
|
||||
@ -543,7 +544,7 @@ mod tests {
|
||||
|
||||
assert_eq!(test_spec.state_root(), H256::from_str("f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9").unwrap());
|
||||
let genesis = test_spec.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
use util::*;
|
||||
use pod_account::*;
|
||||
use rlp::*;
|
||||
@ -81,10 +82,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: storage,
|
||||
code_hash: code.sha3(),
|
||||
code_hash: keccak(&code),
|
||||
code_size: Some(code.len()),
|
||||
code_cache: Arc::new(code),
|
||||
code_filth: Filth::Dirty,
|
||||
@ -101,10 +102,10 @@ impl Account {
|
||||
Account {
|
||||
balance: pod.balance,
|
||||
nonce: pod.nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: pod.storage.into_iter().collect(),
|
||||
code_hash: pod.code.as_ref().map_or(SHA3_EMPTY, |c| c.sha3()),
|
||||
code_hash: pod.code.as_ref().map_or(KECCAK_EMPTY, |c| keccak(c)),
|
||||
code_filth: Filth::Dirty,
|
||||
code_size: Some(pod.code.as_ref().map_or(0, |c| c.len())),
|
||||
code_cache: Arc::new(pod.code.map_or_else(|| { warn!("POD account with unknown code is being created! Assuming no code."); vec![] }, |c| c)),
|
||||
@ -117,10 +118,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: HashMap::new(),
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
code_cache: Arc::new(vec![]),
|
||||
code_size: Some(0),
|
||||
code_filth: Filth::Clean,
|
||||
@ -140,10 +141,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: HashMap::new(),
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
code_cache: Arc::new(vec![]),
|
||||
code_size: None,
|
||||
code_filth: Filth::Clean,
|
||||
@ -154,7 +155,7 @@ impl Account {
|
||||
/// Set this account's code to the given code.
|
||||
/// NOTE: Account should have been created with `new_contract()`
|
||||
pub fn init_code(&mut self, code: Bytes) {
|
||||
self.code_hash = code.sha3();
|
||||
self.code_hash = keccak(&code);
|
||||
self.code_cache = Arc::new(code);
|
||||
self.code_size = Some(self.code_cache.len());
|
||||
self.code_filth = Filth::Dirty;
|
||||
@ -211,7 +212,7 @@ impl Account {
|
||||
pub fn address_hash(&self, address: &Address) -> H256 {
|
||||
let hash = self.address_hash.get();
|
||||
hash.unwrap_or_else(|| {
|
||||
let hash = address.sha3();
|
||||
let hash = keccak(address);
|
||||
self.address_hash.set(Some(hash.clone()));
|
||||
hash
|
||||
})
|
||||
@ -220,7 +221,7 @@ impl Account {
|
||||
/// returns the account's code. If `None` then the code cache isn't available -
|
||||
/// get someone who knows to call `note_code`.
|
||||
pub fn code(&self) -> Option<Arc<Bytes>> {
|
||||
if self.code_hash != SHA3_EMPTY && self.code_cache.is_empty() {
|
||||
if self.code_hash != KECCAK_EMPTY && self.code_cache.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(self.code_cache.clone())
|
||||
@ -235,7 +236,7 @@ impl Account {
|
||||
#[cfg(test)]
|
||||
/// Provide a byte array which hashes to the `code_hash`. returns the hash as a result.
|
||||
pub fn note_code(&mut self, code: Bytes) -> Result<(), H256> {
|
||||
let h = code.sha3();
|
||||
let h = keccak(&code);
|
||||
if self.code_hash == h {
|
||||
self.code_cache = Arc::new(code);
|
||||
self.code_size = Some(self.code_cache.len());
|
||||
@ -247,7 +248,7 @@ impl Account {
|
||||
|
||||
/// Is `code_cache` valid; such that code is going to return Some?
|
||||
pub fn is_cached(&self) -> bool {
|
||||
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == SHA3_EMPTY)
|
||||
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == KECCAK_EMPTY)
|
||||
}
|
||||
|
||||
/// Provide a database to get `code_hash`. Should not be called if it is a contract without code.
|
||||
@ -284,7 +285,7 @@ impl Account {
|
||||
// TODO: fill out self.code_cache;
|
||||
trace!("Account::cache_code_size: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
|
||||
self.code_size.is_some() ||
|
||||
if self.code_hash != SHA3_EMPTY {
|
||||
if self.code_hash != KECCAK_EMPTY {
|
||||
match db.get(&self.code_hash) {
|
||||
Some(x) => {
|
||||
self.code_size = Some(x.len());
|
||||
@ -308,19 +309,19 @@ impl Account {
|
||||
/// NOTE: Will panic if `!self.storage_is_clean()`
|
||||
pub fn is_empty(&self) -> bool {
|
||||
assert!(self.storage_is_clean(), "Account::is_empty() may only legally be called when storage is clean.");
|
||||
self.is_null() && self.storage_root == SHA3_NULL_RLP
|
||||
self.is_null() && self.storage_root == KECCAK_NULL_RLP
|
||||
}
|
||||
|
||||
/// Check if account has zero nonce, balance, no code.
|
||||
pub fn is_null(&self) -> bool {
|
||||
self.balance.is_zero() &&
|
||||
self.nonce.is_zero() &&
|
||||
self.code_hash == SHA3_EMPTY
|
||||
self.code_hash == KECCAK_EMPTY
|
||||
}
|
||||
|
||||
/// Check if account is basic (Has no code).
|
||||
pub fn is_basic(&self) -> bool {
|
||||
self.code_hash == SHA3_EMPTY
|
||||
self.code_hash == KECCAK_EMPTY
|
||||
}
|
||||
|
||||
/// Return the storage root associated with this account or None if it has been altered via the overlay.
|
||||
@ -592,8 +593,8 @@ mod tests {
|
||||
assert_eq!(a.rlp().to_hex(), "f8448045a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
assert_eq!(a.balance(), &U256::from(69u8));
|
||||
assert_eq!(a.nonce(), &U256::from(0u8));
|
||||
assert_eq!(a.code_hash(), SHA3_EMPTY);
|
||||
assert_eq!(a.storage_root().unwrap(), &SHA3_NULL_RLP);
|
||||
assert_eq!(a.code_hash(), KECCAK_EMPTY);
|
||||
assert_eq!(a.storage_root().unwrap(), &KECCAK_NULL_RLP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -24,6 +24,7 @@ use std::collections::hash_map::Entry;
|
||||
use std::collections::{HashMap, BTreeMap, HashSet};
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY};
|
||||
|
||||
use receipt::Receipt;
|
||||
use engines::Engine;
|
||||
@ -552,7 +553,7 @@ impl<B: Backend> State<B> {
|
||||
/// Get an account's code hash.
|
||||
pub fn code_hash(&self, a: &Address) -> trie::Result<H256> {
|
||||
self.ensure_cached(a, RequireCache::None, true,
|
||||
|a| a.as_ref().map_or(SHA3_EMPTY, |a| a.code_hash()))
|
||||
|a| a.as_ref().map_or(KECCAK_EMPTY, |a| a.code_hash()))
|
||||
}
|
||||
|
||||
/// Get accounts' code size.
|
||||
@ -938,7 +939,7 @@ impl<B: Backend> State<B> {
|
||||
/// Returns a merkle proof of the account's trie node omitted or an encountered trie error.
|
||||
/// If the account doesn't exist in the trie, prove that and return defaults.
|
||||
/// Requires a secure trie to be used for accurate results.
|
||||
/// `account_key` == sha3(address)
|
||||
/// `account_key` == keccak(address)
|
||||
pub fn prove_account(&self, account_key: H256) -> trie::Result<(Vec<Bytes>, BasicAccount)> {
|
||||
let mut recorder = Recorder::new();
|
||||
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
|
||||
@ -949,8 +950,8 @@ impl<B: Backend> State<B> {
|
||||
let account = maybe_account.unwrap_or_else(|| BasicAccount {
|
||||
balance: 0.into(),
|
||||
nonce: self.account_start_nonce,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
});
|
||||
|
||||
Ok((recorder.drain().into_iter().map(|r| r.data).collect(), account))
|
||||
@ -959,11 +960,11 @@ impl<B: Backend> State<B> {
|
||||
/// Prove an account's storage key's existence or nonexistence in the state.
|
||||
/// Returns a merkle proof of the account's storage trie.
|
||||
/// Requires a secure trie to be used for correctness.
|
||||
/// `account_key` == sha3(address)
|
||||
/// `storage_key` == sha3(key)
|
||||
/// `account_key` == keccak(address)
|
||||
/// `storage_key` == keccak(key)
|
||||
pub fn prove_storage(&self, account_key: H256, storage_key: H256) -> trie::Result<(Vec<Bytes>, H256)> {
|
||||
// TODO: probably could look into cache somehow but it's keyed by
|
||||
// address, not sha3(address).
|
||||
// address, not keccak(address).
|
||||
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
|
||||
let acc = match trie.get_with(&account_key, Account::from_rlp)? {
|
||||
Some(acc) => acc,
|
||||
@ -1008,13 +1009,13 @@ impl Clone for State<StateDB> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::*;
|
||||
use ethkey::Secret;
|
||||
use util::{U256, H256, Address, Hashable};
|
||||
use util::{U256, H256, Address};
|
||||
use tests::helpers::*;
|
||||
use vm::EnvInfo;
|
||||
use spec::*;
|
||||
@ -1024,7 +1025,7 @@ mod tests {
|
||||
use evm::CallType;
|
||||
|
||||
fn secret() -> Secret {
|
||||
"".sha3().into()
|
||||
keccak("").into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -24,7 +24,8 @@ use util::hash::{H256};
|
||||
use util::hashdb::HashDB;
|
||||
use state::{self, Account};
|
||||
use header::BlockNumber;
|
||||
use util::{Address, DBTransaction, UtilError, Mutex, Hashable};
|
||||
use hash::keccak;
|
||||
use util::{Address, DBTransaction, UtilError, Mutex};
|
||||
use bloom_journal::{Bloom, BloomJournal};
|
||||
use db::COL_ACCOUNT_BLOOM;
|
||||
use byteorder::{LittleEndian, ByteOrder};
|
||||
@ -443,13 +444,13 @@ impl state::Backend for StateDB {
|
||||
fn note_non_null_account(&self, address: &Address) {
|
||||
trace!(target: "account_bloom", "Note account bloom: {:?}", address);
|
||||
let mut bloom = self.account_bloom.lock();
|
||||
bloom.set(&*address.sha3());
|
||||
bloom.set(&*keccak(address));
|
||||
}
|
||||
|
||||
fn is_known_null(&self, address: &Address) -> bool {
|
||||
trace!(target: "account_bloom", "Check account bloom: {:?}", address);
|
||||
let bloom = self.account_bloom.lock();
|
||||
let is_null = !bloom.check(&*address.sha3());
|
||||
let is_null = !bloom.check(&*keccak(address));
|
||||
is_null
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use io::IoChannel;
|
||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
|
||||
use state::{self, State, CleanupMode};
|
||||
@ -254,7 +255,7 @@ fn can_mine() {
|
||||
|
||||
let b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).close();
|
||||
|
||||
assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3());
|
||||
assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().hash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -298,7 +299,7 @@ fn change_history_size() {
|
||||
|
||||
#[test]
|
||||
fn does_not_propagate_delayed_transactions() {
|
||||
let key = KeyPair::from_secret("test".sha3().into()).unwrap();
|
||||
let key = KeyPair::from_secret(keccak("test").into()).unwrap();
|
||||
let secret = key.secret();
|
||||
let tx0 = PendingTransaction::new(Transaction {
|
||||
nonce: 0.into(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Tests of EVM integration with transaction execution.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use vm::{EnvInfo, ActionParams, ActionValue, CallType};
|
||||
use evm::{Factory, VMType};
|
||||
use executive::Executive;
|
||||
@ -16,11 +17,11 @@ use util::*;
|
||||
evm_test!{test_blockhash_eip210: test_blockhash_eip210_jit, test_blockhash_eip210_int}
|
||||
fn test_blockhash_eip210(factory: Factory) {
|
||||
let get_prev_hash_code = Arc::new("600143034060205260206020f3".from_hex().unwrap()); // this returns previous block hash
|
||||
let get_prev_hash_code_hash = get_prev_hash_code.sha3();
|
||||
let get_prev_hash_code_hash = keccak(get_prev_hash_code.as_ref());
|
||||
// This is same as DEFAULT_BLOCKHASH_CONTRACT except for metropolis transition block check removed.
|
||||
let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b";
|
||||
let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap());
|
||||
let blockhash_contract_code_hash = blockhash_contract_code.sha3();
|
||||
let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref());
|
||||
let engine = TestEngine::new_metropolis();
|
||||
let mut env_info = EnvInfo::default();
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethkey::KeyPair;
|
||||
use io::*;
|
||||
use client::{BlockChainClient, Client, ClientConfig};
|
||||
@ -178,7 +179,7 @@ pub fn generate_dummy_client_with_spec_accounts_and_data<F>(get_test_spec: F, ac
|
||||
let mut last_hashes = vec![];
|
||||
let mut last_header = genesis_header.clone();
|
||||
|
||||
let kp = KeyPair::from_secret_slice(&"".sha3()).unwrap();
|
||||
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
||||
let author = kp.address();
|
||||
|
||||
let mut n = 0;
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Client tests of tracing
|
||||
|
||||
use ethkey::KeyPair;
|
||||
use hash::keccak;
|
||||
use block::*;
|
||||
use util::*;
|
||||
use io::*;
|
||||
@ -62,14 +63,14 @@ fn can_trace_block_and_uncle_reward() {
|
||||
// |
|
||||
// block with transaction and uncle
|
||||
|
||||
let genesis_header = spec.genesis_header();
|
||||
let genesis_header = spec.genesis_header();
|
||||
let mut db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap();
|
||||
let mut rolling_timestamp = 40;
|
||||
let mut last_hashes = vec![];
|
||||
let mut last_header = genesis_header.clone();
|
||||
last_hashes.push(last_header.hash());
|
||||
|
||||
let kp = KeyPair::from_secret_slice(&"".sha3()).unwrap();
|
||||
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
||||
let author = kp.address();
|
||||
|
||||
// Add root block first
|
||||
@ -89,7 +90,7 @@ fn can_trace_block_and_uncle_reward() {
|
||||
rolling_timestamp += 10;
|
||||
root_block.set_timestamp(rolling_timestamp);
|
||||
|
||||
let root_block = root_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||
let root_block = root_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||
|
||||
if let Err(e) = client.import_block(root_block.rlp_bytes()) {
|
||||
panic!("error importing block which is valid by definition: {:?}", e);
|
||||
@ -118,7 +119,7 @@ fn can_trace_block_and_uncle_reward() {
|
||||
rolling_timestamp += 10;
|
||||
parent_block.set_timestamp(rolling_timestamp);
|
||||
|
||||
let parent_block = parent_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||
let parent_block = parent_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||
|
||||
if let Err(e) = client.import_block(parent_block.rlp_bytes()) {
|
||||
panic!("error importing block which is valid by definition: {:?}", e);
|
||||
@ -131,14 +132,14 @@ fn can_trace_block_and_uncle_reward() {
|
||||
|
||||
// Add testing block with transaction and uncle
|
||||
let mut block = OpenBlock::new(
|
||||
engine,
|
||||
Default::default(),
|
||||
true,
|
||||
db,
|
||||
&last_header,
|
||||
engine,
|
||||
Default::default(),
|
||||
true,
|
||||
db,
|
||||
&last_header,
|
||||
Arc::new(last_hashes.clone()),
|
||||
author.clone(),
|
||||
(3141562.into(), 31415620.into()),
|
||||
(3141562.into(), 31415620.into()),
|
||||
vec![],
|
||||
false
|
||||
).unwrap();
|
||||
@ -172,7 +173,7 @@ fn can_trace_block_and_uncle_reward() {
|
||||
|
||||
let res = client.import_block(block.rlp_bytes());
|
||||
if res.is_err() {
|
||||
panic!("error importing block: {:#?}", res.err().unwrap());
|
||||
panic!("error importing block: {:#?}", res.err().unwrap());
|
||||
}
|
||||
|
||||
block.drain();
|
||||
@ -202,5 +203,5 @@ fn can_trace_block_and_uncle_reward() {
|
||||
|
||||
// Test1. Check block filter
|
||||
let traces = client.block_traces(BlockId::Number(3));
|
||||
assert_eq!(traces.unwrap().len(), 3);
|
||||
assert_eq!(traces.unwrap().len(), 3);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
use std::ops::Range;
|
||||
use bloomchain::{Filter as BloomFilter, Bloom, Number};
|
||||
use hash::keccak;
|
||||
use util::Address;
|
||||
use util::sha3::Hashable;
|
||||
use bloomable::Bloomable;
|
||||
use basic_types::LogBloom;
|
||||
use trace::flat::FlatTrace;
|
||||
@ -55,7 +55,7 @@ impl AddressesFilter {
|
||||
match self.list.is_empty() {
|
||||
true => vec![LogBloom::default()],
|
||||
false => self.list.iter()
|
||||
.map(|address| LogBloom::from_bloomed(&address.sha3()))
|
||||
.map(|address| LogBloom::from_bloomed(&keccak(address)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ impl AddressesFilter {
|
||||
false => blooms
|
||||
.into_iter()
|
||||
.flat_map(|bloom| self.list.iter()
|
||||
.map(|address| bloom.with_bloomed(&address.sha3()))
|
||||
.map(|address| bloom.with_bloomed(&keccak(address)))
|
||||
.collect::<Vec<_>>())
|
||||
.collect(),
|
||||
}
|
||||
@ -139,7 +139,7 @@ impl Filter {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use util::Address;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use bloomable::Bloomable;
|
||||
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
|
||||
use trace::flat::FlatTrace;
|
||||
@ -169,9 +169,9 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -185,8 +185,8 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -200,8 +200,8 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -215,25 +215,25 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 4);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(4))));
|
||||
|
||||
assert!(blooms[1].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[1].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(!blooms[1].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[1].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[1].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[1].contains_bloomed(&keccak(Address::from(4))));
|
||||
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(3))));
|
||||
|
||||
assert!(blooms[2].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[2].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(!blooms[2].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[2].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(blooms[2].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(blooms[2].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(4))));
|
||||
|
||||
assert!(blooms[3].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[3].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(!blooms[3].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[3].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[3].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(blooms[3].contains_bloomed(&keccak(Address::from(4))));
|
||||
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -17,7 +17,7 @@
|
||||
//! Tracing datatypes.
|
||||
|
||||
use util::{U256, Bytes, Address};
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use bloomable::Bloomable;
|
||||
use rlp::*;
|
||||
|
||||
@ -51,7 +51,7 @@ pub struct CreateResult {
|
||||
impl CreateResult {
|
||||
/// Returns bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.address.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.address))
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@ impl Call {
|
||||
/// Returns call action bloom.
|
||||
/// The bloom contains from and to addresses.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.from.sha3())
|
||||
.with_bloomed(&self.to.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.from))
|
||||
.with_bloomed(&keccak(&self.to))
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ impl Create {
|
||||
/// Returns bloom create action bloom.
|
||||
/// The bloom contains only from address.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.from.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.from))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ pub struct Reward {
|
||||
impl Reward {
|
||||
/// Return reward action bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.author.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.author))
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ pub struct Suicide {
|
||||
impl Suicide {
|
||||
/// Return suicide action bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.address.sha3())
|
||||
.with_bloomed(&self.refund_address.sha3())
|
||||
LogBloom::from_bloomed(&keccak(self.address))
|
||||
.with_bloomed(&keccak(self.refund_address))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use std::ops::Deref;
|
||||
use rlp::*;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, Address, U256, Bytes};
|
||||
use ethkey::{Signature, Secret, Public, recover, public_to_address, Error as EthkeyError};
|
||||
@ -167,7 +167,7 @@ impl Transaction {
|
||||
pub fn hash(&self, chain_id: Option<u64>) -> H256 {
|
||||
let mut stream = RlpStream::new();
|
||||
self.rlp_append_unsigned_transaction(&mut stream, chain_id);
|
||||
stream.as_raw().sha3()
|
||||
keccak(stream.as_raw())
|
||||
}
|
||||
|
||||
/// Signs the transaction as coming from `sender`.
|
||||
@ -274,7 +274,7 @@ impl Decodable for UnverifiedTransaction {
|
||||
if d.item_count()? != 9 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
let hash = d.as_raw().sha3();
|
||||
let hash = keccak(d.as_raw());
|
||||
Ok(UnverifiedTransaction {
|
||||
unsigned: Transaction {
|
||||
nonce: d.val_at(0)?,
|
||||
@ -299,7 +299,7 @@ impl Encodable for UnverifiedTransaction {
|
||||
impl UnverifiedTransaction {
|
||||
/// Used to compute hash of created transactions
|
||||
fn compute_hash(mut self) -> UnverifiedTransaction {
|
||||
let hash = (&*self.rlp_bytes()).sha3();
|
||||
let hash = keccak(&*self.rlp_bytes());
|
||||
self.hash = hash;
|
||||
self
|
||||
}
|
||||
@ -357,7 +357,7 @@ impl UnverifiedTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the hash of this header (sha3 of the RLP).
|
||||
/// Get the hash of this header (keccak of the RLP).
|
||||
pub fn hash(&self) -> H256 {
|
||||
self.hash
|
||||
}
|
||||
@ -545,7 +545,8 @@ impl From<SignedTransaction> for PendingTransaction {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use util::{Hashable, U256};
|
||||
use util::{U256};
|
||||
use hash::keccak;
|
||||
|
||||
#[test]
|
||||
fn sender_test() {
|
||||
@ -575,7 +576,7 @@ mod tests {
|
||||
value: U256::from(1),
|
||||
data: b"Hello!".to_vec()
|
||||
}.sign(&key.secret(), None);
|
||||
assert_eq!(Address::from(key.public().sha3()), t.sender());
|
||||
assert_eq!(Address::from(keccak(key.public())), t.sender());
|
||||
assert_eq!(t.chain_id(), None);
|
||||
}
|
||||
|
||||
@ -609,7 +610,7 @@ mod tests {
|
||||
value: U256::from(1),
|
||||
data: b"Hello!".to_vec()
|
||||
}.sign(&key.secret(), Some(69));
|
||||
assert_eq!(Address::from(key.public().sha3()), t.sender());
|
||||
assert_eq!(Address::from(keccak(key.public())), t.sender());
|
||||
assert_eq!(t.chain_id(), Some(69));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
//! 3. Final verification against the blockchain done before enactment.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::*;
|
||||
use engines::Engine;
|
||||
@ -257,7 +258,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
|
||||
if expected_root != transactions_root {
|
||||
return Err(From::from(BlockError::InvalidTransactionsRoot(Mismatch { expected: expected_root.clone(), found: transactions_root.clone() })))
|
||||
}
|
||||
let expected_uncles = &block.at(2)?.as_raw().sha3();
|
||||
let expected_uncles = &keccak(block.at(2)?.as_raw());
|
||||
if expected_uncles != uncles_hash {
|
||||
return Err(From::from(BlockError::InvalidUnclesHash(Mismatch { expected: expected_uncles.clone(), found: uncles_hash.clone() })))
|
||||
}
|
||||
@ -267,6 +268,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use ethkey::{Random, Generator};
|
||||
use header::*;
|
||||
@ -325,7 +327,7 @@ mod tests {
|
||||
|
||||
pub fn insert(&mut self, bytes: Bytes) {
|
||||
let number = BlockView::new(&bytes).header_view().number();
|
||||
let hash = BlockView::new(&bytes).header_view().sha3();
|
||||
let hash = BlockView::new(&bytes).header_view().hash();
|
||||
self.blocks.insert(hash.clone(), bytes);
|
||||
self.numbers.insert(number, hash.clone());
|
||||
}
|
||||
@ -483,7 +485,7 @@ mod tests {
|
||||
let good_uncles = vec![ good_uncle1.clone(), good_uncle2.clone() ];
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append_list(&good_uncles);
|
||||
let good_uncles_hash = uncles_rlp.as_raw().sha3();
|
||||
let good_uncles_hash = keccak(uncles_rlp.as_raw());
|
||||
let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| ::rlp::encode::<UnverifiedTransaction>(t).into_vec()));
|
||||
|
||||
let mut parent = good.clone();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@ -44,7 +45,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Block header hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
self.sha3()
|
||||
self.header_view().hash()
|
||||
}
|
||||
|
||||
/// Return reference to underlaying rlp.
|
||||
@ -75,7 +76,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Return List of transactions with additional localization info.
|
||||
pub fn localized_transactions(&self) -> Vec<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transactions()
|
||||
.into_iter()
|
||||
@ -101,7 +102,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@ -112,7 +113,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Returns localized transaction at given index.
|
||||
pub fn localized_transaction_at(&self, index: usize) -> Option<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transaction_at(index).map(|t| LocalizedTransaction {
|
||||
signed: t,
|
||||
@ -140,7 +141,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(2).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
@ -154,12 +155,6 @@ impl<'a> BlockView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for BlockView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.header_view().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block body rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@ -78,7 +79,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(0).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(0).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@ -114,7 +115,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
//! View onto block header rlp
|
||||
|
||||
use util::{U256, Bytes, Hashable, H256, Address, H2048};
|
||||
use hash::keccak;
|
||||
use util::{U256, Bytes, H256, Address, H2048};
|
||||
use rlp::Rlp;
|
||||
use header::BlockNumber;
|
||||
|
||||
@ -41,7 +42,9 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
|
||||
/// Returns header hash.
|
||||
pub fn hash(&self) -> H256 { self.sha3() }
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Returns raw rlp.
|
||||
pub fn rlp(&self) -> &Rlp<'a> { &self.rlp }
|
||||
@ -95,12 +98,6 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for HeaderView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
@ -15,7 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! View onto transaction rlp
|
||||
use util::{U256, Bytes, Hashable, H256};
|
||||
use util::{U256, Bytes, H256};
|
||||
use hash::keccak;
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto transaction rlp.
|
||||
@ -43,6 +44,11 @@ impl<'a> TransactionView<'a> {
|
||||
&self.rlp
|
||||
}
|
||||
|
||||
/// Returns transaction hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Get the nonce field of the transaction.
|
||||
pub fn nonce(&self) -> U256 { self.rlp.val_at(0) }
|
||||
|
||||
@ -68,12 +74,6 @@ impl<'a> TransactionView<'a> {
|
||||
pub fn s(&self) -> U256 { self.rlp.val_at(8) }
|
||||
}
|
||||
|
||||
impl<'a> Hashable for TransactionView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
@ -10,6 +10,7 @@ rlp_derive = { path = "../../util/rlp_derive" }
|
||||
ethcore-util = { path = "../../util" }
|
||||
ethjson = { path = "../../json" }
|
||||
bloomable = { path = "../../util/bloomable" }
|
||||
hash = { path = "../../util/hash" }
|
||||
heapsize = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -16,10 +16,11 @@
|
||||
|
||||
//! Blockchain filter
|
||||
|
||||
use util::{Address, H256, Hashable, H2048};
|
||||
use util::{Address, H256, H2048};
|
||||
use bloomable::Bloomable;
|
||||
use ids::BlockId;
|
||||
use log_entry::LogEntry;
|
||||
use hash::keccak;
|
||||
|
||||
/// Blockchain Filter.
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -78,7 +79,7 @@ impl Filter {
|
||||
Some(ref addresses) if !addresses.is_empty() =>
|
||||
addresses.iter().map(|ref address| {
|
||||
let mut bloom = H2048::default();
|
||||
bloom.shift_bloomed(&address.sha3());
|
||||
bloom.shift_bloomed(&keccak(address));
|
||||
bloom
|
||||
}).collect(),
|
||||
_ => vec![H2048::default()]
|
||||
@ -89,7 +90,7 @@ impl Filter {
|
||||
Some(ref topics) => bs.into_iter().flat_map(|bloom| {
|
||||
topics.into_iter().map(|topic| {
|
||||
let mut b = bloom.clone();
|
||||
b.shift_bloomed(&topic.sha3());
|
||||
b.shift_bloomed(&keccak(topic));
|
||||
b
|
||||
}).collect::<Vec<H2048>>()
|
||||
}).collect()
|
||||
|
@ -22,6 +22,7 @@ extern crate rlp;
|
||||
#[macro_use]
|
||||
extern crate rlp_derive;
|
||||
extern crate bloomable;
|
||||
extern crate hash;
|
||||
extern crate heapsize;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -17,8 +17,9 @@
|
||||
//! Log entry type definition.
|
||||
|
||||
use std::ops::Deref;
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, Address, Bytes, Hashable};
|
||||
use util::{H256, Address, Bytes};
|
||||
use bloomable::Bloomable;
|
||||
|
||||
use {BlockNumber};
|
||||
@ -46,7 +47,7 @@ impl HeapSizeOf for LogEntry {
|
||||
impl LogEntry {
|
||||
/// Calculates the bloom of this log entry.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
self.topics.iter().fold(LogBloom::from_bloomed(&self.address.sha3()), |b, t| b.with_bloomed(&t.sha3()))
|
||||
self.topics.iter().fold(LogBloom::from_bloomed(&keccak(&self.address)), |b, t| b.with_bloomed(&keccak(t)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,4 +11,5 @@ common-types = { path = "../types" }
|
||||
evmjit = { path = "../../evmjit", optional = true }
|
||||
ethjson = { path = "../../json" }
|
||||
lazy_static = "0.2"
|
||||
rlp = { path = "../../util/rlp" }
|
||||
rlp = { path = "../../util/rlp" }
|
||||
hash = { path = "../../util/hash" }
|
||||
|
@ -17,7 +17,7 @@
|
||||
//! Evm input params.
|
||||
use util::{Address, Bytes, U256};
|
||||
use util::hash::{H256};
|
||||
use util::sha3::{Hashable, SHA3_EMPTY};
|
||||
use hash::{keccak, KECCAK_EMPTY};
|
||||
use ethjson;
|
||||
|
||||
use call_type::CallType;
|
||||
@ -87,7 +87,7 @@ impl Default for ActionParams {
|
||||
fn default() -> ActionParams {
|
||||
ActionParams {
|
||||
code_address: Address::new(),
|
||||
code_hash: Some(SHA3_EMPTY),
|
||||
code_hash: Some(KECCAK_EMPTY),
|
||||
address: Address::new(),
|
||||
sender: Address::new(),
|
||||
origin: Address::new(),
|
||||
@ -106,7 +106,7 @@ impl From<ethjson::vm::Transaction> for ActionParams {
|
||||
let address: Address = t.address.into();
|
||||
ActionParams {
|
||||
code_address: Address::new(),
|
||||
code_hash: Some((&*t.code).sha3()),
|
||||
code_hash: Some(keccak(&*t.code)),
|
||||
address: address,
|
||||
sender: t.sender.into(),
|
||||
origin: t.origin.into(),
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use util::{U256, Address, H256, Hashable};
|
||||
use hash::keccak;
|
||||
use util::{U256, Address, H256};
|
||||
use types::BlockNumber;
|
||||
use ethjson;
|
||||
|
||||
@ -68,7 +69,7 @@ impl From<ethjson::vm::Env> for EnvInfo {
|
||||
difficulty: e.difficulty.into(),
|
||||
gas_limit: e.gas_limit.into(),
|
||||
timestamp: e.timestamp.into(),
|
||||
last_hashes: Arc::new((1..cmp::min(number + 1, 257)).map(|i| format!("{}", number - i).as_bytes().sha3()).collect()),
|
||||
last_hashes: Arc::new((1..cmp::min(number + 1, 257)).map(|i| keccak(format!("{}", number - i).as_bytes())).collect()),
|
||||
gas_used: U256::default(),
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ extern crate ethcore_util as util;
|
||||
extern crate common_types as types;
|
||||
extern crate ethjson;
|
||||
extern crate rlp;
|
||||
extern crate hash;
|
||||
|
||||
mod action_params;
|
||||
mod call_type;
|
||||
@ -45,4 +46,4 @@ pub trait Vm {
|
||||
/// It returns either an error, a known amount of gas left, or parameters to be used
|
||||
/// to compute the final gas left.
|
||||
fn exec(&mut self, params: ActionParams, ext: &mut Ext) -> Result<GasLeft>;
|
||||
}
|
||||
}
|
||||
|
@ -18,3 +18,4 @@ fetch = { path = "../util/fetch" }
|
||||
ethcore-util = { path = "../util" }
|
||||
parity-reactor = { path = "../util/reactor" }
|
||||
native-contracts = { path = "../ethcore/native_contracts" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
@ -21,11 +21,12 @@ use std::io::Write;
|
||||
use std::sync::Arc;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use hash::keccak_buffer;
|
||||
use fetch::{Fetch, Response, Error as FetchError, Client as FetchClient};
|
||||
use futures::Future;
|
||||
use parity_reactor::Remote;
|
||||
use urlhint::{ContractClient, URLHintContract, URLHint, URLHintResult};
|
||||
use util::{H256, sha3};
|
||||
use util::H256;
|
||||
|
||||
/// API for fetching by hash.
|
||||
pub trait HashFetch: Send + Sync + 'static {
|
||||
@ -101,7 +102,7 @@ fn validate_hash(path: PathBuf, hash: H256, result: Result<Response, FetchError>
|
||||
|
||||
// And validate the hash
|
||||
let mut file_reader = io::BufReader::new(fs::File::open(&path)?);
|
||||
let content_hash = sha3(&mut file_reader)?;
|
||||
let content_hash = keccak_buffer(&mut file_reader)?;
|
||||
if content_hash != hash {
|
||||
Err(Error::HashMismatch{ got: content_hash, expected: hash })
|
||||
} else {
|
||||
|
@ -31,6 +31,7 @@ extern crate native_contracts;
|
||||
extern crate parity_reactor;
|
||||
extern crate rand;
|
||||
extern crate rustc_hex;
|
||||
extern crate hash;
|
||||
|
||||
pub extern crate fetch;
|
||||
|
||||
|
@ -20,10 +20,11 @@ use std::sync::Arc;
|
||||
use rustc_hex::ToHex;
|
||||
use mime::Mime;
|
||||
use mime_guess;
|
||||
use hash::keccak;
|
||||
|
||||
use futures::{future, BoxFuture, Future};
|
||||
use native_contracts::{Registry, Urlhint};
|
||||
use util::{Address, Bytes, Hashable};
|
||||
use util::{Address, Bytes};
|
||||
|
||||
const COMMIT_LEN: usize = 20;
|
||||
|
||||
@ -164,7 +165,7 @@ impl URLHint for URLHintContract {
|
||||
|
||||
let urlhint = self.urlhint.clone();
|
||||
let client = self.client.clone();
|
||||
self.registrar.get_address(do_call, "githubhint".sha3(), "A".into())
|
||||
self.registrar.get_address(do_call, keccak("githubhint"), "A".into())
|
||||
.map(|addr| if addr == Address::default() { None } else { Some(addr) })
|
||||
.and_then(move |address| {
|
||||
let mut fixed_id = [0; 32];
|
||||
|
@ -21,7 +21,8 @@ use std::time::{Instant, Duration};
|
||||
use std::thread::sleep;
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use util::{ToPretty, U256, H256, Address, Hashable};
|
||||
use hash::{keccak, KECCAK_NULL_RLP};
|
||||
use util::{ToPretty, U256, H256, Address};
|
||||
use rlp::PayloadInfo;
|
||||
use ethcore::service::ClientService;
|
||||
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockId};
|
||||
@ -639,13 +640,13 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
|
||||
out.write_fmt(format_args!("\n\"0x{}\": {{\"balance\": \"{:x}\", \"nonce\": \"{:x}\"", account.hex(), balance, client.nonce(&account, at).unwrap_or_else(U256::zero))).expect("Write error");
|
||||
let code = client.code(&account, at).unwrap_or(None).unwrap_or_else(Vec::new);
|
||||
if !code.is_empty() {
|
||||
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", code.sha3().hex())).expect("Write error");
|
||||
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", keccak(&code).hex())).expect("Write error");
|
||||
if cmd.code {
|
||||
out.write_fmt(format_args!(", \"code\": \"{}\"", code.to_hex())).expect("Write error");
|
||||
}
|
||||
}
|
||||
let storage_root = client.storage_root(&account, at).unwrap_or(::util::SHA3_NULL_RLP);
|
||||
if storage_root != ::util::SHA3_NULL_RLP {
|
||||
let storage_root = client.storage_root(&account, at).unwrap_or(KECCAK_NULL_RLP);
|
||||
if storage_root != KECCAK_NULL_RLP {
|
||||
out.write_fmt(format_args!(", \"storage_root\": \"0x{}\"", storage_root.hex())).expect("Write error");
|
||||
if cmd.storage {
|
||||
out.write_fmt(format_args!(", \"storage\": {{")).expect("Write error");
|
||||
|
@ -22,7 +22,8 @@ use std::collections::BTreeMap;
|
||||
use std::cmp::max;
|
||||
use std::str::FromStr;
|
||||
use cli::{Args, ArgsError};
|
||||
use util::{Hashable, H256, U256, Bytes, version_data, Address};
|
||||
use hash::keccak;
|
||||
use util::{H256, U256, Bytes, version_data, Address};
|
||||
use util::journaldb::Algorithm;
|
||||
use util::Colour;
|
||||
use ethsync::{NetworkConfiguration, is_valid_node_url};
|
||||
@ -506,7 +507,7 @@ impl Configuration {
|
||||
io_path: self.directories().db,
|
||||
listen_addr: self.stratum_interface(),
|
||||
port: self.args.flag_ports_shift + self.args.flag_stratum_port,
|
||||
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| s.sha3())),
|
||||
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| keccak(s))),
|
||||
}))
|
||||
} else { Ok(None) }
|
||||
}
|
||||
@ -729,7 +730,7 @@ impl Configuration {
|
||||
ret.listen_address = Some(format!("{}", listen));
|
||||
ret.public_address = public.map(|p| format!("{}", p));
|
||||
ret.use_secret = match self.args.flag_node_key.as_ref()
|
||||
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&s.sha3())).map_err(|e| format!("Invalid key: {:?}", e))
|
||||
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&keccak(s))).map_err(|e| format!("Invalid key: {:?}", e))
|
||||
) {
|
||||
None => None,
|
||||
Some(Ok(key)) => Some(key),
|
||||
|
@ -70,6 +70,7 @@ extern crate parity_whisper;
|
||||
extern crate path;
|
||||
extern crate rpc_cli;
|
||||
extern crate node_filter;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
@ -130,7 +131,7 @@ use std::collections::HashMap;
|
||||
use std::io::{self as stdio, BufReader, Read, Write};
|
||||
use std::fs::{remove_file, metadata, File, create_dir_all};
|
||||
use std::path::PathBuf;
|
||||
use util::sha3::sha3;
|
||||
use hash::keccak_buffer;
|
||||
use cli::Args;
|
||||
use configuration::{Cmd, Execute, Configuration};
|
||||
use deprecated::find_deprecated;
|
||||
@ -140,7 +141,7 @@ use dir::default_hypervisor_path;
|
||||
fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
|
||||
if let Some(file) = maybe_file {
|
||||
let mut f = BufReader::new(File::open(&file).map_err(|_| "Unable to open file".to_owned())?);
|
||||
let hash = sha3(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
|
||||
let hash = keccak_buffer(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
|
||||
Ok(hash.hex())
|
||||
} else {
|
||||
Err("Streaming from standard input not yet supported. Specify a file.".to_owned())
|
||||
|
@ -20,6 +20,7 @@ use std::time::Duration;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use hash::keccak;
|
||||
use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS};
|
||||
use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter};
|
||||
use ethcore::snapshot::service::Service as SnapshotService;
|
||||
@ -65,8 +66,6 @@ pub struct SnapshotCommand {
|
||||
// helper for reading chunks from arbitrary reader and feeding them into the
|
||||
// service.
|
||||
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
|
||||
use util::sha3::Hashable;
|
||||
|
||||
let manifest = reader.manifest();
|
||||
|
||||
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
|
||||
@ -95,7 +94,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
|
||||
let chunk = reader.chunk(state_hash)
|
||||
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", state_hash, e))?;
|
||||
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
if hash != state_hash {
|
||||
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", state_hash, hash));
|
||||
}
|
||||
@ -112,7 +111,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
|
||||
let chunk = reader.chunk(block_hash)
|
||||
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", block_hash, e))?;
|
||||
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
if hash != block_hash {
|
||||
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", block_hash, hash));
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ parity-updater = { path = "../updater" }
|
||||
rlp = { path = "../util/rlp" }
|
||||
stats = { path = "../util/stats" }
|
||||
vm = { path = "../ethcore/vm" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
pretty_assertions = "0.1"
|
||||
|
@ -21,7 +21,8 @@ use std::{fs, time, mem};
|
||||
use itertools::Itertools;
|
||||
use rand::Rng;
|
||||
use rand::os::OsRng;
|
||||
use util::{H256, Hashable};
|
||||
use hash::keccak;
|
||||
use util::H256;
|
||||
|
||||
/// Providing current time in seconds
|
||||
pub trait TimeProvider {
|
||||
@ -162,7 +163,7 @@ impl<T: TimeProvider> AuthCodes<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
let as_token = |code| format!("{}:{}", code, time).sha3();
|
||||
let as_token = |code| keccak(format!("{}:{}", code, time));
|
||||
|
||||
// Check if it's the initial token.
|
||||
if self.is_empty() {
|
||||
@ -231,12 +232,13 @@ mod tests {
|
||||
use std::io::{Read, Write};
|
||||
use std::{time, fs};
|
||||
use std::cell::Cell;
|
||||
use hash::keccak;
|
||||
|
||||
use util::{H256, Hashable};
|
||||
use util::H256;
|
||||
use super::*;
|
||||
|
||||
fn generate_hash(val: &str, time: u64) -> H256 {
|
||||
format!("{}:{}", val, time).sha3()
|
||||
keccak(format!("{}:{}", val, time))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -60,6 +60,7 @@ extern crate parity_reactor;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate rlp;
|
||||
extern crate stats;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -56,7 +56,7 @@ pub fn request(server: Server<ws::Server>, request: &str) -> http_client::Respon
|
||||
#[cfg(test)]
|
||||
mod testing {
|
||||
use std::time;
|
||||
use util::Hashable;
|
||||
use hash::keccak;
|
||||
use devtools::http_client;
|
||||
use super::{serve, request};
|
||||
|
||||
@ -125,7 +125,7 @@ mod testing {
|
||||
{{}}
|
||||
",
|
||||
port,
|
||||
format!("{}:{}", code, timestamp).sha3(),
|
||||
keccak(format!("{}:{}", code, timestamp)),
|
||||
timestamp,
|
||||
)
|
||||
);
|
||||
@ -155,7 +155,7 @@ mod testing {
|
||||
{{}}
|
||||
",
|
||||
port,
|
||||
format!("{}:{}", code, timestamp).sha3(),
|
||||
keccak(format!("{}:{}", code, timestamp)),
|
||||
timestamp,
|
||||
)
|
||||
);
|
||||
@ -171,7 +171,7 @@ mod testing {
|
||||
{{}}
|
||||
",
|
||||
port,
|
||||
format!("{}:{}", code, timestamp).sha3(),
|
||||
keccak(format!("{}:{}", code, timestamp)),
|
||||
timestamp,
|
||||
)
|
||||
);
|
||||
|
@ -26,8 +26,8 @@ use light::client::LightChainClient;
|
||||
use light::on_demand::{request, OnDemand};
|
||||
use light::TransactionQueue as LightTransactionQueue;
|
||||
use rlp;
|
||||
use hash::keccak;
|
||||
use util::{Address, H520, H256, U256, Bytes, Mutex, RwLock};
|
||||
use util::sha3::Hashable;
|
||||
use stats::Corpus;
|
||||
|
||||
use ethkey::Signature;
|
||||
@ -226,7 +226,7 @@ pub fn eth_data_hash(mut data: Bytes) -> H256 {
|
||||
format!("\x19Ethereum Signed Message:\n{}", data.len())
|
||||
.into_bytes();
|
||||
message_data.append(&mut data);
|
||||
message_data.sha3()
|
||||
keccak(message_data)
|
||||
}
|
||||
|
||||
/// Dispatcher for light clients -- fetches default gas price, next nonce, etc. from network.
|
||||
|
@ -24,7 +24,6 @@ use futures::{self, future, BoxFuture, Future};
|
||||
use rlp::{self, UntrustedRlp};
|
||||
use time::get_time;
|
||||
use util::{H160, H256, Address, U256, H64};
|
||||
use util::sha3::Hashable;
|
||||
use util::Mutex;
|
||||
|
||||
use ethash::SeedHashCompute;
|
||||
@ -149,7 +148,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
|
||||
let view = block.header_view();
|
||||
Ok(Some(RichBlock {
|
||||
inner: Block {
|
||||
hash: Some(view.sha3().into()),
|
||||
hash: Some(view.hash().into()),
|
||||
size: Some(block.rlp().as_raw().len().into()),
|
||||
parent_hash: view.parent_hash().into(),
|
||||
uncles_hash: view.uncles_hash().into(),
|
||||
|
@ -38,7 +38,7 @@ use ethcore::filter::Filter as EthcoreFilter;
|
||||
use ethcore::transaction::{Action, SignedTransaction, Transaction as EthTransaction};
|
||||
use ethsync::LightSync;
|
||||
use rlp::UntrustedRlp;
|
||||
use util::sha3::{SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP};
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use util::{RwLock, Mutex, U256};
|
||||
|
||||
use futures::{future, Future, BoxFuture, IntoFuture};
|
||||
@ -295,7 +295,7 @@ impl Eth for EthClient {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
if hdr.transactions_root() == SHA3_NULL_RLP {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
@ -311,7 +311,7 @@ impl Eth for EthClient {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
if hdr.transactions_root() == SHA3_NULL_RLP {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
@ -327,7 +327,7 @@ impl Eth for EthClient {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| {
|
||||
if hdr.uncles_hash() == SHA3_EMPTY_LIST_RLP {
|
||||
if hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
@ -343,7 +343,7 @@ impl Eth for EthClient {
|
||||
let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone());
|
||||
|
||||
self.fetcher().header(num.into()).and_then(move |hdr| {
|
||||
if hdr.uncles_hash() == SHA3_EMPTY_LIST_RLP {
|
||||
if hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
future::ok(Some(U256::from(0).into())).boxed()
|
||||
} else {
|
||||
sync.with_context(|ctx| on_demand.request(ctx, request::Body(hdr.into())))
|
||||
|
@ -23,7 +23,7 @@ use std::sync::Arc;
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::Fetch;
|
||||
use futures::{BoxFuture, Future};
|
||||
use util::sha3;
|
||||
use hash::keccak_buffer;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use v1::helpers::dapps::DappsService;
|
||||
@ -129,7 +129,7 @@ impl<F: Fetch> ParitySet for ParitySetClient<F> {
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(|response| {
|
||||
sha3(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
keccak_buffer(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
})
|
||||
.map(Into::into)
|
||||
}))
|
||||
|
@ -24,7 +24,7 @@ use ethcore::mode::Mode;
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::{self, Fetch};
|
||||
use futures::{BoxFuture, Future};
|
||||
use util::sha3;
|
||||
use hash::keccak_buffer;
|
||||
use updater::{Service as UpdateService};
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
@ -170,7 +170,7 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(|response| {
|
||||
sha3(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
keccak_buffer(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
})
|
||||
.map(Into::into)
|
||||
}))
|
||||
|
@ -15,11 +15,11 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Web3 rpc implementation.
|
||||
use hash::keccak;
|
||||
use jsonrpc_core::*;
|
||||
use util::version;
|
||||
use v1::traits::Web3;
|
||||
use v1::types::{H256, Bytes};
|
||||
use util::sha3::Hashable;
|
||||
|
||||
/// Web3 rpc implementation.
|
||||
pub struct Web3Client;
|
||||
@ -35,6 +35,6 @@ impl Web3 for Web3Client {
|
||||
}
|
||||
|
||||
fn sha3(&self, data: Bytes) -> Result<H256, Error> {
|
||||
Ok(data.0.sha3().into())
|
||||
Ok(keccak(&data.0).into())
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ use ethcore::miner::{MinerOptions, Banning, GasPricer, MinerService, ExternalMin
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethjson::blockchain::BlockChain;
|
||||
use io::IoChannel;
|
||||
use util::{U256, H256, Address, Hashable};
|
||||
use util::{U256, H256, Address};
|
||||
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::impls::{EthClient, SigningUnsafeClient};
|
||||
@ -431,7 +431,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) {
|
||||
for b in chain.blocks_rlp().iter().filter(|b| Block::is_good(b)).map(|b| BlockView::new(b)) {
|
||||
let count = b.transactions_count();
|
||||
|
||||
let hash = b.sha3();
|
||||
let hash = b.hash();
|
||||
let number = b.header_view().number();
|
||||
|
||||
let (req, res) = by_hash(hash, count, &mut id);
|
||||
|
@ -19,3 +19,4 @@ jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "pa
|
||||
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||
parity-rpc = { path = "../rpc" }
|
||||
ethcore-util = { path = "../util" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
@ -9,7 +9,8 @@ use std::thread;
|
||||
use std::time;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use util::{Hashable, Mutex};
|
||||
use hash::keccak;
|
||||
use util::Mutex;
|
||||
use url::Url;
|
||||
use std::fs::File;
|
||||
|
||||
@ -72,7 +73,7 @@ impl Handler for RpcHandler {
|
||||
WsError::new(WsErrorKind::Internal, format!("{}", err))
|
||||
})?;
|
||||
let secs = timestamp.as_secs();
|
||||
let hashed = format!("{}:{}", self.auth_code, secs).sha3();
|
||||
let hashed = keccak(format!("{}:{}", self.auth_code, secs));
|
||||
let proto = format!("{:?}_{}", hashed, secs);
|
||||
r.add_protocol(&proto);
|
||||
Ok(r)
|
||||
|
@ -11,6 +11,7 @@ extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate tempdir;
|
||||
extern crate url;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -29,6 +29,7 @@ ethabi = "2.0"
|
||||
ethcore = { path = "../ethcore" }
|
||||
ethcore-devtools = { path = "../devtools" }
|
||||
ethcore-util = { path = "../util" }
|
||||
hash = { path = "../util/hash" }
|
||||
ethcore-ipc = { path = "../ipc/rpc" }
|
||||
ethcore-ipc-nano = { path = "../ipc/nano" }
|
||||
ethcore-logger = { path = "../logger" }
|
||||
|
@ -15,7 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethkey::{Public, Secret, Random, Generator, math};
|
||||
use util::{U256, H256, Hashable};
|
||||
use util::{U256, H256};
|
||||
use hash::keccak;
|
||||
use key_server_cluster::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -306,7 +307,7 @@ pub fn combine_message_hash_with_public(message_hash: &H256, public: &Public) ->
|
||||
buffer[32..64].copy_from_slice(&public[0..32]);
|
||||
|
||||
// calculate hash of buffer
|
||||
let hash = (&buffer[..]).sha3();
|
||||
let hash = keccak(&buffer[..]);
|
||||
|
||||
// map hash to EC finite field value
|
||||
let hash: U256 = hash.into();
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user