1
1
import { CompiledCircuit } from '@noir-lang/types' ;
2
- import { main } from './codegen' ;
2
+ // import { main } from './codegen';
3
3
import { setTimeout } from "timers/promises" ;
4
4
5
5
import { Noir } from '@noir-lang/noir_js' ;
@@ -19,11 +19,8 @@ async function getCircuit(name: string) {
19
19
return compiled . program ;
20
20
}
21
21
22
- const input1 = { n : 2 } ;
23
- const input2 = { n : 4 } ;
24
-
25
22
async function fullNoirFromCircuit ( circuitName : string ) : Promise < FullNoir > {
26
- const circuit : CompiledCircuit = await getCircuit ( 'not_odd' ) ;
23
+ const circuit : CompiledCircuit = await getCircuit ( circuitName ) ;
27
24
const backend : BarretenbergBackend = new BarretenbergBackend ( circuit , { threads : 8 } ) ;
28
25
const noir : Noir = new Noir ( circuit , backend ) ;
29
26
return { circuit, backend, noir } ;
@@ -36,30 +33,51 @@ type FullNoir = {
36
33
}
37
34
38
35
async function start ( ) {
36
+ // Generate inner proof artifacts
39
37
console . log ( "Creating Noir from circuit..." ) ;
40
38
const simple : FullNoir = await fullNoirFromCircuit ( 'not_odd' ) ;
41
39
42
40
console . log ( "Executing binary circuit for witness..." ) ;
43
- const witness1 = ( await simple . noir . execute ( input1 ) ) . witness ;
41
+ const innerInput = { n : 2 } ;
42
+ const innerWitness = ( await simple . noir . execute ( innerInput ) ) . witness ;
44
43
console . log ( "Generating intermediate proof..." ) ;
45
- const proof1 : ProofData = await simple . backend . generateProof ( witness1 ) ;
44
+ const innerProof : ProofData = await simple . backend . generateProof ( innerWitness ) ;
46
45
47
- if ( 1 ) { // mess up proof
48
- console . log ( "Generating intermediate proof..." ) ;
49
- proof1 . proof [ 0 ] += 1 ;
46
+ if ( false ) { // mess up proof
47
+ console . log ( "Messing intermediate proof..." ) ;
48
+ innerProof . proof [ 0 ] += 1 ;
50
49
}
51
50
52
- // const witness2 = (await simple.noir.execute(input2)).witness;
53
- // const proof2: ProofData = await simple.backend.generateProof(witness2);
54
51
console . log ( "Generating recursive proof artifacts..." ) ;
55
- const { proofAsFields, vkAsFields, vkHash } = await simple . backend . generateRecursiveProofArtifacts ( proof1 , 1 ) ;
52
+ const { proofAsFields, vkAsFields, vkHash } = await simple . backend . generateRecursiveProofArtifacts ( innerProof , 1 ) ;
56
53
// console.log({ proofAsFields, vkAsFields, vkHash });
54
+ simple . backend . destroy ( ) ;
55
+
56
+ // 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..." ) ;
60
+ const outerInput = {
61
+ verification_key : vkAsFields ,
62
+ proof : proofAsFields ,
63
+ public_inputs : [ "0" ] ,
64
+ key_hash : vkHash
65
+ } ;
66
+ const outerWitness = ( await outer . noir . execute (
67
+ outerInput
68
+ ) ) . witness ;
57
69
58
- console . log ( "Executing lib circuit function to verify inner proof" ) ;
59
- let res = await main ( vkAsFields , proofAsFields , [ "7" ] , vkHash ) ;
60
- console . log ( res ) ;
70
+ console . log ( "Generating outer proof..." ) ;
71
+ const outerProof : ProofData = await outer . backend . generateProof ( outerWitness ) ;
61
72
62
- simple . backend . destroy ( ) ;
73
+ 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);
79
+
80
+ outer . backend . destroy ( ) ;
63
81
}
64
82
65
83
start ( ) ;
0 commit comments