@@ -35,55 +35,45 @@ type FullNoir = {
35
35
}
36
36
37
37
async function start ( ) {
38
- const recursive : FullNoir = await fullNoirFromCircuit ( 'recurse' ) ;
38
+ const simple : FullNoir = await fullNoirFromCircuit ( 'not_odd' ) ;
39
+ const outer : FullNoir = await fullNoirFromCircuit ( 'recurse' ) ;
39
40
40
- // Generate artifacts recursively
41
- let verificationProof = {
42
- verification_key : Array < string > ( 114 ) . fill ( "0x00" ) ,
43
- proof : Array < string > ( 93 ) . fill ( "0x00" ) ,
44
- public_inputs : [ "0x06" ] ,
45
- key_hash : "0x00" as string , // circuit should skip `verify_proof` when key_hash is 0.
46
- } ;
47
- let sum = 1 ;
48
- const nodes = [ 3 , 7 ] ;
49
- for ( const [ i , n ] of nodes . entries ( ) ) {
50
- console . log ( "\n\nExecuting (with key_hash %s, sum %d, n %d)" , verificationProof . key_hash , sum , n ) ;
51
- verificationProof . public_inputs = [ "4" ] ;
52
- const { witness, returnValue } = await recursive . noir . execute ( {
53
- ...verificationProof ,
54
- sum,
55
- n
56
- } ) ;
57
- console . log ( "RESULT:" , returnValue , witness ) ;
58
- sum = Number ( returnValue ) as number ;
59
- console . log ( "Generating proof data..." ) ;
60
- const pd : ProofData = await recursive . backend . generateProof ( witness ) ;
61
- console . log ( pd ) ;
62
- if ( i < nodes . length - 1 ) {
63
- console . log ( "Generating recursive proof artifacts (depth %d)..." , i ) ;
64
- ( {
65
- proofAsFields : verificationProof . proof ,
66
- vkAsFields : verificationProof . verification_key ,
67
- vkHash : verificationProof . key_hash
68
- } = await recursive . backend . generateRecursiveProofArtifacts (
69
- pd ,
70
- Number ( verificationProof . public_inputs [ 0 ] )
71
- ) ) ;
72
- }
73
- else {
74
- console . log ( "Verifying final proof..." ) ;
75
- try {
76
- const res : boolean = await recursive . backend . verifyProof ( pd ) ;
77
- console . log ( "Verification" , res ? "PASSED" : "failed" ) ;
78
- }
79
- catch ( e ) {
80
- console . log ( e ) ;
81
- }
41
+ // Generate inner proof artifacts
42
+ console . log ( "Generating intermediate proof artifacts 1..." ) ;
43
+ const innerWitness1 = ( await simple . noir . execute ( { n : 2 } ) ) . witness ;
44
+ const innerProof1 : ProofData = await simple . backend . generateProof ( innerWitness1 ) ;
45
+ const artifacts1 = await simple . backend . generateRecursiveProofArtifacts ( innerProof1 , 1 ) ;
46
+
47
+ console . log ( "Generating intermediate proof artifacts 2..." ) ;
48
+ const innerWitness2 = ( await simple . noir . execute ( { n : 4 } ) ) . witness ;
49
+ const innerProof2 : ProofData = await simple . backend . generateProof ( innerWitness2 ) ;
50
+ const artifacts2 = await simple . backend . generateRecursiveProofArtifacts ( innerProof2 , 1 ) ;
51
+
52
+ simple . backend . destroy ( ) ;
82
53
83
- }
54
+ // Generate and verify outer proof
55
+ const outerInput = {
56
+ verification_key : artifacts1 . vkAsFields ,
57
+ public_inputs : [ "1" ] , // expect output of inner call to be "true"
58
+ key_hash : artifacts1 . vkHash ,
59
+ proof1 : artifacts1 . proofAsFields ,
60
+ proof2 : artifacts2 . proofAsFields
61
+ } ;
62
+ const outerWitness = ( await outer . noir . execute (
63
+ outerInput
64
+ ) ) . witness ;
65
+ try {
66
+ console . log ( "Generating outer proof..." ) ;
67
+ const outerProof : ProofData = await outer . backend . generateProof ( outerWitness ) ;
68
+ console . log ( "Verifying outer proof..." ) ;
69
+ const res : boolean = await outer . backend . verifyProof ( outerProof ) ;
70
+ console . log ( "Verification" , res ? "PASSED" : "failed" ) ;
71
+ }
72
+ catch ( e ) {
73
+ console . log ( e ) ;
84
74
}
85
75
86
- recursive . backend . destroy ( ) ;
76
+ outer . backend . destroy ( ) ;
87
77
}
88
78
89
79
start ( ) ;
0 commit comments