Skip to content

Commit

Permalink
Add comments & improve expression performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nyunyunyunyu committed Aug 27, 2023
1 parent 50d4457 commit e40cfc6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions hashes/zkevm/src/keccak/keccak_packed_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ pub struct KeccakTable {
pub input_rlc: Column<Advice>, // RLC of input bytes
// Byte array input length
pub input_len: Column<Advice>,
// /// RLC of the hash result
// pub output_rlc: Column<Advice>, // RLC of hash of input bytes
/// Output of the hash function
pub output: Word<Column<Advice>>,
}

Expand Down
2 changes: 1 addition & 1 deletion hashes/zkevm/src/keccak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ pub fn keccak_phase0<F: Field>(
));
}

// The rlc of the hash
// Assign the hash result
let is_final = is_final_block && round == NUM_ROUNDS;
hash = if is_final {
let hash_bytes_le = s
Expand Down
10 changes: 7 additions & 3 deletions hashes/zkevm/src/util/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ pub mod from_bytes {
pub fn value<F: PrimeField>(bytes: &[u8]) -> F {
let mut value = F::ZERO;
let mut multiplier = F::ONE;
for byte in bytes.iter() {
value += F::from(*byte as u64) * multiplier;
multiplier *= F::from(256);
let two_pow_64 = F::from_u128(1 << 64);
let two_pow_128 = two_pow_64 * two_pow_64;
for u128_chunk in bytes.chunks(u128::BITS as usize / u8::BITS as usize) {
let mut buffer = [0; 16];
buffer[..u128_chunk.len()].copy_from_slice(u128_chunk);
value += F::from_u128(u128::from_le_bytes(buffer)) * multiplier;
multiplier *= two_pow_128;
}
value
}
Expand Down

0 comments on commit e40cfc6

Please sign in to comment.