@izi-noir/sdk 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +0 -50
- package/dist/index.js +0 -50
- package/dist/providers/arkworks.cjs +0 -50
- package/dist/providers/arkworks.js +0 -50
- package/dist/providers/barretenberg.cjs +0 -50
- package/dist/providers/barretenberg.js +0 -50
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -297,18 +297,12 @@ authors = [""]
|
|
|
297
297
|
parameters.forEach((p, noirIndex) => {
|
|
298
298
|
const r1csIndex = noirIndex + 1;
|
|
299
299
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
300
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
301
300
|
if (p.visibility === "public") {
|
|
302
301
|
publicR1csIndices.push(r1csIndex);
|
|
303
302
|
} else if (p.visibility === "private") {
|
|
304
303
|
privateR1csIndices.push(r1csIndex);
|
|
305
304
|
}
|
|
306
305
|
});
|
|
307
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
308
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
309
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
310
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
311
|
-
console.log("=========================================");
|
|
312
306
|
const r1cs = {
|
|
313
307
|
num_witnesses: parameters.length + 1,
|
|
314
308
|
// +1 for w_0
|
|
@@ -327,25 +321,18 @@ authors = [""]
|
|
|
327
321
|
c: [["0x1", publicIdx]]
|
|
328
322
|
// expected
|
|
329
323
|
});
|
|
330
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
331
|
-
} else {
|
|
332
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
333
324
|
}
|
|
334
325
|
const r1csJson = JSON.stringify(r1cs);
|
|
335
|
-
console.log("R1CS JSON:", r1csJson);
|
|
336
326
|
let provingKey;
|
|
337
327
|
let verifyingKey;
|
|
338
328
|
let verifyingKeyGnark;
|
|
339
329
|
if (this.config.cacheKeys) {
|
|
340
330
|
try {
|
|
341
|
-
console.log("Running trusted setup from R1CS...");
|
|
342
331
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
343
332
|
provingKey = setupResult.proving_key;
|
|
344
333
|
verifyingKey = setupResult.verifying_key;
|
|
345
334
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
346
|
-
console.log("Setup complete!");
|
|
347
335
|
} catch (error) {
|
|
348
|
-
console.error("Setup failed:", error);
|
|
349
336
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
350
337
|
}
|
|
351
338
|
}
|
|
@@ -382,60 +369,23 @@ authors = [""]
|
|
|
382
369
|
const noir = new import_noir_js2.Noir(circuit);
|
|
383
370
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
384
371
|
const witnessMapNoir = (0, import_acvm_js.decompressWitness)(compressedWitness);
|
|
385
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
386
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
387
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
388
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
389
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
390
|
-
console.log("Witness map entries (first 10):");
|
|
391
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
392
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
393
|
-
const strVal = String(value);
|
|
394
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
395
|
-
if (strVal.startsWith("0x")) {
|
|
396
|
-
try {
|
|
397
|
-
const decVal = BigInt(strVal).toString(10);
|
|
398
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
399
|
-
} catch {
|
|
400
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
372
|
const witnessMap = {};
|
|
405
373
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
406
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
407
374
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
408
375
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
409
376
|
const strVal = String(value);
|
|
410
377
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
411
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
412
378
|
}
|
|
413
379
|
const witnessJson = JSON.stringify(witnessMap);
|
|
414
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
415
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
416
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
417
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
418
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
419
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
420
380
|
let provingKey = circuit.provingKey;
|
|
421
381
|
if (!provingKey) {
|
|
422
|
-
console.log("Running setup_from_r1cs...");
|
|
423
382
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
424
383
|
provingKey = setupResult.proving_key;
|
|
425
384
|
circuit.provingKey = provingKey;
|
|
426
385
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
427
386
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
428
387
|
}
|
|
429
|
-
console.log("Generating proof from R1CS...");
|
|
430
388
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
431
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
432
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
433
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
434
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
435
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
436
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
437
|
-
});
|
|
438
|
-
console.log("===========================");
|
|
439
389
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
440
390
|
return {
|
|
441
391
|
proof: proofBytes,
|
package/dist/index.js
CHANGED
|
@@ -274,18 +274,12 @@ authors = [""]
|
|
|
274
274
|
parameters.forEach((p, noirIndex) => {
|
|
275
275
|
const r1csIndex = noirIndex + 1;
|
|
276
276
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
277
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
278
277
|
if (p.visibility === "public") {
|
|
279
278
|
publicR1csIndices.push(r1csIndex);
|
|
280
279
|
} else if (p.visibility === "private") {
|
|
281
280
|
privateR1csIndices.push(r1csIndex);
|
|
282
281
|
}
|
|
283
282
|
});
|
|
284
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
285
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
286
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
287
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
288
|
-
console.log("=========================================");
|
|
289
283
|
const r1cs = {
|
|
290
284
|
num_witnesses: parameters.length + 1,
|
|
291
285
|
// +1 for w_0
|
|
@@ -304,25 +298,18 @@ authors = [""]
|
|
|
304
298
|
c: [["0x1", publicIdx]]
|
|
305
299
|
// expected
|
|
306
300
|
});
|
|
307
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
308
|
-
} else {
|
|
309
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
310
301
|
}
|
|
311
302
|
const r1csJson = JSON.stringify(r1cs);
|
|
312
|
-
console.log("R1CS JSON:", r1csJson);
|
|
313
303
|
let provingKey;
|
|
314
304
|
let verifyingKey;
|
|
315
305
|
let verifyingKeyGnark;
|
|
316
306
|
if (this.config.cacheKeys) {
|
|
317
307
|
try {
|
|
318
|
-
console.log("Running trusted setup from R1CS...");
|
|
319
308
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
320
309
|
provingKey = setupResult.proving_key;
|
|
321
310
|
verifyingKey = setupResult.verifying_key;
|
|
322
311
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
323
|
-
console.log("Setup complete!");
|
|
324
312
|
} catch (error) {
|
|
325
|
-
console.error("Setup failed:", error);
|
|
326
313
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
327
314
|
}
|
|
328
315
|
}
|
|
@@ -359,60 +346,23 @@ authors = [""]
|
|
|
359
346
|
const noir = new Noir2(circuit);
|
|
360
347
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
361
348
|
const witnessMapNoir = decompressWitness(compressedWitness);
|
|
362
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
363
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
364
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
365
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
366
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
367
|
-
console.log("Witness map entries (first 10):");
|
|
368
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
369
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
370
|
-
const strVal = String(value);
|
|
371
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
372
|
-
if (strVal.startsWith("0x")) {
|
|
373
|
-
try {
|
|
374
|
-
const decVal = BigInt(strVal).toString(10);
|
|
375
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
376
|
-
} catch {
|
|
377
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
349
|
const witnessMap = {};
|
|
382
350
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
383
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
384
351
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
385
352
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
386
353
|
const strVal = String(value);
|
|
387
354
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
388
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
389
355
|
}
|
|
390
356
|
const witnessJson = JSON.stringify(witnessMap);
|
|
391
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
392
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
393
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
394
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
395
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
396
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
397
357
|
let provingKey = circuit.provingKey;
|
|
398
358
|
if (!provingKey) {
|
|
399
|
-
console.log("Running setup_from_r1cs...");
|
|
400
359
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
401
360
|
provingKey = setupResult.proving_key;
|
|
402
361
|
circuit.provingKey = provingKey;
|
|
403
362
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
404
363
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
405
364
|
}
|
|
406
|
-
console.log("Generating proof from R1CS...");
|
|
407
365
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
408
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
409
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
410
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
411
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
412
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
413
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
414
|
-
});
|
|
415
|
-
console.log("===========================");
|
|
416
366
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
417
367
|
return {
|
|
418
368
|
proof: proofBytes,
|
|
@@ -202,18 +202,12 @@ authors = [""]
|
|
|
202
202
|
parameters.forEach((p, noirIndex) => {
|
|
203
203
|
const r1csIndex = noirIndex + 1;
|
|
204
204
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
205
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
206
205
|
if (p.visibility === "public") {
|
|
207
206
|
publicR1csIndices.push(r1csIndex);
|
|
208
207
|
} else if (p.visibility === "private") {
|
|
209
208
|
privateR1csIndices.push(r1csIndex);
|
|
210
209
|
}
|
|
211
210
|
});
|
|
212
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
213
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
214
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
215
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
216
|
-
console.log("=========================================");
|
|
217
211
|
const r1cs = {
|
|
218
212
|
num_witnesses: parameters.length + 1,
|
|
219
213
|
// +1 for w_0
|
|
@@ -232,25 +226,18 @@ authors = [""]
|
|
|
232
226
|
c: [["0x1", publicIdx]]
|
|
233
227
|
// expected
|
|
234
228
|
});
|
|
235
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
236
|
-
} else {
|
|
237
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
238
229
|
}
|
|
239
230
|
const r1csJson = JSON.stringify(r1cs);
|
|
240
|
-
console.log("R1CS JSON:", r1csJson);
|
|
241
231
|
let provingKey;
|
|
242
232
|
let verifyingKey;
|
|
243
233
|
let verifyingKeyGnark;
|
|
244
234
|
if (this.config.cacheKeys) {
|
|
245
235
|
try {
|
|
246
|
-
console.log("Running trusted setup from R1CS...");
|
|
247
236
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
248
237
|
provingKey = setupResult.proving_key;
|
|
249
238
|
verifyingKey = setupResult.verifying_key;
|
|
250
239
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
251
|
-
console.log("Setup complete!");
|
|
252
240
|
} catch (error) {
|
|
253
|
-
console.error("Setup failed:", error);
|
|
254
241
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
255
242
|
}
|
|
256
243
|
}
|
|
@@ -287,60 +274,23 @@ authors = [""]
|
|
|
287
274
|
const noir = new import_noir_js.Noir(circuit);
|
|
288
275
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
289
276
|
const witnessMapNoir = (0, import_acvm_js.decompressWitness)(compressedWitness);
|
|
290
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
291
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
292
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
293
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
294
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
295
|
-
console.log("Witness map entries (first 10):");
|
|
296
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
297
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
298
|
-
const strVal = String(value);
|
|
299
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
300
|
-
if (strVal.startsWith("0x")) {
|
|
301
|
-
try {
|
|
302
|
-
const decVal = BigInt(strVal).toString(10);
|
|
303
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
304
|
-
} catch {
|
|
305
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
277
|
const witnessMap = {};
|
|
310
278
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
311
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
312
279
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
313
280
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
314
281
|
const strVal = String(value);
|
|
315
282
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
316
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
317
283
|
}
|
|
318
284
|
const witnessJson = JSON.stringify(witnessMap);
|
|
319
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
320
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
321
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
322
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
323
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
324
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
325
285
|
let provingKey = circuit.provingKey;
|
|
326
286
|
if (!provingKey) {
|
|
327
|
-
console.log("Running setup_from_r1cs...");
|
|
328
287
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
329
288
|
provingKey = setupResult.proving_key;
|
|
330
289
|
circuit.provingKey = provingKey;
|
|
331
290
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
332
291
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
333
292
|
}
|
|
334
|
-
console.log("Generating proof from R1CS...");
|
|
335
293
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
336
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
337
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
338
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
339
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
340
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
341
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
342
|
-
});
|
|
343
|
-
console.log("===========================");
|
|
344
294
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
345
295
|
return {
|
|
346
296
|
proof: proofBytes,
|
|
@@ -179,18 +179,12 @@ authors = [""]
|
|
|
179
179
|
parameters.forEach((p, noirIndex) => {
|
|
180
180
|
const r1csIndex = noirIndex + 1;
|
|
181
181
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
182
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
183
182
|
if (p.visibility === "public") {
|
|
184
183
|
publicR1csIndices.push(r1csIndex);
|
|
185
184
|
} else if (p.visibility === "private") {
|
|
186
185
|
privateR1csIndices.push(r1csIndex);
|
|
187
186
|
}
|
|
188
187
|
});
|
|
189
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
190
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
191
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
192
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
193
|
-
console.log("=========================================");
|
|
194
188
|
const r1cs = {
|
|
195
189
|
num_witnesses: parameters.length + 1,
|
|
196
190
|
// +1 for w_0
|
|
@@ -209,25 +203,18 @@ authors = [""]
|
|
|
209
203
|
c: [["0x1", publicIdx]]
|
|
210
204
|
// expected
|
|
211
205
|
});
|
|
212
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
213
|
-
} else {
|
|
214
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
215
206
|
}
|
|
216
207
|
const r1csJson = JSON.stringify(r1cs);
|
|
217
|
-
console.log("R1CS JSON:", r1csJson);
|
|
218
208
|
let provingKey;
|
|
219
209
|
let verifyingKey;
|
|
220
210
|
let verifyingKeyGnark;
|
|
221
211
|
if (this.config.cacheKeys) {
|
|
222
212
|
try {
|
|
223
|
-
console.log("Running trusted setup from R1CS...");
|
|
224
213
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
225
214
|
provingKey = setupResult.proving_key;
|
|
226
215
|
verifyingKey = setupResult.verifying_key;
|
|
227
216
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
228
|
-
console.log("Setup complete!");
|
|
229
217
|
} catch (error) {
|
|
230
|
-
console.error("Setup failed:", error);
|
|
231
218
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
232
219
|
}
|
|
233
220
|
}
|
|
@@ -264,60 +251,23 @@ authors = [""]
|
|
|
264
251
|
const noir = new Noir(circuit);
|
|
265
252
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
266
253
|
const witnessMapNoir = decompressWitness(compressedWitness);
|
|
267
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
268
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
269
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
270
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
271
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
272
|
-
console.log("Witness map entries (first 10):");
|
|
273
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
274
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
275
|
-
const strVal = String(value);
|
|
276
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
277
|
-
if (strVal.startsWith("0x")) {
|
|
278
|
-
try {
|
|
279
|
-
const decVal = BigInt(strVal).toString(10);
|
|
280
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
281
|
-
} catch {
|
|
282
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
254
|
const witnessMap = {};
|
|
287
255
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
288
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
289
256
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
290
257
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
291
258
|
const strVal = String(value);
|
|
292
259
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
293
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
294
260
|
}
|
|
295
261
|
const witnessJson = JSON.stringify(witnessMap);
|
|
296
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
297
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
298
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
299
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
300
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
301
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
302
262
|
let provingKey = circuit.provingKey;
|
|
303
263
|
if (!provingKey) {
|
|
304
|
-
console.log("Running setup_from_r1cs...");
|
|
305
264
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
306
265
|
provingKey = setupResult.proving_key;
|
|
307
266
|
circuit.provingKey = provingKey;
|
|
308
267
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
309
268
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
310
269
|
}
|
|
311
|
-
console.log("Generating proof from R1CS...");
|
|
312
270
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
313
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
314
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
315
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
316
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
317
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
318
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
319
|
-
});
|
|
320
|
-
console.log("===========================");
|
|
321
271
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
322
272
|
return {
|
|
323
273
|
proof: proofBytes,
|
|
@@ -297,18 +297,12 @@ authors = [""]
|
|
|
297
297
|
parameters.forEach((p, noirIndex) => {
|
|
298
298
|
const r1csIndex = noirIndex + 1;
|
|
299
299
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
300
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
301
300
|
if (p.visibility === "public") {
|
|
302
301
|
publicR1csIndices.push(r1csIndex);
|
|
303
302
|
} else if (p.visibility === "private") {
|
|
304
303
|
privateR1csIndices.push(r1csIndex);
|
|
305
304
|
}
|
|
306
305
|
});
|
|
307
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
308
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
309
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
310
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
311
|
-
console.log("=========================================");
|
|
312
306
|
const r1cs = {
|
|
313
307
|
num_witnesses: parameters.length + 1,
|
|
314
308
|
// +1 for w_0
|
|
@@ -327,25 +321,18 @@ authors = [""]
|
|
|
327
321
|
c: [["0x1", publicIdx]]
|
|
328
322
|
// expected
|
|
329
323
|
});
|
|
330
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
331
|
-
} else {
|
|
332
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
333
324
|
}
|
|
334
325
|
const r1csJson = JSON.stringify(r1cs);
|
|
335
|
-
console.log("R1CS JSON:", r1csJson);
|
|
336
326
|
let provingKey;
|
|
337
327
|
let verifyingKey;
|
|
338
328
|
let verifyingKeyGnark;
|
|
339
329
|
if (this.config.cacheKeys) {
|
|
340
330
|
try {
|
|
341
|
-
console.log("Running trusted setup from R1CS...");
|
|
342
331
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
343
332
|
provingKey = setupResult.proving_key;
|
|
344
333
|
verifyingKey = setupResult.verifying_key;
|
|
345
334
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
346
|
-
console.log("Setup complete!");
|
|
347
335
|
} catch (error) {
|
|
348
|
-
console.error("Setup failed:", error);
|
|
349
336
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
350
337
|
}
|
|
351
338
|
}
|
|
@@ -382,60 +369,23 @@ authors = [""]
|
|
|
382
369
|
const noir = new import_noir_js2.Noir(circuit);
|
|
383
370
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
384
371
|
const witnessMapNoir = (0, import_acvm_js.decompressWitness)(compressedWitness);
|
|
385
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
386
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
387
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
388
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
389
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
390
|
-
console.log("Witness map entries (first 10):");
|
|
391
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
392
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
393
|
-
const strVal = String(value);
|
|
394
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
395
|
-
if (strVal.startsWith("0x")) {
|
|
396
|
-
try {
|
|
397
|
-
const decVal = BigInt(strVal).toString(10);
|
|
398
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
399
|
-
} catch {
|
|
400
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
372
|
const witnessMap = {};
|
|
405
373
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
406
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
407
374
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
408
375
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
409
376
|
const strVal = String(value);
|
|
410
377
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
411
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
412
378
|
}
|
|
413
379
|
const witnessJson = JSON.stringify(witnessMap);
|
|
414
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
415
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
416
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
417
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
418
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
419
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
420
380
|
let provingKey = circuit.provingKey;
|
|
421
381
|
if (!provingKey) {
|
|
422
|
-
console.log("Running setup_from_r1cs...");
|
|
423
382
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
424
383
|
provingKey = setupResult.proving_key;
|
|
425
384
|
circuit.provingKey = provingKey;
|
|
426
385
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
427
386
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
428
387
|
}
|
|
429
|
-
console.log("Generating proof from R1CS...");
|
|
430
388
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
431
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
432
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
433
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
434
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
435
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
436
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
437
|
-
});
|
|
438
|
-
console.log("===========================");
|
|
439
389
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
440
390
|
return {
|
|
441
391
|
proof: proofBytes,
|
|
@@ -274,18 +274,12 @@ authors = [""]
|
|
|
274
274
|
parameters.forEach((p, noirIndex) => {
|
|
275
275
|
const r1csIndex = noirIndex + 1;
|
|
276
276
|
witnessIndexMapping.set(noirIndex, r1csIndex);
|
|
277
|
-
console.log(` Parameter "${p.name}" (${p.visibility}): noir[${noirIndex}] \u2192 R1CS w_${r1csIndex}`);
|
|
278
277
|
if (p.visibility === "public") {
|
|
279
278
|
publicR1csIndices.push(r1csIndex);
|
|
280
279
|
} else if (p.visibility === "private") {
|
|
281
280
|
privateR1csIndices.push(r1csIndex);
|
|
282
281
|
}
|
|
283
282
|
});
|
|
284
|
-
console.log("=== COMPILE: R1CS Witness Assignment ===");
|
|
285
|
-
console.log("Public R1CS indices:", publicR1csIndices);
|
|
286
|
-
console.log("Private R1CS indices:", privateR1csIndices);
|
|
287
|
-
console.log("Witness mapping:", Object.fromEntries(witnessIndexMapping));
|
|
288
|
-
console.log("=========================================");
|
|
289
283
|
const r1cs = {
|
|
290
284
|
num_witnesses: parameters.length + 1,
|
|
291
285
|
// +1 for w_0
|
|
@@ -304,25 +298,18 @@ authors = [""]
|
|
|
304
298
|
c: [["0x1", publicIdx]]
|
|
305
299
|
// expected
|
|
306
300
|
});
|
|
307
|
-
console.log(` Added constraint: w_${privateIdx} * w_${privateIdx} = w_${publicIdx}`);
|
|
308
|
-
} else {
|
|
309
|
-
console.warn("Complex circuit detected - R1CS constraint generation may be incomplete");
|
|
310
301
|
}
|
|
311
302
|
const r1csJson = JSON.stringify(r1cs);
|
|
312
|
-
console.log("R1CS JSON:", r1csJson);
|
|
313
303
|
let provingKey;
|
|
314
304
|
let verifyingKey;
|
|
315
305
|
let verifyingKeyGnark;
|
|
316
306
|
if (this.config.cacheKeys) {
|
|
317
307
|
try {
|
|
318
|
-
console.log("Running trusted setup from R1CS...");
|
|
319
308
|
const setupResult = wasm.setup_from_r1cs(r1csJson);
|
|
320
309
|
provingKey = setupResult.proving_key;
|
|
321
310
|
verifyingKey = setupResult.verifying_key;
|
|
322
311
|
verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
323
|
-
console.log("Setup complete!");
|
|
324
312
|
} catch (error) {
|
|
325
|
-
console.error("Setup failed:", error);
|
|
326
313
|
throw new Error(`R1CS setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
327
314
|
}
|
|
328
315
|
}
|
|
@@ -359,60 +346,23 @@ authors = [""]
|
|
|
359
346
|
const noir = new Noir2(circuit);
|
|
360
347
|
const { witness: compressedWitness } = await noir.execute(inputs);
|
|
361
348
|
const witnessMapNoir = decompressWitness(compressedWitness);
|
|
362
|
-
console.log("=== ARKWORKS WASM DEBUG ===");
|
|
363
|
-
console.log("Circuit ABI parameters:", circuit.abi.parameters);
|
|
364
|
-
console.log("Inputs provided:", JSON.stringify(inputs));
|
|
365
|
-
console.log("Compressed witness size:", compressedWitness.length, "bytes");
|
|
366
|
-
console.log("Decompressed witness entries:", witnessMapNoir.size);
|
|
367
|
-
console.log("Witness map entries (first 10):");
|
|
368
|
-
const sortedWitness = Array.from(witnessMapNoir.entries()).sort(([a], [b]) => a - b);
|
|
369
|
-
for (const [index, value] of sortedWitness.slice(0, 10)) {
|
|
370
|
-
const strVal = String(value);
|
|
371
|
-
console.log(` witness[${index}] = "${strVal.slice(0, 66)}${strVal.length > 66 ? "..." : ""}"`);
|
|
372
|
-
if (strVal.startsWith("0x")) {
|
|
373
|
-
try {
|
|
374
|
-
const decVal = BigInt(strVal).toString(10);
|
|
375
|
-
console.log(` \u2192 decimal: ${decVal}`);
|
|
376
|
-
} catch {
|
|
377
|
-
console.log(` \u2192 failed to parse as BigInt`);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
349
|
const witnessMap = {};
|
|
382
350
|
const witnessMapping = circuit.witnessIndexMapping;
|
|
383
|
-
console.log("Converting noir witness to R1CS witness:");
|
|
384
351
|
for (const [noirIndex, value] of witnessMapNoir.entries()) {
|
|
385
352
|
const r1csIndex = witnessMapping.get(noirIndex) ?? noirIndex + 1;
|
|
386
353
|
const strVal = String(value);
|
|
387
354
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
388
|
-
console.log(` noir[${noirIndex}] \u2192 R1CS w_${r1csIndex} = ${strVal.slice(0, 20)}...`);
|
|
389
355
|
}
|
|
390
356
|
const witnessJson = JSON.stringify(witnessMap);
|
|
391
|
-
console.log("Witness JSON for prove:", witnessJson.slice(0, 200) + "...");
|
|
392
|
-
const r1csParsed = JSON.parse(circuit.r1csJson);
|
|
393
|
-
console.log("R1CS public_inputs:", r1csParsed.public_inputs);
|
|
394
|
-
console.log("R1CS private_inputs:", r1csParsed.private_inputs);
|
|
395
|
-
console.log("R1CS num_witnesses:", r1csParsed.num_witnesses);
|
|
396
|
-
console.log("R1CS constraints:", r1csParsed.constraints.length);
|
|
397
357
|
let provingKey = circuit.provingKey;
|
|
398
358
|
if (!provingKey) {
|
|
399
|
-
console.log("Running setup_from_r1cs...");
|
|
400
359
|
const setupResult = wasm.setup_from_r1cs(circuit.r1csJson);
|
|
401
360
|
provingKey = setupResult.proving_key;
|
|
402
361
|
circuit.provingKey = provingKey;
|
|
403
362
|
circuit.verifyingKey = setupResult.verifying_key;
|
|
404
363
|
circuit.verifyingKeyGnark = setupResult.verifying_key_gnark;
|
|
405
364
|
}
|
|
406
|
-
console.log("Generating proof from R1CS...");
|
|
407
365
|
const proofResult = wasm.prove_from_r1cs(provingKey, circuit.r1csJson, witnessJson);
|
|
408
|
-
console.log("=== PROOF RESULT DEBUG ===");
|
|
409
|
-
console.log("Proof public inputs from arkworks:", proofResult.public_inputs);
|
|
410
|
-
proofResult.public_inputs.forEach((input, i) => {
|
|
411
|
-
const hexValue = input.startsWith("0x") ? input : `0x${input}`;
|
|
412
|
-
const decValue = BigInt(hexValue).toString(10);
|
|
413
|
-
console.log(` Public input ${i}: ${input} (dec: ${decValue})`);
|
|
414
|
-
});
|
|
415
|
-
console.log("===========================");
|
|
416
366
|
const proofBytes = base64ToUint8Array(proofResult.proof_gnark);
|
|
417
367
|
return {
|
|
418
368
|
proof: proofBytes,
|