Skip to content

Commit

Permalink
Fix the bugged MEMORY_HASHES in the zerohashes.rs
Browse files Browse the repository at this point in the history
More specfically, the code that was generating them had a stupid bug.
  • Loading branch information
eljobe committed May 3, 2024
1 parent 5926a83 commit 9ebd8ba
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 133 deletions.
14 changes: 14 additions & 0 deletions arbitrator/prover/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,22 @@ impl Memory {

#[cfg(test)]
mod test {
use arbutil::Bytes32;

use crate::memory::round_up_to_power_of_two;

use super::Memory;

#[test]
pub fn fixed_memory_hash() {
let module_memory_hash = Bytes32::from([
86u8, 177, 192, 60, 217, 123, 221, 153, 118, 79, 229, 122, 210, 48, 187, 104, 40, 84,
112, 63, 137, 86, 54, 2, 56, 118, 72, 158, 242, 225, 65, 80,
]);
let memory = Memory::new(65536, 1);
assert_eq!(memory.hash(), module_memory_hash);
}

#[test]
pub fn empty_leaf_hash() {
let leaf = [0u8; 32];
Expand Down
14 changes: 5 additions & 9 deletions arbitrator/prover/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,25 +539,21 @@ fn correct_capacity() {
#[ignore = "This is just used for generating the zero hashes for the memory merkle trees."]
fn emit_memory_zerohashes() {
// The following code was generated from the empty_leaf_hash() test in the memory package.
let mut left = Bytes32::new_direct([
let mut empty_node = Bytes32::new_direct([
57, 29, 211, 154, 252, 227, 18, 99, 65, 126, 203, 166, 252, 232, 32, 3, 98, 194, 254, 186,
118, 14, 139, 192, 101, 156, 55, 194, 101, 11, 11, 168,
]);
let mut right = Bytes32::new_direct([
57, 29, 211, 154, 252, 227, 18, 99, 65, 126, 203, 166, 252, 232, 32, 3, 98, 194, 254, 186,
118, 14, 139, 192, 101, 156, 55, 194, 101, 11, 11, 168,
]);
])
.clone();
for _ in 0..64 {
print!("Bytes32::new_direct([");
for i in 0..32 {
print!("{}", left[i]);
print!("{}", empty_node[i]);
if i < 31 {
print!(", ");
}
}
println!("]),");
left = hash_node(MerkleType::Memory, left, right);
right = hash_node(MerkleType::Memory, left, right);
empty_node = hash_node(MerkleType::Memory, empty_node, empty_node);
}
}

Expand Down
Loading

0 comments on commit 9ebd8ba

Please sign in to comment.