Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
feat: Add Keccak Hash function (#259)
Browse files Browse the repository at this point in the history
* Add keccak hash function

* rename keccak to keccak256
  • Loading branch information
kevaundray authored May 4, 2023
1 parent 45c45f7 commit 443c734
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions acvm/src/pwg/hash.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -41,6 +42,23 @@ pub fn sha256(
Ok(OpcodeResolution::Solved)
}

pub 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)
}

pub fn hash_to_field_128_security(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
func_call: &BlackBoxFuncCall,
Expand Down

0 comments on commit 443c734

Please sign in to comment.