From 0529fa06a5bf283d97ec48c1dbec3bf23cc0020f Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Sun, 9 Apr 2023 17:35:38 -0400 Subject: [PATCH] Change endianness within generate_keccak_general --- evm/src/witness/operation.rs | 7 ++++++- evm/src/witness/util.rs | 17 ++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/evm/src/witness/operation.rs b/evm/src/witness/operation.rs index 8ed0e551..aebb7c31 100644 --- a/evm/src/witness/operation.rs +++ b/evm/src/witness/operation.rs @@ -127,7 +127,12 @@ pub(crate) fn generate_keccak_general( log::debug!("Hashing {:?}", input); let hash = keccak(&input); - let log_push = stack_push_log_and_fill(state, &mut row, hash.into_uint())?; + let val_u64s: [u64; 4] = + core::array::from_fn(|i| u64::from_le_bytes(core::array::from_fn(|j| hash.0[i * 8 + j]))); + let hash_int = U256(val_u64s); + + let mut log_push = stack_push_log_and_fill(state, &mut row, hash_int)?; + log_push.value = hash.into_uint(); keccak_sponge_log(state, base_address, input); diff --git a/evm/src/witness/util.rs b/evm/src/witness/util.rs index afd8bad1..a5ebf2ac 100644 --- a/evm/src/witness/util.rs +++ b/evm/src/witness/util.rs @@ -1,4 +1,4 @@ -use ethereum_types::{BigEndianHash, H256, U256}; +use ethereum_types::U256; use plonky2::field::types::Field; use crate::cpu::columns::CpuColumnsView; @@ -135,18 +135,9 @@ pub(crate) fn mem_write_gp_log_and_fill( channel.addr_context = F::from_canonical_usize(address.context); channel.addr_segment = F::from_canonical_usize(address.segment); channel.addr_virtual = F::from_canonical_usize(address.virt); - if row.is_keccak_sponge.is_one() { - // Retrieve hash value as it was computed and store the values in memory the same way the kernel hash is stored. - let val_h256 = H256::from_uint(&val).0; - let val_u32s: [u32; 8] = core::array::from_fn(|i| { - u32::from_le_bytes(core::array::from_fn(|j| val_h256[i * 4 + j])) - }); - channel.value = val_u32s.map(F::from_canonical_u32); - } else { - for (i, limb) in val_limbs.into_iter().enumerate() { - channel.value[2 * i] = F::from_canonical_u32(limb as u32); - channel.value[2 * i + 1] = F::from_canonical_u32((limb >> 32) as u32); - } + for (i, limb) in val_limbs.into_iter().enumerate() { + channel.value[2 * i] = F::from_canonical_u32(limb as u32); + channel.value[2 * i + 1] = F::from_canonical_u32((limb >> 32) as u32); } op