Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Remove keccak code added before acvm v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 5, 2023
1 parent 014e598 commit f71a57f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 59 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
58 changes: 1 addition & 57 deletions src/acvm_interop/pwg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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<Witness, FieldElement>,
func_call: &BlackBoxFuncCall,
) -> Result<OpcodeResolution, OpcodeResolutionError> {
let hash = generic_hash_256::<Keccak256>(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<Witness, FieldElement>,
) -> 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<D: Digest>(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
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)
}

0 comments on commit f71a57f

Please sign in to comment.