@aztec/bb-prover 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
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 +7 -6
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +38 -15
- package/dest/bb/cli.d.ts +1 -1
- package/dest/bb/execute.d.ts +9 -17
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +74 -165
- package/dest/bb/index.d.ts +1 -1
- package/dest/config.d.ts +1 -1
- package/dest/honk.d.ts +2 -2
- package/dest/honk.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/instrumentation.d.ts +3 -3
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +21 -43
- package/dest/prover/client/bb_private_kernel_prover.d.ts +12 -6
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/client/bb_private_kernel_prover.js +38 -7
- 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 +1 -1
- package/dest/prover/proof_utils.d.ts +9 -9
- package/dest/prover/proof_utils.d.ts.map +1 -1
- package/dest/prover/proof_utils.js +42 -25
- package/dest/prover/server/bb_prover.d.ts +27 -50
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +478 -182
- 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 -25
- 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 +24 -34
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +506 -85
- package/dest/test/test_verifier.d.ts +3 -1
- package/dest/test/test_verifier.d.ts.map +1 -1
- package/dest/test/test_verifier.js +15 -0
- package/dest/verification_key/verification_key_data.d.ts +1 -8
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +1 -20
- package/dest/verifier/bb_verifier.d.ts +3 -5
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +23 -28
- package/dest/verifier/index.d.ts +2 -2
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -1
- 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_ivc_verifier.js → queued_chonk_verifier.js} +10 -41
- package/package.json +23 -23
- package/src/avm_proving_tests/avm_proving_tester.ts +49 -35
- package/src/bb/execute.ts +50 -148
- package/src/honk.ts +1 -1
- package/src/instrumentation.ts +22 -45
- package/src/prover/client/bb_private_kernel_prover.ts +50 -10
- package/src/prover/client/bundle.ts +10 -0
- package/src/prover/client/lazy.ts +10 -0
- package/src/prover/proof_utils.ts +53 -31
- package/src/prover/server/bb_prover.ts +252 -324
- package/src/test/delay_values.ts +38 -24
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +229 -155
- package/src/test/test_verifier.ts +8 -0
- package/src/verification_key/verification_key_data.ts +1 -26
- package/src/verifier/bb_verifier.ts +33 -36
- package/src/verifier/index.ts +1 -1
- package/src/verifier/{queued_ivc_verifier.ts → queued_chonk_verifier.ts} +10 -41
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +0 -23
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/client/native/bb_native_private_kernel_prover.js +0 -66
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +0 -15
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +0 -48
- package/dest/prover/client/wasm/bundle.d.ts +0 -6
- package/dest/prover/client/wasm/bundle.d.ts.map +0 -1
- package/dest/prover/client/wasm/bundle.js +0 -8
- package/dest/prover/client/wasm/lazy.d.ts +0 -6
- package/dest/prover/client/wasm/lazy.d.ts.map +0 -1
- package/dest/prover/client/wasm/lazy.js +0 -8
- package/dest/stats.d.ts +0 -4
- package/dest/stats.d.ts.map +0 -1
- package/dest/stats.js +0 -45
- package/dest/verifier/queued_ivc_verifier.d.ts +0 -15
- package/dest/verifier/queued_ivc_verifier.d.ts.map +0 -1
- package/src/prover/client/native/bb_native_private_kernel_prover.ts +0 -105
- package/src/prover/client/wasm/bb_wasm_private_kernel_prover.ts +0 -60
- package/src/prover/client/wasm/bundle.ts +0 -11
- package/src/prover/client/wasm/lazy.ts +0 -11
- package/src/stats.ts +0 -47
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
2
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
4
3
|
import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
|
|
5
4
|
|
|
6
|
-
import { strict as assert } from 'assert';
|
|
7
5
|
import { promises as fs } from 'fs';
|
|
8
6
|
import * as path from 'path';
|
|
9
7
|
|
|
@@ -25,26 +23,3 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
|
|
|
25
23
|
const vkAsFields = await VerificationKeyAsFields.fromKey(fields);
|
|
26
24
|
return new VerificationKeyData(vkAsFields, rawBinary);
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
|
|
31
|
-
* We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
|
|
32
|
-
* @param vkDirectoryPath - The directory containing the verification key binary data file.
|
|
33
|
-
* @returns The verification key data
|
|
34
|
-
*/
|
|
35
|
-
export async function extractAvmVkData(vkDirectoryPath: string): Promise<VerificationKeyData> {
|
|
36
|
-
const rawBinary = await fs.readFile(path.join(vkDirectoryPath, VK_FILENAME));
|
|
37
|
-
|
|
38
|
-
const numFields = rawBinary.length / Fr.SIZE_IN_BYTES;
|
|
39
|
-
assert(numFields <= AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, 'Invalid AVM verification key length');
|
|
40
|
-
const reader = BufferReader.asReader(rawBinary);
|
|
41
|
-
const fieldsArray = reader.readArray(numFields, Fr);
|
|
42
|
-
|
|
43
|
-
const fieldsArrayPadded = fieldsArray.concat(
|
|
44
|
-
Array(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED - fieldsArray.length).fill(new Fr(0)),
|
|
45
|
-
);
|
|
46
|
-
const vkAsFields = await VerificationKeyAsFields.fromKey(fieldsArrayPadded);
|
|
47
|
-
// TODO(#16644): We should have a different type for AVM verification keys since we don't have circuit size or num public inputs in AVM VKs.
|
|
48
|
-
const vk = new VerificationKeyData(vkAsFields, rawBinary);
|
|
49
|
-
return vk;
|
|
50
|
-
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
5
|
+
import {
|
|
6
|
+
type ClientProtocolArtifact,
|
|
7
|
+
type ProtocolArtifact,
|
|
8
|
+
type ServerProtocolArtifact,
|
|
9
|
+
mapProtocolArtifactNameToCircuitName,
|
|
10
|
+
} from '@aztec/noir-protocol-circuits-types/types';
|
|
6
11
|
import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
|
|
7
12
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
8
13
|
import type { CircuitVerificationStats } from '@aztec/stdlib/stats';
|
|
@@ -11,26 +16,18 @@ import type { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
|
11
16
|
|
|
12
17
|
import { promises as fs } from 'fs';
|
|
13
18
|
import * as path from 'path';
|
|
14
|
-
import { fileURLToPath } from 'url';
|
|
15
19
|
|
|
16
20
|
import {
|
|
17
21
|
BB_RESULT,
|
|
18
22
|
PROOF_FILENAME,
|
|
19
23
|
PUBLIC_INPUTS_FILENAME,
|
|
20
24
|
VK_FILENAME,
|
|
21
|
-
|
|
25
|
+
verifyChonkProof,
|
|
22
26
|
verifyProof,
|
|
23
27
|
} from '../bb/execute.js';
|
|
24
28
|
import type { BBConfig } from '../config.js';
|
|
25
29
|
import { getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
26
|
-
import {
|
|
27
|
-
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
28
|
-
|
|
29
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
-
|
|
31
|
-
// Built by yarn generate
|
|
32
|
-
export const PRIVATE_TAIL_CIVC_VK = path.join(__dirname, '../../artifacts/private-civc-vk');
|
|
33
|
-
export const PUBLIC_TAIL_CIVC_VK = path.join(__dirname, '../../artifacts/public-civc-vk');
|
|
30
|
+
import { writeChonkProofToPath } from '../prover/proof_utils.js';
|
|
34
31
|
|
|
35
32
|
export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
36
33
|
private constructor(
|
|
@@ -43,14 +40,17 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
public static async new(config: BBConfig, logger = createLogger('bb-prover:verifier')) {
|
|
43
|
+
if (!config.bbWorkingDirectory) {
|
|
44
|
+
throw new Error(`Barretenberg working directory (BB_WORKING_DIRECTORY) is not set`);
|
|
45
|
+
}
|
|
46
46
|
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
47
47
|
return new BBCircuitVerifier(config, logger);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
public getVerificationKeyData(
|
|
51
|
-
const vk =
|
|
50
|
+
public getVerificationKeyData(circuit: ProtocolArtifact): VerificationKeyData {
|
|
51
|
+
const vk = ProtocolCircuitVks[circuit];
|
|
52
52
|
if (vk === undefined) {
|
|
53
|
-
throw new Error(
|
|
53
|
+
throw new Error(`Could not find VK for artifact ${circuit}`);
|
|
54
54
|
}
|
|
55
55
|
return vk;
|
|
56
56
|
}
|
|
@@ -93,51 +93,48 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
public async verifyProof(tx: Tx): Promise<IVCProofVerificationResult> {
|
|
96
|
+
const proofType = 'Chonk';
|
|
96
97
|
try {
|
|
97
98
|
const totalTimer = new Timer();
|
|
98
99
|
let verificationDuration = 0;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// are not being saved along the other vks yet. Reuse the 'verifyProofForCircuit' method above once
|
|
102
|
-
// we have all the verification keys available.
|
|
103
|
-
const expectedCircuit: ClientProtocolArtifact = tx.data.forPublic
|
|
104
|
-
? 'PrivateKernelTailToPublicArtifact'
|
|
105
|
-
: 'PrivateKernelTailArtifact';
|
|
106
|
-
const circuit = 'ClientIVC';
|
|
100
|
+
|
|
101
|
+
const circuit: ClientProtocolArtifact = tx.data.forPublic ? 'HidingKernelToPublic' : 'HidingKernelToRollup';
|
|
107
102
|
|
|
108
103
|
// Block below is almost copy-pasted from verifyProofForCircuit
|
|
109
104
|
const operation = async (bbWorkingDirectory: string) => {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
const proofPath = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
106
|
+
await writeChonkProofToPath(tx.chonkProof.attachPublicInputs(tx.data.publicInputs().toFields()), proofPath);
|
|
107
|
+
|
|
108
|
+
const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
|
|
109
|
+
const verificationKey = this.getVerificationKeyData(circuit);
|
|
110
|
+
await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
|
|
113
111
|
|
|
114
|
-
await writeClientIVCProofToOutputDirectory(tx.clientIvcProof, bbWorkingDirectory);
|
|
115
112
|
const timer = new Timer();
|
|
116
|
-
const result = await
|
|
113
|
+
const result = await verifyChonkProof(
|
|
117
114
|
this.config.bbBinaryPath,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
proofPath,
|
|
116
|
+
verificationKeyPath,
|
|
117
|
+
this.logger,
|
|
121
118
|
this.config.bbIVCConcurrency,
|
|
122
119
|
);
|
|
123
120
|
verificationDuration = timer.ms();
|
|
124
121
|
|
|
125
122
|
if (result.status === BB_RESULT.FAILURE) {
|
|
126
|
-
const errorMessage = `Failed to verify ${
|
|
123
|
+
const errorMessage = `Failed to verify ${proofType} proof for ${circuit}!`;
|
|
127
124
|
throw new Error(errorMessage);
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
this.logger.debug(`${
|
|
131
|
-
circuitName: mapProtocolArtifactNameToCircuitName(
|
|
127
|
+
this.logger.debug(`${proofType} verification successful`, {
|
|
128
|
+
circuitName: mapProtocolArtifactNameToCircuitName(circuit),
|
|
132
129
|
duration: result.durationMs,
|
|
133
130
|
eventName: 'circuit-verification',
|
|
134
|
-
proofType: '
|
|
131
|
+
proofType: 'chonk',
|
|
135
132
|
} satisfies CircuitVerificationStats);
|
|
136
133
|
};
|
|
137
134
|
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup, this.logger);
|
|
138
135
|
return { valid: true, durationMs: verificationDuration, totalDurationMs: totalTimer.ms() };
|
|
139
136
|
} catch (err) {
|
|
140
|
-
this.logger.warn(`Failed to verify
|
|
137
|
+
this.logger.warn(`Failed to verify ${proofType} proof for tx ${tx.getTxHash().toString()}: ${String(err)}`);
|
|
141
138
|
return { valid: false, durationMs: 0, totalDurationMs: 0 };
|
|
142
139
|
}
|
|
143
140
|
}
|
package/src/verifier/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './bb_verifier.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './queued_chonk_verifier.js';
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type ObservableGauge,
|
|
11
11
|
type TelemetryClient,
|
|
12
12
|
type UpDownCounter,
|
|
13
|
-
|
|
13
|
+
createUpDownCounterWithDefault,
|
|
14
14
|
getTelemetryClient,
|
|
15
15
|
} from '@aztec/telemetry-client';
|
|
16
16
|
|
|
@@ -36,49 +36,18 @@ class IVCVerifierMetrics {
|
|
|
36
36
|
constructor(client: TelemetryClient, name = 'QueuedIVCVerifier') {
|
|
37
37
|
const meter = client.getMeter(name);
|
|
38
38
|
|
|
39
|
-
this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME
|
|
40
|
-
unit: 'ms',
|
|
41
|
-
description: 'Duration to verify client IVC proofs',
|
|
42
|
-
valueType: ValueType.INT,
|
|
43
|
-
});
|
|
39
|
+
this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME);
|
|
44
40
|
|
|
45
|
-
this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME
|
|
46
|
-
unit: 'ms',
|
|
47
|
-
description: 'Total duration to verify client IVC proofs, including serde',
|
|
48
|
-
valueType: ValueType.INT,
|
|
49
|
-
});
|
|
41
|
+
this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
|
|
50
42
|
|
|
51
|
-
this.ivcFailureCount = meter
|
|
52
|
-
description: 'Count of failed IVC proof verifications',
|
|
53
|
-
valueType: ValueType.INT,
|
|
54
|
-
});
|
|
43
|
+
this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
|
|
55
44
|
|
|
56
45
|
this.aggDurationMetrics = {
|
|
57
|
-
avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX, {
|
|
63
|
-
valueType: ValueType.DOUBLE,
|
|
64
|
-
description: 'MAX ivc verification',
|
|
65
|
-
unit: 'ms',
|
|
66
|
-
}),
|
|
67
|
-
min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN, {
|
|
68
|
-
valueType: ValueType.DOUBLE,
|
|
69
|
-
description: 'MIN ivc verification',
|
|
70
|
-
unit: 'ms',
|
|
71
|
-
}),
|
|
72
|
-
p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50, {
|
|
73
|
-
valueType: ValueType.DOUBLE,
|
|
74
|
-
description: 'P50 ivc verification',
|
|
75
|
-
unit: 'ms',
|
|
76
|
-
}),
|
|
77
|
-
p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90, {
|
|
78
|
-
valueType: ValueType.DOUBLE,
|
|
79
|
-
description: 'P90 ivc verification',
|
|
80
|
-
unit: 'ms',
|
|
81
|
-
}),
|
|
46
|
+
avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),
|
|
47
|
+
max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX),
|
|
48
|
+
min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN),
|
|
49
|
+
p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50),
|
|
50
|
+
p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90),
|
|
82
51
|
};
|
|
83
52
|
|
|
84
53
|
meter.addBatchObservableCallback(this.aggregate, Object.values(this.aggDurationMetrics));
|
|
@@ -120,7 +89,7 @@ export class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
|
|
|
120
89
|
config: BBConfig,
|
|
121
90
|
private verifier: ClientProtocolCircuitVerifier,
|
|
122
91
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
123
|
-
private logger = createLogger('bb-prover:
|
|
92
|
+
private logger = createLogger('bb-prover:queued_chonk_verifier'),
|
|
124
93
|
) {
|
|
125
94
|
this.metrics = new IVCVerifierMetrics(this.telemetry, 'QueuedIVCVerifier');
|
|
126
95
|
this.queue = new SerialQueue();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
-
import type { CircuitSimulator } from '@aztec/simulator/server';
|
|
3
|
-
import { type PrivateExecutionStep } from '@aztec/stdlib/kernel';
|
|
4
|
-
import type { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
5
|
-
import type { BBConfig } from '../../../config.js';
|
|
6
|
-
import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
|
|
7
|
-
/**
|
|
8
|
-
* This proof creator implementation uses the native bb binary.
|
|
9
|
-
*/
|
|
10
|
-
export declare class BBNativePrivateKernelProver extends BBPrivateKernelProver {
|
|
11
|
-
private bbBinaryPath;
|
|
12
|
-
private bbWorkingDirectory;
|
|
13
|
-
private skipCleanup;
|
|
14
|
-
protected simulator: CircuitSimulator;
|
|
15
|
-
protected log: Logger;
|
|
16
|
-
private constructor();
|
|
17
|
-
static new(config: BBConfig, simulator: CircuitSimulator, log?: Logger): Promise<BBNativePrivateKernelProver>;
|
|
18
|
-
private _createClientIvcProof;
|
|
19
|
-
createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof>;
|
|
20
|
-
computeGateCountForCircuit(bytecode: Buffer, circuitName: string): Promise<number>;
|
|
21
|
-
private runInDirectory;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=bb_native_private_kernel_prover.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bb_native_private_kernel_prover.d.ts","sourceRoot":"","sources":["../../../../src/prover/client/native/bb_native_private_kernel_prover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,KAAK,oBAAoB,EAAkC,MAAM,sBAAsB,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,qBAAqB;IAElE,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,WAAW;cACA,SAAS,EAAE,gBAAgB;cAC3B,GAAG;IALxB,OAAO;WAUa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM;YAWrE,qBAAqB;IAuBb,oBAAoB,CAAC,cAAc,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAQrF,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBxG,OAAO,CAAC,cAAc;CAavB"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { runInDirectory } from '@aztec/foundation/fs';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
4
|
-
import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { BB_RESULT, computeGateCountForCircuit, executeBbClientIvcProof } from '../../../bb/execute.js';
|
|
8
|
-
import { readClientIVCProofFromOutputDirectory } from '../../proof_utils.js';
|
|
9
|
-
import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
|
|
10
|
-
/**
|
|
11
|
-
* This proof creator implementation uses the native bb binary.
|
|
12
|
-
*/ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
|
|
13
|
-
bbBinaryPath;
|
|
14
|
-
bbWorkingDirectory;
|
|
15
|
-
skipCleanup;
|
|
16
|
-
simulator;
|
|
17
|
-
log;
|
|
18
|
-
constructor(bbBinaryPath, bbWorkingDirectory, skipCleanup, simulator, log = createLogger('bb-prover:native')){
|
|
19
|
-
super(new BundleArtifactProvider(), simulator, log), this.bbBinaryPath = bbBinaryPath, this.bbWorkingDirectory = bbWorkingDirectory, this.skipCleanup = skipCleanup, this.simulator = simulator, this.log = log;
|
|
20
|
-
}
|
|
21
|
-
static async new(config, simulator, log) {
|
|
22
|
-
await fs.mkdir(config.bbWorkingDirectory, {
|
|
23
|
-
recursive: true
|
|
24
|
-
});
|
|
25
|
-
return new BBNativePrivateKernelProver(config.bbBinaryPath, config.bbWorkingDirectory, !!config.bbSkipCleanup, simulator, log);
|
|
26
|
-
}
|
|
27
|
-
async _createClientIvcProof(directory, executionSteps) {
|
|
28
|
-
const inputsPath = path.join(directory, 'ivc-inputs.msgpack');
|
|
29
|
-
await fs.writeFile(inputsPath, serializePrivateExecutionSteps(executionSteps));
|
|
30
|
-
const provingResult = await executeBbClientIvcProof(this.bbBinaryPath, directory, inputsPath, this.log.info);
|
|
31
|
-
if (provingResult.status === BB_RESULT.FAILURE) {
|
|
32
|
-
this.log.error(`Failed to generate client ivc proof`);
|
|
33
|
-
throw new Error(provingResult.reason);
|
|
34
|
-
}
|
|
35
|
-
const proof = await readClientIVCProofFromOutputDirectory(directory);
|
|
36
|
-
this.log.info(`Generated IVC proof`, {
|
|
37
|
-
duration: provingResult.durationMs,
|
|
38
|
-
eventName: 'circuit-proving'
|
|
39
|
-
});
|
|
40
|
-
return proof;
|
|
41
|
-
}
|
|
42
|
-
async createClientIvcProof(executionSteps) {
|
|
43
|
-
this.log.info(`Generating Client IVC proof`);
|
|
44
|
-
const operation = async (directory)=>{
|
|
45
|
-
return await this._createClientIvcProof(directory, executionSteps);
|
|
46
|
-
};
|
|
47
|
-
return await this.runInDirectory(operation);
|
|
48
|
-
}
|
|
49
|
-
async computeGateCountForCircuit(bytecode, circuitName) {
|
|
50
|
-
const logFunction = (message)=>{
|
|
51
|
-
this.log.debug(`$bb gates ${circuitName} - ${message}`);
|
|
52
|
-
};
|
|
53
|
-
const result = await computeGateCountForCircuit(this.bbBinaryPath, this.bbWorkingDirectory, circuitName, bytecode, 'mega_honk', logFunction);
|
|
54
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
55
|
-
throw new Error(result.reason);
|
|
56
|
-
}
|
|
57
|
-
return result.circuitSize;
|
|
58
|
-
}
|
|
59
|
-
runInDirectory(fn) {
|
|
60
|
-
const log = this.log;
|
|
61
|
-
return runInDirectory(this.bbWorkingDirectory, (dir)=>fn(dir).catch((err)=>{
|
|
62
|
-
log.error(`Error running operation at ${dir}: ${err}`);
|
|
63
|
-
throw err;
|
|
64
|
-
}), this.skipCleanup, this.log);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ArtifactProvider } from '@aztec/noir-protocol-circuits-types/types';
|
|
2
|
-
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
3
|
-
import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
|
|
4
|
-
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
5
|
-
import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
|
|
6
|
-
export declare abstract class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
|
|
7
|
-
protected artifactProvider: ArtifactProvider;
|
|
8
|
-
protected simulator: CircuitSimulator;
|
|
9
|
-
private threads;
|
|
10
|
-
protected log: import("@aztec/foundation/log").Logger;
|
|
11
|
-
constructor(artifactProvider: ArtifactProvider, simulator: CircuitSimulator, threads?: number, log?: import("@aztec/foundation/log").Logger);
|
|
12
|
-
createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof>;
|
|
13
|
-
computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=bb_wasm_private_kernel_prover.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bb_wasm_private_kernel_prover.d.ts","sourceRoot":"","sources":["../../../../src/prover/client/wasm/bb_wasm_private_kernel_prover.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,8BAAsB,yBAA0B,SAAQ,qBAAqB;cAEtD,gBAAgB,EAAE,gBAAgB;cAClC,SAAS,EAAE,gBAAgB;IAC9C,OAAO,CAAC,OAAO;cACI,GAAG;gBAHH,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,gBAAgB,EACtC,OAAO,GAAE,MAAU,EACR,GAAG,yCAAiC;IAKnC,oBAAoB,CAAC,cAAc,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAuBrF,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAa3G"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { AztecClientBackend } from '@aztec/bb.js';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
-
import { serializeWitness } from '@aztec/noir-noirc_abi';
|
|
5
|
-
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
6
|
-
import { ungzip } from 'pako';
|
|
7
|
-
import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
|
|
8
|
-
export class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
|
|
9
|
-
artifactProvider;
|
|
10
|
-
simulator;
|
|
11
|
-
threads;
|
|
12
|
-
log;
|
|
13
|
-
constructor(artifactProvider, simulator, threads = 1, log = createLogger('bb-prover:wasm')){
|
|
14
|
-
super(artifactProvider, simulator, log), this.artifactProvider = artifactProvider, this.simulator = simulator, this.threads = threads, this.log = log;
|
|
15
|
-
}
|
|
16
|
-
async createClientIvcProof(executionSteps) {
|
|
17
|
-
const timer = new Timer();
|
|
18
|
-
this.log.info(`Generating ClientIVC proof...`);
|
|
19
|
-
const backend = new AztecClientBackend(executionSteps.map((step)=>ungzip(step.bytecode)), {
|
|
20
|
-
threads: this.threads,
|
|
21
|
-
logger: this.log.verbose,
|
|
22
|
-
wasmPath: process.env.BB_WASM_PATH
|
|
23
|
-
});
|
|
24
|
-
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1297): the vk is not provided to the network anymore.
|
|
25
|
-
// Move this sanity check inside the wasm code and remove the vk from the return value.
|
|
26
|
-
const [proof, _vk] = await backend.prove(executionSteps.map((step)=>ungzip(serializeWitness(step.witness))), executionSteps.map((step)=>step.vk));
|
|
27
|
-
await backend.destroy();
|
|
28
|
-
this.log.info(`Generated ClientIVC proof`, {
|
|
29
|
-
eventName: 'client-ivc-proof-generation',
|
|
30
|
-
duration: timer.ms(),
|
|
31
|
-
proofSize: proof.length
|
|
32
|
-
});
|
|
33
|
-
return new ClientIvcProof(Buffer.from(proof));
|
|
34
|
-
}
|
|
35
|
-
async computeGateCountForCircuit(_bytecode, _circuitName) {
|
|
36
|
-
// Note we do not pass the vk to the backend. This is unneeded for gate counts.
|
|
37
|
-
const backend = new AztecClientBackend([
|
|
38
|
-
ungzip(_bytecode)
|
|
39
|
-
], {
|
|
40
|
-
threads: this.threads,
|
|
41
|
-
logger: this.log.verbose,
|
|
42
|
-
wasmPath: process.env.BB_WASM_PATH
|
|
43
|
-
});
|
|
44
|
-
const gateCount = await backend.gates();
|
|
45
|
-
await backend.destroy();
|
|
46
|
-
return gateCount[0];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
2
|
-
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
3
|
-
export declare class BBWASMBundlePrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
4
|
-
constructor(simulator: CircuitSimulator, threads?: number, log?: import("@aztec/foundation/log").Logger);
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../../src/prover/client/wasm/bundle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,qBAAa,+BAAgC,SAAQ,yBAAyB;gBAChE,SAAS,EAAE,gBAAgB,EAAE,OAAO,SAAK,EAAE,GAAG,yCAAwC;CAGnG"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
3
|
-
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
4
|
-
export class BBWASMBundlePrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
5
|
-
constructor(simulator, threads = 16, log = createLogger('bb-prover:wasm:bundle')){
|
|
6
|
-
super(new BundleArtifactProvider(), simulator, threads, log);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
2
|
-
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
3
|
-
export declare class BBWASMLazyPrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
4
|
-
constructor(simulator: CircuitSimulator, threads?: number, log?: import("@aztec/foundation/log").Logger);
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../../src/prover/client/wasm/lazy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,qBAAa,6BAA8B,SAAQ,yBAAyB;gBAC9D,SAAS,EAAE,gBAAgB,EAAE,OAAO,SAAK,EAAE,GAAG,yCAAsC;CAGjG"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
|
|
3
|
-
import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
|
|
4
|
-
export class BBWASMLazyPrivateKernelProver extends BBWASMPrivateKernelProver {
|
|
5
|
-
constructor(simulator, threads = 16, log = createLogger('bb-prover:wasm:lazy')){
|
|
6
|
-
super(new LazyArtifactProvider(), simulator, threads, log);
|
|
7
|
-
}
|
|
8
|
-
}
|
package/dest/stats.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
|
|
2
|
-
import type { CircuitName } from '@aztec/stdlib/stats';
|
|
3
|
-
export declare function mapProtocolArtifactNameToCircuitName(artifact: ProtocolArtifact): CircuitName;
|
|
4
|
-
//# sourceMappingURL=stats.d.ts.map
|
package/dest/stats.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../src/stats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,oCAAoC,CAAC,QAAQ,EAAE,gBAAgB,GAAG,WAAW,CA2C5F"}
|
package/dest/stats.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export function mapProtocolArtifactNameToCircuitName(artifact) {
|
|
2
|
-
switch(artifact){
|
|
3
|
-
case 'BaseParityArtifact':
|
|
4
|
-
return 'base-parity';
|
|
5
|
-
case 'RootParityArtifact':
|
|
6
|
-
return 'root-parity';
|
|
7
|
-
case 'PrivateBaseRollupArtifact':
|
|
8
|
-
return 'private-base-rollup';
|
|
9
|
-
case 'PublicBaseRollupArtifact':
|
|
10
|
-
return 'public-base-rollup';
|
|
11
|
-
case 'MergeRollupArtifact':
|
|
12
|
-
return 'merge-rollup';
|
|
13
|
-
case 'BlockRootRollupArtifact':
|
|
14
|
-
return 'block-root-rollup';
|
|
15
|
-
case 'SingleTxBlockRootRollupArtifact':
|
|
16
|
-
return 'single-tx-block-root-rollup';
|
|
17
|
-
case 'EmptyBlockRootRollupArtifact':
|
|
18
|
-
return 'empty-block-root-rollup';
|
|
19
|
-
case 'PaddingBlockRootRollupArtifact':
|
|
20
|
-
return 'padding-block-root-rollup';
|
|
21
|
-
case 'BlockMergeRollupArtifact':
|
|
22
|
-
return 'block-merge-rollup';
|
|
23
|
-
case 'RootRollupArtifact':
|
|
24
|
-
return 'root-rollup';
|
|
25
|
-
case 'PrivateKernelInitArtifact':
|
|
26
|
-
return 'private-kernel-init';
|
|
27
|
-
case 'PrivateKernelInnerArtifact':
|
|
28
|
-
return 'private-kernel-inner';
|
|
29
|
-
case 'PrivateKernelTailArtifact':
|
|
30
|
-
return 'private-kernel-tail';
|
|
31
|
-
case 'PrivateKernelTailToPublicArtifact':
|
|
32
|
-
return 'private-kernel-tail-to-public';
|
|
33
|
-
case 'HidingKernelToRollup':
|
|
34
|
-
return 'hiding-kernel-to-rollup';
|
|
35
|
-
case 'HidingKernelToPublic':
|
|
36
|
-
return 'hiding-kernel-to-public';
|
|
37
|
-
default:
|
|
38
|
-
{
|
|
39
|
-
if (artifact.startsWith('PrivateKernelReset')) {
|
|
40
|
-
return 'private-kernel-reset';
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`Unknown circuit type: ${artifact}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type { Tx } from '@aztec/stdlib/tx';
|
|
3
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
-
import type { BBConfig } from '../config.js';
|
|
5
|
-
export declare class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
|
|
6
|
-
private verifier;
|
|
7
|
-
private telemetry;
|
|
8
|
-
private logger;
|
|
9
|
-
private queue;
|
|
10
|
-
private metrics;
|
|
11
|
-
constructor(config: BBConfig, verifier: ClientProtocolCircuitVerifier, telemetry?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
|
|
12
|
-
verifyProof(tx: Tx): Promise<IVCProofVerificationResult>;
|
|
13
|
-
stop(): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=queued_ivc_verifier.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queued_ivc_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/queued_ivc_verifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAML,KAAK,eAAe,EAIrB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAgG7C,qBAAa,iBAAkB,YAAW,6BAA6B;IAMnE,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAqB;gBAGlC,MAAM,EAAE,QAAQ,EACR,QAAQ,EAAE,6BAA6B,EACvC,SAAS,GAAE,eAAsC,EACjD,MAAM,yCAAgD;IAQnD,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAMrE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtB"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { runInDirectory } from '@aztec/foundation/fs';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
4
|
-
import type { CircuitSimulator } from '@aztec/simulator/server';
|
|
5
|
-
import { type PrivateExecutionStep, serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
|
|
6
|
-
import type { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
7
|
-
|
|
8
|
-
import { promises as fs } from 'fs';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
|
|
11
|
-
import { BB_RESULT, computeGateCountForCircuit, executeBbClientIvcProof } from '../../../bb/execute.js';
|
|
12
|
-
import type { BBConfig } from '../../../config.js';
|
|
13
|
-
import { readClientIVCProofFromOutputDirectory } from '../../proof_utils.js';
|
|
14
|
-
import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* This proof creator implementation uses the native bb binary.
|
|
18
|
-
*/
|
|
19
|
-
export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
|
|
20
|
-
private constructor(
|
|
21
|
-
private bbBinaryPath: string,
|
|
22
|
-
private bbWorkingDirectory: string,
|
|
23
|
-
private skipCleanup: boolean,
|
|
24
|
-
protected override simulator: CircuitSimulator,
|
|
25
|
-
protected override log = createLogger('bb-prover:native'),
|
|
26
|
-
) {
|
|
27
|
-
super(new BundleArtifactProvider(), simulator, log);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public static async new(config: BBConfig, simulator: CircuitSimulator, log?: Logger) {
|
|
31
|
-
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
32
|
-
return new BBNativePrivateKernelProver(
|
|
33
|
-
config.bbBinaryPath,
|
|
34
|
-
config.bbWorkingDirectory,
|
|
35
|
-
!!config.bbSkipCleanup,
|
|
36
|
-
simulator,
|
|
37
|
-
log,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private async _createClientIvcProof(
|
|
42
|
-
directory: string,
|
|
43
|
-
executionSteps: PrivateExecutionStep[],
|
|
44
|
-
): Promise<ClientIvcProof> {
|
|
45
|
-
const inputsPath = path.join(directory, 'ivc-inputs.msgpack');
|
|
46
|
-
await fs.writeFile(inputsPath, serializePrivateExecutionSteps(executionSteps));
|
|
47
|
-
const provingResult = await executeBbClientIvcProof(this.bbBinaryPath, directory, inputsPath, this.log.info);
|
|
48
|
-
|
|
49
|
-
if (provingResult.status === BB_RESULT.FAILURE) {
|
|
50
|
-
this.log.error(`Failed to generate client ivc proof`);
|
|
51
|
-
throw new Error(provingResult.reason);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const proof = await readClientIVCProofFromOutputDirectory(directory);
|
|
55
|
-
|
|
56
|
-
this.log.info(`Generated IVC proof`, {
|
|
57
|
-
duration: provingResult.durationMs,
|
|
58
|
-
eventName: 'circuit-proving',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return proof;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public override async createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof> {
|
|
65
|
-
this.log.info(`Generating Client IVC proof`);
|
|
66
|
-
const operation = async (directory: string) => {
|
|
67
|
-
return await this._createClientIvcProof(directory, executionSteps);
|
|
68
|
-
};
|
|
69
|
-
return await this.runInDirectory(operation);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public override async computeGateCountForCircuit(bytecode: Buffer, circuitName: string): Promise<number> {
|
|
73
|
-
const logFunction = (message: string) => {
|
|
74
|
-
this.log.debug(`$bb gates ${circuitName} - ${message}`);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const result = await computeGateCountForCircuit(
|
|
78
|
-
this.bbBinaryPath,
|
|
79
|
-
this.bbWorkingDirectory,
|
|
80
|
-
circuitName,
|
|
81
|
-
bytecode,
|
|
82
|
-
'mega_honk',
|
|
83
|
-
logFunction,
|
|
84
|
-
);
|
|
85
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
86
|
-
throw new Error(result.reason);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return result.circuitSize as number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
|
|
93
|
-
const log = this.log;
|
|
94
|
-
return runInDirectory(
|
|
95
|
-
this.bbWorkingDirectory,
|
|
96
|
-
(dir: string) =>
|
|
97
|
-
fn(dir).catch(err => {
|
|
98
|
-
log.error(`Error running operation at ${dir}: ${err}`);
|
|
99
|
-
throw err;
|
|
100
|
-
}),
|
|
101
|
-
this.skipCleanup,
|
|
102
|
-
this.log,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|