diff --git a/acvm/Cargo.toml b/acvm/Cargo.toml index c8f6132fc..f2cc02db2 100644 --- a/acvm/Cargo.toml +++ b/acvm/Cargo.toml @@ -18,6 +18,7 @@ stdlib.workspace = true blake2 = "0.9.1" sha2 = "0.9.3" +sha3 = "0.9.1" crc32fast = "1.3.2" k256 = { version = "0.7.2", features = [ "ecdsa", diff --git a/acvm/src/pwg/hash.rs b/acvm/src/pwg/hash.rs index d636da8e7..8a6f0cd4b 100644 --- a/acvm/src/pwg/hash.rs +++ b/acvm/src/pwg/hash.rs @@ -1,6 +1,7 @@ use acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness, FieldElement}; use blake2::{Blake2s, Digest}; use sha2::Sha256; +use sha3::Keccak256; use std::collections::BTreeMap; use crate::{OpcodeResolution, OpcodeResolutionError}; @@ -41,6 +42,23 @@ pub fn sha256( Ok(OpcodeResolution::Solved) } +pub fn keccak256( + initial_witness: &mut BTreeMap, + func_call: &BlackBoxFuncCall, +) -> Result { + let hash = generic_hash_256::(initial_witness, func_call)?; + + for (output_witness, value) in func_call.outputs.iter().zip(hash.iter()) { + insert_value( + output_witness, + FieldElement::from_be_bytes_reduce(&[*value]), + initial_witness, + )?; + } + + Ok(OpcodeResolution::Solved) +} + pub fn hash_to_field_128_security( initial_witness: &mut BTreeMap, func_call: &BlackBoxFuncCall,