@aztec/bb-prover 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +16 -10
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +182 -111
- package/dest/bb/bb_js_backend.d.ts +196 -0
- package/dest/bb/bb_js_backend.d.ts.map +1 -0
- package/dest/bb/bb_js_backend.js +379 -0
- package/dest/bb/bb_js_debug.d.ts +52 -0
- package/dest/bb/bb_js_debug.d.ts.map +1 -0
- package/dest/bb/bb_js_debug.js +176 -0
- package/dest/bb/file_names.d.ts +4 -0
- package/dest/bb/file_names.d.ts.map +1 -0
- package/dest/bb/file_names.js +5 -0
- package/dest/config.d.ts +17 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/instrumentation.d.ts +1 -1
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +21 -43
- package/dest/prover/client/bb_private_kernel_prover.d.ts +29 -7
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/client/bb_private_kernel_prover.js +90 -16
- package/dest/prover/client/bundle.d.ts +3 -3
- package/dest/prover/client/bundle.d.ts.map +1 -1
- package/dest/prover/client/bundle.js +2 -3
- package/dest/prover/client/lazy.d.ts +3 -3
- package/dest/prover/client/lazy.d.ts.map +1 -1
- package/dest/prover/client/lazy.js +2 -3
- package/dest/prover/proof_utils.d.ts +11 -1
- package/dest/prover/proof_utils.d.ts.map +1 -1
- package/dest/prover/proof_utils.js +25 -2
- package/dest/prover/server/bb_prover.d.ts +9 -13
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +613 -113
- 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 +28 -26
- 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 +5 -5
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +462 -59
- 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 +2 -21
- package/dest/verifier/batch_chonk_verifier.d.ts +56 -0
- package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/batch_chonk_verifier.js +384 -0
- package/dest/verifier/bb_verifier.d.ts +4 -1
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +134 -48
- 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 +2 -3
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
- package/dest/verifier/queued_chonk_verifier.js +15 -45
- package/package.json +20 -18
- package/src/avm_proving_tests/avm_proving_tester.ts +91 -142
- package/src/bb/bb_js_backend.ts +435 -0
- package/src/bb/bb_js_debug.ts +227 -0
- package/src/bb/file_names.ts +6 -0
- package/src/config.ts +16 -0
- package/src/index.ts +2 -1
- package/src/instrumentation.ts +20 -43
- package/src/prover/client/bb_private_kernel_prover.ts +259 -25
- package/src/prover/client/bundle.ts +3 -4
- package/src/prover/client/lazy.ts +3 -4
- package/src/prover/proof_utils.ts +42 -2
- package/src/prover/server/bb_prover.ts +132 -162
- package/src/test/delay_values.ts +30 -26
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +11 -16
- package/src/verification_key/verification_key_data.ts +2 -27
- package/src/verifier/batch_chonk_verifier.ts +415 -0
- package/src/verifier/bb_verifier.ts +66 -80
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +15 -47
- package/dest/bb/execute.d.ts +0 -107
- package/dest/bb/execute.d.ts.map +0 -1
- package/dest/bb/execute.js +0 -676
- package/src/bb/execute.ts +0 -706
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
3
3
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
-
import type { BBConfig } from '../config.js';
|
|
5
4
|
export declare class QueuedIVCVerifier implements ClientProtocolCircuitVerifier {
|
|
6
5
|
private verifier;
|
|
7
6
|
private telemetry;
|
|
8
7
|
private logger;
|
|
9
8
|
private queue;
|
|
10
9
|
private metrics;
|
|
11
|
-
constructor(
|
|
10
|
+
constructor(verifier: ClientProtocolCircuitVerifier, concurrency: number, telemetry?: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
|
|
12
11
|
verifyProof(tx: Tx): Promise<IVCProofVerificationResult>;
|
|
13
12
|
stop(): Promise<void>;
|
|
14
13
|
}
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVldWVkX2Nob25rX3ZlcmlmaWVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvcXVldWVkX2Nob25rX3ZlcmlmaWVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLDZCQUE2QixFQUFFLDBCQUEwQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakgsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDM0MsT0FBTyxFQU1MLEtBQUssZUFBZSxFQUlyQixNQUFNLHlCQUF5QixDQUFDO0FBbUVqQyxxQkFBYSxpQkFBa0IsWUFBVyw2QkFBNkI7SUFLbkUsT0FBTyxDQUFDLFFBQVE7SUFFaEIsT0FBTyxDQUFDLFNBQVM7SUFDakIsT0FBTyxDQUFDLE1BQU07SUFQaEIsT0FBTyxDQUFDLEtBQUssQ0FBYztJQUMzQixPQUFPLENBQUMsT0FBTyxDQUFxQjtJQUVwQyxZQUNVLFFBQVEsRUFBRSw2QkFBNkIsRUFDL0MsV0FBVyxFQUFFLE1BQU0sRUFDWCxTQUFTLEdBQUUsZUFBc0MsRUFDakQsTUFBTSx5Q0FBa0QsRUFNakU7SUFFWSxXQUFXLENBQUMsRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsMEJBQTBCLENBQUMsQ0FJcEU7SUFFSyxJQUFJLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUcxQjtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queued_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/queued_chonk_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;
|
|
1
|
+
{"version":3,"file":"queued_chonk_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/queued_chonk_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;AAmEjC,qBAAa,iBAAkB,YAAW,6BAA6B;IAKnE,OAAO,CAAC,QAAQ;IAEhB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAqB;IAEpC,YACU,QAAQ,EAAE,6BAA6B,EAC/C,WAAW,EAAE,MAAM,EACX,SAAS,GAAE,eAAsC,EACjD,MAAM,yCAAkD,EAMjE;IAEY,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAIpE;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1B;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
|
-
import { Attributes, Metrics,
|
|
3
|
+
import { Attributes, Metrics, createUpDownCounterWithDefault, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
import { createHistogram } from 'node:perf_hooks';
|
|
5
5
|
class IVCVerifierMetrics {
|
|
6
6
|
ivcVerificationHistogram;
|
|
@@ -17,46 +17,15 @@ class IVCVerifierMetrics {
|
|
|
17
17
|
aggDurationMetrics;
|
|
18
18
|
constructor(client, name = 'QueuedIVCVerifier'){
|
|
19
19
|
const meter = client.getMeter(name);
|
|
20
|
-
this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
valueType: ValueType.INT
|
|
24
|
-
});
|
|
25
|
-
this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME, {
|
|
26
|
-
unit: 'ms',
|
|
27
|
-
description: 'Total duration to verify chonk proofs, including serde',
|
|
28
|
-
valueType: ValueType.INT
|
|
29
|
-
});
|
|
30
|
-
this.ivcFailureCount = meter.createUpDownCounter(Metrics.IVC_VERIFIER_FAILURE_COUNT, {
|
|
31
|
-
description: 'Count of failed IVC proof verifications',
|
|
32
|
-
valueType: ValueType.INT
|
|
33
|
-
});
|
|
20
|
+
this.ivcVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TIME);
|
|
21
|
+
this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
|
|
22
|
+
this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
|
|
34
23
|
this.aggDurationMetrics = {
|
|
35
|
-
avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX, {
|
|
41
|
-
valueType: ValueType.DOUBLE,
|
|
42
|
-
description: 'MAX ivc verification',
|
|
43
|
-
unit: 'ms'
|
|
44
|
-
}),
|
|
45
|
-
min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN, {
|
|
46
|
-
valueType: ValueType.DOUBLE,
|
|
47
|
-
description: 'MIN ivc verification',
|
|
48
|
-
unit: 'ms'
|
|
49
|
-
}),
|
|
50
|
-
p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50, {
|
|
51
|
-
valueType: ValueType.DOUBLE,
|
|
52
|
-
description: 'P50 ivc verification',
|
|
53
|
-
unit: 'ms'
|
|
54
|
-
}),
|
|
55
|
-
p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90, {
|
|
56
|
-
valueType: ValueType.DOUBLE,
|
|
57
|
-
description: 'P90 ivc verification',
|
|
58
|
-
unit: 'ms'
|
|
59
|
-
})
|
|
24
|
+
avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),
|
|
25
|
+
max: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MAX),
|
|
26
|
+
min: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_MIN),
|
|
27
|
+
p50: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P50),
|
|
28
|
+
p90: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_P90)
|
|
60
29
|
};
|
|
61
30
|
meter.addBatchObservableCallback(this.aggregate, Object.values(this.aggDurationMetrics));
|
|
62
31
|
}
|
|
@@ -112,21 +81,22 @@ export class QueuedIVCVerifier {
|
|
|
112
81
|
logger;
|
|
113
82
|
queue;
|
|
114
83
|
metrics;
|
|
115
|
-
constructor(
|
|
84
|
+
constructor(verifier, concurrency, telemetry = getTelemetryClient(), logger = createLogger('bb-prover:queued_chonk_verifier')){
|
|
116
85
|
this.verifier = verifier;
|
|
117
86
|
this.telemetry = telemetry;
|
|
118
87
|
this.logger = logger;
|
|
119
88
|
this.metrics = new IVCVerifierMetrics(this.telemetry, 'QueuedIVCVerifier');
|
|
120
89
|
this.queue = new SerialQueue();
|
|
121
|
-
this.logger.info(`Starting QueuedIVCVerifier with ${
|
|
122
|
-
this.queue.start(
|
|
90
|
+
this.logger.info(`Starting QueuedIVCVerifier with ${concurrency} concurrent verifiers`);
|
|
91
|
+
this.queue.start(concurrency);
|
|
123
92
|
}
|
|
124
93
|
async verifyProof(tx) {
|
|
125
94
|
const result = await this.queue.put(()=>this.verifier.verifyProof(tx));
|
|
126
95
|
this.metrics.recordIVCVerification(result);
|
|
127
96
|
return result;
|
|
128
97
|
}
|
|
129
|
-
stop() {
|
|
130
|
-
|
|
98
|
+
async stop() {
|
|
99
|
+
await this.queue.end();
|
|
100
|
+
await this.verifier.stop();
|
|
131
101
|
}
|
|
132
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d58ff9d0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"./client": "./dest/prover/client/bb_private_kernel_prover.js",
|
|
10
10
|
"./verifier": "./dest/verifier/index.js",
|
|
11
11
|
"./test": "./dest/test/index.js",
|
|
12
|
-
"./config": "./dest/config.js"
|
|
12
|
+
"./config": "./dest/config.js",
|
|
13
|
+
"./debug": "./dest/bb/bb_js_debug.js"
|
|
13
14
|
},
|
|
14
15
|
"bin": {
|
|
15
16
|
"bb-cli": "./dest/bb/index.js"
|
|
@@ -69,32 +70,33 @@
|
|
|
69
70
|
]
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
73
|
-
"@aztec/constants": "0.0.1-commit.
|
|
74
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
75
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
76
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
77
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
80
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
81
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb.js": "0.0.1-commit.d58ff9d0",
|
|
74
|
+
"@aztec/constants": "0.0.1-commit.d58ff9d0",
|
|
75
|
+
"@aztec/foundation": "0.0.1-commit.d58ff9d0",
|
|
76
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.d58ff9d0",
|
|
77
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.d58ff9d0",
|
|
78
|
+
"@aztec/noir-types": "0.0.1-commit.d58ff9d0",
|
|
79
|
+
"@aztec/simulator": "0.0.1-commit.d58ff9d0",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.d58ff9d0",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.d58ff9d0",
|
|
82
|
+
"@aztec/world-state": "0.0.1-commit.d58ff9d0",
|
|
82
83
|
"commander": "^12.1.0",
|
|
84
|
+
"msgpackr": "^1.11.2",
|
|
83
85
|
"pako": "^2.1.0",
|
|
84
86
|
"source-map-support": "^0.5.21",
|
|
85
87
|
"tslib": "^2.4.0"
|
|
86
88
|
},
|
|
87
89
|
"devDependencies": {
|
|
88
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
89
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
90
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
91
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
92
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
90
|
+
"@aztec/ethereum": "0.0.1-commit.d58ff9d0",
|
|
91
|
+
"@aztec/kv-store": "0.0.1-commit.d58ff9d0",
|
|
92
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.d58ff9d0",
|
|
93
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.d58ff9d0",
|
|
94
|
+
"@aztec/protocol-contracts": "0.0.1-commit.d58ff9d0",
|
|
93
95
|
"@jest/globals": "^30.0.0",
|
|
94
96
|
"@types/jest": "^30.0.0",
|
|
95
97
|
"@types/node": "^22.15.17",
|
|
96
98
|
"@types/source-map-support": "^0.5.10",
|
|
97
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
99
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
98
100
|
"jest": "^30.0.0",
|
|
99
101
|
"jest-mock-extended": "^4.0.0",
|
|
100
102
|
"ts-node": "^10.9.1",
|
|
@@ -1,104 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvmStat } from '@aztec/bb.js';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import {
|
|
5
|
+
type MeasuredSimulatorFactory,
|
|
4
6
|
PublicTxSimulationTester,
|
|
5
7
|
SimpleContractDataSource,
|
|
6
8
|
type TestEnqueuedCall,
|
|
7
9
|
type TestExecutorMetrics,
|
|
8
10
|
type TestPrivateInsertions,
|
|
9
11
|
} from '@aztec/simulator/public/fixtures';
|
|
12
|
+
import { AvmSimulatorPool, MeasuredPublicTxSimulator } from '@aztec/simulator/server';
|
|
10
13
|
import type { PublicTxResult } from '@aztec/simulator/server';
|
|
11
14
|
import { AvmCircuitInputs, AvmCircuitPublicInputs, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
12
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
|
+
import type { Gas } from '@aztec/stdlib/gas';
|
|
13
17
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
14
18
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
19
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
16
20
|
|
|
17
|
-
import fs from 'node:fs/promises';
|
|
18
|
-
import { tmpdir } from 'node:os';
|
|
19
21
|
import path from 'path';
|
|
20
22
|
|
|
21
|
-
import {
|
|
22
|
-
type BBResult,
|
|
23
|
-
type BBSuccess,
|
|
24
|
-
BB_RESULT,
|
|
25
|
-
VK_FILENAME,
|
|
26
|
-
generateAvmProof,
|
|
27
|
-
verifyAvmProof,
|
|
28
|
-
} from '../bb/execute.js';
|
|
23
|
+
import { BBJsFactory } from '../bb/bb_js_backend.js';
|
|
29
24
|
|
|
30
25
|
const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb-avm');
|
|
31
26
|
|
|
32
|
-
// An InterceptingLogger that records all log messages and forwards them to a wrapped logger.
|
|
33
|
-
class InterceptingLogger implements Logger {
|
|
34
|
-
public readonly logs: string[] = [];
|
|
35
|
-
public level: LogLevel;
|
|
36
|
-
public module: string;
|
|
37
|
-
|
|
38
|
-
private logger: Logger;
|
|
39
|
-
|
|
40
|
-
constructor(logger: Logger) {
|
|
41
|
-
this.logger = logger;
|
|
42
|
-
this.level = logger.level;
|
|
43
|
-
this.module = logger.module;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
isLevelEnabled(level: LogLevel): boolean {
|
|
47
|
-
return this.logger.isLevelEnabled(level);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
createChild(_childModule: string): Logger {
|
|
51
|
-
throw new Error('Not implemented');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private intercept(level: LogLevel, msg: string, ...args: any[]) {
|
|
55
|
-
this.logs.push(...msg.split('\n'));
|
|
56
|
-
// Forward to the wrapped logger
|
|
57
|
-
(this.logger[level] as LogFn)(msg, ...args);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Log methods for each level
|
|
61
|
-
silent(msg: string, ...args: any[]) {
|
|
62
|
-
this.intercept('silent', msg, ...args);
|
|
63
|
-
}
|
|
64
|
-
fatal(msg: string, ...args: any[]) {
|
|
65
|
-
this.intercept('fatal', msg, ...args);
|
|
66
|
-
}
|
|
67
|
-
warn(msg: string, ...args: any[]) {
|
|
68
|
-
this.intercept('warn', msg, ...args);
|
|
69
|
-
}
|
|
70
|
-
info(msg: string, ...args: any[]) {
|
|
71
|
-
this.intercept('info', msg, ...args);
|
|
72
|
-
}
|
|
73
|
-
verbose(msg: string, ...args: any[]) {
|
|
74
|
-
this.intercept('verbose', msg, ...args);
|
|
75
|
-
}
|
|
76
|
-
debug(msg: string, ...args: any[]) {
|
|
77
|
-
this.intercept('debug', msg, ...args);
|
|
78
|
-
}
|
|
79
|
-
trace(msg: string, ...args: any[]) {
|
|
80
|
-
this.intercept('trace', msg, ...args);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Error log function can be string or Error
|
|
84
|
-
error(err: Error | string, ...args: any[]) {
|
|
85
|
-
const msg = typeof err === 'string' ? err : err.message;
|
|
86
|
-
this.logs.push(msg);
|
|
87
|
-
this.logger.error(msg, err, ...args);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
27
|
// Config with collectHints enabled for proving tests
|
|
92
28
|
const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
|
|
93
29
|
skipFeeEnforcement: false,
|
|
94
|
-
collectCallMetadata: true,
|
|
30
|
+
collectCallMetadata: true, // For results.
|
|
95
31
|
collectDebugLogs: false,
|
|
96
32
|
collectHints: true, // Required for proving!
|
|
33
|
+
collectPublicInputs: true, // Required for proving!
|
|
97
34
|
collectStatistics: false,
|
|
98
35
|
});
|
|
99
36
|
|
|
100
37
|
export class AvmProvingTester extends PublicTxSimulationTester {
|
|
101
|
-
private
|
|
38
|
+
private readonly bbJsFactory = new BBJsFactory(BB_PATH, {
|
|
39
|
+
debugDir: process.env.BB_DEBUG_OUTPUT_DIR,
|
|
40
|
+
logger: createLogger('bb-prover:avm-proving-tester'),
|
|
41
|
+
});
|
|
102
42
|
|
|
103
43
|
constructor(
|
|
104
44
|
private checkCircuitOnly: boolean,
|
|
@@ -106,9 +46,9 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
106
46
|
merkleTrees: MerkleTreeWriteOperations,
|
|
107
47
|
globals?: GlobalVariables,
|
|
108
48
|
metrics?: TestExecutorMetrics,
|
|
49
|
+
simulatorFactory?: MeasuredSimulatorFactory,
|
|
109
50
|
) {
|
|
110
|
-
|
|
111
|
-
super(merkleTrees, contractDataSource, globals, metrics, /*simulatorFactory=*/ undefined, provingConfig);
|
|
51
|
+
super(merkleTrees, contractDataSource, globals, metrics, simulatorFactory, provingConfig);
|
|
112
52
|
}
|
|
113
53
|
|
|
114
54
|
static async new(
|
|
@@ -119,56 +59,82 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
119
59
|
) {
|
|
120
60
|
const contractDataSource = new SimpleContractDataSource();
|
|
121
61
|
const merkleTrees = await worldStateService.fork();
|
|
122
|
-
|
|
62
|
+
|
|
63
|
+
const avmSimulator = await AvmSimulatorPool.spawn({ wsdbIpcPath: worldStateService.getIpcPath() });
|
|
64
|
+
const simulatorFactory: MeasuredSimulatorFactory = (mt, cdb, g, m, c) =>
|
|
65
|
+
new MeasuredPublicTxSimulator(avmSimulator, g, cdb, mt.getRevision().forkId, m, c, undefined);
|
|
66
|
+
|
|
67
|
+
const tester = new AvmProvingTester(
|
|
68
|
+
checkCircuitOnly,
|
|
69
|
+
contractDataSource,
|
|
70
|
+
merkleTrees,
|
|
71
|
+
globals,
|
|
72
|
+
metrics,
|
|
73
|
+
simulatorFactory,
|
|
74
|
+
);
|
|
75
|
+
tester.avmSimulator = avmSimulator;
|
|
76
|
+
return tester;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public override async close(): Promise<void> {
|
|
80
|
+
const results = await Promise.allSettled([super.close(), this.bbJsFactory.destroy()]);
|
|
81
|
+
const errors = results.flatMap(result => (result.status === 'rejected' ? [result.reason] : []));
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
throw new AggregateError(errors, `Failed to close AVM proving tester`);
|
|
84
|
+
}
|
|
123
85
|
}
|
|
124
86
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Generate an AVM proof (or run check-circuit if configured). Records per-stage timings in the test metrics.
|
|
89
|
+
* Returns the in-memory proof fields on success; throws via jest expect() on failure.
|
|
90
|
+
*/
|
|
91
|
+
async prove(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx'): Promise<Uint8Array[]> {
|
|
92
|
+
const inputsBuffer = avmCircuitInputs.serializeWithMessagePack();
|
|
128
93
|
|
|
129
|
-
|
|
94
|
+
if (this.checkCircuitOnly) {
|
|
95
|
+
await using instance = await this.bbJsFactory.getInstance();
|
|
96
|
+
const { passed, stats } = await instance.checkAvmCircuit(inputsBuffer);
|
|
97
|
+
this.recordProverMetrics(stats, txLabel);
|
|
98
|
+
expect(passed).toBe(true);
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
130
101
|
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
|
|
102
|
+
await using instance = await this.bbJsFactory.getInstance();
|
|
103
|
+
const { proof, stats } = await instance.generateAvmProof(inputsBuffer);
|
|
104
|
+
this.recordProverMetrics(stats, txLabel);
|
|
105
|
+
return proof;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async verify(proof: Uint8Array[], publicInputs: AvmCircuitPublicInputs): Promise<void> {
|
|
109
|
+
if (this.checkCircuitOnly) {
|
|
110
|
+
// Check-circuit did not generate a proof; nothing to verify.
|
|
111
|
+
return;
|
|
141
112
|
}
|
|
142
|
-
|
|
113
|
+
const piBuffer = publicInputs.serializeWithMessagePack();
|
|
114
|
+
await using instance = await this.bbJsFactory.getInstance();
|
|
115
|
+
const { verified } = await instance.verifyAvmProof(proof, piBuffer);
|
|
116
|
+
expect(verified).toBe(true);
|
|
117
|
+
}
|
|
143
118
|
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// const match = log.match(/\b(\w+): (\d+) \(~2/);
|
|
149
|
-
// if (match) {
|
|
150
|
-
// traceSizes.push({
|
|
151
|
-
// name: match[1],
|
|
152
|
-
// size: parseInt(match[2]),
|
|
153
|
-
// });
|
|
154
|
-
// }
|
|
155
|
-
// });
|
|
156
|
-
const times: { [key: string]: number } = {};
|
|
157
|
-
logs.forEach(log => {
|
|
158
|
-
const match = log.match(/\b([\w/]+)_ms: (\d+)/);
|
|
159
|
-
if (match) {
|
|
160
|
-
times[match[1]] = parseInt(match[2]);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
119
|
+
public async proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx') {
|
|
120
|
+
const proof = await this.prove(avmCircuitInputs, txLabel);
|
|
121
|
+
await this.verify(proof, avmCircuitInputs.publicInputs);
|
|
122
|
+
}
|
|
163
123
|
|
|
164
|
-
|
|
124
|
+
private recordProverMetrics(stats: AvmStat[], txLabel: string) {
|
|
125
|
+
// Build a lookup keyed on the stage name with the `_ms` suffix stripped, matching the legacy
|
|
126
|
+
// stdout-scraped shape. bb::avm2::Stats::time() stores keys with `_ms` appended.
|
|
127
|
+
const times: { [key: string]: number } = {};
|
|
128
|
+
for (const { name, valueMs } of stats) {
|
|
129
|
+
const key = name.endsWith('_ms') ? name.slice(0, -'_ms'.length) : name;
|
|
130
|
+
times[key] = valueMs;
|
|
131
|
+
}
|
|
165
132
|
if (Object.keys(times).length === 0) {
|
|
166
|
-
throw new Error('AVM
|
|
133
|
+
throw new Error('AVM response did not contain any proving-stage timings!');
|
|
167
134
|
}
|
|
168
|
-
|
|
169
135
|
// Hack to make labels match.
|
|
170
136
|
const txLabelWithCount = `${txLabel}/${this.txCount - 1}`;
|
|
171
|
-
//
|
|
137
|
+
// Cast because TS doesn't realize `metrics` is protected, not private on the parent class.
|
|
172
138
|
(this as any).metrics?.recordProverMetrics(txLabelWithCount, {
|
|
173
139
|
proverSimulationStepMs: times['simulation/all'],
|
|
174
140
|
proverProvingStepMs: times['proving/all'],
|
|
@@ -181,33 +147,6 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
181
147
|
provingLogDerivativeInverseCommitmentsMs: times['prove/log_derivative_inverse_commitments_round'],
|
|
182
148
|
provingWireCommitmentsMs: times['prove/wire_commitments_round'],
|
|
183
149
|
});
|
|
184
|
-
|
|
185
|
-
return proofRes as BBSuccess;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async verify(proofRes: BBSuccess, publicInputs: AvmCircuitPublicInputs): Promise<BBResult> {
|
|
189
|
-
if (this.checkCircuitOnly) {
|
|
190
|
-
// Skip verification if we are only checking the circuit.
|
|
191
|
-
// Check-circuit does not generate a proof to verify.
|
|
192
|
-
return proofRes;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return await verifyAvmProof(
|
|
196
|
-
BB_PATH,
|
|
197
|
-
this.bbWorkingDirectory,
|
|
198
|
-
proofRes.proofPath!,
|
|
199
|
-
publicInputs,
|
|
200
|
-
path.join(proofRes.vkDirectoryPath!, VK_FILENAME),
|
|
201
|
-
this.logger,
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
public async proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx') {
|
|
206
|
-
const provingRes = await this.prove(avmCircuitInputs, txLabel);
|
|
207
|
-
expect(provingRes.status).toEqual(BB_RESULT.SUCCESS);
|
|
208
|
-
|
|
209
|
-
const verificationRes = await this.verify(provingRes as BBSuccess, avmCircuitInputs.publicInputs);
|
|
210
|
-
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
|
|
211
150
|
}
|
|
212
151
|
|
|
213
152
|
public async simProveVerify(
|
|
@@ -220,7 +159,9 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
220
159
|
privateInsertions?: TestPrivateInsertions,
|
|
221
160
|
txLabel: string = 'unlabeledTx',
|
|
222
161
|
disableRevertCheck: boolean = false,
|
|
162
|
+
gasLimits?: Gas,
|
|
223
163
|
): Promise<PublicTxResult> {
|
|
164
|
+
const simTimer = new Timer();
|
|
224
165
|
const simRes = await this.simulateTx(
|
|
225
166
|
sender,
|
|
226
167
|
setupCalls,
|
|
@@ -229,7 +170,10 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
229
170
|
feePayer,
|
|
230
171
|
privateInsertions,
|
|
231
172
|
txLabel,
|
|
173
|
+
gasLimits,
|
|
232
174
|
);
|
|
175
|
+
const simDuration = simTimer.ms();
|
|
176
|
+
this.logger.info(`Simulation took ${simDuration} ms for tx ${txLabel}`);
|
|
233
177
|
|
|
234
178
|
if (!disableRevertCheck) {
|
|
235
179
|
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
@@ -237,7 +181,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
237
181
|
|
|
238
182
|
const opString = this.checkCircuitOnly ? 'Check circuit' : 'Proving and verification';
|
|
239
183
|
|
|
240
|
-
const avmCircuitInputs = new AvmCircuitInputs(simRes.hints!, simRes.publicInputs);
|
|
184
|
+
const avmCircuitInputs = new AvmCircuitInputs(simRes.hints!, simRes.publicInputs!);
|
|
241
185
|
const timer = new Timer();
|
|
242
186
|
await this.proveVerify(avmCircuitInputs, txLabel);
|
|
243
187
|
this.logger.info(`${opString} took ${timer.ms()} ms for tx ${txLabel}`);
|
|
@@ -253,6 +197,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
253
197
|
teardownCall?: TestEnqueuedCall,
|
|
254
198
|
feePayer?: AztecAddress,
|
|
255
199
|
privateInsertions?: TestPrivateInsertions,
|
|
200
|
+
gasLimits?: Gas,
|
|
256
201
|
) {
|
|
257
202
|
return await this.simProveVerify(
|
|
258
203
|
sender,
|
|
@@ -264,6 +209,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
264
209
|
privateInsertions,
|
|
265
210
|
txLabel,
|
|
266
211
|
true,
|
|
212
|
+
gasLimits,
|
|
267
213
|
);
|
|
268
214
|
}
|
|
269
215
|
|
|
@@ -271,9 +217,10 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
271
217
|
appCall: TestEnqueuedCall,
|
|
272
218
|
expectRevert?: boolean,
|
|
273
219
|
txLabel: string = 'unlabeledTx',
|
|
220
|
+
gasLimits?: Gas,
|
|
274
221
|
) {
|
|
275
222
|
await this.simProveVerify(
|
|
276
|
-
/*sender=*/ AztecAddress.
|
|
223
|
+
/*sender=*/ AztecAddress.fromNumberUnsafe(42),
|
|
277
224
|
/*setupCalls=*/ [],
|
|
278
225
|
[appCall],
|
|
279
226
|
undefined,
|
|
@@ -281,6 +228,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
281
228
|
/*feePayer=*/ undefined,
|
|
282
229
|
/*privateInsertions=*/ undefined,
|
|
283
230
|
txLabel,
|
|
231
|
+
/*disableRevertCheck=*/ false,
|
|
232
|
+
gasLimits,
|
|
284
233
|
);
|
|
285
234
|
}
|
|
286
235
|
}
|