Hashable::sha3 -> fn keccak for ethcore

This commit is contained in:
debris
2017-08-30 19:18:28 +02:00
parent e120c75d17
commit f0e8abb07b
69 changed files with 429 additions and 398 deletions

View File

@@ -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()

View File

@@ -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.

View File

@@ -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(),
};

View File

@@ -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());