@aztec/bb-prover 0.0.0-test.0 → 0.0.1-commit.0208eb9
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 +146 -79
- package/dest/bb/cli.d.ts +1 -1
- package/dest/bb/execute.d.ts +17 -50
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +145 -278
- 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 +11 -43
- package/dest/prover/client/bb_private_kernel_prover.d.ts +38 -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} +53 -21
- 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 +7 -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 +7 -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 +97 -0
- package/dest/prover/server/bb_prover.d.ts.map +1 -0
- package/dest/prover/server/bb_prover.js +712 -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 +37 -23
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/test_circuit_prover.d.ts +27 -36
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +517 -88
- 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 +1 -2
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +9 -34
- 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 +45 -27
- 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 +101 -0
- package/package.json +35 -33
- package/src/avm_proving_tests/avm_proving_tester.ts +223 -113
- package/src/bb/execute.ts +116 -291
- package/src/config.ts +2 -0
- package/src/honk.ts +3 -2
- package/src/index.ts +1 -0
- package/src/instrumentation.ts +10 -43
- package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +94 -33
- package/src/prover/client/bundle.ts +10 -0
- package/src/prover/client/lazy.ts +10 -0
- package/src/prover/index.ts +2 -3
- package/src/prover/proof_utils.ts +115 -0
- package/src/prover/server/bb_prover.ts +718 -0
- package/src/test/delay_values.ts +38 -22
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +264 -154
- package/src/test/test_verifier.ts +15 -3
- package/src/verification_key/verification_key_data.ts +11 -31
- package/src/verifier/bb_verifier.ts +62 -35
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +109 -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
package/src/honk.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/server';
|
|
2
2
|
|
|
3
|
-
export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_rollup_honk';
|
|
3
|
+
export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_starknet_honk' | 'ultra_rollup_honk';
|
|
4
4
|
|
|
5
5
|
const UltraKeccakHonkCircuits = ['RootRollupArtifact'] as const satisfies ServerProtocolArtifact[];
|
|
6
|
-
const UltraHonkCircuits = ['
|
|
6
|
+
const UltraHonkCircuits = ['ParityBaseArtifact', 'ParityRootArtifact'] as const satisfies ServerProtocolArtifact[];
|
|
7
7
|
|
|
8
8
|
export type UltraKeccakHonkServerProtocolArtifact = (typeof UltraKeccakHonkCircuits)[number];
|
|
9
9
|
export type UltraHonkServerProtocolArtifact = (typeof UltraHonkCircuits)[number];
|
|
@@ -17,6 +17,7 @@ export function getUltraHonkFlavorForCircuit(artifact: UltraHonkServerProtocolAr
|
|
|
17
17
|
export function getUltraHonkFlavorForCircuit(artifact: UltraRollupHonkServerProtocolArtifact): 'ultra_rollup_honk';
|
|
18
18
|
export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor;
|
|
19
19
|
export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor {
|
|
20
|
+
// STARKNET: how to allow for the distinction between keccak/starknet? ultra_keccak_honk is returned in both cases
|
|
20
21
|
if (isUltraKeccakHonkCircuit(artifact)) {
|
|
21
22
|
return 'ultra_keccak_honk';
|
|
22
23
|
} else if (UltraHonkCircuits.includes(artifact as UltraHonkServerProtocolArtifact)) {
|
package/src/index.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from './verifier/index.js';
|
|
|
4
4
|
export * from './config.js';
|
|
5
5
|
export * from './bb/execute.js';
|
|
6
6
|
export * from './honk.js';
|
|
7
|
+
export * from './verification_key/verification_key_data.js';
|
|
7
8
|
|
|
8
9
|
export { type ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
package/src/instrumentation.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type Tracer,
|
|
10
|
-
ValueType,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -31,51 +30,21 @@ export class ProverInstrumentation {
|
|
|
31
30
|
this.tracer = telemetry.getTracer(name);
|
|
32
31
|
const meter = telemetry.getMeter(name);
|
|
33
32
|
|
|
34
|
-
this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION
|
|
35
|
-
description: 'Records how long it takes to simulate a circuit',
|
|
36
|
-
unit: 'ms',
|
|
37
|
-
valueType: ValueType.INT,
|
|
38
|
-
});
|
|
33
|
+
this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION);
|
|
39
34
|
|
|
40
|
-
this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION
|
|
41
|
-
description: 'Records how long it takes to generate the partial witness for a circuit',
|
|
42
|
-
unit: 's',
|
|
43
|
-
valueType: ValueType.DOUBLE,
|
|
44
|
-
});
|
|
35
|
+
this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION);
|
|
45
36
|
|
|
46
|
-
this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION
|
|
47
|
-
unit: 's',
|
|
48
|
-
description: 'Records how long it takes to prove a circuit',
|
|
49
|
-
valueType: ValueType.DOUBLE,
|
|
50
|
-
});
|
|
37
|
+
this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION);
|
|
51
38
|
|
|
52
|
-
this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE
|
|
53
|
-
unit: 'By',
|
|
54
|
-
description: 'Records the size of the input to the witness generation',
|
|
55
|
-
valueType: ValueType.INT,
|
|
56
|
-
});
|
|
39
|
+
this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE);
|
|
57
40
|
|
|
58
|
-
this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE
|
|
59
|
-
unit: 'By',
|
|
60
|
-
description: 'Records the size of the output of the witness generation',
|
|
61
|
-
valueType: ValueType.INT,
|
|
62
|
-
});
|
|
41
|
+
this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE);
|
|
63
42
|
|
|
64
|
-
this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE
|
|
65
|
-
unit: 'By',
|
|
66
|
-
description: 'Records the size of the proof generated for a circuit',
|
|
67
|
-
valueType: ValueType.INT,
|
|
68
|
-
});
|
|
43
|
+
this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE);
|
|
69
44
|
|
|
70
|
-
this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT
|
|
71
|
-
description: 'Records the number of public inputs in a circuit',
|
|
72
|
-
valueType: ValueType.INT,
|
|
73
|
-
});
|
|
45
|
+
this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT);
|
|
74
46
|
|
|
75
|
-
this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE
|
|
76
|
-
description: 'Records the size of the circuit in gates',
|
|
77
|
-
valueType: ValueType.INT,
|
|
78
|
-
});
|
|
47
|
+
this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE);
|
|
79
48
|
}
|
|
80
49
|
|
|
81
50
|
/**
|
|
@@ -86,13 +55,12 @@ export class ProverInstrumentation {
|
|
|
86
55
|
*/
|
|
87
56
|
recordDuration(
|
|
88
57
|
metric: 'simulationDuration' | 'witGenDuration' | 'provingDuration',
|
|
89
|
-
circuitName: CircuitName
|
|
58
|
+
circuitName: CircuitName,
|
|
90
59
|
timerOrMS: Timer | number,
|
|
91
60
|
) {
|
|
92
61
|
const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
|
|
93
62
|
this[metric].record(s, {
|
|
94
63
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
95
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
96
64
|
});
|
|
97
65
|
}
|
|
98
66
|
|
|
@@ -117,12 +85,11 @@ export class ProverInstrumentation {
|
|
|
117
85
|
*/
|
|
118
86
|
recordSize(
|
|
119
87
|
metric: 'witGenInputSize' | 'witGenOutputSize' | 'proofSize' | 'circuitSize' | 'circuitPublicInputCount',
|
|
120
|
-
circuitName: CircuitName
|
|
88
|
+
circuitName: CircuitName,
|
|
121
89
|
size: number,
|
|
122
90
|
) {
|
|
123
91
|
this[metric].record(Math.ceil(size), {
|
|
124
92
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
125
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
126
93
|
});
|
|
127
94
|
}
|
|
128
95
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AztecClientBackend, type BackendOptions, Barretenberg } from '@aztec/bb.js';
|
|
2
|
+
import { type LogLevel, type Logger, 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,20 +39,23 @@ 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
|
|
|
48
|
+
export type BBPrivateKernelProverOptions = Omit<BackendOptions, 'logger'> & { logger?: Logger };
|
|
37
49
|
export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
50
|
+
private log: Logger;
|
|
51
|
+
|
|
38
52
|
constructor(
|
|
39
53
|
protected artifactProvider: ArtifactProvider,
|
|
40
|
-
protected
|
|
41
|
-
protected
|
|
42
|
-
) {
|
|
54
|
+
protected simulator: CircuitSimulator,
|
|
55
|
+
protected options: BBPrivateKernelProverOptions = {},
|
|
56
|
+
) {
|
|
57
|
+
this.log = options.logger || createLogger('bb-prover:private-kernel');
|
|
58
|
+
}
|
|
43
59
|
|
|
44
60
|
public async generateInitOutput(
|
|
45
61
|
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
@@ -150,6 +166,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
150
166
|
);
|
|
151
167
|
}
|
|
152
168
|
|
|
169
|
+
public async generateHidingToRollupOutput(
|
|
170
|
+
inputs: HidingKernelToRollupPrivateInputs,
|
|
171
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
172
|
+
return await this.generateCircuitOutput(
|
|
173
|
+
inputs,
|
|
174
|
+
'HidingKernelToRollup',
|
|
175
|
+
convertHidingKernelToRollupInputsToWitnessMapWithAbi,
|
|
176
|
+
convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public async generateHidingToPublicOutput(
|
|
181
|
+
inputs: HidingKernelToPublicPrivateInputs,
|
|
182
|
+
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
183
|
+
return await this.generateCircuitOutput(
|
|
184
|
+
inputs,
|
|
185
|
+
'HidingKernelToPublic',
|
|
186
|
+
convertHidingKernelPublicInputsToWitnessMapWithAbi,
|
|
187
|
+
convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
153
191
|
public async simulateCircuitOutput<
|
|
154
192
|
I extends { toBuffer: () => Buffer },
|
|
155
193
|
O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
|
|
@@ -159,15 +197,13 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
159
197
|
convertInputs: (inputs: I, abi: Abi) => WitnessMap,
|
|
160
198
|
convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
|
|
161
199
|
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
162
|
-
const compiledCircuit:
|
|
163
|
-
circuitType
|
|
164
|
-
);
|
|
200
|
+
const compiledCircuit: NoirCompiledCircuitWithName =
|
|
201
|
+
await this.artifactProvider.getSimulatedClientCircuitArtifactByName(circuitType);
|
|
165
202
|
|
|
166
203
|
const witnessMap = convertInputs(inputs, compiledCircuit.abi);
|
|
167
204
|
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
.executeProtocolCircuit(witnessMap, compiledCircuit)
|
|
205
|
+
const outputWitness = await this.simulator
|
|
206
|
+
.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
|
|
171
207
|
.catch((err: Error) => {
|
|
172
208
|
this.log.debug(`Failed to simulate ${circuitType}`, {
|
|
173
209
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
@@ -175,12 +211,12 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
175
211
|
});
|
|
176
212
|
throw err;
|
|
177
213
|
});
|
|
178
|
-
const output = convertOutputs(outputWitness, compiledCircuit.abi);
|
|
214
|
+
const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
|
|
179
215
|
|
|
180
216
|
this.log.debug(`Simulated ${circuitType}`, {
|
|
181
217
|
eventName: 'circuit-simulation',
|
|
182
218
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
183
|
-
duration:
|
|
219
|
+
duration: outputWitness.duration,
|
|
184
220
|
inputSize: inputs.toBuffer().length,
|
|
185
221
|
outputSize: output.toBuffer().length,
|
|
186
222
|
} satisfies CircuitSimulationStats);
|
|
@@ -198,30 +234,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
198
234
|
convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
|
|
199
235
|
): Promise<PrivateKernelSimulateOutput<O>> {
|
|
200
236
|
this.log.debug(`Generating witness for ${circuitType}`);
|
|
201
|
-
const compiledCircuit:
|
|
202
|
-
circuitType
|
|
203
|
-
);
|
|
237
|
+
const compiledCircuit: NoirCompiledCircuitWithName =
|
|
238
|
+
await this.artifactProvider.getClientCircuitArtifactByName(circuitType);
|
|
204
239
|
|
|
205
240
|
const witnessMap = convertInputs(inputs, compiledCircuit.abi);
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const output = convertOutputs(outputWitness, compiledCircuit.abi);
|
|
241
|
+
const outputWitness = await this.simulator.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler);
|
|
242
|
+
const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
|
|
209
243
|
|
|
210
244
|
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
211
245
|
eventName: 'circuit-witness-generation',
|
|
212
246
|
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
213
|
-
duration:
|
|
247
|
+
duration: outputWitness.duration,
|
|
214
248
|
inputSize: inputs.toBuffer().length,
|
|
215
249
|
outputSize: output.toBuffer().length,
|
|
216
250
|
} satisfies CircuitWitnessGenerationStats);
|
|
217
251
|
|
|
218
|
-
const verificationKey =
|
|
252
|
+
const verificationKey = await this.artifactProvider.getCircuitVkByName(circuitType);
|
|
219
253
|
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
220
254
|
|
|
221
255
|
const kernelOutput: PrivateKernelSimulateOutput<O> = {
|
|
222
256
|
publicInputs: output,
|
|
223
257
|
verificationKey,
|
|
224
|
-
outputWitness,
|
|
258
|
+
outputWitness: outputWitness.witness,
|
|
225
259
|
bytecode,
|
|
226
260
|
};
|
|
227
261
|
return kernelOutput;
|
|
@@ -232,18 +266,45 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
232
266
|
>(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
|
|
233
267
|
const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
|
|
234
268
|
publicInputs,
|
|
235
|
-
verificationKey:
|
|
269
|
+
verificationKey: await this.artifactProvider.getCircuitVkByName(circuitType),
|
|
236
270
|
outputWitness: new Map(),
|
|
237
271
|
bytecode: Buffer.from([]),
|
|
238
272
|
};
|
|
239
273
|
return kernelProofOutput;
|
|
240
274
|
}
|
|
241
275
|
|
|
242
|
-
public
|
|
243
|
-
|
|
276
|
+
public async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
|
|
277
|
+
const timer = new Timer();
|
|
278
|
+
this.log.info(`Generating ClientIVC proof...`);
|
|
279
|
+
const barretenberg = await Barretenberg.initSingleton({
|
|
280
|
+
...this.options,
|
|
281
|
+
logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
|
|
282
|
+
});
|
|
283
|
+
const backend = new AztecClientBackend(
|
|
284
|
+
executionSteps.map(step => ungzip(step.bytecode)),
|
|
285
|
+
barretenberg,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const [proof] = await backend.prove(
|
|
289
|
+
executionSteps.map(step => ungzip(serializeWitness(step.witness))),
|
|
290
|
+
executionSteps.map(step => step.vk),
|
|
291
|
+
);
|
|
292
|
+
this.log.info(`Generated ClientIVC proof`, {
|
|
293
|
+
eventName: 'client-ivc-proof-generation',
|
|
294
|
+
duration: timer.ms(),
|
|
295
|
+
proofSize: proof.length,
|
|
296
|
+
});
|
|
297
|
+
return ChonkProofWithPublicInputs.fromBufferArray(proof);
|
|
244
298
|
}
|
|
245
299
|
|
|
246
|
-
public computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
247
|
-
|
|
300
|
+
public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
301
|
+
// Note we do not pass the vk to the backend. This is unneeded for gate counts.
|
|
302
|
+
const barretenberg = await Barretenberg.initSingleton({
|
|
303
|
+
...this.options,
|
|
304
|
+
logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
|
|
305
|
+
});
|
|
306
|
+
const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg);
|
|
307
|
+
const gateCount = await backend.gates();
|
|
308
|
+
return gateCount[0];
|
|
248
309
|
}
|
|
249
310
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
2
|
+
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
3
|
+
|
|
4
|
+
import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
|
|
5
|
+
|
|
6
|
+
export class BBBundlePrivateKernelProver extends BBPrivateKernelProver {
|
|
7
|
+
constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
|
|
8
|
+
super(new BundleArtifactProvider(), simulator, options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
|
|
2
|
+
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
3
|
+
|
|
4
|
+
import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
|
|
5
|
+
|
|
6
|
+
export class BBLazyPrivateKernelProver extends BBPrivateKernelProver {
|
|
7
|
+
constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
|
|
8
|
+
super(new LazyArtifactProvider(), simulator, options);
|
|
9
|
+
}
|
|
10
|
+
}
|
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
|
+
}
|