create-izi-noir 0.2.14 → 0.2.16
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.js +53 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -316,7 +316,7 @@ function createGitProgress() {
|
|
|
316
316
|
function generatePackageJson(options) {
|
|
317
317
|
const isSolana = options.provider === "arkworks";
|
|
318
318
|
const dependencies = {
|
|
319
|
-
"@izi-noir/sdk": "^0.1.
|
|
319
|
+
"@izi-noir/sdk": "^0.1.11",
|
|
320
320
|
"@noir-lang/acvm_js": "1.0.0-beta.13-1d260df.nightly",
|
|
321
321
|
"@noir-lang/noirc_abi": "1.0.0-beta.13-1d260df.nightly",
|
|
322
322
|
"react": "^18.3.1",
|
|
@@ -393,39 +393,41 @@ function generateTsconfig() {
|
|
|
393
393
|
// src/generators/circuits.ts
|
|
394
394
|
function generateBalanceProof() {
|
|
395
395
|
return `/**
|
|
396
|
-
*
|
|
396
|
+
* Square Proof Circuit
|
|
397
397
|
*
|
|
398
|
-
* Proves
|
|
399
|
-
*
|
|
398
|
+
* Proves knowledge of a secret number whose square equals a public value.
|
|
399
|
+
* This is a fundamental ZK proof pattern that demonstrates the SDK capabilities.
|
|
400
400
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
401
|
+
* Example: To prove you know the secret 7, set expected = 49 (7\xB2)
|
|
402
|
+
*
|
|
403
|
+
* @param expected - The expected result (secret\xB2) (public)
|
|
404
|
+
* @param secret - The secret number to prove (private, not revealed)
|
|
403
405
|
*/
|
|
404
406
|
export function balanceProof(
|
|
405
|
-
[
|
|
406
|
-
[
|
|
407
|
+
[expected]: [number],
|
|
408
|
+
[secret]: [number]
|
|
407
409
|
): void {
|
|
408
|
-
assert(
|
|
410
|
+
assert(secret * secret == expected);
|
|
409
411
|
}
|
|
410
412
|
`;
|
|
411
413
|
}
|
|
412
414
|
function generateAgeProof() {
|
|
413
415
|
return `/**
|
|
414
|
-
*
|
|
416
|
+
* Another Square Proof Circuit
|
|
415
417
|
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
+
* Another example proving knowledge of a secret whose square equals a public value.
|
|
419
|
+
* This demonstrates the same ZK pattern with different default values.
|
|
418
420
|
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* @param
|
|
421
|
+
* Example: To prove you know the secret 4, set expected = 16 (4\xB2)
|
|
422
|
+
*
|
|
423
|
+
* @param expected - The expected result (secret\xB2) (public)
|
|
424
|
+
* @param secret - The secret square root to prove (private, not revealed)
|
|
422
425
|
*/
|
|
423
426
|
export function ageProof(
|
|
424
|
-
[
|
|
425
|
-
[
|
|
427
|
+
[expected]: [number],
|
|
428
|
+
[secret]: [number]
|
|
426
429
|
): void {
|
|
427
|
-
|
|
428
|
-
assert(age >= minAge);
|
|
430
|
+
assert(secret * secret == expected);
|
|
429
431
|
}
|
|
430
432
|
`;
|
|
431
433
|
}
|
|
@@ -433,18 +435,20 @@ function generateMinimalCircuit() {
|
|
|
433
435
|
return `/**
|
|
434
436
|
* My Custom Circuit
|
|
435
437
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
+
* A minimal ZK proof that proves knowledge of a secret whose square
|
|
439
|
+
* equals the public expected value.
|
|
438
440
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
+
* Replace with your own circuit logic using assert() statements.
|
|
442
|
+
*
|
|
443
|
+
* @param expected - The expected result (secret\xB2) (public)
|
|
444
|
+
* @param secret - The secret value to prove (private, not revealed)
|
|
441
445
|
*/
|
|
442
446
|
export function myCircuit(
|
|
443
|
-
[
|
|
444
|
-
[
|
|
447
|
+
[expected]: [number],
|
|
448
|
+
[secret]: [number]
|
|
445
449
|
): void {
|
|
446
|
-
//
|
|
447
|
-
assert(
|
|
450
|
+
// Prove that secret\xB2 = expected
|
|
451
|
+
assert(secret * secret == expected);
|
|
448
452
|
}
|
|
449
453
|
`;
|
|
450
454
|
}
|
|
@@ -891,6 +895,7 @@ import {
|
|
|
891
895
|
markWasmInitialized,
|
|
892
896
|
AcornParser,
|
|
893
897
|
generateNoir,
|
|
898
|
+
type ParsedCircuit,
|
|
894
899
|
} from '@izi-noir/sdk';${solanaImports}
|
|
895
900
|
import { CodeBlock } from './components/CodeBlock';
|
|
896
901
|
${circuitImports}
|
|
@@ -942,6 +947,7 @@ function App() {
|
|
|
942
947
|
// IziNoir instance and compiled code tracking
|
|
943
948
|
const [iziInstance, setIziInstance] = useState<IziNoir | null>(null);
|
|
944
949
|
const [compiledNoirCode, setCompiledNoirCode] = useState<string | null>(null);
|
|
950
|
+
const [parsedCircuit, setParsedCircuit] = useState<ParsedCircuit | null>(null);
|
|
945
951
|
${solanaHooks}
|
|
946
952
|
${solanaState}
|
|
947
953
|
|
|
@@ -959,7 +965,8 @@ ${solanaState}
|
|
|
959
965
|
setNoirCode(null);
|
|
960
966
|
// Reset compiled instance (forces recompilation)
|
|
961
967
|
setIziInstance(null);
|
|
962
|
-
setCompiledNoirCode(null)
|
|
968
|
+
setCompiledNoirCode(null);
|
|
969
|
+
setParsedCircuit(null);${solanaCircuitResetCode}
|
|
963
970
|
}
|
|
964
971
|
}, [selectedCircuit]);
|
|
965
972
|
|
|
@@ -979,9 +986,10 @@ ${solanaState}
|
|
|
979
986
|
.filter(([key]) => circuit.privateInputKeys.includes(key))
|
|
980
987
|
.map(([, val]) => Number(val));
|
|
981
988
|
|
|
982
|
-
const
|
|
983
|
-
const result = generateNoir(
|
|
989
|
+
const parsed = parser.parse(circuit.fn, publicInputs, privateInputs);
|
|
990
|
+
const result = generateNoir(parsed);
|
|
984
991
|
setNoirCode(result);
|
|
992
|
+
setParsedCircuit(parsed);
|
|
985
993
|
} catch (error) {
|
|
986
994
|
setTranspileError((error as Error).message);
|
|
987
995
|
setNoirCode(null);
|
|
@@ -1016,7 +1024,8 @@ ${solanaState}
|
|
|
1016
1024
|
provider: Provider.${capitalizeFirst(options.provider)},${solanaProviderConfig}
|
|
1017
1025
|
});
|
|
1018
1026
|
|
|
1019
|
-
|
|
1027
|
+
// Pass parsedCircuit for dynamic R1CS generation
|
|
1028
|
+
await izi.compile(noirCode, parsedCircuit ? { parsedCircuit } : undefined);
|
|
1020
1029
|
setIziInstance(izi);
|
|
1021
1030
|
setCompiledNoirCode(noirCode);${solanaRecompileResetCode}
|
|
1022
1031
|
}
|
|
@@ -1045,7 +1054,7 @@ ${solanaState}
|
|
|
1045
1054
|
} finally {
|
|
1046
1055
|
setIsGenerating(false);
|
|
1047
1056
|
}
|
|
1048
|
-
}, [noirCode, inputs, iziInstance, compiledNoirCode]);
|
|
1057
|
+
}, [noirCode, inputs, iziInstance, compiledNoirCode, parsedCircuit]);
|
|
1049
1058
|
${solanaHandlers}
|
|
1050
1059
|
|
|
1051
1060
|
return (
|
|
@@ -1177,9 +1186,9 @@ function getCircuitOptions(template) {
|
|
|
1177
1186
|
{
|
|
1178
1187
|
name: 'myCircuit',
|
|
1179
1188
|
fn: myCircuit,
|
|
1180
|
-
publicInputKeys: ['
|
|
1181
|
-
privateInputKeys: ['
|
|
1182
|
-
defaultInputs: {
|
|
1189
|
+
publicInputKeys: ['expected'],
|
|
1190
|
+
privateInputKeys: ['secret'],
|
|
1191
|
+
defaultInputs: { expected: '49', secret: '7' },
|
|
1183
1192
|
},
|
|
1184
1193
|
]`;
|
|
1185
1194
|
case "balance-proof":
|
|
@@ -1187,9 +1196,9 @@ function getCircuitOptions(template) {
|
|
|
1187
1196
|
{
|
|
1188
1197
|
name: 'balanceProof',
|
|
1189
1198
|
fn: balanceProof,
|
|
1190
|
-
publicInputKeys: ['
|
|
1191
|
-
privateInputKeys: ['
|
|
1192
|
-
defaultInputs: {
|
|
1199
|
+
publicInputKeys: ['expected'],
|
|
1200
|
+
privateInputKeys: ['secret'],
|
|
1201
|
+
defaultInputs: { expected: '49', secret: '7' },
|
|
1193
1202
|
},
|
|
1194
1203
|
]`;
|
|
1195
1204
|
default:
|
|
@@ -1197,16 +1206,16 @@ function getCircuitOptions(template) {
|
|
|
1197
1206
|
{
|
|
1198
1207
|
name: 'balanceProof',
|
|
1199
1208
|
fn: balanceProof,
|
|
1200
|
-
publicInputKeys: ['
|
|
1201
|
-
privateInputKeys: ['
|
|
1202
|
-
defaultInputs: {
|
|
1209
|
+
publicInputKeys: ['expected'],
|
|
1210
|
+
privateInputKeys: ['secret'],
|
|
1211
|
+
defaultInputs: { expected: '49', secret: '7' },
|
|
1203
1212
|
},
|
|
1204
1213
|
{
|
|
1205
1214
|
name: 'ageProof',
|
|
1206
1215
|
fn: ageProof,
|
|
1207
|
-
publicInputKeys: ['
|
|
1208
|
-
privateInputKeys: ['
|
|
1209
|
-
defaultInputs: {
|
|
1216
|
+
publicInputKeys: ['expected'],
|
|
1217
|
+
privateInputKeys: ['secret'],
|
|
1218
|
+
defaultInputs: { expected: '16', secret: '4' },
|
|
1210
1219
|
},
|
|
1211
1220
|
]`;
|
|
1212
1221
|
}
|