Skip to content

Commit ebb3ed1

Browse files
committed
fix public input length with hidden size
1 parent 969dd83 commit ebb3ed1

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

how-to/recursive-proofs/main.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function start() {
3838
const leaf: FullNoir = await fullNoirFromCircuit('sum');
3939

4040
const leafParams = { a: 1, b: 3 };
41+
let numPubInputs = 2;
4142

4243
// Generate leaf proof artifacts
4344
let { witness, returnValue } = await leaf.noir.execute(leafParams);
@@ -46,12 +47,12 @@ async function start() {
4647
console.log("Generating intermediate proof artifacts leaf...");
4748
const artifacts1 = await leaf.backend.generateRecursiveProofArtifacts(
4849
innerProof1,
49-
Object.keys(leafParams).length + 1
50+
numPubInputs + 1 // +1 for public return
5051
);
5152

5253

5354
let pub_inputs: string[] = [
54-
...(Object.values(leafParams).map(a => Number(a).toString())),
55+
...(Object.values(leafParams).map(n => Number(n).toString())),
5556
Number(returnValue).toString()
5657
];
5758

@@ -62,43 +63,40 @@ async function start() {
6263

6364
const nodeParams = {
6465
verification_key: artifacts1.vkAsFields,
65-
public_inputs: pub_inputs,
66+
public_inputs: pub_inputs, // public, each counted individually
6667
key_hash: artifacts1.vkHash,
6768
proof: artifacts1.proofAsFields,
6869
num: 5
6970
};
71+
numPubInputs = pub_inputs.length;
7072

7173
({ witness, returnValue } = await recurseLeaf.noir.execute(nodeParams));
7274
console.log("recurseLeaf: %d + %d = ", a, b, Number(returnValue).toString());
7375
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-
7876
console.log("Generating intermediate proof artifacts recurseLeaf...");
7977
const artifacts2 = await recurseLeaf.backend.generateRecursiveProofArtifacts(
8078
innerProof2,
81-
Object.keys(nodeParams).length + 1
79+
numPubInputs + 1 + 16 // +1 for public return +16 for hidden aggregation object
8280
);
8381
console.log("artifacts2 generated.");
8482

8583
// 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();
102100
recurseLeaf.backend.destroy();
103101
leaf.backend.destroy();
104102
}

0 commit comments

Comments
 (0)