Skip to content

Commit

Permalink
MOD: program trace
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyuanyang-uu committed Nov 27, 2023
1 parent 8da1a1e commit 1906d93
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use plonky2::field::goldilocks_field::GoldilocksField;

pub trait Hasher<Hash> {
/// Gets the hash of the byte sequence.
fn hash_bytes<I: IntoIterator<Item = GoldilocksField>>(&self, value: I) -> Hash;
fn hash_bytes(&self, value: &Vec<GoldilocksField>) -> Hash;
/// Get the hash of the hashes sequence.
fn hash_elements<I: IntoIterator<Item = Hash>>(&self, elements: I) -> Hash;
/// Merges two hashes into one.
Expand Down
5 changes: 2 additions & 3 deletions core/src/crypto/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use plonky2::hash::poseidon::PoseidonPermutation;
pub struct PoseidonHasher;

impl Hasher<TreeValue> for PoseidonHasher {
fn hash_bytes<I: IntoIterator<Item = GoldilocksField>>(&self, value: I) -> TreeValue {
let value_iter: Vec<_> = value.into_iter().collect();
hash_n_to_hash_no_pad::<GoldilocksField, PoseidonPermutation>(&value_iter).elements
fn hash_bytes(&self, value: &Vec<GoldilocksField>) -> TreeValue {
hash_n_to_hash_no_pad::<GoldilocksField, PoseidonPermutation>(&value).elements
}

/// Get the hash of the hashes sequence.
Expand Down
4 changes: 2 additions & 2 deletions core/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
) -> Result<Vec<TreeValue>, 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)?;
Expand All @@ -51,7 +51,7 @@ where
&mut self,
contract: &Vec<GoldilocksField>,
) -> Result<TreeValue, StateError> {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/trace/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub struct Trace {
// pub raw_instructions: HashMap<u64, Instruction>,
pub raw_instructions: HashMap<u64, String>,
pub raw_binary_instructions: Vec<String>,
pub addr_program_hash: HashMap<String, TreeValue>,
pub addr_program_hash: HashMap<String, Vec<GoldilocksField>>,
pub start_end_roots: (TreeValue, TreeValue),
// todo need limit the trace size
pub exec: Vec<Step>,
Expand Down
4 changes: 2 additions & 2 deletions executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()),

Expand Down
4 changes: 2 additions & 2 deletions zk-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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();
Expand Down

0 comments on commit 1906d93

Please sign in to comment.