@aztec/bb.js 0.0.0-devnet → 0.0.0-test.1
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/README.md +10 -2
- package/dest/browser/522.6386c00ebfb22619e11b.js +3 -0
- package/dest/browser/barretenberg/backend.d.ts +7 -2
- package/dest/browser/barretenberg/backend.d.ts.map +1 -1
- package/dest/browser/barretenberg/index.d.ts +6 -2
- package/dest/browser/barretenberg/index.d.ts.map +1 -1
- package/dest/browser/barretenberg-threads.js +32 -0
- package/dest/browser/barretenberg.js +32 -0
- package/dest/browser/barretenberg_api/index.d.ts +5 -2
- package/dest/browser/barretenberg_api/index.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
- package/dest/browser/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
- package/dest/browser/barretenberg_wasm/index.d.ts +2 -2
- package/dest/browser/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/browser/bigint-array/index.d.ts +17 -2
- package/dest/browser/bigint-array/index.d.ts.map +1 -1
- package/dest/browser/crs/net_crs.d.ts.map +1 -1
- package/dest/browser/crs/node/index.d.ts +6 -4
- package/dest/browser/crs/node/index.d.ts.map +1 -1
- package/dest/browser/index.d.ts.map +1 -1
- package/dest/browser/index.js +10583 -16082
- package/dest/browser/index.js.LICENSE.txt +16 -0
- package/dest/browser/main.worker.worker.js.LICENSE.txt +5 -0
- package/dest/browser/proof/index.d.ts +10 -0
- package/dest/browser/proof/index.d.ts.map +1 -1
- package/dest/browser/retry/index.d.ts +26 -0
- package/dest/browser/retry/index.d.ts.map +1 -0
- package/dest/browser/thread.worker.worker.js.LICENSE.txt +5 -0
- package/dest/browser/thread.worker.worker.worker.js.LICENSE.txt +5 -0
- package/dest/browser/types/fields.d.ts +6 -5
- package/dest/browser/types/fields.d.ts.map +1 -1
- package/dest/node/barretenberg/__snapshots__/pedersen.test.js.snap +156 -0
- package/dest/node/barretenberg/__snapshots__/poseidon.test.js.snap +40 -0
- package/dest/node/barretenberg/backend.d.ts +7 -2
- package/dest/node/barretenberg/backend.d.ts.map +1 -1
- package/dest/node/barretenberg/backend.js +54 -4
- package/dest/node/barretenberg/blake2s.test.js +2 -2
- package/dest/node/barretenberg/index.d.ts +6 -2
- package/dest/node/barretenberg/index.d.ts.map +1 -1
- package/dest/node/barretenberg/index.js +15 -20
- package/dest/node/barretenberg/pedersen.test.js +2 -2
- package/dest/node/barretenberg/poseidon.test.js +2 -2
- package/dest/node/barretenberg_api/index.d.ts +5 -2
- package/dest/node/barretenberg_api/index.d.ts.map +1 -1
- package/dest/node/barretenberg_api/index.js +32 -2
- package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -6
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.js +16 -11
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js +7 -9
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +3 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/barretenberg.js +3 -0
- package/dest/node/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
- package/dest/node/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/fetch_code/browser/index.js +31 -8
- package/dest/node/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
- package/dest/node/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/fetch_code/node/index.js +3 -3
- package/dest/node/barretenberg_wasm/index.d.ts +2 -2
- package/dest/node/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/node/barretenberg_wasm/index.js +12 -10
- package/dest/node/barretenberg_wasm/index.test.js +3 -3
- package/dest/node/bigint-array/index.d.ts +17 -2
- package/dest/node/bigint-array/index.d.ts.map +1 -1
- package/dest/node/bigint-array/index.js +34 -18
- package/dest/node/crs/net_crs.d.ts.map +1 -1
- package/dest/node/crs/net_crs.js +6 -5
- package/dest/node/crs/node/index.d.ts +6 -4
- package/dest/node/crs/node/index.d.ts.map +1 -1
- package/dest/node/crs/node/index.js +16 -13
- package/dest/node/examples/simple.test.js +2 -2
- package/dest/node/index.d.ts.map +1 -1
- package/dest/node/index.js +1 -1
- package/dest/node/main.d.ts.map +1 -1
- package/dest/node/main.js +57 -65
- package/dest/node/proof/index.d.ts +10 -0
- package/dest/node/proof/index.d.ts.map +1 -1
- package/dest/node/proof/index.js +1 -1
- package/dest/node/retry/index.d.ts +26 -0
- package/dest/node/retry/index.d.ts.map +1 -0
- package/dest/node/retry/index.js +50 -0
- package/dest/node/types/fields.d.ts +6 -5
- package/dest/node/types/fields.d.ts.map +1 -1
- package/dest/node/types/fields.js +15 -10
- package/dest/node-cjs/barretenberg/backend.d.ts +7 -2
- package/dest/node-cjs/barretenberg/backend.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg/backend.js +56 -5
- package/dest/node-cjs/barretenberg/blake2s.test.js +2 -2
- package/dest/node-cjs/barretenberg/index.d.ts +6 -2
- package/dest/node-cjs/barretenberg/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg/index.js +15 -19
- package/dest/node-cjs/barretenberg/pedersen.test.js +2 -2
- package/dest/node-cjs/barretenberg/poseidon.test.js +2 -2
- package/dest/node-cjs/barretenberg_api/index.d.ts +5 -2
- package/dest/node-cjs/barretenberg_api/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_api/index.js +32 -2
- package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_base/index.js +5 -6
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts +1 -1
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.js +16 -11
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.d.ts +1 -1
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.js +7 -9
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts +3 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.d.ts.map +1 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +6 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts +3 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.d.ts.map +1 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/barretenberg.js +6 -0
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.d.ts +1 -1
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/fetch_code/browser/index.js +31 -8
- package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.d.ts +1 -1
- package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/fetch_code/node/index.js +3 -3
- package/dest/node-cjs/barretenberg_wasm/index.d.ts +2 -2
- package/dest/node-cjs/barretenberg_wasm/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg_wasm/index.js +12 -10
- package/dest/node-cjs/barretenberg_wasm/index.test.js +3 -3
- package/dest/node-cjs/bigint-array/index.d.ts +17 -2
- package/dest/node-cjs/bigint-array/index.d.ts.map +1 -1
- package/dest/node-cjs/bigint-array/index.js +39 -21
- package/dest/node-cjs/crs/net_crs.d.ts.map +1 -1
- package/dest/node-cjs/crs/net_crs.js +6 -5
- package/dest/node-cjs/crs/node/index.d.ts +6 -4
- package/dest/node-cjs/crs/node/index.d.ts.map +1 -1
- package/dest/node-cjs/crs/node/index.js +16 -13
- package/dest/node-cjs/examples/simple.test.js +2 -2
- package/dest/node-cjs/index.d.ts.map +1 -1
- package/dest/node-cjs/index.js +1 -1
- package/dest/node-cjs/main.d.ts.map +1 -1
- package/dest/node-cjs/main.js +57 -65
- package/dest/node-cjs/proof/index.d.ts +10 -0
- package/dest/node-cjs/proof/index.d.ts.map +1 -1
- package/dest/node-cjs/proof/index.js +1 -1
- package/dest/node-cjs/retry/index.d.ts +26 -0
- package/dest/node-cjs/retry/index.d.ts.map +1 -0
- package/dest/node-cjs/retry/index.js +56 -0
- package/dest/node-cjs/types/fields.d.ts +6 -5
- package/dest/node-cjs/types/fields.d.ts.map +1 -1
- package/dest/node-cjs/types/fields.js +14 -9
- package/package.json +5 -5
- package/src/barretenberg/backend.ts +79 -3
- package/src/barretenberg/blake2s.test.ts +1 -1
- package/src/barretenberg/index.ts +27 -21
- package/src/barretenberg/pedersen.test.ts +1 -1
- package/src/barretenberg/poseidon.test.ts +1 -1
- package/src/barretenberg_api/index.ts +49 -2
- package/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +4 -6
- package/src/barretenberg_wasm/barretenberg_wasm_main/heap_allocator.ts +14 -10
- package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +7 -10
- package/src/barretenberg_wasm/fetch_code/browser/barretenberg-threads.ts +3 -0
- package/src/barretenberg_wasm/fetch_code/browser/barretenberg.ts +3 -0
- package/src/barretenberg_wasm/fetch_code/browser/index.ts +28 -7
- package/src/barretenberg_wasm/fetch_code/node/index.ts +2 -2
- package/src/barretenberg_wasm/index.test.ts +2 -2
- package/src/barretenberg_wasm/index.ts +22 -11
- package/src/bigint-array/index.ts +39 -17
- package/src/crs/net_crs.ts +18 -9
- package/src/crs/node/index.ts +31 -15
- package/src/examples/simple.test.ts +1 -1
- package/src/index.ts +1 -0
- package/src/main.ts +61 -70
- package/src/proof/index.ts +11 -0
- package/src/retry/index.ts +50 -0
- package/src/types/fields.ts +24 -13
- package/dest/browser/522.index.js +0 -10
- /package/src/barretenberg_wasm/fetch_code/{browser/wasm-module.d.ts → wasm-module.d.ts} +0 -0
package/src/main.ts
CHANGED
|
@@ -22,18 +22,18 @@ const debug = createDebug('bb.js');
|
|
|
22
22
|
const MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM = 2 ** 19;
|
|
23
23
|
const threads = +process.env.HARDWARE_CONCURRENCY! || undefined;
|
|
24
24
|
|
|
25
|
-
function getBytecode(bytecodePath: string) {
|
|
25
|
+
function getBytecode(bytecodePath: string): Uint8Array {
|
|
26
26
|
const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);
|
|
27
27
|
|
|
28
28
|
if (extension == 'json') {
|
|
29
29
|
const encodedCircuit = JSON.parse(readFileSync(bytecodePath, 'utf8'));
|
|
30
30
|
const decompressed = gunzipSync(Buffer.from(encodedCircuit.bytecode, 'base64'));
|
|
31
|
-
return decompressed;
|
|
31
|
+
return Uint8Array.from(decompressed);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const encodedCircuit = readFileSync(bytecodePath);
|
|
35
35
|
const decompressed = gunzipSync(encodedCircuit);
|
|
36
|
-
return decompressed;
|
|
36
|
+
return Uint8Array.from(decompressed);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function base64ToUint8Array(base64: string) {
|
|
@@ -62,14 +62,14 @@ async function getGatesUltra(bytecodePath: string, recursive: boolean, honkRecur
|
|
|
62
62
|
return total;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function getWitness(witnessPath: string) {
|
|
65
|
+
function getWitness(witnessPath: string): Uint8Array {
|
|
66
66
|
const data = readFileSync(witnessPath);
|
|
67
67
|
const decompressed = gunzipSync(data);
|
|
68
|
-
return decompressed;
|
|
68
|
+
return Uint8Array.from(decompressed);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async function computeCircuitSize(bytecodePath: string, recursive: boolean, honkRecursion: boolean, api: Barretenberg) {
|
|
72
|
-
debug(`
|
|
72
|
+
debug(`Computing circuit size for ${bytecodePath}`);
|
|
73
73
|
const bytecode = getBytecode(bytecodePath);
|
|
74
74
|
const [total, subgroup] = await api.acirGetCircuitSizes(bytecode, recursive, honkRecursion);
|
|
75
75
|
return { total, subgroup };
|
|
@@ -84,6 +84,7 @@ async function initUltraPlonk(
|
|
|
84
84
|
) {
|
|
85
85
|
const api = await Barretenberg.new({ threads });
|
|
86
86
|
|
|
87
|
+
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1248): Get rid of this call to avoid building the circuit twice.
|
|
87
88
|
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): use specific UltraPlonk function
|
|
88
89
|
const circuitSize = await getGatesUltra(bytecodePath, recursive, honkRecursion, api);
|
|
89
90
|
// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin
|
|
@@ -92,9 +93,7 @@ async function initUltraPlonk(
|
|
|
92
93
|
if (subgroupSize > MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM) {
|
|
93
94
|
throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_ULTRAPLONK_CIRCUIT_SIZE_IN_WASM}`);
|
|
94
95
|
}
|
|
95
|
-
debug(`circuit
|
|
96
|
-
debug(`subgroup size: ${subgroupSize}`);
|
|
97
|
-
debug('loading crs...');
|
|
96
|
+
debug(`Loading CRS for UltraPlonk with circuit-size=${circuitSize} subgroup-size=${subgroupSize}`);
|
|
98
97
|
// Plus 1 needed! (Move +1 into Crs?)
|
|
99
98
|
const crs = await Crs.new(subgroupSize + 1, crsPath);
|
|
100
99
|
|
|
@@ -112,14 +111,13 @@ async function initUltraPlonk(
|
|
|
112
111
|
async function initUltraHonk(bytecodePath: string, recursive: boolean, crsPath: string) {
|
|
113
112
|
const api = await Barretenberg.new({ threads });
|
|
114
113
|
|
|
114
|
+
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1248): Get rid of this call to avoid building the circuit twice.
|
|
115
115
|
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1126): use specific UltraHonk function
|
|
116
116
|
const circuitSize = await getGatesUltra(bytecodePath, recursive, /*honkRecursion=*/ true, api);
|
|
117
117
|
// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin
|
|
118
118
|
const dyadicCircuitSize = Math.pow(2, Math.ceil(Math.log2(circuitSize)));
|
|
119
119
|
|
|
120
|
-
debug(`circuit
|
|
121
|
-
debug(`dyadic circuit size size: ${dyadicCircuitSize}`);
|
|
122
|
-
debug('loading crs...');
|
|
120
|
+
debug(`Loading CRS for UltraHonk with circuit-size=${circuitSize} dyadic-circuit-size=${dyadicCircuitSize}`);
|
|
123
121
|
const crs = await Crs.new(dyadicCircuitSize + 1, crsPath);
|
|
124
122
|
|
|
125
123
|
// Load CRS into wasm global CRS state.
|
|
@@ -131,7 +129,7 @@ async function initUltraHonk(bytecodePath: string, recursive: boolean, crsPath:
|
|
|
131
129
|
async function initClientIVC(crsPath: string) {
|
|
132
130
|
const api = await Barretenberg.new({ threads });
|
|
133
131
|
|
|
134
|
-
debug('
|
|
132
|
+
debug('Loading CRS for ClientIVC');
|
|
135
133
|
const crs = await Crs.new(2 ** 21 + 1, crsPath);
|
|
136
134
|
const grumpkinCrs = await GrumpkinCrs.new(2 ** 16 + 1, crsPath);
|
|
137
135
|
|
|
@@ -161,7 +159,7 @@ export async function proveAndVerify(bytecodePath: string, recursive: boolean, w
|
|
|
161
159
|
|
|
162
160
|
const { api, acirComposer, circuitSize, subgroupSize } = await initUltraPlonk(bytecodePath, recursive, crsPath);
|
|
163
161
|
try {
|
|
164
|
-
debug(`
|
|
162
|
+
debug(`Creating proof bytecode=${bytecodePath} witness=${witnessPath} recursive=${recursive}`);
|
|
165
163
|
const bytecode = getBytecode(bytecodePath);
|
|
166
164
|
const witness = getWitness(witnessPath);
|
|
167
165
|
|
|
@@ -175,9 +173,9 @@ export async function proveAndVerify(bytecodePath: string, recursive: boolean, w
|
|
|
175
173
|
const proof = await api.acirCreateProof(acirComposer, bytecode, recursive, witness);
|
|
176
174
|
writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads });
|
|
177
175
|
|
|
178
|
-
debug(`
|
|
176
|
+
debug(`Proof complete. Verifying.`);
|
|
179
177
|
const verified = await api.acirVerifyProof(acirComposer, proof);
|
|
180
|
-
debug(`
|
|
178
|
+
debug(`Verification ${verified ? 'successful' : 'failed'}`);
|
|
181
179
|
return verified;
|
|
182
180
|
} finally {
|
|
183
181
|
await api.destroy();
|
|
@@ -233,7 +231,7 @@ export async function proveAndVerifyAztecClient(bytecodePath: string, witnessPat
|
|
|
233
231
|
const witness = readStack(witnessPath);
|
|
234
232
|
|
|
235
233
|
const verified = await api.acirProveAndVerifyAztecClient(bytecode, witness);
|
|
236
|
-
|
|
234
|
+
debug(`Verification ${verified ? 'successful' : 'failed'}`);
|
|
237
235
|
return verified;
|
|
238
236
|
} finally {
|
|
239
237
|
await api.destroy();
|
|
@@ -254,7 +252,7 @@ export async function foldAndVerifyProgram(
|
|
|
254
252
|
const witness = getWitness(witnessPath);
|
|
255
253
|
|
|
256
254
|
const verified = await api.acirFoldAndVerifyProgramStack(bytecode, recursive, witness);
|
|
257
|
-
debug(`
|
|
255
|
+
debug(`Verification ${verified ? 'successful' : 'failed'}`);
|
|
258
256
|
return verified;
|
|
259
257
|
} finally {
|
|
260
258
|
await api.destroy();
|
|
@@ -271,18 +269,17 @@ export async function prove(
|
|
|
271
269
|
) {
|
|
272
270
|
const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
|
|
273
271
|
try {
|
|
274
|
-
debug(`
|
|
272
|
+
debug(`Creating proof bytecode=${bytecodePath} witness=${witnessPath} recursive=${recursive}`);
|
|
275
273
|
const bytecode = getBytecode(bytecodePath);
|
|
276
274
|
const witness = getWitness(witnessPath);
|
|
277
275
|
const proof = await api.acirCreateProof(acirComposer, bytecode, recursive, witness);
|
|
278
|
-
debug(`done.`);
|
|
279
276
|
|
|
280
277
|
if (outputPath === '-') {
|
|
281
278
|
process.stdout.write(proof);
|
|
282
|
-
debug(`
|
|
279
|
+
debug(`Proof written to stdout`);
|
|
283
280
|
} else {
|
|
284
281
|
writeFileSync(outputPath, proof);
|
|
285
|
-
debug(`
|
|
282
|
+
debug(`Proof written to ${outputPath}`);
|
|
286
283
|
}
|
|
287
284
|
} finally {
|
|
288
285
|
await api.destroy();
|
|
@@ -293,14 +290,14 @@ export async function gateCountUltra(bytecodePath: string, recursive: boolean, h
|
|
|
293
290
|
const api = await Barretenberg.new({ threads: 1 });
|
|
294
291
|
try {
|
|
295
292
|
const numberOfGates = await getGatesUltra(bytecodePath, recursive, honkRecursion, api);
|
|
296
|
-
debug(`
|
|
293
|
+
debug(`Number of gates: ${numberOfGates}`);
|
|
297
294
|
// Create an 8-byte buffer and write the number into it.
|
|
298
295
|
// Writing number directly to stdout will result in a variable sized
|
|
299
296
|
// input depending on the size.
|
|
300
297
|
const buffer = Buffer.alloc(8);
|
|
301
298
|
buffer.writeBigInt64LE(BigInt(numberOfGates));
|
|
302
299
|
|
|
303
|
-
process.stdout.write(buffer);
|
|
300
|
+
process.stdout.write(Uint8Array.from(buffer));
|
|
304
301
|
} finally {
|
|
305
302
|
await api.destroy();
|
|
306
303
|
}
|
|
@@ -310,8 +307,8 @@ export async function verify(proofPath: string, vkPath: string, crsPath: string)
|
|
|
310
307
|
const { api, acirComposer } = await initLite(crsPath);
|
|
311
308
|
try {
|
|
312
309
|
await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
|
|
313
|
-
const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath));
|
|
314
|
-
debug(`
|
|
310
|
+
const verified = await api.acirVerifyProof(acirComposer, Uint8Array.from(readFileSync(proofPath)));
|
|
311
|
+
debug(`Verification ${verified ? 'successful' : 'failed'}`);
|
|
315
312
|
return verified;
|
|
316
313
|
} finally {
|
|
317
314
|
await api.destroy();
|
|
@@ -321,15 +318,16 @@ export async function verify(proofPath: string, vkPath: string, crsPath: string)
|
|
|
321
318
|
export async function contract(outputPath: string, vkPath: string, crsPath: string) {
|
|
322
319
|
const { api, acirComposer } = await initLite(crsPath);
|
|
323
320
|
try {
|
|
321
|
+
debug(`Creating verifier contract vk=${vkPath}`);
|
|
324
322
|
await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
|
|
325
323
|
const contract = await api.acirGetSolidityVerifier(acirComposer);
|
|
326
324
|
|
|
327
325
|
if (outputPath === '-') {
|
|
328
326
|
process.stdout.write(contract);
|
|
329
|
-
debug(`contract written to stdout`);
|
|
327
|
+
debug(`Solidity verifier contract written to stdout`);
|
|
330
328
|
} else {
|
|
331
329
|
writeFileSync(outputPath, contract);
|
|
332
|
-
debug(`contract written to
|
|
330
|
+
debug(`Solidity verifier contract written to ${outputPath}`);
|
|
333
331
|
}
|
|
334
332
|
} finally {
|
|
335
333
|
await api.destroy();
|
|
@@ -339,18 +337,17 @@ export async function contract(outputPath: string, vkPath: string, crsPath: stri
|
|
|
339
337
|
export async function contractUltraHonk(bytecodePath: string, vkPath: string, crsPath: string, outputPath: string) {
|
|
340
338
|
const { api } = await initUltraHonk(bytecodePath, false, crsPath);
|
|
341
339
|
try {
|
|
342
|
-
|
|
340
|
+
debug(`Creating UltraHonk verifier contract bytecode=${bytecodePath} vk=${vkPath}`);
|
|
343
341
|
const bytecode = getBytecode(bytecodePath);
|
|
344
|
-
console.log('vkPath', vkPath);
|
|
345
342
|
const vk = new RawBuffer(readFileSync(vkPath));
|
|
346
343
|
const contract = await api.acirHonkSolidityVerifier(bytecode, vk);
|
|
347
344
|
|
|
348
345
|
if (outputPath === '-') {
|
|
349
346
|
process.stdout.write(contract);
|
|
350
|
-
debug(`contract written to stdout`);
|
|
347
|
+
debug(`Solidity verifier contract written to stdout`);
|
|
351
348
|
} else {
|
|
352
349
|
writeFileSync(outputPath, contract);
|
|
353
|
-
debug(`contract written to
|
|
350
|
+
debug(`Solidity verifier contract written to ${outputPath}`);
|
|
354
351
|
}
|
|
355
352
|
} finally {
|
|
356
353
|
await api.destroy();
|
|
@@ -360,19 +357,19 @@ export async function contractUltraHonk(bytecodePath: string, vkPath: string, cr
|
|
|
360
357
|
export async function writeVk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
|
|
361
358
|
const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
|
|
362
359
|
try {
|
|
363
|
-
debug(
|
|
360
|
+
debug(`Initializing proving key bytecode=${bytecodePath} recursive=${recursive}`);
|
|
364
361
|
const bytecode = getBytecode(bytecodePath);
|
|
365
362
|
await api.acirInitProvingKey(acirComposer, bytecode, recursive);
|
|
366
363
|
|
|
367
|
-
debug(
|
|
364
|
+
debug(`Initializing verification key`);
|
|
368
365
|
const vk = await api.acirGetVerificationKey(acirComposer);
|
|
369
366
|
|
|
370
367
|
if (outputPath === '-') {
|
|
371
368
|
process.stdout.write(vk);
|
|
372
|
-
debug(`
|
|
369
|
+
debug(`Verification key written to stdout`);
|
|
373
370
|
} else {
|
|
374
371
|
writeFileSync(outputPath, vk);
|
|
375
|
-
debug(`
|
|
372
|
+
debug(`Verification key written to ${outputPath}`);
|
|
376
373
|
}
|
|
377
374
|
} finally {
|
|
378
375
|
await api.destroy();
|
|
@@ -382,16 +379,16 @@ export async function writeVk(bytecodePath: string, recursive: boolean, crsPath:
|
|
|
382
379
|
export async function writePk(bytecodePath: string, recursive: boolean, crsPath: string, outputPath: string) {
|
|
383
380
|
const { api, acirComposer } = await initUltraPlonk(bytecodePath, recursive, crsPath);
|
|
384
381
|
try {
|
|
385
|
-
debug(
|
|
382
|
+
debug(`Initializing proving key bytecode=${bytecodePath} recursive=${recursive}`);
|
|
386
383
|
const bytecode = getBytecode(bytecodePath);
|
|
387
384
|
const pk = await api.acirGetProvingKey(acirComposer, bytecode, recursive);
|
|
388
385
|
|
|
389
386
|
if (outputPath === '-') {
|
|
390
387
|
process.stdout.write(pk);
|
|
391
|
-
debug(`
|
|
388
|
+
debug(`Proving key written to stdout`);
|
|
392
389
|
} else {
|
|
393
390
|
writeFileSync(outputPath, pk);
|
|
394
|
-
debug(`
|
|
391
|
+
debug(`Proving key written to ${outputPath}`);
|
|
395
392
|
}
|
|
396
393
|
} finally {
|
|
397
394
|
await api.destroy();
|
|
@@ -402,24 +399,22 @@ export async function proofAsFields(proofPath: string, vkPath: string, outputPat
|
|
|
402
399
|
const { api, acirComposer } = await initLite(crsPath);
|
|
403
400
|
|
|
404
401
|
try {
|
|
405
|
-
debug(
|
|
402
|
+
debug(`Serializing proof byte array into field elements proof=${proofPath} vk=${vkPath}`);
|
|
406
403
|
const numPublicInputs = readFileSync(vkPath).readUint32BE(8);
|
|
407
404
|
const proofAsFields = await api.acirSerializeProofIntoFields(
|
|
408
405
|
acirComposer,
|
|
409
|
-
readFileSync(proofPath),
|
|
406
|
+
Uint8Array.from(readFileSync(proofPath)),
|
|
410
407
|
numPublicInputs,
|
|
411
408
|
);
|
|
412
409
|
const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
|
|
413
410
|
|
|
414
411
|
if (outputPath === '-') {
|
|
415
412
|
process.stdout.write(jsonProofAsFields);
|
|
416
|
-
debug(`
|
|
413
|
+
debug(`Proof as fields written to stdout`);
|
|
417
414
|
} else {
|
|
418
415
|
writeFileSync(outputPath, jsonProofAsFields);
|
|
419
|
-
debug(`
|
|
416
|
+
debug(`Proof as fields written to ${outputPath}`);
|
|
420
417
|
}
|
|
421
|
-
|
|
422
|
-
debug('done.');
|
|
423
418
|
} finally {
|
|
424
419
|
await api.destroy();
|
|
425
420
|
}
|
|
@@ -429,7 +424,7 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string, crsPath
|
|
|
429
424
|
const { api, acirComposer } = await initLite(crsPath);
|
|
430
425
|
|
|
431
426
|
try {
|
|
432
|
-
debug(
|
|
427
|
+
debug(`Serializing vk byte array into field elements vk=${vkPath}`);
|
|
433
428
|
await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath)));
|
|
434
429
|
const [vkAsFields, vkHash] = await api.acirSerializeVerificationKeyIntoFields(acirComposer);
|
|
435
430
|
const output = [vkHash, ...vkAsFields].map(f => f.toString());
|
|
@@ -437,13 +432,11 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string, crsPath
|
|
|
437
432
|
|
|
438
433
|
if (vkeyOutputPath === '-') {
|
|
439
434
|
process.stdout.write(jsonVKAsFields);
|
|
440
|
-
debug(`
|
|
435
|
+
debug(`Verification key as fields written to stdout`);
|
|
441
436
|
} else {
|
|
442
437
|
writeFileSync(vkeyOutputPath, jsonVKAsFields);
|
|
443
|
-
debug(`
|
|
438
|
+
debug(`Verification key as fields written to ${vkeyOutputPath}`);
|
|
444
439
|
}
|
|
445
|
-
|
|
446
|
-
debug('done.');
|
|
447
440
|
} finally {
|
|
448
441
|
await api.destroy();
|
|
449
442
|
}
|
|
@@ -459,7 +452,7 @@ export async function proveUltraHonk(
|
|
|
459
452
|
) {
|
|
460
453
|
const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
|
|
461
454
|
try {
|
|
462
|
-
debug(`
|
|
455
|
+
debug(`Creating UltraHonk proof bytecode=${bytecodePath} recursive=${recursive}`);
|
|
463
456
|
const bytecode = getBytecode(bytecodePath);
|
|
464
457
|
const witness = getWitness(witnessPath);
|
|
465
458
|
|
|
@@ -467,14 +460,13 @@ export async function proveUltraHonk(
|
|
|
467
460
|
? api.acirProveUltraKeccakHonk.bind(api)
|
|
468
461
|
: api.acirProveUltraHonk.bind(api);
|
|
469
462
|
const proof = await acirProveUltraHonk(bytecode, recursive, witness);
|
|
470
|
-
debug(`done.`);
|
|
471
463
|
|
|
472
464
|
if (outputPath === '-') {
|
|
473
465
|
process.stdout.write(proof);
|
|
474
|
-
debug(`
|
|
466
|
+
debug(`Proof written to stdout`);
|
|
475
467
|
} else {
|
|
476
468
|
writeFileSync(outputPath, proof);
|
|
477
|
-
debug(`
|
|
469
|
+
debug(`Proof written to ${outputPath}`);
|
|
478
470
|
}
|
|
479
471
|
} finally {
|
|
480
472
|
await api.destroy();
|
|
@@ -491,7 +483,7 @@ export async function writeVkUltraHonk(
|
|
|
491
483
|
const { api } = await initUltraHonk(bytecodePath, recursive, crsPath);
|
|
492
484
|
try {
|
|
493
485
|
const bytecode = getBytecode(bytecodePath);
|
|
494
|
-
debug(
|
|
486
|
+
debug(`Initializing UltraHonk verification key bytecode=${bytecodePath} recursive=${recursive}`);
|
|
495
487
|
|
|
496
488
|
const acirWriteVkUltraHonk = options?.keccak
|
|
497
489
|
? api.acirWriteVkUltraKeccakHonk.bind(api)
|
|
@@ -500,10 +492,10 @@ export async function writeVkUltraHonk(
|
|
|
500
492
|
|
|
501
493
|
if (outputPath === '-') {
|
|
502
494
|
process.stdout.write(vk);
|
|
503
|
-
debug(`
|
|
495
|
+
debug(`Verification key written to stdout`);
|
|
504
496
|
} else {
|
|
505
497
|
writeFileSync(outputPath, vk);
|
|
506
|
-
debug(`
|
|
498
|
+
debug(`Verification key written to ${outputPath}`);
|
|
507
499
|
}
|
|
508
500
|
} finally {
|
|
509
501
|
await api.destroy();
|
|
@@ -521,9 +513,12 @@ export async function verifyUltraHonk(
|
|
|
521
513
|
const acirVerifyUltraHonk = options?.keccak
|
|
522
514
|
? api.acirVerifyUltraKeccakHonk.bind(api)
|
|
523
515
|
: api.acirVerifyUltraHonk.bind(api);
|
|
524
|
-
const verified = await acirVerifyUltraHonk(
|
|
516
|
+
const verified = await acirVerifyUltraHonk(
|
|
517
|
+
Uint8Array.from(readFileSync(proofPath)),
|
|
518
|
+
new RawBuffer(readFileSync(vkPath)),
|
|
519
|
+
);
|
|
525
520
|
|
|
526
|
-
debug(`
|
|
521
|
+
debug(`Verification ${verified ? 'successful' : 'failed'}`);
|
|
527
522
|
return verified;
|
|
528
523
|
} finally {
|
|
529
524
|
await api.destroy();
|
|
@@ -533,19 +528,17 @@ export async function verifyUltraHonk(
|
|
|
533
528
|
export async function proofAsFieldsUltraHonk(proofPath: string, outputPath: string, crsPath: string) {
|
|
534
529
|
const { api } = await initLite(crsPath);
|
|
535
530
|
try {
|
|
536
|
-
debug(
|
|
537
|
-
const proofAsFields = await api.acirProofAsFieldsUltraHonk(readFileSync(proofPath));
|
|
531
|
+
debug(`Outputting UltraHonk proof as vector of fields proof=${proofPath}`);
|
|
532
|
+
const proofAsFields = await api.acirProofAsFieldsUltraHonk(Uint8Array.from(readFileSync(proofPath)));
|
|
538
533
|
const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString()));
|
|
539
534
|
|
|
540
535
|
if (outputPath === '-') {
|
|
541
536
|
process.stdout.write(jsonProofAsFields);
|
|
542
|
-
debug(`
|
|
537
|
+
debug(`Proof as fields written to stdout`);
|
|
543
538
|
} else {
|
|
544
539
|
writeFileSync(outputPath, jsonProofAsFields);
|
|
545
|
-
debug(`
|
|
540
|
+
debug(`Proof as fields written to ${outputPath}`);
|
|
546
541
|
}
|
|
547
|
-
|
|
548
|
-
debug('done.');
|
|
549
542
|
} finally {
|
|
550
543
|
await api.destroy();
|
|
551
544
|
}
|
|
@@ -555,19 +548,17 @@ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string
|
|
|
555
548
|
const { api } = await initLite(crsPath);
|
|
556
549
|
|
|
557
550
|
try {
|
|
558
|
-
debug(
|
|
551
|
+
debug(`Serializing vk byte array into field elements vk=${vkPath}`);
|
|
559
552
|
const vkAsFields = await api.acirVkAsFieldsUltraHonk(new RawBuffer(readFileSync(vkPath)));
|
|
560
553
|
const jsonVKAsFields = JSON.stringify(vkAsFields.map(f => f.toString()));
|
|
561
554
|
|
|
562
555
|
if (vkeyOutputPath === '-') {
|
|
563
556
|
process.stdout.write(jsonVKAsFields);
|
|
564
|
-
debug(`
|
|
557
|
+
debug(`Verification key as fields written to stdout`);
|
|
565
558
|
} else {
|
|
566
559
|
writeFileSync(vkeyOutputPath, jsonVKAsFields);
|
|
567
|
-
debug(`
|
|
560
|
+
debug(`Verification key as fields written to ${vkeyOutputPath}`);
|
|
568
561
|
}
|
|
569
|
-
|
|
570
|
-
debug('done.');
|
|
571
562
|
} finally {
|
|
572
563
|
await api.destroy();
|
|
573
564
|
}
|
package/src/proof/index.ts
CHANGED
|
@@ -9,6 +9,17 @@ export type ProofData = {
|
|
|
9
9
|
proof: Uint8Array;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* The representation of a proof
|
|
15
|
+
* */
|
|
16
|
+
export type ProofDataForRecursion = {
|
|
17
|
+
/** @description Public inputs of a proof */
|
|
18
|
+
publicInputs: string[];
|
|
19
|
+
/** @description An byte array representing the proof */
|
|
20
|
+
proof: string[];
|
|
21
|
+
};
|
|
22
|
+
|
|
12
23
|
// Buffers are prepended with their size. The size takes 4 bytes.
|
|
13
24
|
const serializedBufferSize = 4;
|
|
14
25
|
const fieldByteSize = 32;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a backoff sequence for retrying operations with an increasing delay.
|
|
3
|
+
* The backoff sequence follows this pattern: 1, 1, 1, 2, 4, 8, 16, 32, 64, ...
|
|
4
|
+
* This generator can be used in combination with the `retry` function to perform
|
|
5
|
+
* retries with exponential backoff and capped at 64 seconds between attempts.
|
|
6
|
+
*
|
|
7
|
+
* @returns A generator that yields the next backoff value in seconds as an integer.
|
|
8
|
+
*/
|
|
9
|
+
export function* backoffGenerator() {
|
|
10
|
+
const v = [1, 1, 1, 2, 4, 8, 16, 32, 64];
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (true) {
|
|
13
|
+
yield v[Math.min(i++, v.length - 1)];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generates a backoff sequence based on the array of retry intervals to use with the `retry` function.
|
|
19
|
+
* @param retries - Intervals to retry (in seconds).
|
|
20
|
+
* @returns A generator sequence.
|
|
21
|
+
*/
|
|
22
|
+
export function* makeBackoff(retries: number[]) {
|
|
23
|
+
for (const retry of retries) {
|
|
24
|
+
yield retry;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Retry a given asynchronous function with a specific backoff strategy, until it succeeds or backoff generator ends.
|
|
30
|
+
* It logs the error and retry interval in case an error is caught. The function can be named for better log output.
|
|
31
|
+
*
|
|
32
|
+
* @param fn - The asynchronous function to be retried.
|
|
33
|
+
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
|
|
34
|
+
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
35
|
+
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
36
|
+
*/
|
|
37
|
+
export async function retry<Result>(fn: () => Promise<Result>, backoff = backoffGenerator()) {
|
|
38
|
+
while (true) {
|
|
39
|
+
try {
|
|
40
|
+
return await fn();
|
|
41
|
+
} catch (err: any) {
|
|
42
|
+
const s = backoff.next().value;
|
|
43
|
+
if (s === undefined) {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
await new Promise(resolve => setTimeout(resolve, s * 1000));
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/types/fields.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { randomBytes } from '../random/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
buffer32BytesToBigIntBE,
|
|
4
|
+
uint8ArrayToBigIntBE,
|
|
5
|
+
bigIntToBufferBE,
|
|
6
|
+
bigIntToUint8ArrayBE,
|
|
7
|
+
} from '../bigint-array/index.js';
|
|
3
8
|
import { BufferReader, uint8ArrayToHexString } from '../serialize/index.js';
|
|
4
9
|
|
|
5
10
|
// TODO(#4189): Replace with implementation in yarn-project/foundation/src/fields/fields.ts
|
|
@@ -15,30 +20,36 @@ export class Fr {
|
|
|
15
20
|
static SIZE_IN_BYTES = 32;
|
|
16
21
|
value: Uint8Array;
|
|
17
22
|
|
|
18
|
-
constructor(value: Uint8Array | bigint) {
|
|
23
|
+
constructor(value: Uint8Array | Buffer | bigint) {
|
|
19
24
|
// We convert buffer value to bigint to be able to check it fits within modulus
|
|
20
|
-
const valueBigInt =
|
|
25
|
+
const valueBigInt =
|
|
26
|
+
typeof value === 'bigint'
|
|
27
|
+
? value
|
|
28
|
+
: value instanceof Buffer
|
|
29
|
+
? buffer32BytesToBigIntBE(value)
|
|
30
|
+
: uint8ArrayToBigIntBE(value);
|
|
21
31
|
|
|
22
32
|
if (valueBigInt > Fr.MAX_VALUE) {
|
|
23
33
|
throw new Error(`Value 0x${valueBigInt.toString(16)} is greater or equal to field modulus.`);
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
this.value =
|
|
36
|
+
this.value =
|
|
37
|
+
typeof value === 'bigint' ? bigIntToUint8ArrayBE(value) : value instanceof Buffer ? new Uint8Array(value) : value;
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
static random() {
|
|
30
|
-
const r =
|
|
41
|
+
const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fr.MODULUS;
|
|
31
42
|
return new this(r);
|
|
32
43
|
}
|
|
33
44
|
|
|
34
|
-
static fromBuffer(buffer: Uint8Array | BufferReader) {
|
|
45
|
+
static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
|
|
35
46
|
const reader = BufferReader.asReader(buffer);
|
|
36
47
|
return new this(reader.readBytes(this.SIZE_IN_BYTES));
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
static fromBufferReduce(buffer: Uint8Array | BufferReader) {
|
|
40
51
|
const reader = BufferReader.asReader(buffer);
|
|
41
|
-
return new this(
|
|
52
|
+
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
static fromString(str: string) {
|
|
@@ -79,18 +90,18 @@ export class Fq {
|
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
static random() {
|
|
82
|
-
const r =
|
|
93
|
+
const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fq.MODULUS;
|
|
83
94
|
return new this(r);
|
|
84
95
|
}
|
|
85
96
|
|
|
86
|
-
static fromBuffer(buffer: Uint8Array | BufferReader) {
|
|
97
|
+
static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
|
|
87
98
|
const reader = BufferReader.asReader(buffer);
|
|
88
|
-
return new this(
|
|
99
|
+
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
static fromBufferReduce(buffer: Uint8Array | BufferReader) {
|
|
102
|
+
static fromBufferReduce(buffer: Uint8Array | Buffer | BufferReader) {
|
|
92
103
|
const reader = BufferReader.asReader(buffer);
|
|
93
|
-
return new this(
|
|
104
|
+
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
static fromString(str: string) {
|
|
@@ -98,7 +109,7 @@ export class Fq {
|
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
toBuffer() {
|
|
101
|
-
return
|
|
112
|
+
return bigIntToBufferBE(this.value, Fq.SIZE_IN_BYTES);
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
toString() {
|
|
File without changes
|