Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions circuits/keccak/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "keccak"
type = "bin"
authors = [""]

[dependencies]

keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
13 changes: 13 additions & 0 deletions circuits/keccak/src/main.nr
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions scripts/generate-solidity-verifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -55,6 +56,7 @@ async function generateSolidityVerfier(
"ecdsa_secp256k1",
ecdsaSecp256k1Circuit as CompiledCircuit,
);
await generateSolidityVerfier("keccak", keccakCircuit as CompiledCircuit);

process.exit(0);
} catch (error) {
Expand Down
12 changes: 12 additions & 0 deletions scripts/mock-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
},
};
7 changes: 7 additions & 0 deletions ts/test-prover-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions ts/test-prover-app/src/mockInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
};