Skip to content

Commit

Permalink
fix: fix bug in keccak precompile. (#216)
Browse files Browse the repository at this point in the history
* fix: convert to u32 in keccak precompile.

* fix: offset in keccak trace generation.
  • Loading branch information
VanhGer authored Jan 14, 2025
1 parent bb9fb74 commit 0e62a05
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion prover/src/witness/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ pub(crate) fn generate_keccak<
let addr = MemoryAddress::new(0, Segment::Code, map_addr);
let (word, mem_op) = mem_read_gp_with_log_and_fill(j, addr, state, &mut cpu_row);
let bytes = word.to_be_bytes();
let final_len = if i + 4 > len { len } else { 4 };
let final_len = if i + 4 > len { len - i } else { 4 };
keccak_value_byte_be[i..i + final_len].copy_from_slice(&bytes[0..final_len]);
keccak_data_addr.push(addr);
state.traces.push_memory(mem_op);
Expand Down
2 changes: 1 addition & 1 deletion runtime/precompiles/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn keccak(data: &[u8]) -> [u8; 32] {
// covert to u32 to align the memory
for i in (0..len).step_by(4) {
if i + 4 <= len {
let u32_value = u32::from_be_bytes([data[0], data[1], data[2], data[3]]);
let u32_value = u32::from_be_bytes([data[i], data[i + 1], data[i + 2], data[i + 3]]);
u32_array.push(u32_value);
} else {
let mut padded_chunk = [0u8; 4];
Expand Down

0 comments on commit 0e62a05

Please sign in to comment.