diff --git a/Nargo.toml b/Nargo.toml index 51bda83..b1b92a2 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -6,7 +6,8 @@ members = [ "circuits/withdraw", "circuits/simple", "circuits/ecdsa_secp256r1", - "circuits/ecdsa_secp256k1" + "circuits/ecdsa_secp256k1", + "circuits/keccak" ] # Shared dependencies here for reference diff --git a/circuits/keccak/Nargo.toml b/circuits/keccak/Nargo.toml new file mode 100644 index 0000000..d21e31e --- /dev/null +++ b/circuits/keccak/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "keccak" +type = "bin" +authors = [""] + +[dependencies] + +keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" } \ No newline at end of file diff --git a/circuits/keccak/src/main.nr b/circuits/keccak/src/main.nr new file mode 100644 index 0000000..e9383b2 --- /dev/null +++ b/circuits/keccak/src/main.nr @@ -0,0 +1,13 @@ +use dep::keccak256; + +fn main(preimage: [u8; 320], y: pub [u8; 32]) { + let hashed_preimage = keccak256::keccak256(preimage, preimage.len() as u32); + assert(hashed_preimage == y); +} + +#[test] +fn test_main() { + let preimage = [0u8; 320]; + let y = keccak256::keccak256(preimage, preimage.len() as u32); + main(preimage, y); +} diff --git a/scripts/generate-solidity-verifiers.ts b/scripts/generate-solidity-verifiers.ts index b1f8909..1985c02 100644 --- a/scripts/generate-solidity-verifiers.ts +++ b/scripts/generate-solidity-verifiers.ts @@ -7,6 +7,7 @@ import withdrawCircuit from "../target/withdraw.json"; import simpleTestCircuit from "../target/simple.json"; import ecdsaSecp256r1Circuit from "../target/ecdsa_secp256r1.json"; import ecdsaSecp256k1Circuit from "../target/ecdsa_secp256k1.json"; +import keccakCircuit from "../target/keccak.json"; import { CompiledCircuit } from "@noir-lang/noir_js"; async function generateSolidityVerfier( @@ -55,6 +56,7 @@ async function generateSolidityVerfier( "ecdsa_secp256k1", ecdsaSecp256k1Circuit as CompiledCircuit, ); + await generateSolidityVerfier("keccak", keccakCircuit as CompiledCircuit); process.exit(0); } catch (error) { diff --git a/scripts/mock-inputs.ts b/scripts/mock-inputs.ts index a5eca91..7b9360b 100644 --- a/scripts/mock-inputs.ts +++ b/scripts/mock-inputs.ts @@ -223,3 +223,15 @@ export const SIMPLE_MOCK_INPUTS = { x: 3, y: 3, }; + +export const KECCAK_MOCK_INPUTS = { + witness: { + preimage: Array(320).fill(0), + }, + public_inputs: { + y: [ + 45, 119, 210, 8, 219, 140, 96, 27, 149, 60, 26, 16, 123, 99, 50, 38, 131, + 85, 118, 150, 127, 228, 222, 193, 35, 117, 176, 122, 108, 106, 56, 207, + ], + }, +}; diff --git a/ts/test-prover-app/src/App.tsx b/ts/test-prover-app/src/App.tsx index 26fe84a..7bfae86 100644 --- a/ts/test-prover-app/src/App.tsx +++ b/ts/test-prover-app/src/App.tsx @@ -8,6 +8,7 @@ import { ECDSA_SECP256R1_TEST_MOCK_INPUTS, SIMPLE_MOCK_INPUTS, ECDSA_SECP256K1_TEST_MOCK_INPUTS, + KECCAK_MOCK_INPUTS, } from "./mockInputs"; import newAccountCircuit from "../../../target/new_account.json"; @@ -16,6 +17,7 @@ import withdrawCircuit from "../../../target/withdraw.json"; import simpleCircuit from "../../../target/simple.json"; import ecdsaSecp256r1Circuit from "../../../target/ecdsa_secp256r1.json"; import ecdsaSecp256k1Circuit from "../../../target/ecdsa_secp256k1.json"; +import keccakCircuit from "../../../target/keccak.json"; interface Circuit { name: string; circuit: CompiledCircuit; @@ -53,6 +55,11 @@ const circuits: Circuit[] = [ circuit: ecdsaSecp256k1Circuit as unknown as CompiledCircuit, inputs: ECDSA_SECP256K1_TEST_MOCK_INPUTS, }, + { + name: "Keccak(320 bytes)", + circuit: keccakCircuit as unknown as CompiledCircuit, + inputs: KECCAK_MOCK_INPUTS, + }, ]; function App() { diff --git a/ts/test-prover-app/src/mockInputs.ts b/ts/test-prover-app/src/mockInputs.ts index abda1fb..8c7709f 100644 --- a/ts/test-prover-app/src/mockInputs.ts +++ b/ts/test-prover-app/src/mockInputs.ts @@ -224,3 +224,11 @@ function noteHash(note: Note): bigint { ]; return poseidon2Hash(input); } + +export const KECCAK_MOCK_INPUTS = { + preimage: Array(320).fill(0), + y: [ + 45, 119, 210, 8, 219, 140, 96, 27, 149, 60, 26, 16, 123, 99, 50, 38, 131, + 85, 118, 150, 127, 228, 222, 193, 35, 117, 176, 122, 108, 106, 56, 207, + ], +};