@aztec-labs/bb-prover 6.0.0-rc.2 → 6.0.0-rc.4

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.
Files changed (33) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +1 -1
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +2 -1
  4. package/dest/bb/bb_js_debug.d.ts +1 -1
  5. package/dest/bb/bb_js_debug.d.ts.map +1 -1
  6. package/dest/bb/bb_js_debug.js +1 -0
  7. package/dest/prover/client/bb_private_kernel_prover.d.ts +2 -1
  8. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  9. package/dest/prover/client/bb_private_kernel_prover.js +3 -1
  10. package/dest/prover/proof_utils.d.ts +1 -1
  11. package/dest/prover/proof_utils.d.ts.map +1 -1
  12. package/dest/prover/proof_utils.js +1 -0
  13. package/dest/prover/server/bb_prover.d.ts +1 -1
  14. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  15. package/dest/prover/server/bb_prover.js +1 -0
  16. package/dest/verifier/batch_chonk_verifier.d.ts +25 -2
  17. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -1
  18. package/dest/verifier/batch_chonk_verifier.js +100 -40
  19. package/dest/verifier/index.d.ts +2 -1
  20. package/dest/verifier/index.d.ts.map +1 -1
  21. package/dest/verifier/index.js +1 -0
  22. package/dest/verifier/self_healing_chonk_verifier.d.ts +76 -0
  23. package/dest/verifier/self_healing_chonk_verifier.d.ts.map +1 -0
  24. package/dest/verifier/self_healing_chonk_verifier.js +231 -0
  25. package/package.json +17 -16
  26. package/src/avm_proving_tests/avm_proving_tester.ts +2 -1
  27. package/src/bb/bb_js_debug.ts +1 -0
  28. package/src/prover/client/bb_private_kernel_prover.ts +3 -1
  29. package/src/prover/proof_utils.ts +1 -0
  30. package/src/prover/server/bb_prover.ts +1 -0
  31. package/src/verifier/batch_chonk_verifier.ts +83 -37
  32. package/src/verifier/index.ts +1 -0
  33. package/src/verifier/self_healing_chonk_verifier.ts +242 -0
@@ -0,0 +1,76 @@
1
+ import type { ClientProtocolCircuitVerifier, IVCProofVerificationResult } from '@aztec-labs/stdlib/interfaces/server';
2
+ import type { Tx } from '@aztec-labs/stdlib/tx';
3
+ import type { BBConfig } from '../config.js';
4
+ /** A verifier that, once failed, stays failed: {@link BatchChonkVerifier}, or a double of it in tests. */
5
+ export interface FailingChonkVerifier extends ClientProtocolCircuitVerifier {
6
+ /** Whether the verifier has failed permanently and must be replaced. */
7
+ isFailed(): boolean;
8
+ }
9
+ /**
10
+ * Keeps a {@link BatchChonkVerifier} running by replacing it whenever its bb process dies, so callers only ever get a
11
+ * verdict on a proof.
12
+ *
13
+ * The verifier holds a session on one bb process (verification keys, worker pool, result FIFO), and a bb death leaves
14
+ * it failed for good. Everything that session holds comes from configuration, so a fresh verifier restores it exactly.
15
+ *
16
+ * A bb death fails every proof in flight at once, without saying which of them caused it. So each of those is checked
17
+ * again on its own, with no other proof in flight (see {@link verifyProof}), and a death then is down to that proof: it
18
+ * is invalid, and remembered, so it doesn't crash bb again when it is sent again. A bb that dies on every proof looks
19
+ * the same from here, so a proof is only blamed once bb has given a verdict on some other proof since it last blamed
20
+ * one, and waits for one until then. A bb that never works therefore blames nothing (and verifies nothing, which the
21
+ * verification metrics show), rather than giving anyone who can crash it a way to shut the node down.
22
+ *
23
+ * A bb that cannot be started at all is nothing the node can work around, so it exits for its orchestrator to restart
24
+ * it. Replacements are made at most once a `replaceIntervalMs`.
25
+ */
26
+ export declare class SelfHealingChonkVerifier implements ClientProtocolCircuitVerifier {
27
+ private readonly create;
28
+ private readonly label;
29
+ private readonly replaceIntervalMs;
30
+ private readonly exitNode;
31
+ /** How many proofs that crashed bb are remembered. */
32
+ static readonly CRASHED_PROOFS_REMEMBERED = 1024;
33
+ private readonly logger;
34
+ /** The verifier verifications go to, or the creation of its replacement. */
35
+ private current;
36
+ /** The verifier in use, which stop() stops; unset while its replacement is being created. */
37
+ private started;
38
+ /** When the verifier was last replaced, as a `Date.now()` timestamp in ms; 0 if it never has been. */
39
+ private lastReplacedAtMs;
40
+ private stopped;
41
+ /** Wakes verifications waiting for the next replacement when the verifier stops. */
42
+ private readonly sleeper;
43
+ /**
44
+ * Every check holds this lock: shared normally, so bb batches proofs together, and exclusive for a proof checked on
45
+ * its own after a bb death, so that no other proof is in flight with it.
46
+ */
47
+ private readonly checkLock;
48
+ /** Proofs found to crash bb, by the hash of their tx, so they are answered without sending them to bb again. */
49
+ private readonly crashedProofs;
50
+ /** Whether bb has given a verdict on any proof since a proof was last blamed for crashing it. */
51
+ private verdictSinceLastBlame;
52
+ /** Resolved when bb next gives a verdict, or the verifier stops. */
53
+ private nextVerdict;
54
+ constructor(create: () => Promise<FailingChonkVerifier>, first: FailingChonkVerifier, label: string, replaceIntervalMs?: number, exitNode?: (err: unknown) => never);
55
+ /** Start a batch verifier for the protocol circuits, replaced whenever it fails. */
56
+ static new(config: BBConfig, batchSize: number, label: string): Promise<SelfHealingChonkVerifier>;
57
+ /**
58
+ * Verifies a tx's Chonk proof. Answers valid or invalid, and rejects only once stopped or on an error other than bb
59
+ * dying:
60
+ * 1. The proof is checked alongside any others, so bb batches it with them.
61
+ * 2. If bb dies with it in flight, it is checked again on its own: proofs already in flight finish first, new ones
62
+ * wait once its turn starts, and proofs checked on their own go one at a time, in order.
63
+ * 3. If bb dies on it again, it is blamed and answered invalid, provided bb has given a verdict on some other proof
64
+ * since it last blamed one. Otherwise it waits for such a verdict and goes back to step 2.
65
+ */
66
+ verifyProof(tx: Tx): Promise<IVCProofVerificationResult>;
67
+ stop(): Promise<void>;
68
+ private verifyOnItsOwn;
69
+ /** Whether a copy of this tx has crashed bb. Skips the hash, which serializes the whole tx, until some proof has. */
70
+ private crashedBefore;
71
+ private verifyOnLiveVerifier;
72
+ private liveVerifier;
73
+ private startReplacement;
74
+ private retire;
75
+ }
76
+ //# sourceMappingURL=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AE,MAAM,OAAO,CAAC,oBAAoB,CAAC,EAC5D,KAAK,EAAE,oBAAoB,EACV,KAAK,EAAE,MAAM,EACb,iBAAiB,SAAO,EACxB,QAAQ,GAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAA8B,EAI5E;IAED,oFAAoF;IACpF,OAAa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAGtG;IAED;;;;;;;;OAQG;IACU,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAwBpE;IAEY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAKjC;YAOa,cAAc;IAiB5B,qHAAqH;IACrH,OAAO,CAAC,aAAa;YAQP,oBAAoB;YAgBpB,YAAY;YA4BZ,gBAAgB;YAoBhB,MAAM;CAOrB"}
@@ -0,0 +1,231 @@
1
+ import { CHONK_PROOF_LENGTH } from '@aztec-labs/constants';
2
+ import { LruSet } from '@aztec-labs/foundation/collection';
3
+ import { createLogger } from '@aztec-labs/foundation/log';
4
+ import { promiseWithResolvers } from '@aztec-labs/foundation/promise';
5
+ import { ReadWriteLock } from '@aztec-labs/foundation/queue';
6
+ import { InterruptibleSleep } from '@aztec-labs/foundation/sleep';
7
+ import { Timer } from '@aztec-labs/foundation/timer';
8
+ import { createHash } from 'node:crypto';
9
+ import { BatchChonkVerifier } from './batch_chonk_verifier.js';
10
+ /**
11
+ * Keeps a {@link BatchChonkVerifier} running by replacing it whenever its bb process dies, so callers only ever get a
12
+ * verdict on a proof.
13
+ *
14
+ * The verifier holds a session on one bb process (verification keys, worker pool, result FIFO), and a bb death leaves
15
+ * it failed for good. Everything that session holds comes from configuration, so a fresh verifier restores it exactly.
16
+ *
17
+ * A bb death fails every proof in flight at once, without saying which of them caused it. So each of those is checked
18
+ * again on its own, with no other proof in flight (see {@link verifyProof}), and a death then is down to that proof: it
19
+ * is invalid, and remembered, so it doesn't crash bb again when it is sent again. A bb that dies on every proof looks
20
+ * the same from here, so a proof is only blamed once bb has given a verdict on some other proof since it last blamed
21
+ * one, and waits for one until then. A bb that never works therefore blames nothing (and verifies nothing, which the
22
+ * verification metrics show), rather than giving anyone who can crash it a way to shut the node down.
23
+ *
24
+ * A bb that cannot be started at all is nothing the node can work around, so it exits for its orchestrator to restart
25
+ * it. Replacements are made at most once a `replaceIntervalMs`.
26
+ */ export class SelfHealingChonkVerifier {
27
+ create;
28
+ label;
29
+ replaceIntervalMs;
30
+ exitNode;
31
+ /** How many proofs that crashed bb are remembered. */ static CRASHED_PROOFS_REMEMBERED = 1024;
32
+ logger;
33
+ /** The verifier verifications go to, or the creation of its replacement. */ current;
34
+ /** The verifier in use, which stop() stops; unset while its replacement is being created. */ started;
35
+ /** When the verifier was last replaced, as a `Date.now()` timestamp in ms; 0 if it never has been. */ lastReplacedAtMs;
36
+ stopped;
37
+ /** Wakes verifications waiting for the next replacement when the verifier stops. */ sleeper;
38
+ /**
39
+ * Every check holds this lock: shared normally, so bb batches proofs together, and exclusive for a proof checked on
40
+ * its own after a bb death, so that no other proof is in flight with it.
41
+ */ checkLock;
42
+ /** Proofs found to crash bb, by the hash of their tx, so they are answered without sending them to bb again. */ crashedProofs;
43
+ /** Whether bb has given a verdict on any proof since a proof was last blamed for crashing it. */ verdictSinceLastBlame;
44
+ /** Resolved when bb next gives a verdict, or the verifier stops. */ nextVerdict;
45
+ constructor(create, first, label, replaceIntervalMs = 1000, exitNode = exitBecauseBbWontStart){
46
+ this.create = create;
47
+ this.label = label;
48
+ this.replaceIntervalMs = replaceIntervalMs;
49
+ this.exitNode = exitNode;
50
+ this.logger = createLogger('bb-prover:self_healing_chonk_verifier');
51
+ this.lastReplacedAtMs = 0;
52
+ this.stopped = false;
53
+ this.sleeper = new InterruptibleSleep();
54
+ this.checkLock = new ReadWriteLock();
55
+ this.crashedProofs = new LruSet(SelfHealingChonkVerifier.CRASHED_PROOFS_REMEMBERED);
56
+ this.verdictSinceLastBlame = false;
57
+ this.nextVerdict = promiseWithResolvers();
58
+ this.started = first;
59
+ this.current = Promise.resolve(first);
60
+ }
61
+ /** Start a batch verifier for the protocol circuits, replaced whenever it fails. */ static async new(config, batchSize, label) {
62
+ const create = ()=>BatchChonkVerifier.new(config, batchSize, label);
63
+ return new SelfHealingChonkVerifier(create, await create(), label);
64
+ }
65
+ /**
66
+ * Verifies a tx's Chonk proof. Answers valid or invalid, and rejects only once stopped or on an error other than bb
67
+ * dying:
68
+ * 1. The proof is checked alongside any others, so bb batches it with them.
69
+ * 2. If bb dies with it in flight, it is checked again on its own: proofs already in flight finish first, new ones
70
+ * wait once its turn starts, and proofs checked on their own go one at a time, in order.
71
+ * 3. If bb dies on it again, it is blamed and answered invalid, provided bb has given a verdict on some other proof
72
+ * since it last blamed one. Otherwise it waits for such a verdict and goes back to step 2.
73
+ */ async verifyProof(tx) {
74
+ const timer = new Timer();
75
+ // A tx with no proof is invalid without asking bb, and must not count as bb giving a verdict.
76
+ if (tx.chonkProof.fields.length !== CHONK_PROOF_LENGTH) {
77
+ return {
78
+ valid: false,
79
+ durationMs: 0,
80
+ totalDurationMs: timer.ms()
81
+ };
82
+ }
83
+ if (this.crashedBefore(tx)) {
84
+ return {
85
+ valid: false,
86
+ durationMs: 0,
87
+ totalDurationMs: timer.ms()
88
+ };
89
+ }
90
+ const result = await this.checkLock.runShared(()=>this.verifyOnLiveVerifier(tx));
91
+ if (result) {
92
+ return result;
93
+ }
94
+ for(;;){
95
+ const result = await this.checkLock.runExclusive(()=>this.verifyOnItsOwn(tx, timer));
96
+ if (result) {
97
+ return result;
98
+ }
99
+ this.logger.warn('Chonk verifier went down on a proof checked on its own, but has given no verdict since it last did', {
100
+ label: this.label,
101
+ txHash: tx.getTxHash().toString()
102
+ });
103
+ await this.nextVerdict.promise;
104
+ }
105
+ }
106
+ async stop() {
107
+ this.stopped = true;
108
+ this.sleeper.interrupt();
109
+ this.nextVerdict.resolve();
110
+ await this.started?.stop();
111
+ }
112
+ /**
113
+ * Checks a proof with no other proof in flight, and blames it if bb dies on it. Both happen within its exclusive
114
+ * turn, so a copy of the same tx checked next is answered from `crashedProofs` rather than crashing bb again. Returns
115
+ * undefined if bb died but has given no verdict since it last blamed a proof, so nothing can be blamed yet.
116
+ */ async verifyOnItsOwn(tx, timer) {
117
+ if (this.crashedBefore(tx)) {
118
+ return {
119
+ valid: false,
120
+ durationMs: 0,
121
+ totalDurationMs: timer.ms()
122
+ };
123
+ }
124
+ const result = await this.verifyOnLiveVerifier(tx);
125
+ if (result || !this.verdictSinceLastBlame) {
126
+ return result;
127
+ }
128
+ this.logger.warn('Proof took the Chonk verifier down when checked on its own', {
129
+ label: this.label,
130
+ txHash: tx.getTxHash().toString()
131
+ });
132
+ this.verdictSinceLastBlame = false;
133
+ this.crashedProofs.add(crashKey(tx));
134
+ return {
135
+ valid: false,
136
+ durationMs: 0,
137
+ totalDurationMs: timer.ms()
138
+ };
139
+ }
140
+ /** Whether a copy of this tx has crashed bb. Skips the hash, which serializes the whole tx, until some proof has. */ crashedBefore(tx) {
141
+ return this.crashedProofs.size > 0 && this.crashedProofs.has(crashKey(tx));
142
+ }
143
+ /**
144
+ * Verifies on the live verifier. Returns undefined if that verifier died with the proof in flight, so the proof was
145
+ * never checked.
146
+ */ async verifyOnLiveVerifier(tx) {
147
+ const verifier = await this.liveVerifier();
148
+ try {
149
+ const result = await verifier.verifyProof(tx);
150
+ this.verdictSinceLastBlame = true;
151
+ this.nextVerdict.resolve();
152
+ this.nextVerdict = promiseWithResolvers();
153
+ return result;
154
+ } catch (err) {
155
+ if (verifier.isFailed() && !this.stopped) {
156
+ return undefined;
157
+ }
158
+ throw err;
159
+ }
160
+ }
161
+ async liveVerifier() {
162
+ for(;;){
163
+ const current = this.current;
164
+ const verifier = await current;
165
+ if (this.stopped) {
166
+ throw new Error('Chonk verifier stopped');
167
+ }
168
+ if (!verifier.isFailed()) {
169
+ return verifier;
170
+ }
171
+ // Only the first caller to find this verifier failed replaces it; the rest share the replacement. Either way the
172
+ // loop checks the replacement too, since it may have failed before the proof gets to it.
173
+ if (this.current !== current) {
174
+ continue;
175
+ }
176
+ const waitMs = this.lastReplacedAtMs + this.replaceIntervalMs - Date.now();
177
+ if (waitMs > 0) {
178
+ await this.sleeper.sleep(waitMs);
179
+ continue;
180
+ }
181
+ this.lastReplacedAtMs = Date.now();
182
+ this.logger.warn('Replacing the failed Chonk verifier', {
183
+ label: this.label
184
+ });
185
+ this.started = undefined;
186
+ void this.retire(verifier);
187
+ this.current = this.startReplacement();
188
+ }
189
+ }
190
+ async startReplacement() {
191
+ let verifier;
192
+ try {
193
+ verifier = await this.create();
194
+ } catch (err) {
195
+ if (this.stopped) {
196
+ throw new Error('Chonk verifier stopped');
197
+ }
198
+ this.exitNode(err);
199
+ }
200
+ if (this.stopped) {
201
+ // stop() did not wait for this one, so it stops itself.
202
+ await this.retire(verifier);
203
+ throw new Error('Chonk verifier stopped');
204
+ }
205
+ this.started = verifier;
206
+ this.logger.info('Replaced the failed Chonk verifier', {
207
+ label: this.label
208
+ });
209
+ return verifier;
210
+ }
211
+ async retire(verifier) {
212
+ try {
213
+ await verifier.stop();
214
+ } catch (err) {
215
+ this.logger.warn('Error stopping a replaced Chonk verifier', {
216
+ label: this.label,
217
+ err
218
+ });
219
+ }
220
+ }
221
+ }
222
+ /** Identifies a tx by its full contents: its hash does not cover the proof, so it could be reused with an honest one. */ function crashKey(tx) {
223
+ return createHash('sha256').update(tx.toBuffer()).digest('hex');
224
+ }
225
+ /**
226
+ * Exits the process because no bb process could be started to replace a dead one. No proof is involved in starting
227
+ * bb, so the environment is broken: crash, and let the orchestrator restart the node.
228
+ */ function exitBecauseBbWontStart(err) {
229
+ createLogger('bb-prover:self_healing_chonk_verifier').fatal('Could not start a bb process to replace the failed Chonk verifier; exiting', err);
230
+ process.exit(1);
231
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec-labs/bb-prover",
3
- "version": "6.0.0-rc.2",
3
+ "version": "6.0.0-rc.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -70,15 +70,16 @@
70
70
  ]
71
71
  },
72
72
  "dependencies": {
73
- "@aztec-foundation/bb.js": "6.0.0-rc.5",
74
- "@aztec-foundation/noir-noirc_abi": "6.0.0-rc.5",
75
- "@aztec-foundation/noir-types": "6.0.0-rc.5",
76
- "@aztec-labs/constants": "6.0.0-rc.2",
77
- "@aztec-labs/foundation": "6.0.0-rc.2",
78
- "@aztec-labs/noir-protocol-circuits-types": "6.0.0-rc.2",
79
- "@aztec-labs/simulator": "6.0.0-rc.2",
80
- "@aztec-labs/stdlib": "6.0.0-rc.2",
81
- "@aztec-labs/telemetry-client": "6.0.0-rc.2",
73
+ "@aztec-foundation/bb.js": "6.0.0-rc.7",
74
+ "@aztec-foundation/noir-noirc_abi": "6.0.0-rc.7",
75
+ "@aztec-foundation/noir-types": "6.0.0-rc.7",
76
+ "@aztec-labs/constants": "6.0.0-rc.4",
77
+ "@aztec-labs/foundation": "6.0.0-rc.4",
78
+ "@aztec-labs/noir-protocol-circuits-types": "6.0.0-rc.4",
79
+ "@aztec-labs/simulator": "6.0.0-rc.4",
80
+ "@aztec-labs/stdlib": "6.0.0-rc.4",
81
+ "@aztec-labs/telemetry-client": "6.0.0-rc.4",
82
+ "buffer": "^6.0.3",
82
83
  "commander": "^12.1.0",
83
84
  "msgpackr": "^1.11.2",
84
85
  "pako": "^2.1.0",
@@ -86,10 +87,10 @@
86
87
  "tslib": "^2.4.0"
87
88
  },
88
89
  "devDependencies": {
89
- "@aztec-labs/noir-contracts.js": "6.0.0-rc.2",
90
- "@aztec-labs/noir-test-contracts.js": "6.0.0-rc.2",
91
- "@aztec-labs/protocol-contracts": "6.0.0-rc.2",
92
- "@aztec-labs/world-state": "6.0.0-rc.2",
90
+ "@aztec-labs/noir-contracts.js": "6.0.0-rc.4",
91
+ "@aztec-labs/noir-test-contracts.js": "6.0.0-rc.4",
92
+ "@aztec-labs/protocol-contracts": "6.0.0-rc.4",
93
+ "@aztec-labs/world-state": "6.0.0-rc.4",
93
94
  "@jest/globals": "^30.0.0",
94
95
  "@types/jest": "^30.0.0",
95
96
  "@types/node": "^22.15.17",
@@ -99,7 +100,7 @@
99
100
  "jest-mock-extended": "^4.0.0",
100
101
  "ts-node": "^10.9.1",
101
102
  "typescript": "^5.3.3",
102
- "viem": "npm:@aztec/viem@2.38.3"
103
+ "viem": "2.57.1"
103
104
  },
104
105
  "files": [
105
106
  "dest",
@@ -108,6 +109,6 @@
108
109
  ],
109
110
  "types": "./dest/index.d.ts",
110
111
  "engines": {
111
- "node": ">=20.10"
112
+ "node": ">=20.16"
112
113
  }
113
114
  }
@@ -1,5 +1,6 @@
1
1
  import type { AvmStat } from '@aztec-foundation/bb.js';
2
2
 
3
+ import { getEnv } from '@aztec-labs/foundation/config/env';
3
4
  import { createLogger } from '@aztec-labs/foundation/log';
4
5
  import { Timer } from '@aztec-labs/foundation/timer';
5
6
  import {
@@ -36,7 +37,7 @@ const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
36
37
 
37
38
  export class AvmProvingTester extends PublicTxSimulationTester {
38
39
  private readonly bbJsFactory = new BBJsFactory(BB_PATH, {
39
- debugDir: process.env.BB_DEBUG_OUTPUT_DIR,
40
+ debugDir: getEnv().BB_DEBUG_OUTPUT_DIR,
40
41
  logger: createLogger('bb-prover:avm-proving-tester'),
41
42
  });
42
43
 
@@ -1,6 +1,7 @@
1
1
  import type { AvmStat } from '@aztec-foundation/bb.js';
2
2
 
3
3
  import type { Logger } from '@aztec-labs/foundation/log';
4
+ import { Buffer } from 'buffer';
4
5
  import { promises as fs } from 'fs';
5
6
  import * as path from 'path';
6
7
  import { gzipSync } from 'zlib';
@@ -2,6 +2,7 @@ import { AztecClientBackend, type BackendOptions, Barretenberg } from '@aztec-fo
2
2
  import { serializeWitness } from '@aztec-foundation/noir-noirc_abi';
3
3
  import type { Abi, WitnessMap } from '@aztec-foundation/noir-types';
4
4
 
5
+ import { getEnv } from '@aztec-labs/foundation/config/env';
5
6
  import { type LogLevel, type Logger, createLogger } from '@aztec-labs/foundation/log';
6
7
  import { Timer } from '@aztec-labs/foundation/timer';
7
8
  import {
@@ -68,6 +69,7 @@ import type {
68
69
  import type { NoirCompiledCircuitWithName } from '@aztec-labs/stdlib/noir';
69
70
  import { ChonkProofWithPublicInputs } from '@aztec-labs/stdlib/proofs';
70
71
  import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec-labs/stdlib/stats';
72
+ import { Buffer } from 'buffer';
71
73
  import { ungzip } from 'pako';
72
74
 
73
75
  export type BBPrivateKernelProverOptions = Omit<BackendOptions, 'logger'> & { logger?: Logger };
@@ -526,7 +528,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
526
528
  // Note we do not pass the vk to the backend. This is unneeded for gate counts.
527
529
  const barretenberg = await Barretenberg.initSingleton({
528
530
  ...this.options,
529
- logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
531
+ logger: this.options.logger?.[(getEnv().LOG_LEVEL as LogLevel) || 'verbose'],
530
532
  });
531
533
  const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName], [_circuitKind]);
532
534
  const gateCount = await backend.gates();
@@ -12,6 +12,7 @@ import type { Logger } from '@aztec-labs/foundation/log';
12
12
  import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec-labs/stdlib/proofs';
13
13
  import type { VerificationKeyData } from '@aztec-labs/stdlib/vks';
14
14
  import assert from 'assert';
15
+ import { Buffer } from 'buffer';
15
16
  import { promises as fs } from 'fs';
16
17
  import * as path from 'path';
17
18
 
@@ -72,6 +72,7 @@ import {
72
72
  import type { CircuitProvingStats, CircuitWitnessGenerationStats } from '@aztec-labs/stdlib/stats';
73
73
  import { VerificationKeyData } from '@aztec-labs/stdlib/vks';
74
74
  import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec-labs/telemetry-client';
75
+ import { Buffer } from 'buffer';
75
76
  import { promises as fs } from 'fs';
76
77
  import { ungzip } from 'pako';
77
78
  import * as path from 'path';