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

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