@@ -38,6 +38,7 @@ async function start() {
38
38
const leaf : FullNoir = await fullNoirFromCircuit ( 'sum' ) ;
39
39
40
40
const leafParams = { a : 1 , b : 3 } ;
41
+ let numPubInputs = 2 ;
41
42
42
43
// Generate leaf proof artifacts
43
44
let { witness, returnValue } = await leaf . noir . execute ( leafParams ) ;
@@ -46,12 +47,12 @@ async function start() {
46
47
console . log ( "Generating intermediate proof artifacts leaf..." ) ;
47
48
const artifacts1 = await leaf . backend . generateRecursiveProofArtifacts (
48
49
innerProof1 ,
49
- Object . keys ( leafParams ) . length + 1
50
+ numPubInputs + 1 // +1 for public return
50
51
) ;
51
52
52
53
53
54
let pub_inputs : string [ ] = [
54
- ...( Object . values ( leafParams ) . map ( a => Number ( a ) . toString ( ) ) ) ,
55
+ ...( Object . values ( leafParams ) . map ( n => Number ( n ) . toString ( ) ) ) ,
55
56
Number ( returnValue ) . toString ( )
56
57
] ;
57
58
@@ -62,43 +63,40 @@ async function start() {
62
63
63
64
const nodeParams = {
64
65
verification_key : artifacts1 . vkAsFields ,
65
- public_inputs : pub_inputs ,
66
+ public_inputs : pub_inputs , // public, each counted individually
66
67
key_hash : artifacts1 . vkHash ,
67
68
proof : artifacts1 . proofAsFields ,
68
69
num : 5
69
70
} ;
71
+ numPubInputs = pub_inputs . length ;
70
72
71
73
( { witness, returnValue } = await recurseLeaf . noir . execute ( nodeParams ) ) ;
72
74
console . log ( "recurseLeaf: %d + %d = " , a , b , Number ( returnValue ) . toString ( ) ) ;
73
75
const innerProof2 : ProofData = await recurseLeaf . backend . generateProof ( witness ) ;
74
- console . log ( "Verifying intermediate proof recurseLeaf..." ) ;
75
- const res : boolean = await recurseLeaf . backend . verifyProof ( innerProof2 ) ;
76
- console . log ( "Verification" , res ? "PASSED" : "failed" ) ;
77
-
78
76
console . log ( "Generating intermediate proof artifacts recurseLeaf..." ) ;
79
77
const artifacts2 = await recurseLeaf . backend . generateRecursiveProofArtifacts (
80
78
innerProof2 ,
81
- Object . keys ( nodeParams ) . length + 1
79
+ numPubInputs + 1 + 16 // +1 for public return +16 for hidden aggregation object
82
80
) ;
83
81
console . log ( "artifacts2 generated." ) ;
84
82
85
83
// Generate and verify outer proof
86
- // const outerParams = {
87
- // verification_key: artifacts2.vkAsFields,
88
- // public_inputs: [...(Object.values(nodeParams)), returnValue], // returns proven sum
89
- // key_hash: artifacts2.vkHash,
90
- // proof: artifacts2.proofAsFields
91
- // };
92
-
93
- // const recurseNode: FullNoir = await fullNoirFromCircuit('recurseNode');
94
- // ({ witness, returnValue } = await recurseNode.noir.execute(outerParams));
95
- // console.log("Generating outer proof...");
96
- // const outerProof: ProofData = await recurseNode.backend.generateProof(witness);
97
- // console.log("Verifying outer proof...");
98
- // const res : boolean = await recurseNode.backend.verifyProof(outerProof);
99
- // console.log("Verification", res ? "PASSED" : "failed");
100
-
101
- // recurseNode.backend.destroy();
84
+ const outerParams = {
85
+ verification_key : artifacts2 . vkAsFields ,
86
+ public_inputs : [ 1 , 3 , 4 , returnValue ] . map . toString ( ) , // returns proven sum
87
+ key_hash : artifacts2 . vkHash ,
88
+ proof : artifacts2 . proofAsFields
89
+ } ;
90
+
91
+ const recurseNode : FullNoir = await fullNoirFromCircuit ( 'recurseNode' ) ;
92
+ ( { witness, returnValue } = await recurseNode . noir . execute ( outerParams ) ) ;
93
+ console . log ( "Generating outer proof..." ) ;
94
+ const outerProof : ProofData = await recurseNode . backend . generateProof ( witness ) ;
95
+ console . log ( "Verifying outer proof..." ) ;
96
+ const resNode : boolean = await recurseNode . backend . verifyProof ( outerProof ) ;
97
+ console . log ( "Verification" , resNode ? "PASSED" : "failed" ) ;
98
+
99
+ recurseNode . backend . destroy ( ) ;
102
100
recurseLeaf . backend . destroy ( ) ;
103
101
leaf . backend . destroy ( ) ;
104
102
}
0 commit comments