@aztec/bb-prover 0.0.0-test.1 → 0.0.1-commit.03f7ef2
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/dest/avm_proving_tests/avm_proving_tester.d.ts +14 -18
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +143 -79
- package/dest/bb/cli.d.ts +1 -1
- package/dest/bb/execute.d.ts +14 -47
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +133 -237
- package/dest/bb/index.d.ts +1 -1
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/honk.d.ts +3 -3
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +3 -2
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation.d.ts +3 -3
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +2 -4
- package/dest/prover/client/bb_private_kernel_prover.d.ts +32 -0
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +42 -20
- package/dest/prover/client/bundle.d.ts +6 -0
- package/dest/prover/client/bundle.d.ts.map +1 -0
- package/dest/prover/client/bundle.js +8 -0
- package/dest/prover/client/lazy.d.ts +6 -0
- package/dest/prover/client/lazy.d.ts.map +1 -0
- package/dest/prover/client/lazy.js +8 -0
- package/dest/prover/index.d.ts +3 -4
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -3
- package/dest/prover/proof_utils.d.ts +19 -0
- package/dest/prover/proof_utils.d.ts.map +1 -0
- package/dest/prover/proof_utils.js +72 -0
- package/dest/prover/server/bb_prover.d.ts +100 -0
- package/dest/prover/server/bb_prover.d.ts.map +1 -0
- package/dest/prover/server/bb_prover.js +336 -0
- package/dest/test/delay_values.d.ts +1 -1
- package/dest/test/delay_values.d.ts.map +1 -1
- package/dest/test/delay_values.js +33 -21
- package/dest/test/index.d.ts +1 -1
- package/dest/test/test_circuit_prover.d.ts +25 -34
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +85 -59
- package/dest/test/test_verifier.d.ts +6 -3
- package/dest/test/test_verifier.d.ts.map +1 -1
- package/dest/test/test_verifier.js +23 -1
- package/dest/verification_key/verification_key_data.d.ts +7 -1
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +24 -30
- package/dest/verifier/bb_verifier.d.ts +6 -5
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +46 -25
- package/dest/verifier/index.d.ts +2 -1
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -0
- package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/queued_chonk_verifier.js +132 -0
- package/package.json +35 -33
- package/src/avm_proving_tests/avm_proving_tester.ts +224 -104
- package/src/bb/execute.ts +104 -251
- package/src/config.ts +2 -0
- package/src/honk.ts +3 -2
- package/src/index.ts +1 -0
- package/src/instrumentation.ts +2 -4
- package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +78 -30
- package/src/prover/client/bundle.ts +11 -0
- package/src/prover/client/lazy.ts +11 -0
- package/src/prover/index.ts +2 -3
- package/src/prover/proof_utils.ts +115 -0
- package/src/prover/server/bb_prover.ts +728 -0
- package/src/test/delay_values.ts +33 -21
- package/src/test/test_circuit_prover.ts +260 -147
- package/src/test/test_verifier.ts +15 -3
- package/src/verification_key/verification_key_data.ts +30 -25
- package/src/verifier/bb_verifier.ts +63 -32
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +140 -0
- package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
- package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_native_private_kernel_prover.js +0 -69
- package/dest/prover/bb_private_kernel_prover.d.ts +0 -32
- package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.d.ts +0 -120
- package/dest/prover/bb_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.js +0 -423
- package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
- package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
- package/dest/prover/client_ivc_proof_utils.js +0 -43
- package/dest/stats.d.ts +0 -5
- package/dest/stats.d.ts.map +0 -1
- package/dest/stats.js +0 -62
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
- package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
- package/dest/wasm/bundle.d.ts +0 -6
- package/dest/wasm/bundle.d.ts.map +0 -1
- package/dest/wasm/bundle.js +0 -8
- package/dest/wasm/lazy.d.ts +0 -6
- package/dest/wasm/lazy.d.ts.map +0 -1
- package/dest/wasm/lazy.js +0 -8
- package/src/prover/bb_native_private_kernel_prover.ts +0 -119
- package/src/prover/bb_prover.ts +0 -781
- package/src/prover/client_ivc_proof_utils.ts +0 -42
- package/src/stats.ts +0 -64
- package/src/wasm/bb_wasm_private_kernel_prover.ts +0 -55
- package/src/wasm/bundle.ts +0 -11
- package/src/wasm/lazy.ts +0 -11
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { AztecClientBackend, Barretenberg } from '@aztec/bb.js';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { serializeWitness } from '@aztec/noir-noirc_abi';
|
|
3
5
|
import {
|
|
6
|
+
convertHidingKernelPublicInputsToWitnessMapWithAbi,
|
|
7
|
+
convertHidingKernelToRollupInputsToWitnessMapWithAbi,
|
|
4
8
|
convertPrivateKernelInitInputsToWitnessMapWithAbi,
|
|
5
9
|
convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
|
|
6
10
|
convertPrivateKernelInnerInputsToWitnessMapWithAbi,
|
|
@@ -11,13 +15,22 @@ import {
|
|
|
11
15
|
convertPrivateKernelTailInputsToWitnessMapWithAbi,
|
|
12
16
|
convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
|
|
13
17
|
convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
|
|
18
|
+
foreignCallHandler,
|
|
14
19
|
getPrivateKernelResetArtifactName,
|
|
15
20
|
updateResetCircuitSampleInputs,
|
|
16
21
|
} from '@aztec/noir-protocol-circuits-types/client';
|
|
17
|
-
import
|
|
18
|
-
|
|
22
|
+
import {
|
|
23
|
+
type ArtifactProvider,
|
|
24
|
+
type ClientProtocolArtifact,
|
|
25
|
+
mapProtocolArtifactNameToCircuitName,
|
|
26
|
+
} from '@aztec/noir-protocol-circuits-types/types';
|
|
27
|
+
import type { Abi, WitnessMap } from '@aztec/noir-types';
|
|
28
|
+
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
19
29
|
import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
20
30
|
import type {
|
|
31
|
+
HidingKernelToPublicPrivateInputs,
|
|
32
|
+
HidingKernelToRollupPrivateInputs,
|
|
33
|
+
PrivateExecutionStep,
|
|
21
34
|
PrivateKernelCircuitPublicInputs,
|
|
22
35
|
PrivateKernelInitCircuitPrivateInputs,
|
|
23
36
|
PrivateKernelInnerCircuitPrivateInputs,
|
|
@@ -26,18 +39,16 @@ import type {
|
|
|
26
39
|
PrivateKernelTailCircuitPrivateInputs,
|
|
27
40
|
PrivateKernelTailCircuitPublicInputs,
|
|
28
41
|
} from '@aztec/stdlib/kernel';
|
|
29
|
-
import type {
|
|
30
|
-
import
|
|
42
|
+
import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
43
|
+
import { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
|
|
31
44
|
import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
|
|
32
45
|
|
|
33
|
-
import
|
|
34
|
-
|
|
35
|
-
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
46
|
+
import { ungzip } from 'pako';
|
|
36
47
|
|
|
37
48
|
export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
38
49
|
constructor(
|
|
39
50
|
protected artifactProvider: ArtifactProvider,
|
|
40
|
-
protected
|
|
51
|
+
protected simulator: CircuitSimulator,
|
|
41
52
|
protected log = createLogger('bb-prover'),
|
|
42
53
|
) {}
|
|
43
54
|
|
|
@@ -150,6 +161,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
150
161
|
);
|
|
151
162
|
}
|
|
152
163
|
|
|
164
|
+
public async generateHidingToRollupOutput(
|
|
165
|
+
inputs: HidingKernelToRollupPrivateInputs,
|
|
166
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
167
|
+
return await this.generateCircuitOutput(
|
|
168
|
+
inputs,
|
|
169
|
+
'HidingKernelToRollup',
|
|
170
|
+
convertHidingKernelToRollupInputsToWitnessMapWithAbi,
|
|
171
|
+
convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async generateHidingToPublicOutput(
|
|
176
|
+
inputs: HidingKernelToPublicPrivateInputs,
|
|
177
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
178
|
+
return await this.generateCircuitOutput(
|
|
179
|
+
inputs,
|
|
180
|
+
'HidingKernelToPublic',
|
|
181
|
+
convertHidingKernelPublicInputsToWitnessMapWithAbi,
|
|
182
|
+
convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
153
186
|
public async simulateCircuitOutput<
|
|
154
187
|
I extends { toBuffer: () => Buffer },
|
|
155
188
|
O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
|
|
@@ -159,15 +192,13 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
159
192
|
convertInputs: (inputs: I, abi: Abi) => WitnessMap,
|
|
160
193
|
convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
|
|
161
194
|
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
162
|
-
const compiledCircuit:
|
|
163
|
-
circuitType
|
|
164
|
-
);
|
|
195
|
+
const compiledCircuit: NoirCompiledCircuitWithName =
|
|
196
|
+
await this.artifactProvider.getSimulatedClientCircuitArtifactByName(circuitType);
|
|
165
197
|
|
|
166
198
|
const witnessMap = convertInputs(inputs, compiledCircuit.abi);
|
|
167
199
|
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
.executeProtocolCircuit(witnessMap, compiledCircuit)
|
|
200
|
+
const outputWitness = await this.simulator
|
|
201
|
+
.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
|
|
171
202
|
.catch((err: Error) => {
|
|
172
203
|
this.log.debug(`Failed to simulate ${circuitType}`, {
|
|
173
204
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
@@ -175,12 +206,12 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
175
206
|
});
|
|
176
207
|
throw err;
|
|
177
208
|
});
|
|
178
|
-
const output = convertOutputs(outputWitness, compiledCircuit.abi);
|
|
209
|
+
const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
|
|
179
210
|
|
|
180
211
|
this.log.debug(`Simulated ${circuitType}`, {
|
|
181
212
|
eventName: 'circuit-simulation',
|
|
182
213
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
183
|
-
duration:
|
|
214
|
+
duration: outputWitness.duration,
|
|
184
215
|
inputSize: inputs.toBuffer().length,
|
|
185
216
|
outputSize: output.toBuffer().length,
|
|
186
217
|
} satisfies CircuitSimulationStats);
|
|
@@ -198,30 +229,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
198
229
|
convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
|
|
199
230
|
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
200
231
|
this.log.debug(`Generating witness for ${circuitType}`);
|
|
201
|
-
const compiledCircuit:
|
|
202
|
-
circuitType
|
|
203
|
-
);
|
|
232
|
+
const compiledCircuit: NoirCompiledCircuitWithName =
|
|
233
|
+
await this.artifactProvider.getClientCircuitArtifactByName(circuitType);
|
|
204
234
|
|
|
205
235
|
const witnessMap = convertInputs(inputs, compiledCircuit.abi);
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const output = convertOutputs(outputWitness, compiledCircuit.abi);
|
|
236
|
+
const outputWitness = await this.simulator.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler);
|
|
237
|
+
const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
|
|
209
238
|
|
|
210
239
|
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
211
240
|
eventName: 'circuit-witness-generation',
|
|
212
241
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
213
|
-
duration:
|
|
242
|
+
duration: outputWitness.duration,
|
|
214
243
|
inputSize: inputs.toBuffer().length,
|
|
215
244
|
outputSize: output.toBuffer().length,
|
|
216
245
|
} satisfies CircuitWitnessGenerationStats);
|
|
217
246
|
|
|
218
|
-
const verificationKey =
|
|
247
|
+
const verificationKey = await this.artifactProvider.getCircuitVkByName(circuitType);
|
|
219
248
|
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
220
249
|
|
|
221
250
|
const kernelOutput: PrivateKernelSimulateOutput<O> = {
|
|
222
251
|
publicInputs: output,
|
|
223
252
|
verificationKey,
|
|
224
|
-
outputWitness,
|
|
253
|
+
outputWitness: outputWitness.witness,
|
|
225
254
|
bytecode,
|
|
226
255
|
};
|
|
227
256
|
return kernelOutput;
|
|
@@ -232,18 +261,37 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
232
261
|
>(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
|
|
233
262
|
const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
|
|
234
263
|
publicInputs,
|
|
235
|
-
verificationKey:
|
|
264
|
+
verificationKey: await this.artifactProvider.getCircuitVkByName(circuitType),
|
|
236
265
|
outputWitness: new Map(),
|
|
237
266
|
bytecode: Buffer.from([]),
|
|
238
267
|
};
|
|
239
268
|
return kernelProofOutput;
|
|
240
269
|
}
|
|
241
270
|
|
|
242
|
-
public
|
|
243
|
-
|
|
271
|
+
public async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
|
|
272
|
+
const timer = new Timer();
|
|
273
|
+
this.log.info(`Generating ClientIVC proof...`);
|
|
274
|
+
const backend = new AztecClientBackend(
|
|
275
|
+
executionSteps.map(step => ungzip(step.bytecode)),
|
|
276
|
+
await Barretenberg.initSingleton(),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const [proof] = await backend.prove(
|
|
280
|
+
executionSteps.map(step => ungzip(serializeWitness(step.witness))),
|
|
281
|
+
executionSteps.map(step => step.vk),
|
|
282
|
+
);
|
|
283
|
+
this.log.info(`Generated ClientIVC proof`, {
|
|
284
|
+
eventName: 'client-ivc-proof-generation',
|
|
285
|
+
duration: timer.ms(),
|
|
286
|
+
proofSize: proof.length,
|
|
287
|
+
});
|
|
288
|
+
return ChonkProofWithPublicInputs.fromBufferArray(proof);
|
|
244
289
|
}
|
|
245
290
|
|
|
246
|
-
public computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
247
|
-
|
|
291
|
+
public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
292
|
+
// Note we do not pass the vk to the backend. This is unneeded for gate counts.
|
|
293
|
+
const backend = new AztecClientBackend([ungzip(_bytecode)], await Barretenberg.initSingleton());
|
|
294
|
+
const gateCount = await backend.gates();
|
|
295
|
+
return gateCount[0];
|
|
248
296
|
}
|
|
249
297
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
3
|
+
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
4
|
+
|
|
5
|
+
import { BBPrivateKernelProver } from './bb_private_kernel_prover.js';
|
|
6
|
+
|
|
7
|
+
export class BBBundlePrivateKernelProver extends BBPrivateKernelProver {
|
|
8
|
+
constructor(simulator: CircuitSimulator, log = createLogger('bb-prover:bundle')) {
|
|
9
|
+
super(new BundleArtifactProvider(), simulator, log);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
|
|
3
|
+
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
4
|
+
|
|
5
|
+
import { BBPrivateKernelProver } from './bb_private_kernel_prover.js';
|
|
6
|
+
|
|
7
|
+
export class BBLazyPrivateKernelProver extends BBPrivateKernelProver {
|
|
8
|
+
constructor(simulator: CircuitSimulator, log = createLogger('bb-prover:lazy')) {
|
|
9
|
+
super(new LazyArtifactProvider(), simulator, log);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/prover/index.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './bb_prover.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './client_ivc_proof_utils.js';
|
|
1
|
+
export * from './server/bb_prover.js';
|
|
2
|
+
export * from './proof_utils.js';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHONK_PROOF_LENGTH,
|
|
3
|
+
HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE,
|
|
4
|
+
IPA_CLAIM_SIZE,
|
|
5
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
+
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
|
+
PAIRING_POINTS_SIZE,
|
|
8
|
+
ULTRA_KECCAK_PROOF_LENGTH,
|
|
9
|
+
} from '@aztec/constants';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
12
|
+
import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
13
|
+
import type { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
14
|
+
|
|
15
|
+
import assert from 'assert';
|
|
16
|
+
import { promises as fs } from 'fs';
|
|
17
|
+
import * as path from 'path';
|
|
18
|
+
|
|
19
|
+
import { PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/execute.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a ChonkProof proof file.
|
|
23
|
+
*
|
|
24
|
+
* @param directory the directory to read the proof from.
|
|
25
|
+
* @returns the encapsulated chonk proof
|
|
26
|
+
*/
|
|
27
|
+
export async function readChonkProofFromOutputDirectory(directory: string) {
|
|
28
|
+
const proofFilename = path.join(directory, PROOF_FILENAME);
|
|
29
|
+
const binaryProof = await fs.readFile(proofFilename);
|
|
30
|
+
const proofFields = splitBufferIntoFields(binaryProof);
|
|
31
|
+
return new ChonkProofWithPublicInputs(proofFields);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Serialize a ChonkProof to a proof file.
|
|
36
|
+
*
|
|
37
|
+
* @param proof the ChonkProof from object
|
|
38
|
+
* @param directory the directory to write in
|
|
39
|
+
*/
|
|
40
|
+
export async function writeChonkProofToPath(chonkProof: ChonkProofWithPublicInputs, outputPath: string) {
|
|
41
|
+
// NB: Don't use chonkProof.toBuffer here because it will include the proof length.
|
|
42
|
+
const fieldsBuf = Buffer.concat(chonkProof.fieldsWithPublicInputs.map(field => field.toBuffer()));
|
|
43
|
+
await fs.writeFile(outputPath, fieldsBuf);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getNumCustomPublicInputs(proofLength: number, vkData: VerificationKeyData) {
|
|
47
|
+
let numPublicInputs = vkData.numPublicInputs;
|
|
48
|
+
if (proofLength == CHONK_PROOF_LENGTH) {
|
|
49
|
+
numPublicInputs -= HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE;
|
|
50
|
+
} else {
|
|
51
|
+
numPublicInputs -= PAIRING_POINTS_SIZE;
|
|
52
|
+
if (proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH) {
|
|
53
|
+
numPublicInputs -= IPA_CLAIM_SIZE;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return numPublicInputs;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function splitBufferIntoFields(buffer: Buffer): Fr[] {
|
|
60
|
+
const fields: Fr[] = [];
|
|
61
|
+
for (let i = 0; i < buffer.length / Fr.SIZE_IN_BYTES; i++) {
|
|
62
|
+
fields.push(Fr.fromBuffer(buffer.subarray(i * Fr.SIZE_IN_BYTES, (i + 1) * Fr.SIZE_IN_BYTES)));
|
|
63
|
+
}
|
|
64
|
+
return fields;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function readProofsFromOutputDirectory<PROOF_LENGTH extends number>(
|
|
68
|
+
directory: string,
|
|
69
|
+
vkData: VerificationKeyData,
|
|
70
|
+
proofLength: PROOF_LENGTH,
|
|
71
|
+
logger: Logger,
|
|
72
|
+
): Promise<RecursiveProof<PROOF_LENGTH>> {
|
|
73
|
+
assert(
|
|
74
|
+
proofLength == CHONK_PROOF_LENGTH ||
|
|
75
|
+
proofLength == NESTED_RECURSIVE_PROOF_LENGTH ||
|
|
76
|
+
proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH ||
|
|
77
|
+
proofLength == ULTRA_KECCAK_PROOF_LENGTH,
|
|
78
|
+
`Proof length must be one of the expected proof lengths, received ${proofLength}`,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const publicInputsFilename = path.join(directory, PUBLIC_INPUTS_FILENAME);
|
|
82
|
+
const proofFilename = path.join(directory, PROOF_FILENAME);
|
|
83
|
+
|
|
84
|
+
// Handle CHONK separately because bb outputs the proof fields with public inputs for CHONK.
|
|
85
|
+
const isChonk = proofLength == CHONK_PROOF_LENGTH;
|
|
86
|
+
|
|
87
|
+
const [binaryPublicInputs, binaryProof] = await Promise.all([
|
|
88
|
+
isChonk ? Buffer.alloc(0) : fs.readFile(publicInputsFilename),
|
|
89
|
+
fs.readFile(proofFilename),
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
const numPublicInputs = getNumCustomPublicInputs(proofLength, vkData);
|
|
93
|
+
let fieldsWithoutPublicInputs = splitBufferIntoFields(binaryProof);
|
|
94
|
+
if (isChonk) {
|
|
95
|
+
fieldsWithoutPublicInputs = fieldsWithoutPublicInputs.slice(numPublicInputs);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
assert(
|
|
99
|
+
fieldsWithoutPublicInputs.length == proofLength,
|
|
100
|
+
`Proof fields length mismatch: ${fieldsWithoutPublicInputs.length} != ${proofLength}`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Concat binary public inputs and binary proof
|
|
104
|
+
// This buffer will have the form: [binary public inputs, binary proof]
|
|
105
|
+
const binaryProofWithPublicInputs = Buffer.concat([binaryPublicInputs, binaryProof]);
|
|
106
|
+
logger.debug(
|
|
107
|
+
`Circuit path: ${directory}, proof fields length: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}`,
|
|
108
|
+
);
|
|
109
|
+
return new RecursiveProof(
|
|
110
|
+
fieldsWithoutPublicInputs,
|
|
111
|
+
new Proof(binaryProofWithPublicInputs, numPublicInputs),
|
|
112
|
+
true,
|
|
113
|
+
proofLength,
|
|
114
|
+
);
|
|
115
|
+
}
|