From f71a57f2b300f61f3c58a1992a1709a5270b4a45 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 5 May 2023 14:32:15 -0700 Subject: [PATCH] Remove keccak code added before acvm v0.11.0 --- Cargo.lock | 1 - Cargo.toml | 1 - src/acvm_interop/pwg.rs | 58 +---------------------------------------- 3 files changed, 1 insertion(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd5ea760..a9e4ac65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,6 @@ dependencies = [ "pkg-config", "reqwest", "rust-embed", - "sha3", "sled", "tempfile", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 9c54f787..1290ce6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ acvm = { version = "0.11.0", features = ["bn254"] } thiserror = "1.0.21" blake2 = "0.9.1" -sha3 = "0.9.1" dirs = { version = "3.0", optional = true } reqwest = { version = "0.11.16", optional = true, default-features = false, features = [ "stream", diff --git a/src/acvm_interop/pwg.rs b/src/acvm_interop/pwg.rs index 6ad44134..623954d6 100644 --- a/src/acvm_interop/pwg.rs +++ b/src/acvm_interop/pwg.rs @@ -24,7 +24,7 @@ impl PartialWitnessGenerator for Barretenberg { match func_call.name { BlackBoxFunc::SHA256 => hash::sha256(initial_witness, func_call), BlackBoxFunc::Blake2s => hash::blake2s(initial_witness, func_call), - BlackBoxFunc::Keccak256 => keccak256(initial_witness, func_call), + BlackBoxFunc::Keccak256 => hash::keccak256(initial_witness, func_call), BlackBoxFunc::EcdsaSecp256k1 => { signature::ecdsa::secp256k1_prehashed(initial_witness, func_call) } @@ -193,59 +193,3 @@ impl PartialWitnessGenerator for Barretenberg { } } } - -// All of the code below can be removed once we update to acvm 0.11 or greater. -use sha3::Keccak256; -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) -} -fn insert_value( - witness: &Witness, - value_to_insert: FieldElement, - initial_witness: &mut BTreeMap, -) -> Result<(), OpcodeResolutionError> { - let optional_old_value = initial_witness.insert(*witness, value_to_insert); - - let old_value = match optional_old_value { - Some(old_value) => old_value, - None => return Ok(()), - }; - - if old_value != value_to_insert { - return Err(OpcodeResolutionError::UnsatisfiedConstrain); - } - - Ok(()) -} -fn generic_hash_256( - initial_witness: &mut BTreeMap, - func_call: &BlackBoxFuncCall, -) -> Result<[u8; 32], OpcodeResolutionError> { - let mut hasher = D::new(); - - // Read witness assignments into hasher. - for input in func_call.inputs.iter() { - let witness = input.witness; - let num_bits = input.num_bits as usize; - - let witness_assignment = witness_to_value(initial_witness, witness)?; - let bytes = witness_assignment.fetch_nearest_bytes(num_bits); - hasher.update(bytes); - } - - let result = hasher.finalize().as_slice().try_into().unwrap(); - Ok(result) -}