diff --git a/core/src/crypto/hash.rs b/core/src/crypto/hash.rs index d907a648..7ff9e460 100644 --- a/core/src/crypto/hash.rs +++ b/core/src/crypto/hash.rs @@ -4,7 +4,7 @@ use plonky2::field::goldilocks_field::GoldilocksField; pub trait Hasher { /// Gets the hash of the byte sequence. - fn hash_bytes>(&self, value: I) -> Hash; + fn hash_bytes(&self, value: &Vec) -> Hash; /// Get the hash of the hashes sequence. fn hash_elements>(&self, elements: I) -> Hash; /// Merges two hashes into one. diff --git a/core/src/crypto/poseidon.rs b/core/src/crypto/poseidon.rs index fe6a29ab..178ffa9f 100644 --- a/core/src/crypto/poseidon.rs +++ b/core/src/crypto/poseidon.rs @@ -15,9 +15,8 @@ use plonky2::hash::poseidon::PoseidonPermutation; pub struct PoseidonHasher; impl Hasher for PoseidonHasher { - fn hash_bytes>(&self, value: I) -> TreeValue { - let value_iter: Vec<_> = value.into_iter().collect(); - hash_n_to_hash_no_pad::(&value_iter).elements + fn hash_bytes(&self, value: &Vec) -> TreeValue { + hash_n_to_hash_no_pad::(&value).elements } /// Get the hash of the hashes sequence. diff --git a/core/src/state/mod.rs b/core/src/state/mod.rs index 325fd86c..e423be56 100644 --- a/core/src/state/mod.rs +++ b/core/src/state/mod.rs @@ -40,7 +40,7 @@ where ) -> Result, StateError> { let mut code_hashes = Vec::new(); for code in contracts { - code_hashes.push(self.hasher.hash_bytes(code.clone())); + code_hashes.push(self.hasher.hash_bytes(&code)); } self.state_storage .save_contracts(&code_hashes, &contracts)?; @@ -51,7 +51,7 @@ where &mut self, contract: &Vec, ) -> Result { - let code_hash = self.hasher.hash_bytes(contract.clone()); + let code_hash = self.hasher.hash_bytes(&contract); self.state_storage.save_contract(&code_hash, &contract)?; return Ok(code_hash); } diff --git a/core/src/trace/trace.rs b/core/src/trace/trace.rs index 9e635de0..a04aa701 100644 --- a/core/src/trace/trace.rs +++ b/core/src/trace/trace.rs @@ -320,7 +320,7 @@ pub struct Trace { // pub raw_instructions: HashMap, pub raw_instructions: HashMap, pub raw_binary_instructions: Vec, - pub addr_program_hash: HashMap, + pub addr_program_hash: HashMap>, pub start_end_roots: (TreeValue, TreeValue), // todo need limit the trace size pub exec: Vec, diff --git a/executor/src/tests.rs b/executor/src/tests.rs index b0b27d27..90b3577e 100644 --- a/executor/src/tests.rs +++ b/executor/src/tests.rs @@ -43,7 +43,7 @@ fn executor_run_test_program( .clone() .map(|e| GoldilocksField::from_canonical_u64(u64::from_str_radix(&e[2..], 16).unwrap())) .collect(); - let code_hash = hash.hash_bytes(code); + let code_hash = hash.hash_bytes(&code); let mut prophets = HashMap::new(); for item in program.prophets { prophets.insert(item.host as u64, item); @@ -99,7 +99,7 @@ fn executor_run_test_program( program .trace .addr_program_hash - .insert(encode_addr(&callee_exe_addr), code_hash); + .insert(encode_addr(&callee_exe_addr), code); let mut account_tree = AccountTree::new_test(); //let mut account_tree =AccountTree::new_db_test("./".to_string()), diff --git a/zk-vm/src/lib.rs b/zk-vm/src/lib.rs index 7714ac53..968899ef 100644 --- a/zk-vm/src/lib.rs +++ b/zk-vm/src/lib.rs @@ -144,7 +144,7 @@ impl OlaVM { if get_code { let contract = self.get_contract(&code_hash)?; - for inst in contract { + for inst in &contract { program .instructions .push(format!("0x{:x}", inst.to_canonical_u64())); @@ -162,7 +162,7 @@ impl OlaVM { program .trace .addr_program_hash - .insert(encode_addr(&exe_code_addr), code_hash); + .insert(encode_addr(&exe_code_addr), contract); } let prophet = self.get_prophet(&code_hash).unwrap();