Skip to content

Commit 53a91e0

Browse files
committed
Verify two inner proofs (exception)
1 parent ed0371f commit 53a91e0

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

how-to/recursive-proofs/circuits/recurse/src/main.nr

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ use dep::std;
22

33
fn main(
44
verification_key: [Field; 114],
5-
proof: [Field; 93],
65
public_inputs: [Field; 1],
7-
key_hash: Field
6+
key_hash: Field,
7+
proof1: [Field; 93],
8+
proof2: [Field; 93]
89
) {
910
std::verify_proof(
1011
verification_key.as_slice(),
11-
proof.as_slice(),
12+
proof1.as_slice(),
13+
public_inputs.as_slice(),
14+
key_hash
15+
);
16+
std::verify_proof(
17+
verification_key.as_slice(),
18+
proof2.as_slice(),
1219
public_inputs.as_slice(),
1320
key_hash
1421
);

how-to/recursive-proofs/main.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,39 @@ type FullNoir = {
3333
}
3434

3535
async function start() {
36-
// Generate inner proof artifacts
37-
console.log("Creating Noir from circuit...");
3836
const simple: FullNoir = await fullNoirFromCircuit('not_odd');
37+
const outer: FullNoir = await fullNoirFromCircuit('recurse');
3938

40-
console.log("Executing binary circuit for witness...");
41-
const innerInput = { n: 2 };
42-
const innerWitness = (await simple.noir.execute(innerInput)).witness;
43-
console.log("Generating intermediate proof...");
44-
const innerProof: ProofData = await simple.backend.generateProof(innerWitness);
39+
// Generate inner proof artifacts
40+
console.log("Generating intermediate proof artifacts 1...");
41+
const innerWitness1 = (await simple.noir.execute({ n: 2 })).witness;
42+
const innerProof1: ProofData = await simple.backend.generateProof(innerWitness1);
43+
const artifacts1 = await simple.backend.generateRecursiveProofArtifacts(innerProof1, 1);
4544

46-
if (false) { // mess up proof
47-
console.log("Messing intermediate proof...");
48-
innerProof.proof[0] += 1;
49-
}
45+
console.log("Generating intermediate proof artifacts 2...");
46+
const innerWitness2 = (await simple.noir.execute({ n: 4 })).witness;
47+
const innerProof2: ProofData = await simple.backend.generateProof(innerWitness2);
48+
const artifacts2 = await simple.backend.generateRecursiveProofArtifacts(innerProof2, 1);
5049

51-
console.log("Generating recursive proof artifacts...");
52-
const { proofAsFields, vkAsFields, vkHash } = await simple.backend.generateRecursiveProofArtifacts(innerProof, 1);
53-
// console.log({ proofAsFields, vkAsFields, vkHash });
5450
simple.backend.destroy();
5551

5652
// Generate and verify outer proof
57-
console.log("Creating Noir from circuit...");
58-
const outer: FullNoir = await fullNoirFromCircuit('recurse');
59-
console.log("Executing binary circuit for witness...");
53+
console.log("Generating outer proof...");
6054
const outerInput = {
61-
verification_key: vkAsFields,
62-
proof: proofAsFields,
63-
public_inputs: ["0"],
64-
key_hash: vkHash
55+
verification_key: artifacts1.vkAsFields,
56+
public_inputs: ["1"], // expect output of inner call to be "true"
57+
key_hash: artifacts1.vkHash,
58+
proof1: artifacts1.proofAsFields,
59+
proof2: artifacts2.proofAsFields
6560
};
6661
const outerWitness = (await outer.noir.execute(
6762
outerInput
6863
)).witness;
69-
70-
console.log("Generating outer proof...");
7164
const outerProof: ProofData = await outer.backend.generateProof(outerWitness);
7265

7366
console.log("Verifying outer proof...");
74-
console.log(await outer.backend.verifyProof(outerProof));
75-
76-
// console.log("Executing lib circuit function to verify inner proof");
77-
// let res = await main(vkAsFields, proofAsFields, ["7"], vkHash);
78-
// console.log(res);
67+
const res: boolean = await outer.backend.verifyProof(outerProof);
68+
console.log("Verification", res ? "PASSED" : "failed");
7969

8070
outer.backend.destroy();
8171
}

0 commit comments

Comments
 (0)