@izi-noir/sdk 0.1.13 → 0.1.15
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 +180 -6
- package/dist/index.d.cts +106 -55
- package/dist/index.d.ts +106 -55
- package/dist/index.js +180 -6
- package/dist/providers/arkworks.cjs +180 -6
- package/dist/providers/arkworks.d.cts +6 -0
- package/dist/providers/arkworks.d.ts +6 -0
- package/dist/providers/arkworks.js +180 -6
- package/dist/providers/barretenberg.cjs +180 -6
- package/dist/providers/barretenberg.js +180 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -142,10 +142,13 @@ var init_R1csBuilder = __esm({
|
|
|
142
142
|
// w_0 = 1 is reserved
|
|
143
143
|
publicIndices = [];
|
|
144
144
|
privateIndices = [];
|
|
145
|
+
auxWitnessComputations = [];
|
|
145
146
|
// BN254 scalar field modulus - 1 (for representing -1)
|
|
146
147
|
// Fr modulus = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001
|
|
147
148
|
// -1 mod Fr = Fr - 1
|
|
148
149
|
NEG_ONE = "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000";
|
|
150
|
+
// Number of bits for range checks (64 bits handles values up to ~18 quintillion)
|
|
151
|
+
COMPARISON_BITS = 64;
|
|
149
152
|
/**
|
|
150
153
|
* Build R1CS definition from the parsed circuit
|
|
151
154
|
*/
|
|
@@ -158,7 +161,8 @@ var init_R1csBuilder = __esm({
|
|
|
158
161
|
num_witnesses: this.nextWitnessIdx,
|
|
159
162
|
public_inputs: this.publicIndices,
|
|
160
163
|
private_inputs: this.privateIndices,
|
|
161
|
-
constraints: this.constraints
|
|
164
|
+
constraints: this.constraints,
|
|
165
|
+
auxWitnessComputations: this.auxWitnessComputations.length > 0 ? this.auxWitnessComputations : void 0
|
|
162
166
|
};
|
|
163
167
|
}
|
|
164
168
|
/**
|
|
@@ -255,13 +259,18 @@ var init_R1csBuilder = __esm({
|
|
|
255
259
|
throw new Error(
|
|
256
260
|
`Arithmetic operator ${operator} must be part of an equality assertion. Use: assert(a ${operator} b == c)`
|
|
257
261
|
);
|
|
258
|
-
case "
|
|
262
|
+
case ">=":
|
|
263
|
+
this.processGreaterThanOrEqual(left, right);
|
|
264
|
+
break;
|
|
259
265
|
case ">":
|
|
266
|
+
this.processGreaterThan(left, right);
|
|
267
|
+
break;
|
|
260
268
|
case "<=":
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
);
|
|
269
|
+
this.processGreaterThanOrEqual(right, left);
|
|
270
|
+
break;
|
|
271
|
+
case "<":
|
|
272
|
+
this.processGreaterThan(right, left);
|
|
273
|
+
break;
|
|
265
274
|
case "&":
|
|
266
275
|
case "|":
|
|
267
276
|
throw new Error(
|
|
@@ -368,6 +377,105 @@ var init_R1csBuilder = __esm({
|
|
|
368
377
|
// = c
|
|
369
378
|
});
|
|
370
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Process greater than or equal: assert(a >= b)
|
|
382
|
+
* Uses bit decomposition to prove that a - b is non-negative.
|
|
383
|
+
*
|
|
384
|
+
* The approach:
|
|
385
|
+
* 1. Create diff = a - b
|
|
386
|
+
* 2. Decompose diff into COMPARISON_BITS bits
|
|
387
|
+
* 3. For each bit: bit_i * (1 - bit_i) = 0 (ensures 0 or 1)
|
|
388
|
+
* 4. Sum of bits * powers of 2 = diff
|
|
389
|
+
*
|
|
390
|
+
* If decomposition succeeds, diff is in [0, 2^COMPARISON_BITS - 1], so a >= b
|
|
391
|
+
*/
|
|
392
|
+
processGreaterThanOrEqual(left, right) {
|
|
393
|
+
const leftIdx = this.getOrCreateWitness(left);
|
|
394
|
+
const rightIdx = this.getOrCreateWitness(right);
|
|
395
|
+
const diffIdx = this.nextWitnessIdx++;
|
|
396
|
+
this.auxWitnessComputations.push({
|
|
397
|
+
type: "subtract",
|
|
398
|
+
targetIdx: diffIdx,
|
|
399
|
+
leftIdx,
|
|
400
|
+
rightIdx
|
|
401
|
+
});
|
|
402
|
+
this.constraints.push({
|
|
403
|
+
a: [
|
|
404
|
+
["0x1", leftIdx],
|
|
405
|
+
[this.NEG_ONE, rightIdx]
|
|
406
|
+
],
|
|
407
|
+
b: [["0x1", 0]],
|
|
408
|
+
// * 1
|
|
409
|
+
c: [["0x1", diffIdx]]
|
|
410
|
+
});
|
|
411
|
+
this.addBitDecompositionConstraints(diffIdx);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Process greater than: assert(a > b)
|
|
415
|
+
* Equivalent to assert(a - b - 1 >= 0), or assert(a >= b + 1)
|
|
416
|
+
*/
|
|
417
|
+
processGreaterThan(left, right) {
|
|
418
|
+
const leftIdx = this.getOrCreateWitness(left);
|
|
419
|
+
const rightIdx = this.getOrCreateWitness(right);
|
|
420
|
+
const diffIdx = this.nextWitnessIdx++;
|
|
421
|
+
this.auxWitnessComputations.push({
|
|
422
|
+
type: "subtract",
|
|
423
|
+
targetIdx: diffIdx,
|
|
424
|
+
leftIdx,
|
|
425
|
+
rightIdx,
|
|
426
|
+
offset: -1
|
|
427
|
+
// For > operator: diff = left - right - 1
|
|
428
|
+
});
|
|
429
|
+
this.constraints.push({
|
|
430
|
+
a: [
|
|
431
|
+
["0x1", leftIdx],
|
|
432
|
+
[this.NEG_ONE, rightIdx],
|
|
433
|
+
[this.NEG_ONE, 0]
|
|
434
|
+
// -1 (using w_0 = 1)
|
|
435
|
+
],
|
|
436
|
+
b: [["0x1", 0]],
|
|
437
|
+
// * 1
|
|
438
|
+
c: [["0x1", diffIdx]]
|
|
439
|
+
});
|
|
440
|
+
this.addBitDecompositionConstraints(diffIdx);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Add bit decomposition constraints for a value.
|
|
444
|
+
* Creates COMPARISON_BITS witnesses for the bits and constrains:
|
|
445
|
+
* 1. Each bit is 0 or 1: bit * (1 - bit) = 0
|
|
446
|
+
* 2. Sum of bits * 2^i = value
|
|
447
|
+
*/
|
|
448
|
+
addBitDecompositionConstraints(valueIdx) {
|
|
449
|
+
const bitIndices = [];
|
|
450
|
+
for (let i = 0; i < this.COMPARISON_BITS; i++) {
|
|
451
|
+
const bitIdx = this.nextWitnessIdx++;
|
|
452
|
+
bitIndices.push(bitIdx);
|
|
453
|
+
this.constraints.push({
|
|
454
|
+
a: [["0x1", bitIdx]],
|
|
455
|
+
b: [["0x1", bitIdx]],
|
|
456
|
+
c: [["0x1", bitIdx]]
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
this.auxWitnessComputations.push({
|
|
460
|
+
type: "bit_decompose",
|
|
461
|
+
targetIdx: bitIndices[0],
|
|
462
|
+
// First bit index (for reference)
|
|
463
|
+
sourceIdx: valueIdx,
|
|
464
|
+
bitIndices,
|
|
465
|
+
numBits: this.COMPARISON_BITS
|
|
466
|
+
});
|
|
467
|
+
const sumTerms = [];
|
|
468
|
+
for (let i = 0; i < this.COMPARISON_BITS; i++) {
|
|
469
|
+
const coeff = (1n << BigInt(i)).toString(16);
|
|
470
|
+
sumTerms.push([`0x${coeff}`, bitIndices[i]]);
|
|
471
|
+
}
|
|
472
|
+
this.constraints.push({
|
|
473
|
+
a: sumTerms,
|
|
474
|
+
b: [["0x1", 0]],
|
|
475
|
+
// * 1
|
|
476
|
+
c: [["0x1", valueIdx]]
|
|
477
|
+
});
|
|
478
|
+
}
|
|
371
479
|
/**
|
|
372
480
|
* Process a variable declaration: let x = expr
|
|
373
481
|
* Creates a new witness for x and adds constraint if needed
|
|
@@ -789,6 +897,15 @@ authors = [""]
|
|
|
789
897
|
const strVal = String(value);
|
|
790
898
|
witnessMap[r1csIndex.toString()] = strVal;
|
|
791
899
|
}
|
|
900
|
+
const r1cs = JSON.parse(circuit.r1csJson);
|
|
901
|
+
if (r1cs.auxWitnessComputations && r1cs.auxWitnessComputations.length > 0) {
|
|
902
|
+
console.log("=== AUXILIARY WITNESS COMPUTATION ===");
|
|
903
|
+
console.log("Input witnesses:", JSON.stringify(witnessMap, null, 2));
|
|
904
|
+
console.log("Computations:", JSON.stringify(r1cs.auxWitnessComputations, null, 2));
|
|
905
|
+
this.computeAuxiliaryWitnesses(witnessMap, r1cs.auxWitnessComputations);
|
|
906
|
+
console.log("After aux computation:", JSON.stringify(witnessMap, null, 2));
|
|
907
|
+
console.log("=====================================");
|
|
908
|
+
}
|
|
792
909
|
const witnessJson = JSON.stringify(witnessMap);
|
|
793
910
|
let provingKey = circuit.provingKey;
|
|
794
911
|
if (!provingKey) {
|
|
@@ -841,6 +958,63 @@ authors = [""]
|
|
|
841
958
|
publicInputs.length
|
|
842
959
|
);
|
|
843
960
|
}
|
|
961
|
+
/**
|
|
962
|
+
* Compute auxiliary witnesses based on computation instructions from R1csBuilder.
|
|
963
|
+
* This handles witnesses that noir_js cannot compute (e.g., bit decomposition for >= operator).
|
|
964
|
+
*/
|
|
965
|
+
computeAuxiliaryWitnesses(witnessMap, computations) {
|
|
966
|
+
const FR_MODULUS = BigInt("0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
|
|
967
|
+
const getWitnessValue = (idx) => {
|
|
968
|
+
if (idx === 0) return 1n;
|
|
969
|
+
const val = witnessMap[idx.toString()];
|
|
970
|
+
if (val === void 0) {
|
|
971
|
+
throw new Error(`Witness w_${idx} not found`);
|
|
972
|
+
}
|
|
973
|
+
if (val.startsWith("0x")) {
|
|
974
|
+
return BigInt(val);
|
|
975
|
+
}
|
|
976
|
+
return BigInt(val);
|
|
977
|
+
};
|
|
978
|
+
const setWitnessValue = (idx, val) => {
|
|
979
|
+
const normalized = (val % FR_MODULUS + FR_MODULUS) % FR_MODULUS;
|
|
980
|
+
witnessMap[idx.toString()] = "0x" + normalized.toString(16);
|
|
981
|
+
};
|
|
982
|
+
for (const comp of computations) {
|
|
983
|
+
switch (comp.type) {
|
|
984
|
+
case "subtract": {
|
|
985
|
+
const left = getWitnessValue(comp.leftIdx);
|
|
986
|
+
const right = getWitnessValue(comp.rightIdx);
|
|
987
|
+
const offset = BigInt(comp.offset ?? 0);
|
|
988
|
+
const result = left - right + offset;
|
|
989
|
+
setWitnessValue(comp.targetIdx, result);
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
case "bit_decompose": {
|
|
993
|
+
const source = getWitnessValue(comp.sourceIdx);
|
|
994
|
+
const bitIndices = comp.bitIndices;
|
|
995
|
+
const numBits = comp.numBits;
|
|
996
|
+
if (source < 0n) {
|
|
997
|
+
throw new Error(
|
|
998
|
+
`Bit decomposition failed: value ${source} is negative. This means the comparison constraint is not satisfied.`
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
const maxVal = (1n << BigInt(numBits)) - 1n;
|
|
1002
|
+
if (source > maxVal) {
|
|
1003
|
+
throw new Error(
|
|
1004
|
+
`Bit decomposition failed: value ${source} exceeds ${numBits} bits (max: ${maxVal}). Consider using a larger bit width or smaller values.`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
for (let i = 0; i < numBits; i++) {
|
|
1008
|
+
const bit = source >> BigInt(i) & 1n;
|
|
1009
|
+
setWitnessValue(bitIndices[i], bit);
|
|
1010
|
+
}
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
default:
|
|
1014
|
+
throw new Error(`Unknown auxiliary witness computation type: ${comp.type}`);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
844
1018
|
/**
|
|
845
1019
|
* Get the verifying key in gnark format for on-chain deployment
|
|
846
1020
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { I as IChainFormatter } from './wasmInit-Wyynuk6r.cjs';
|
|
|
2
2
|
export { C as ChainProofDataFor, D as DeployResult, a as IziNoir, S as SolanaDeployData, V as VerifyOnChainResult, W as WalletAdapter, i as initNoirWasm, b as isWasmInitialized, m as markWasmInitialized } from './wasmInit-Wyynuk6r.cjs';
|
|
3
3
|
import { P as ProofData, S as SolanaProofData, a as CircuitFunction, I as InputValue, b as ProofResult } from './types-CxkI04bP.cjs';
|
|
4
4
|
export { C as CompileResult, c as ProofTimings, d as ProverOptions, e as VerifierOptions, V as VerifyingKeyData } from './types-CxkI04bP.cjs';
|
|
5
|
-
import {
|
|
5
|
+
import { g as ParsedCircuit, c as CircuitMetadata, S as SolanaChainMetadata, I as IProvingSystem } from './IProvingSystem-SfzgcbqH.cjs';
|
|
6
6
|
export { A as AssertStatement, B as BinaryExpr, o as BinaryOperator, e as Chain, b as ChainId, h as ChainMetadata, d as ChainMetadataFor, l as CircuitParam, C as CircuitPaths, f as CompileOptions, E as EthereumChainMetadata, m as Expr, i as ICompiler, j as IProver, k as IVerifier, n as IdentifierExpr, a as IziNoirConfig, L as LiteralExpr, M as MemberExpr, q as NETWORK_CONFIG, N as Network, t as NetworkConfig, P as Provider, p as Statement, s as getExplorerAccountUrl, r as getExplorerTxUrl } from './IProvingSystem-SfzgcbqH.cjs';
|
|
7
7
|
import { ArkworksWasm, ArkworksWasmConfig } from './providers/arkworks.cjs';
|
|
8
8
|
export { ArkworksCompiledCircuit, ArkworksProofResult, ArkworksSetupResult, ArkworksWasmModule, isArkworksCircuit } from './providers/arkworks.cjs';
|
|
@@ -11,60 +11,6 @@ export { CompiledCircuit, InputMap } from '@noir-lang/types';
|
|
|
11
11
|
export { Barretenberg } from './providers/barretenberg.cjs';
|
|
12
12
|
export { IZI_NOIR_PROGRAM_ID, buildInitVkFromBytesData, buildVerifyProofData, calculateVkAccountRent, calculateVkAccountSize, parseProof, parsePublicInputs, parseVerifyingKey } from './providers/solana.cjs';
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Formatter for Solana-compatible proof data.
|
|
16
|
-
*
|
|
17
|
-
* Converts generic ProofData into SolanaProofData format with:
|
|
18
|
-
* - Verifying key in gnark format (compatible with gnark-verifier-solana)
|
|
19
|
-
* - Proof bytes (256 bytes Groth16)
|
|
20
|
-
* - Public inputs as 32-byte arrays
|
|
21
|
-
* - VK account size and rent estimates
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const formatter = new SolanaFormatter(arkworksProvider);
|
|
26
|
-
* const solanaProof = await formatter.formatProof(proofData, circuit, metadata);
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
30
|
-
private arkworksProvider;
|
|
31
|
-
readonly chainId: "solana";
|
|
32
|
-
constructor(arkworksProvider: ArkworksWasm);
|
|
33
|
-
/**
|
|
34
|
-
* Format a generic proof for Solana on-chain verification.
|
|
35
|
-
*
|
|
36
|
-
* @param proofData - Generic proof data from Arkworks
|
|
37
|
-
* @param circuit - The compiled circuit (must be Arkworks circuit)
|
|
38
|
-
* @param metadata - Circuit metadata with public input count
|
|
39
|
-
* @returns SolanaProofData ready for on-chain verification
|
|
40
|
-
*/
|
|
41
|
-
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<SolanaProofData>;
|
|
42
|
-
/**
|
|
43
|
-
* Get Solana-specific metadata for a circuit.
|
|
44
|
-
*
|
|
45
|
-
* @param publicInputCount - Number of public inputs in the circuit
|
|
46
|
-
* @returns Solana metadata with account size and rent estimates
|
|
47
|
-
*/
|
|
48
|
-
getChainMetadata(publicInputCount: number): SolanaChainMetadata;
|
|
49
|
-
/**
|
|
50
|
-
* Calculate the size of a VK account for a given number of public inputs.
|
|
51
|
-
* Matches the Rust `vk_account_size` function in the Solana program.
|
|
52
|
-
*/
|
|
53
|
-
private calculateVkAccountSize;
|
|
54
|
-
/**
|
|
55
|
-
* Calculate the minimum rent for a VK account.
|
|
56
|
-
*/
|
|
57
|
-
private calculateVkAccountRent;
|
|
58
|
-
/**
|
|
59
|
-
* Convert Uint8Array to base64 string.
|
|
60
|
-
*/
|
|
61
|
-
private uint8ArrayToBase64;
|
|
62
|
-
/**
|
|
63
|
-
* Convert hex string to Uint8Array.
|
|
64
|
-
*/
|
|
65
|
-
private hexToBytes;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
14
|
/**
|
|
69
15
|
* R1csBuilder - Generates R1CS constraints from ParsedCircuit
|
|
70
16
|
*
|
|
@@ -88,6 +34,28 @@ interface R1csConstraint {
|
|
|
88
34
|
b: [string, number][];
|
|
89
35
|
c: [string, number][];
|
|
90
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Auxiliary witness computation instruction
|
|
39
|
+
* Tells the prover how to compute auxiliary witnesses from input witnesses
|
|
40
|
+
*/
|
|
41
|
+
interface AuxWitnessComputation {
|
|
42
|
+
/** Type of computation */
|
|
43
|
+
type: 'subtract' | 'bit_decompose';
|
|
44
|
+
/** Witness index to compute */
|
|
45
|
+
targetIdx: number;
|
|
46
|
+
/** For 'subtract': left operand witness index */
|
|
47
|
+
leftIdx?: number;
|
|
48
|
+
/** For 'subtract': right operand witness index */
|
|
49
|
+
rightIdx?: number;
|
|
50
|
+
/** For 'subtract': additional constant offset to subtract (e.g., -1 for > operator) */
|
|
51
|
+
offset?: number;
|
|
52
|
+
/** For 'bit_decompose': source value witness index */
|
|
53
|
+
sourceIdx?: number;
|
|
54
|
+
/** For 'bit_decompose': array of bit witness indices (LSB first) */
|
|
55
|
+
bitIndices?: number[];
|
|
56
|
+
/** For 'bit_decompose': number of bits */
|
|
57
|
+
numBits?: number;
|
|
58
|
+
}
|
|
91
59
|
/**
|
|
92
60
|
* Complete R1CS definition for arkworks-groth16-wasm
|
|
93
61
|
*/
|
|
@@ -96,6 +64,8 @@ interface R1csDefinition {
|
|
|
96
64
|
public_inputs: number[];
|
|
97
65
|
private_inputs: number[];
|
|
98
66
|
constraints: R1csConstraint[];
|
|
67
|
+
/** Instructions for computing auxiliary witnesses */
|
|
68
|
+
auxWitnessComputations?: AuxWitnessComputation[];
|
|
99
69
|
}
|
|
100
70
|
/**
|
|
101
71
|
* Builds R1CS constraints from a ParsedCircuit
|
|
@@ -107,7 +77,9 @@ declare class R1csBuilder {
|
|
|
107
77
|
private nextWitnessIdx;
|
|
108
78
|
private publicIndices;
|
|
109
79
|
private privateIndices;
|
|
80
|
+
private auxWitnessComputations;
|
|
110
81
|
private readonly NEG_ONE;
|
|
82
|
+
private readonly COMPARISON_BITS;
|
|
111
83
|
constructor(parsedCircuit: ParsedCircuit);
|
|
112
84
|
/**
|
|
113
85
|
* Build R1CS definition from the parsed circuit
|
|
@@ -156,6 +128,31 @@ declare class R1csBuilder {
|
|
|
156
128
|
* R1CS: (a - b) * 1 = c
|
|
157
129
|
*/
|
|
158
130
|
private processSubtractionEquality;
|
|
131
|
+
/**
|
|
132
|
+
* Process greater than or equal: assert(a >= b)
|
|
133
|
+
* Uses bit decomposition to prove that a - b is non-negative.
|
|
134
|
+
*
|
|
135
|
+
* The approach:
|
|
136
|
+
* 1. Create diff = a - b
|
|
137
|
+
* 2. Decompose diff into COMPARISON_BITS bits
|
|
138
|
+
* 3. For each bit: bit_i * (1 - bit_i) = 0 (ensures 0 or 1)
|
|
139
|
+
* 4. Sum of bits * powers of 2 = diff
|
|
140
|
+
*
|
|
141
|
+
* If decomposition succeeds, diff is in [0, 2^COMPARISON_BITS - 1], so a >= b
|
|
142
|
+
*/
|
|
143
|
+
private processGreaterThanOrEqual;
|
|
144
|
+
/**
|
|
145
|
+
* Process greater than: assert(a > b)
|
|
146
|
+
* Equivalent to assert(a - b - 1 >= 0), or assert(a >= b + 1)
|
|
147
|
+
*/
|
|
148
|
+
private processGreaterThan;
|
|
149
|
+
/**
|
|
150
|
+
* Add bit decomposition constraints for a value.
|
|
151
|
+
* Creates COMPARISON_BITS witnesses for the bits and constrains:
|
|
152
|
+
* 1. Each bit is 0 or 1: bit * (1 - bit) = 0
|
|
153
|
+
* 2. Sum of bits * 2^i = value
|
|
154
|
+
*/
|
|
155
|
+
private addBitDecompositionConstraints;
|
|
159
156
|
/**
|
|
160
157
|
* Process a variable declaration: let x = expr
|
|
161
158
|
* Creates a new witness for x and adds constraint if needed
|
|
@@ -176,6 +173,60 @@ declare class R1csBuilder {
|
|
|
176
173
|
private getOrCreateWitness;
|
|
177
174
|
}
|
|
178
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Formatter for Solana-compatible proof data.
|
|
178
|
+
*
|
|
179
|
+
* Converts generic ProofData into SolanaProofData format with:
|
|
180
|
+
* - Verifying key in gnark format (compatible with gnark-verifier-solana)
|
|
181
|
+
* - Proof bytes (256 bytes Groth16)
|
|
182
|
+
* - Public inputs as 32-byte arrays
|
|
183
|
+
* - VK account size and rent estimates
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const formatter = new SolanaFormatter(arkworksProvider);
|
|
188
|
+
* const solanaProof = await formatter.formatProof(proofData, circuit, metadata);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
192
|
+
private arkworksProvider;
|
|
193
|
+
readonly chainId: "solana";
|
|
194
|
+
constructor(arkworksProvider: ArkworksWasm);
|
|
195
|
+
/**
|
|
196
|
+
* Format a generic proof for Solana on-chain verification.
|
|
197
|
+
*
|
|
198
|
+
* @param proofData - Generic proof data from Arkworks
|
|
199
|
+
* @param circuit - The compiled circuit (must be Arkworks circuit)
|
|
200
|
+
* @param metadata - Circuit metadata with public input count
|
|
201
|
+
* @returns SolanaProofData ready for on-chain verification
|
|
202
|
+
*/
|
|
203
|
+
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<SolanaProofData>;
|
|
204
|
+
/**
|
|
205
|
+
* Get Solana-specific metadata for a circuit.
|
|
206
|
+
*
|
|
207
|
+
* @param publicInputCount - Number of public inputs in the circuit
|
|
208
|
+
* @returns Solana metadata with account size and rent estimates
|
|
209
|
+
*/
|
|
210
|
+
getChainMetadata(publicInputCount: number): SolanaChainMetadata;
|
|
211
|
+
/**
|
|
212
|
+
* Calculate the size of a VK account for a given number of public inputs.
|
|
213
|
+
* Matches the Rust `vk_account_size` function in the Solana program.
|
|
214
|
+
*/
|
|
215
|
+
private calculateVkAccountSize;
|
|
216
|
+
/**
|
|
217
|
+
* Calculate the minimum rent for a VK account.
|
|
218
|
+
*/
|
|
219
|
+
private calculateVkAccountRent;
|
|
220
|
+
/**
|
|
221
|
+
* Convert Uint8Array to base64 string.
|
|
222
|
+
*/
|
|
223
|
+
private uint8ArrayToBase64;
|
|
224
|
+
/**
|
|
225
|
+
* Convert hex string to Uint8Array.
|
|
226
|
+
*/
|
|
227
|
+
private hexToBytes;
|
|
228
|
+
}
|
|
229
|
+
|
|
179
230
|
interface IParser {
|
|
180
231
|
parse(fn: CircuitFunction, publicInputs: InputValue[], privateInputs: InputValue[]): ParsedCircuit;
|
|
181
232
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { I as IChainFormatter } from './wasmInit-D3RyRKIC.js';
|
|
|
2
2
|
export { C as ChainProofDataFor, D as DeployResult, a as IziNoir, S as SolanaDeployData, V as VerifyOnChainResult, W as WalletAdapter, i as initNoirWasm, b as isWasmInitialized, m as markWasmInitialized } from './wasmInit-D3RyRKIC.js';
|
|
3
3
|
import { P as ProofData, S as SolanaProofData, a as CircuitFunction, I as InputValue, b as ProofResult } from './types-CxkI04bP.js';
|
|
4
4
|
export { C as CompileResult, c as ProofTimings, d as ProverOptions, e as VerifierOptions, V as VerifyingKeyData } from './types-CxkI04bP.js';
|
|
5
|
-
import {
|
|
5
|
+
import { g as ParsedCircuit, c as CircuitMetadata, S as SolanaChainMetadata, I as IProvingSystem } from './IProvingSystem-BKgFRl27.js';
|
|
6
6
|
export { A as AssertStatement, B as BinaryExpr, o as BinaryOperator, e as Chain, b as ChainId, h as ChainMetadata, d as ChainMetadataFor, l as CircuitParam, C as CircuitPaths, f as CompileOptions, E as EthereumChainMetadata, m as Expr, i as ICompiler, j as IProver, k as IVerifier, n as IdentifierExpr, a as IziNoirConfig, L as LiteralExpr, M as MemberExpr, q as NETWORK_CONFIG, N as Network, t as NetworkConfig, P as Provider, p as Statement, s as getExplorerAccountUrl, r as getExplorerTxUrl } from './IProvingSystem-BKgFRl27.js';
|
|
7
7
|
import { ArkworksWasm, ArkworksWasmConfig } from './providers/arkworks.js';
|
|
8
8
|
export { ArkworksCompiledCircuit, ArkworksProofResult, ArkworksSetupResult, ArkworksWasmModule, isArkworksCircuit } from './providers/arkworks.js';
|
|
@@ -11,60 +11,6 @@ export { CompiledCircuit, InputMap } from '@noir-lang/types';
|
|
|
11
11
|
export { Barretenberg } from './providers/barretenberg.js';
|
|
12
12
|
export { IZI_NOIR_PROGRAM_ID, buildInitVkFromBytesData, buildVerifyProofData, calculateVkAccountRent, calculateVkAccountSize, parseProof, parsePublicInputs, parseVerifyingKey } from './providers/solana.js';
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Formatter for Solana-compatible proof data.
|
|
16
|
-
*
|
|
17
|
-
* Converts generic ProofData into SolanaProofData format with:
|
|
18
|
-
* - Verifying key in gnark format (compatible with gnark-verifier-solana)
|
|
19
|
-
* - Proof bytes (256 bytes Groth16)
|
|
20
|
-
* - Public inputs as 32-byte arrays
|
|
21
|
-
* - VK account size and rent estimates
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const formatter = new SolanaFormatter(arkworksProvider);
|
|
26
|
-
* const solanaProof = await formatter.formatProof(proofData, circuit, metadata);
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
30
|
-
private arkworksProvider;
|
|
31
|
-
readonly chainId: "solana";
|
|
32
|
-
constructor(arkworksProvider: ArkworksWasm);
|
|
33
|
-
/**
|
|
34
|
-
* Format a generic proof for Solana on-chain verification.
|
|
35
|
-
*
|
|
36
|
-
* @param proofData - Generic proof data from Arkworks
|
|
37
|
-
* @param circuit - The compiled circuit (must be Arkworks circuit)
|
|
38
|
-
* @param metadata - Circuit metadata with public input count
|
|
39
|
-
* @returns SolanaProofData ready for on-chain verification
|
|
40
|
-
*/
|
|
41
|
-
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<SolanaProofData>;
|
|
42
|
-
/**
|
|
43
|
-
* Get Solana-specific metadata for a circuit.
|
|
44
|
-
*
|
|
45
|
-
* @param publicInputCount - Number of public inputs in the circuit
|
|
46
|
-
* @returns Solana metadata with account size and rent estimates
|
|
47
|
-
*/
|
|
48
|
-
getChainMetadata(publicInputCount: number): SolanaChainMetadata;
|
|
49
|
-
/**
|
|
50
|
-
* Calculate the size of a VK account for a given number of public inputs.
|
|
51
|
-
* Matches the Rust `vk_account_size` function in the Solana program.
|
|
52
|
-
*/
|
|
53
|
-
private calculateVkAccountSize;
|
|
54
|
-
/**
|
|
55
|
-
* Calculate the minimum rent for a VK account.
|
|
56
|
-
*/
|
|
57
|
-
private calculateVkAccountRent;
|
|
58
|
-
/**
|
|
59
|
-
* Convert Uint8Array to base64 string.
|
|
60
|
-
*/
|
|
61
|
-
private uint8ArrayToBase64;
|
|
62
|
-
/**
|
|
63
|
-
* Convert hex string to Uint8Array.
|
|
64
|
-
*/
|
|
65
|
-
private hexToBytes;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
14
|
/**
|
|
69
15
|
* R1csBuilder - Generates R1CS constraints from ParsedCircuit
|
|
70
16
|
*
|
|
@@ -88,6 +34,28 @@ interface R1csConstraint {
|
|
|
88
34
|
b: [string, number][];
|
|
89
35
|
c: [string, number][];
|
|
90
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Auxiliary witness computation instruction
|
|
39
|
+
* Tells the prover how to compute auxiliary witnesses from input witnesses
|
|
40
|
+
*/
|
|
41
|
+
interface AuxWitnessComputation {
|
|
42
|
+
/** Type of computation */
|
|
43
|
+
type: 'subtract' | 'bit_decompose';
|
|
44
|
+
/** Witness index to compute */
|
|
45
|
+
targetIdx: number;
|
|
46
|
+
/** For 'subtract': left operand witness index */
|
|
47
|
+
leftIdx?: number;
|
|
48
|
+
/** For 'subtract': right operand witness index */
|
|
49
|
+
rightIdx?: number;
|
|
50
|
+
/** For 'subtract': additional constant offset to subtract (e.g., -1 for > operator) */
|
|
51
|
+
offset?: number;
|
|
52
|
+
/** For 'bit_decompose': source value witness index */
|
|
53
|
+
sourceIdx?: number;
|
|
54
|
+
/** For 'bit_decompose': array of bit witness indices (LSB first) */
|
|
55
|
+
bitIndices?: number[];
|
|
56
|
+
/** For 'bit_decompose': number of bits */
|
|
57
|
+
numBits?: number;
|
|
58
|
+
}
|
|
91
59
|
/**
|
|
92
60
|
* Complete R1CS definition for arkworks-groth16-wasm
|
|
93
61
|
*/
|
|
@@ -96,6 +64,8 @@ interface R1csDefinition {
|
|
|
96
64
|
public_inputs: number[];
|
|
97
65
|
private_inputs: number[];
|
|
98
66
|
constraints: R1csConstraint[];
|
|
67
|
+
/** Instructions for computing auxiliary witnesses */
|
|
68
|
+
auxWitnessComputations?: AuxWitnessComputation[];
|
|
99
69
|
}
|
|
100
70
|
/**
|
|
101
71
|
* Builds R1CS constraints from a ParsedCircuit
|
|
@@ -107,7 +77,9 @@ declare class R1csBuilder {
|
|
|
107
77
|
private nextWitnessIdx;
|
|
108
78
|
private publicIndices;
|
|
109
79
|
private privateIndices;
|
|
80
|
+
private auxWitnessComputations;
|
|
110
81
|
private readonly NEG_ONE;
|
|
82
|
+
private readonly COMPARISON_BITS;
|
|
111
83
|
constructor(parsedCircuit: ParsedCircuit);
|
|
112
84
|
/**
|
|
113
85
|
* Build R1CS definition from the parsed circuit
|
|
@@ -156,6 +128,31 @@ declare class R1csBuilder {
|
|
|
156
128
|
* R1CS: (a - b) * 1 = c
|
|
157
129
|
*/
|
|
158
130
|
private processSubtractionEquality;
|
|
131
|
+
/**
|
|
132
|
+
* Process greater than or equal: assert(a >= b)
|
|
133
|
+
* Uses bit decomposition to prove that a - b is non-negative.
|
|
134
|
+
*
|
|
135
|
+
* The approach:
|
|
136
|
+
* 1. Create diff = a - b
|
|
137
|
+
* 2. Decompose diff into COMPARISON_BITS bits
|
|
138
|
+
* 3. For each bit: bit_i * (1 - bit_i) = 0 (ensures 0 or 1)
|
|
139
|
+
* 4. Sum of bits * powers of 2 = diff
|
|
140
|
+
*
|
|
141
|
+
* If decomposition succeeds, diff is in [0, 2^COMPARISON_BITS - 1], so a >= b
|
|
142
|
+
*/
|
|
143
|
+
private processGreaterThanOrEqual;
|
|
144
|
+
/**
|
|
145
|
+
* Process greater than: assert(a > b)
|
|
146
|
+
* Equivalent to assert(a - b - 1 >= 0), or assert(a >= b + 1)
|
|
147
|
+
*/
|
|
148
|
+
private processGreaterThan;
|
|
149
|
+
/**
|
|
150
|
+
* Add bit decomposition constraints for a value.
|
|
151
|
+
* Creates COMPARISON_BITS witnesses for the bits and constrains:
|
|
152
|
+
* 1. Each bit is 0 or 1: bit * (1 - bit) = 0
|
|
153
|
+
* 2. Sum of bits * 2^i = value
|
|
154
|
+
*/
|
|
155
|
+
private addBitDecompositionConstraints;
|
|
159
156
|
/**
|
|
160
157
|
* Process a variable declaration: let x = expr
|
|
161
158
|
* Creates a new witness for x and adds constraint if needed
|
|
@@ -176,6 +173,60 @@ declare class R1csBuilder {
|
|
|
176
173
|
private getOrCreateWitness;
|
|
177
174
|
}
|
|
178
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Formatter for Solana-compatible proof data.
|
|
178
|
+
*
|
|
179
|
+
* Converts generic ProofData into SolanaProofData format with:
|
|
180
|
+
* - Verifying key in gnark format (compatible with gnark-verifier-solana)
|
|
181
|
+
* - Proof bytes (256 bytes Groth16)
|
|
182
|
+
* - Public inputs as 32-byte arrays
|
|
183
|
+
* - VK account size and rent estimates
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const formatter = new SolanaFormatter(arkworksProvider);
|
|
188
|
+
* const solanaProof = await formatter.formatProof(proofData, circuit, metadata);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
192
|
+
private arkworksProvider;
|
|
193
|
+
readonly chainId: "solana";
|
|
194
|
+
constructor(arkworksProvider: ArkworksWasm);
|
|
195
|
+
/**
|
|
196
|
+
* Format a generic proof for Solana on-chain verification.
|
|
197
|
+
*
|
|
198
|
+
* @param proofData - Generic proof data from Arkworks
|
|
199
|
+
* @param circuit - The compiled circuit (must be Arkworks circuit)
|
|
200
|
+
* @param metadata - Circuit metadata with public input count
|
|
201
|
+
* @returns SolanaProofData ready for on-chain verification
|
|
202
|
+
*/
|
|
203
|
+
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<SolanaProofData>;
|
|
204
|
+
/**
|
|
205
|
+
* Get Solana-specific metadata for a circuit.
|
|
206
|
+
*
|
|
207
|
+
* @param publicInputCount - Number of public inputs in the circuit
|
|
208
|
+
* @returns Solana metadata with account size and rent estimates
|
|
209
|
+
*/
|
|
210
|
+
getChainMetadata(publicInputCount: number): SolanaChainMetadata;
|
|
211
|
+
/**
|
|
212
|
+
* Calculate the size of a VK account for a given number of public inputs.
|
|
213
|
+
* Matches the Rust `vk_account_size` function in the Solana program.
|
|
214
|
+
*/
|
|
215
|
+
private calculateVkAccountSize;
|
|
216
|
+
/**
|
|
217
|
+
* Calculate the minimum rent for a VK account.
|
|
218
|
+
*/
|
|
219
|
+
private calculateVkAccountRent;
|
|
220
|
+
/**
|
|
221
|
+
* Convert Uint8Array to base64 string.
|
|
222
|
+
*/
|
|
223
|
+
private uint8ArrayToBase64;
|
|
224
|
+
/**
|
|
225
|
+
* Convert hex string to Uint8Array.
|
|
226
|
+
*/
|
|
227
|
+
private hexToBytes;
|
|
228
|
+
}
|
|
229
|
+
|
|
179
230
|
interface IParser {
|
|
180
231
|
parse(fn: CircuitFunction, publicInputs: InputValue[], privateInputs: InputValue[]): ParsedCircuit;
|
|
181
232
|
}
|