Skip to content

Commit c29b67c

Browse files
committed
User intermediate proof in circuit
1 parent 2b36a15 commit c29b67c

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#[recursive]
2-
fn main(n: Field) -> pub u8 {
3-
// not_odd(n);
4-
n as u8
2+
fn main(n: Field) -> pub bool {
3+
not_odd(n)
54
}
65

7-
// fn main(x: Field, y: Field) -> pub bool {
8-
// not_odd(x) & not_odd(y) & not_equal(x, y);
9-
// }
10-
116
fn not_equal(x: Field, y: Field) -> bool {
127
x != y
138
}
Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
use dep::std;
2-
// use dep::simple;
3-
4-
// #[export]
5-
// fn main_call(x: Field, y: Field) -> bool {
6-
// let mut res = simple::not_odd(x);
7-
// res &= simple::not_odd(y);
8-
// res &= simple::not_equal(x, y);
9-
// res
10-
// }
112

123
#[export]
13-
fn main(x: Field, y: Field) -> pub bool {
14-
// Hash public inputs together
15-
//TODO: take proofs
16-
x != y
4+
fn main(verification_key: [Field; 114], proof: [Field; 93], public_inputs: [Field; 1], key_hash: Field) {
5+
std::verify_proof(
6+
verification_key.as_slice(),
7+
proof.as_slice(),
8+
public_inputs.as_slice(),
9+
key_hash
10+
);
1711
}
18-
19-
// #[test]
20-
// fn test_not_equal() {
21-
// assert(main_call(2, 4));
22-
// // Uncomment to make test fail
23-
// // assert(not_equal(1, 1));
24-
// }

how-to/recursive-proofs/main.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ async function getCircuit(name: string) {
1313
const basePath = resolve(join('./circuits', name));
1414
const fm = createFileManager(basePath);
1515
const compiled = await compile(fm, basePath);
16-
console.log(compiled.program.abi);
1716
if (!('program' in compiled)) {
1817
throw new Error('Compilation failed');
1918
}
@@ -23,21 +22,35 @@ async function getCircuit(name: string) {
2322
const input1 = { n: 2 };
2423
const input2 = { n: 4 };
2524

25+
async function fullNoirFromCircuit(circuitName: string): Promise<FullNoir> {
26+
const circuit: CompiledCircuit = await getCircuit('not_odd');
27+
const backend: BarretenbergBackend = new BarretenbergBackend(circuit, { threads: 8 });
28+
const noir: Noir = new Noir(circuit, backend);
29+
return { circuit, backend, noir };
30+
}
31+
32+
type FullNoir = {
33+
circuit: CompiledCircuit,
34+
backend: BarretenbergBackend,
35+
noir: Noir
36+
}
37+
2638
async function start() {
27-
let simpleCircuit: CompiledCircuit = await getCircuit('not_odd');
28-
let simpleBackend: BarretenbergBackend = new BarretenbergBackend(simpleCircuit, { threads: 8 });
29-
let simpleNoir: Noir = new Noir(simpleCircuit, simpleBackend);
39+
const simple: FullNoir = await fullNoirFromCircuit('not_odd');
40+
41+
const witness1 = (await simple.noir.execute(input1)).witness;
42+
const proof1: ProofData = await simple.backend.generateProof(witness1);
3043

31-
const witness1 = (await simpleNoir.execute(input1)).witness;
32-
let proof1: ProofData = await simpleBackend.generateProof(witness1);
44+
// const witness2 = (await simple.noir.execute(input2)).witness;
45+
// const proof2: ProofData = await simple.backend.generateProof(witness2);
3346

34-
const witness2 = (await simpleNoir.execute(input2)).witness;
35-
let proof2: ProofData = await simpleBackend.generateProof(witness2);
47+
const { proofAsFields, vkAsFields, vkHash } = await simple.backend.generateRecursiveProofArtifacts(proof1, 1);
48+
// console.log({ proofAsFields, vkAsFields, vkHash });
3649

37-
// let res = await main(/* intermediate proofs */);
38-
// console.log(res);
50+
let res = await main(vkAsFields, proofAsFields, ["7"], vkHash);
51+
console.log(res);
3952

40-
simpleBackend.destroy();
53+
simple.backend.destroy();
4154
}
4255

4356
start();

0 commit comments

Comments
 (0)