@aztec/bb-prover 0.80.0 → 0.82.0

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 (35) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +3 -3
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +7 -9
  4. package/dest/bb/execute.d.ts +4 -8
  5. package/dest/bb/execute.d.ts.map +1 -1
  6. package/dest/bb/execute.js +28 -14
  7. package/dest/prover/bb_native_private_kernel_prover.d.ts +3 -2
  8. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +1 -1
  9. package/dest/prover/bb_native_private_kernel_prover.js +18 -7
  10. package/dest/prover/bb_private_kernel_prover.d.ts +2 -2
  11. package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
  12. package/dest/prover/bb_private_kernel_prover.js +4 -4
  13. package/dest/prover/bb_prover.d.ts.map +1 -1
  14. package/dest/prover/bb_prover.js +7 -5
  15. package/dest/prover/client_ivc_proof_utils.d.ts +6 -14
  16. package/dest/prover/client_ivc_proof_utils.d.ts.map +1 -1
  17. package/dest/prover/client_ivc_proof_utils.js +10 -31
  18. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  19. package/dest/test/test_circuit_prover.js +9 -7
  20. package/dest/verifier/bb_verifier.d.ts +2 -0
  21. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  22. package/dest/verifier/bb_verifier.js +7 -2
  23. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +2 -2
  24. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -1
  25. package/dest/wasm/bb_wasm_private_kernel_prover.js +7 -6
  26. package/package.json +16 -15
  27. package/src/avm_proving_tests/avm_proving_tester.ts +6 -10
  28. package/src/bb/execute.ts +25 -13
  29. package/src/prover/bb_native_private_kernel_prover.ts +20 -12
  30. package/src/prover/bb_private_kernel_prover.ts +13 -8
  31. package/src/prover/bb_prover.ts +13 -8
  32. package/src/prover/client_ivc_proof_utils.ts +10 -24
  33. package/src/test/test_circuit_prover.ts +21 -10
  34. package/src/verifier/bb_verifier.ts +9 -2
  35. package/src/wasm/bb_wasm_private_kernel_prover.ts +7 -6
@@ -5,6 +5,8 @@ import type { Proof } from '@aztec/stdlib/proofs';
5
5
  import { Tx } from '@aztec/stdlib/tx';
6
6
  import type { VerificationKeyData } from '@aztec/stdlib/vks';
7
7
  import type { BBConfig } from '../config.js';
8
+ export declare const PRIVATE_TAIL_CIVC_VK: string;
9
+ export declare const PUBLIC_TAIL_CIVC_VK: string;
8
10
  export declare class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
9
11
  private config;
10
12
  private logger;
@@ -1 +1 @@
1
- {"version":3,"file":"bb_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/bb_verifier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAA0B,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAChH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAM7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAK7C,qBAAa,iBAAkB,YAAW,6BAA6B;IACjD,OAAO,CAAC,MAAM;IAAY,OAAO,CAAC,MAAM;IAA5D,OAAO;WAEa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAqC;IAK9E,sBAAsB,CAAC,WAAW,EAAE,sBAAsB,GAAG,mBAAmB;IAQ1E,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,KAAK;IAkCnE,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CA4CnD"}
1
+ {"version":3,"file":"bb_verifier.d.ts","sourceRoot":"","sources":["../../src/verifier/bb_verifier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAA0B,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAChH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAO7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAQ7C,eAAO,MAAM,oBAAoB,QAA0D,CAAC;AAC5F,eAAO,MAAM,mBAAmB,QAAyD,CAAC;AAE1F,qBAAa,iBAAkB,YAAW,6BAA6B;IACjD,OAAO,CAAC,MAAM;IAAY,OAAO,CAAC,MAAM;IAA5D,OAAO;WAEa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAqC;IAK9E,sBAAsB,CAAC,WAAW,EAAE,sBAAsB,GAAG,mBAAmB;IAQ1E,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,KAAK;IAkCnE,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CA4CnD"}
@@ -4,10 +4,15 @@ import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks
4
4
  import { Tx } from '@aztec/stdlib/tx';
5
5
  import { promises as fs } from 'fs';
6
6
  import * as path from 'path';
7
+ import { fileURLToPath } from 'url';
7
8
  import { BB_RESULT, PROOF_FILENAME, VK_FILENAME, verifyClientIvcProof, verifyProof } from '../bb/execute.js';
8
9
  import { getUltraHonkFlavorForCircuit } from '../honk.js';
9
10
  import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
10
11
  import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
12
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
+ // Built by yarn generate
14
+ export const PRIVATE_TAIL_CIVC_VK = path.join(__dirname, '../../artifacts/private-civc-vk');
15
+ export const PUBLIC_TAIL_CIVC_VK = path.join(__dirname, '../../artifacts/public-civc-vk');
11
16
  export class BBCircuitVerifier {
12
17
  config;
13
18
  logger;
@@ -64,7 +69,7 @@ export class BBCircuitVerifier {
64
69
  this.logger.debug(`${circuit} BB out - ${message}`);
65
70
  };
66
71
  await writeToOutputDirectory(tx.clientIvcProof, bbWorkingDirectory);
67
- const result = await verifyClientIvcProof(this.config.bbBinaryPath, bbWorkingDirectory.concat('/proof'), bbWorkingDirectory.concat('/vk'), logFunction);
72
+ const result = await verifyClientIvcProof(this.config.bbBinaryPath, bbWorkingDirectory.concat('/proof'), tx.data.forPublic ? PUBLIC_TAIL_CIVC_VK : PRIVATE_TAIL_CIVC_VK, logFunction);
68
73
  if (result.status === BB_RESULT.FAILURE) {
69
74
  const errorMessage = `Failed to verify ${circuit} proof!`;
70
75
  throw new Error(errorMessage);
@@ -79,7 +84,7 @@ export class BBCircuitVerifier {
79
84
  await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup, this.logger);
80
85
  return true;
81
86
  } catch (err) {
82
- this.logger.warn(`Failed to verify ClientIVC proof for tx ${Tx.getHash(tx)}: ${String(err)}`);
87
+ this.logger.warn(`Failed to verify ClientIVC proof for tx ${await Tx.getHash(tx)}: ${String(err)}`);
83
88
  return false;
84
89
  }
85
90
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import type { ArtifactProvider } from '@aztec/noir-protocol-circuits-types/types';
4
- import type { WitnessMap } from '@aztec/noir-types';
5
4
  import type { SimulationProvider } from '@aztec/simulator/client';
5
+ import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
6
6
  import { ClientIvcProof } from '@aztec/stdlib/proofs';
7
7
  import { BBPrivateKernelProver } from '../prover/bb_private_kernel_prover.js';
8
8
  export declare abstract class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
@@ -11,7 +11,7 @@ export declare abstract class BBWASMPrivateKernelProver extends BBPrivateKernelP
11
11
  private threads;
12
12
  protected log: import("@aztec/foundation/log").Logger;
13
13
  constructor(artifactProvider: ArtifactProvider, simulationProvider: SimulationProvider, threads?: number, log?: import("@aztec/foundation/log").Logger);
14
- createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof>;
14
+ createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof>;
15
15
  computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number>;
16
16
  }
17
17
  //# sourceMappingURL=bb_wasm_private_kernel_prover.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bb_wasm_private_kernel_prover.d.ts","sourceRoot":"","sources":["../../src/wasm/bb_wasm_private_kernel_prover.ts"],"names":[],"mappings":";;AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,8BAAsB,yBAA0B,SAAQ,qBAAqB;cAEtD,gBAAgB,EAAE,gBAAgB;cAClC,kBAAkB,EAAE,kBAAkB;IACzD,OAAO,CAAC,OAAO;cACI,GAAG;gBAHH,gBAAgB,EAAE,gBAAgB,EAClC,kBAAkB,EAAE,kBAAkB,EACjD,OAAO,GAAE,MAAU,EACR,GAAG,yCAAiC;IAKnC,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAmB1F,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAY3G"}
1
+ {"version":3,"file":"bb_wasm_private_kernel_prover.d.ts","sourceRoot":"","sources":["../../src/wasm/bb_wasm_private_kernel_prover.ts"],"names":[],"mappings":";;AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,8BAAsB,yBAA0B,SAAQ,qBAAqB;cAEtD,gBAAgB,EAAE,gBAAgB;cAClC,kBAAkB,EAAE,kBAAkB;IACzD,OAAO,CAAC,OAAO;cACI,GAAG;gBAHH,gBAAgB,EAAE,gBAAgB,EAClC,kBAAkB,EAAE,kBAAkB,EACjD,OAAO,GAAE,MAAU,EACR,GAAG,yCAAiC;IAKnC,oBAAoB,CAAC,cAAc,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAoBrF,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAY3G"}
@@ -13,23 +13,24 @@ export class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
13
13
  constructor(artifactProvider, simulationProvider, threads = 1, log = createLogger('bb-prover:wasm')){
14
14
  super(artifactProvider, simulationProvider, log), this.artifactProvider = artifactProvider, this.simulationProvider = simulationProvider, this.threads = threads, this.log = log;
15
15
  }
16
- async createClientIvcProof(acirs, witnessStack) {
16
+ async createClientIvcProof(executionSteps) {
17
17
  const timer = new Timer();
18
18
  this.log.info(`Generating ClientIVC proof...`);
19
- const backend = new AztecClientBackend(acirs.map((acir)=>ungzip(acir)), {
19
+ const backend = new AztecClientBackend(executionSteps.map((step)=>ungzip(step.bytecode)), {
20
20
  threads: this.threads,
21
21
  logger: this.log.verbose,
22
22
  wasmPath: process.env.BB_WASM_PATH
23
23
  });
24
- const [proof, vk] = await backend.prove(witnessStack.map((witnessMap)=>ungzip(serializeWitness(witnessMap))));
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))));
25
27
  await backend.destroy();
26
28
  this.log.info(`Generated ClientIVC proof`, {
27
29
  eventName: 'client-ivc-proof-generation',
28
30
  duration: timer.ms(),
29
- proofSize: proof.length,
30
- vkSize: vk.length
31
+ proofSize: proof.length
31
32
  });
32
- return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
33
+ return new ClientIvcProof(Buffer.from(proof));
33
34
  }
34
35
  async computeGateCountForCircuit(_bytecode, _circuitName) {
35
36
  const backend = new AztecClientBackend([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bb-prover",
3
- "version": "0.80.0",
3
+ "version": "0.82.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -30,6 +30,7 @@
30
30
  "clean": "rm -rf ./dest .tsbuildinfo",
31
31
  "formatting": "run -T prettier --check ./src && run -T eslint ./src",
32
32
  "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
33
+ "generate": "scripts/generate_civc_vks.sh",
33
34
  "bb": "node --no-warnings ./dest/bb/index.js",
34
35
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
35
36
  },
@@ -67,16 +68,16 @@
67
68
  ]
68
69
  },
69
70
  "dependencies": {
70
- "@aztec/bb.js": "0.80.0",
71
- "@aztec/constants": "0.80.0",
72
- "@aztec/foundation": "0.80.0",
73
- "@aztec/noir-noirc_abi": "0.80.0",
74
- "@aztec/noir-protocol-circuits-types": "0.80.0",
75
- "@aztec/noir-types": "0.80.0",
76
- "@aztec/simulator": "0.80.0",
77
- "@aztec/stdlib": "0.80.0",
78
- "@aztec/telemetry-client": "0.80.0",
79
- "@aztec/world-state": "0.80.0",
71
+ "@aztec/bb.js": "0.82.0",
72
+ "@aztec/constants": "0.82.0",
73
+ "@aztec/foundation": "0.82.0",
74
+ "@aztec/noir-noirc_abi": "0.82.0",
75
+ "@aztec/noir-protocol-circuits-types": "0.82.0",
76
+ "@aztec/noir-types": "0.82.0",
77
+ "@aztec/simulator": "0.82.0",
78
+ "@aztec/stdlib": "0.82.0",
79
+ "@aztec/telemetry-client": "0.82.0",
80
+ "@aztec/world-state": "0.82.0",
80
81
  "@msgpack/msgpack": "^3.0.0-beta2",
81
82
  "commander": "^12.1.0",
82
83
  "pako": "^2.1.0",
@@ -84,10 +85,10 @@
84
85
  "tslib": "^2.4.0"
85
86
  },
86
87
  "devDependencies": {
87
- "@aztec/ethereum": "0.80.0",
88
- "@aztec/kv-store": "0.80.0",
89
- "@aztec/noir-contracts.js": "0.80.0",
90
- "@aztec/protocol-contracts": "0.80.0",
88
+ "@aztec/ethereum": "0.82.0",
89
+ "@aztec/kv-store": "0.82.0",
90
+ "@aztec/noir-contracts.js": "0.82.0",
91
+ "@aztec/protocol-contracts": "0.82.0",
91
92
  "@jest/globals": "^29.5.0",
92
93
  "@types/jest": "^29.5.0",
93
94
  "@types/memdown": "^3.0.0",
@@ -1,5 +1,5 @@
1
1
  import { PublicTxSimulationTester, type TestEnqueuedCall } from '@aztec/simulator/public/fixtures';
2
- import { SimpleContractDataSource, WorldStateDB } from '@aztec/simulator/server';
2
+ import { SimpleContractDataSource } from '@aztec/simulator/server';
3
3
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
@@ -28,11 +28,10 @@ export class AvmProvingTester extends PublicTxSimulationTester {
28
28
  constructor(
29
29
  private bbWorkingDirectory: string,
30
30
  private checkCircuitOnly: boolean,
31
- worldStateDB: WorldStateDB,
31
+ merkleTree: MerkleTreeWriteOperations,
32
32
  contractDataSource: SimpleContractDataSource,
33
- merkleTrees: MerkleTreeWriteOperations,
34
33
  ) {
35
- super(worldStateDB, contractDataSource, merkleTrees);
34
+ super(merkleTree, contractDataSource);
36
35
  }
37
36
 
38
37
  static override async create(checkCircuitOnly: boolean = false) {
@@ -40,8 +39,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
40
39
 
41
40
  const contractDataSource = new SimpleContractDataSource();
42
41
  const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
43
- const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
44
- return new AvmProvingTester(bbWorkingDirectory, checkCircuitOnly, worldStateDB, contractDataSource, merkleTrees);
42
+ return new AvmProvingTester(bbWorkingDirectory, checkCircuitOnly, merkleTrees, contractDataSource);
45
43
  }
46
44
 
47
45
  async prove(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
@@ -108,11 +106,10 @@ export class AvmProvingTester extends PublicTxSimulationTester {
108
106
  export class AvmProvingTesterV2 extends PublicTxSimulationTester {
109
107
  constructor(
110
108
  private bbWorkingDirectory: string,
111
- worldStateDB: WorldStateDB,
112
109
  contractDataSource: SimpleContractDataSource,
113
110
  merkleTrees: MerkleTreeWriteOperations,
114
111
  ) {
115
- super(worldStateDB, contractDataSource, merkleTrees);
112
+ super(merkleTrees, contractDataSource);
116
113
  }
117
114
 
118
115
  static override async create() {
@@ -120,8 +117,7 @@ export class AvmProvingTesterV2 extends PublicTxSimulationTester {
120
117
 
121
118
  const contractDataSource = new SimpleContractDataSource();
122
119
  const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
123
- const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
124
- return new AvmProvingTesterV2(bbWorkingDirectory, worldStateDB, contractDataSource, merkleTrees);
120
+ return new AvmProvingTesterV2(bbWorkingDirectory, contractDataSource, merkleTrees);
125
121
  }
126
122
 
127
123
  async proveV2(avmCircuitInputs: AvmCircuitInputs): Promise<BBResult> {
package/src/bb/execute.ts CHANGED
@@ -8,7 +8,7 @@ import { promises as fs } from 'fs';
8
8
  import { basename, dirname, join } from 'path';
9
9
 
10
10
  import type { UltraHonkFlavor } from '../honk.js';
11
- import { CLIENT_IVC_PROOF_FILE_NAME, CLIENT_IVC_VK_FILE_NAME } from '../prover/client_ivc_proof_utils.js';
11
+ import { CLIENT_IVC_PROOF_FILE_NAME } from '../prover/client_ivc_proof_utils.js';
12
12
 
13
13
  export const VK_FILENAME = 'vk';
14
14
  export const VK_FIELDS_FILENAME = 'vk_fields.json';
@@ -62,6 +62,7 @@ type BBExecResult = {
62
62
  * @param command - The command to execute
63
63
  * @param args - The arguments to pass
64
64
  * @param logger - A log function
65
+ * @param timeout - An optional timeout before killing the BB process
65
66
  * @param resultParser - An optional handler for detecting success or failure
66
67
  * @returns The completed partial witness outputted from the circuit
67
68
  */
@@ -70,6 +71,7 @@ export function executeBB(
70
71
  command: string,
71
72
  args: string[],
72
73
  logger: LogFn,
74
+ timeout?: number,
73
75
  resultParser = (code: number) => code === 0,
74
76
  ): Promise<BBExecResult> {
75
77
  return new Promise<BBExecResult>(resolve => {
@@ -80,6 +82,18 @@ export function executeBB(
80
82
  const bb = proc.spawn(pathToBB, [command, ...args], {
81
83
  env,
82
84
  });
85
+
86
+ let timeoutId: NodeJS.Timeout | undefined;
87
+ if (timeout !== undefined) {
88
+ timeoutId = setTimeout(() => {
89
+ logger(`BB execution timed out after ${timeout}ms, killing process`);
90
+ if (bb.pid) {
91
+ bb.kill('SIGKILL');
92
+ }
93
+ resolve({ status: BB_RESULT.FAILURE, exitCode: -1, signal: 'TIMEOUT' });
94
+ }, timeout);
95
+ }
96
+
83
97
  bb.stdout.on('data', data => {
84
98
  const message = data.toString('utf-8').replace(/\n$/, '');
85
99
  logger(message);
@@ -89,6 +103,9 @@ export function executeBB(
89
103
  logger(message);
90
104
  });
91
105
  bb.on('close', (exitCode: number, signal?: string) => {
106
+ if (timeoutId) {
107
+ clearTimeout(timeoutId);
108
+ }
92
109
  if (resultParser(exitCode)) {
93
110
  resolve({ status: BB_RESULT.SUCCESS, exitCode, signal });
94
111
  } else {
@@ -98,7 +115,6 @@ export function executeBB(
98
115
  }).catch(_ => ({ status: BB_RESULT.FAILURE, exitCode: -1, signal: undefined }));
99
116
  }
100
117
 
101
- // TODO(#7369) comment this etc (really just take inspiration from this and rewrite it all O:))
102
118
  export async function executeBbClientIvcProof(
103
119
  pathToBB: string,
104
120
  workingDirectory: string,
@@ -275,17 +291,13 @@ export async function generateProof(
275
291
  /**
276
292
  * Used for generating proofs of the tube circuit
277
293
  * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
278
- * @param pathToBB - The full path to the bb binary
279
- * @param workingDirectory - A working directory for use by bb
280
- * @param circuitName - An identifier for the circuit
281
- * @param bytecode - The compiled circuit bytecode
282
- * @param inputWitnessFile - The circuit input witness
283
- * @param log - A logging function
294
+ *
284
295
  * @returns An object containing a result indication, the location of the proof and the duration taken
285
296
  */
286
297
  export async function generateTubeProof(
287
298
  pathToBB: string,
288
299
  workingDirectory: string,
300
+ vkPath: string,
289
301
  log: LogFn,
290
302
  ): Promise<BBFailure | BBSuccess> {
291
303
  // Check that the working directory exists
@@ -295,8 +307,7 @@ export async function generateTubeProof(
295
307
  return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
296
308
  }
297
309
 
298
- // // Paths for the inputs
299
- const vkPath = join(workingDirectory, CLIENT_IVC_VK_FILE_NAME);
310
+ // Paths for the inputs
300
311
  const proofPath = join(workingDirectory, CLIENT_IVC_PROOF_FILE_NAME);
301
312
 
302
313
  // The proof is written to e.g. /workingDirectory/proof
@@ -313,10 +324,10 @@ export async function generateTubeProof(
313
324
  }
314
325
 
315
326
  try {
316
- if (!(await filePresent(vkPath)) || !(await filePresent(proofPath))) {
327
+ if (!(await filePresent(proofPath))) {
317
328
  return { status: BB_RESULT.FAILURE, reason: `Client IVC input files not present in ${workingDirectory}` };
318
329
  }
319
- const args = ['-o', outputPath, '-v'];
330
+ const args = ['-o', outputPath, '-k', vkPath, '-v'];
320
331
 
321
332
  const timer = new Timer();
322
333
  const logFunction = (message: string) => {
@@ -610,7 +621,8 @@ export async function verifyClientIvcProof(
610
621
  const args = ['--scheme', 'client_ivc', '-p', proofPath, '-k', keyPath];
611
622
  const timer = new Timer();
612
623
  const command = 'verify';
613
- const result = await executeBB(pathToBB, command, args, log);
624
+ const timeout = 1000; // 1s verification timeout for invalid proofs
625
+ const result = await executeBB(pathToBB, command, args, log, timeout);
614
626
  const duration = timer.ms();
615
627
  if (result.status == BB_RESULT.SUCCESS) {
616
628
  return { status: BB_RESULT.SUCCESS, durationMs: duration };
@@ -2,8 +2,8 @@ import { runInDirectory } from '@aztec/foundation/fs';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { serializeWitness } from '@aztec/noir-noirc_abi';
4
4
  import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
5
- import type { WitnessMap } from '@aztec/noir-types';
6
5
  import type { SimulationProvider } from '@aztec/simulator/server';
6
+ import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
7
7
  import type { ClientIvcProof } from '@aztec/stdlib/proofs';
8
8
 
9
9
  import { encode } from '@msgpack/msgpack';
@@ -40,18 +40,26 @@ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
40
40
  );
41
41
  }
42
42
 
43
+ // TODO(#7371): This is duplicated.
44
+ // Longer term we won't use this hacked together msgpack format
45
+ // Leaving duplicated as this eventually bb will provide a serialization
46
+ // helper for passing to a generic msgpack RPC endpoint.
47
+ private async _createClientIvcProofFiles(directory: string, executionSteps: PrivateExecutionStep[]) {
48
+ const acirPath = path.join(directory, 'acir.msgpack');
49
+ const witnessPath = path.join(directory, 'witnesses.msgpack');
50
+ await fs.writeFile(acirPath, encode(executionSteps.map(map => map.bytecode)));
51
+ await fs.writeFile(witnessPath, encode(executionSteps.map(map => serializeWitness(map.witness))));
52
+ return {
53
+ acirPath,
54
+ witnessPath,
55
+ };
56
+ }
57
+
43
58
  private async _createClientIvcProof(
44
59
  directory: string,
45
- acirs: Buffer[],
46
- witnessStack: WitnessMap[],
60
+ executionSteps: PrivateExecutionStep[],
47
61
  ): Promise<ClientIvcProof> {
48
- // TODO(#7371): Longer term we won't use this hacked together msgpack format
49
- // and instead properly create the bincode serialization from rust
50
- await fs.writeFile(path.join(directory, 'acir.msgpack'), encode(acirs));
51
- await fs.writeFile(
52
- path.join(directory, 'witnesses.msgpack'),
53
- encode(witnessStack.map(map => serializeWitness(map))),
54
- );
62
+ await this._createClientIvcProofFiles(directory, executionSteps);
55
63
  const provingResult = await executeBbClientIvcProof(
56
64
  this.bbBinaryPath,
57
65
  directory,
@@ -75,10 +83,10 @@ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
75
83
  return proof;
76
84
  }
77
85
 
78
- public override async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
86
+ public override async createClientIvcProof(executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof> {
79
87
  this.log.info(`Generating Client IVC proof`);
80
88
  const operation = async (directory: string) => {
81
- return await this._createClientIvcProof(directory, acirs, witnessStack);
89
+ return await this._createClientIvcProof(directory, executionSteps);
82
90
  };
83
91
  return await this.runInDirectory(operation);
84
92
  }
@@ -11,6 +11,7 @@ import {
11
11
  convertPrivateKernelTailInputsToWitnessMapWithAbi,
12
12
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
13
13
  convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
14
+ foreignCallHandler,
14
15
  getPrivateKernelResetArtifactName,
15
16
  updateResetCircuitSampleInputs,
16
17
  } from '@aztec/noir-protocol-circuits-types/client';
@@ -19,6 +20,7 @@ import type { Abi, WitnessMap } from '@aztec/noir-types';
19
20
  import type { SimulationProvider } from '@aztec/simulator/client';
20
21
  import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
21
22
  import type {
23
+ PrivateExecutionStep,
22
24
  PrivateKernelCircuitPublicInputs,
23
25
  PrivateKernelInitCircuitPrivateInputs,
24
26
  PrivateKernelInnerCircuitPrivateInputs,
@@ -27,7 +29,7 @@ import type {
27
29
  PrivateKernelTailCircuitPrivateInputs,
28
30
  PrivateKernelTailCircuitPublicInputs,
29
31
  } from '@aztec/stdlib/kernel';
30
- import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
32
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
31
33
  import type { ClientIvcProof } from '@aztec/stdlib/proofs';
32
34
  import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
33
35
 
@@ -158,15 +160,14 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
158
160
  convertInputs: (inputs: I, abi: Abi) => WitnessMap,
159
161
  convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
160
162
  ): Promise<PrivateKernelSimulateOutput<O>> {
161
- const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getSimulatedClientCircuitArtifactByName(
162
- circuitType,
163
- );
163
+ const compiledCircuit: NoirCompiledCircuitWithName =
164
+ await this.artifactProvider.getSimulatedClientCircuitArtifactByName(circuitType);
164
165
 
165
166
  const witnessMap = convertInputs(inputs, compiledCircuit.abi);
166
167
 
167
168
  const timer = new Timer();
168
169
  const outputWitness = await this.simulationProvider
169
- .executeProtocolCircuit(witnessMap, compiledCircuit)
170
+ .executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
170
171
  .catch((err: Error) => {
171
172
  this.log.debug(`Failed to simulate ${circuitType}`, {
172
173
  circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
@@ -197,13 +198,17 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
197
198
  convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
198
199
  ): Promise<PrivateKernelSimulateOutput<O>> {
199
200
  this.log.debug(`Generating witness for ${circuitType}`);
200
- const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getClientCircuitArtifactByName(
201
+ const compiledCircuit: NoirCompiledCircuitWithName = await this.artifactProvider.getClientCircuitArtifactByName(
201
202
  circuitType,
202
203
  );
203
204
 
204
205
  const witnessMap = convertInputs(inputs, compiledCircuit.abi);
205
206
  const timer = new Timer();
206
- const outputWitness = await this.simulationProvider.executeProtocolCircuit(witnessMap, compiledCircuit);
207
+ const outputWitness = await this.simulationProvider.executeProtocolCircuit(
208
+ witnessMap,
209
+ compiledCircuit,
210
+ foreignCallHandler,
211
+ );
207
212
  const output = convertOutputs(outputWitness, compiledCircuit.abi);
208
213
 
209
214
  this.log.debug(`Generated witness for ${circuitType}`, {
@@ -238,7 +243,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
238
243
  return kernelProofOutput;
239
244
  }
240
245
 
241
- public createClientIvcProof(_acirs: Buffer[], _witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
246
+ public createClientIvcProof(_executionSteps: PrivateExecutionStep[]): Promise<ClientIvcProof> {
242
247
  throw new Error('Not implemented');
243
248
  }
244
249
 
@@ -14,7 +14,6 @@ import { createLogger } from '@aztec/foundation/log';
14
14
  import { BufferReader } from '@aztec/foundation/serialize';
15
15
  import { Timer } from '@aztec/foundation/timer';
16
16
  import {
17
- ServerCircuitArtifacts,
18
17
  type ServerProtocolArtifact,
19
18
  convertBaseParityInputsToWitnessMap,
20
19
  convertBaseParityOutputsFromWitnessMap,
@@ -36,6 +35,7 @@ import {
36
35
  convertRootRollupOutputsFromWitnessMap,
37
36
  convertSingleTxBlockRootRollupInputsToWitnessMap,
38
37
  convertSingleTxBlockRootRollupOutputsFromWitnessMap,
38
+ getServerCircuitArtifact,
39
39
  } from '@aztec/noir-protocol-circuits-types/server';
40
40
  import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
41
41
  import type { WitnessMap } from '@aztec/noir-types';
@@ -92,6 +92,7 @@ import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js';
92
92
  import { ProverInstrumentation } from '../instrumentation.js';
93
93
  import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
94
94
  import { extractAvmVkData, extractVkData } from '../verification_key/verification_key_data.js';
95
+ import { PRIVATE_TAIL_CIVC_VK, PUBLIC_TAIL_CIVC_VK } from '../verifier/bb_verifier.js';
95
96
  import { writeToOutputDirectory } from './client_ivc_proof_utils.js';
96
97
 
97
98
  const logger = createLogger('bb-prover');
@@ -410,13 +411,14 @@ export class BBNativeRollupProver implements ServerCircuitProver {
410
411
  outputWitnessFile,
411
412
  );
412
413
 
413
- const artifact = ServerCircuitArtifacts[circuitType];
414
+ const artifact = getServerCircuitArtifact(circuitType);
414
415
 
415
416
  logger.debug(`Generating witness data for ${circuitType}`);
416
417
 
417
418
  const inputWitness = convertInput(input);
418
419
  const timer = new Timer();
419
- const outputWitness = await simulator.executeProtocolCircuit(inputWitness, artifact);
420
+ const foreignCallHandler = undefined; // We don't handle foreign calls in the native ACVM simulator
421
+ const outputWitness = await simulator.executeProtocolCircuit(inputWitness, artifact, foreignCallHandler);
420
422
  const output = convertOutput(outputWitness);
421
423
 
422
424
  const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
@@ -520,12 +522,18 @@ export class BBNativeRollupProver implements ServerCircuitProver {
520
522
  hasher.update(input.toBuffer());
521
523
 
522
524
  await writeToOutputDirectory(input.clientIVCData, bbWorkingDirectory);
523
- const provingResult = await generateTubeProof(this.config.bbBinaryPath, bbWorkingDirectory, logger.verbose);
525
+ const provingResult = await generateTubeProof(
526
+ this.config.bbBinaryPath,
527
+ bbWorkingDirectory,
528
+ input.usePublicTailVk ? PUBLIC_TAIL_CIVC_VK : PRIVATE_TAIL_CIVC_VK,
529
+ logger.verbose,
530
+ );
524
531
 
525
532
  if (provingResult.status === BB_RESULT.FAILURE) {
526
533
  logger.error(`Failed to generate proof for tube circuit: ${provingResult.reason}`);
527
534
  throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
528
535
  }
536
+
529
537
  return provingResult;
530
538
  }
531
539
 
@@ -740,10 +748,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
740
748
 
741
749
  assert(json.length - numPublicInputs == proofLength, 'Proof length mismatch');
742
750
 
743
- const fieldsWithoutPublicInputs = json
744
- .slice(0, 3)
745
- .map(Fr.fromHexString)
746
- .concat(json.slice(3 + numPublicInputs).map(Fr.fromHexString));
751
+ const fieldsWithoutPublicInputs = json.slice(numPublicInputs).map(Fr.fromHexString);
747
752
  logger.debug(
748
753
  `Circuit path: ${filePath}, complete proof length: ${json.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}, is recursive: ${vkData.isRecursive}, raw length: ${binaryProof.length}`,
749
754
  );
@@ -3,40 +3,26 @@ import { ClientIvcProof } from '@aztec/stdlib/proofs';
3
3
  import { promises as fs } from 'fs';
4
4
  import { join } from 'path';
5
5
 
6
- export const CLIENT_IVC_VK_FILE_NAME = 'vk';
7
6
  export const CLIENT_IVC_PROOF_FILE_NAME = 'proof';
8
7
 
9
8
  /**
10
- * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs
11
- * Create a ClientIvcProof from the result of client_ivc_prove_output_all or client_ivc_prove_output_all_msgpack
12
- * @param directory the directory of results
9
+ * Create a ClientIvcProof proof file.
10
+ *
11
+ * @param directory the directory to read the proof from.
13
12
  * @returns the encapsulated client ivc proof
14
13
  */
15
14
  export async function readFromOutputDirectory(directory: string) {
16
- const [clientIvcVkBuffer, clientIvcProofBuffer] = await Promise.all(
17
- [CLIENT_IVC_VK_FILE_NAME, CLIENT_IVC_PROOF_FILE_NAME].map(fileName => fs.readFile(join(directory, fileName))),
18
- );
19
- return new ClientIvcProof(clientIvcProofBuffer, clientIvcVkBuffer);
15
+ const clientIvcProofBuffer = await fs.readFile(join(directory, CLIENT_IVC_PROOF_FILE_NAME));
16
+ return new ClientIvcProof(clientIvcProofBuffer);
20
17
  }
21
18
 
22
19
  /**
23
- * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs
24
- * Serialize a ClientIvcProof to the files expected by prove_tube
20
+ * Serialize a ClientIvcProof to a proof file.
25
21
  *
26
- * Example usage:
27
- * await runInDirectory(bbWorkingDirectory, async (dir: string) => {
28
- * await privateTx.clientIvcProof!.writeToOutputDirectory(bbWorkingDirectory);
29
- * const result = await generateTubeProof(bbPath, dir, logger.info)
30
- * expect(result.status).toBe(BB_RESULT.SUCCESS)
31
- * });
32
- * @param proof the ClientIvcProof from readFromOutputDirectory
33
- * @param directory the directory of results
22
+ * @param proof the ClientIvcProof from object
23
+ * @param directory the directory to write in
34
24
  */
35
25
  export async function writeToOutputDirectory(clientIvcProof: ClientIvcProof, directory: string) {
36
- const { clientIvcProofBuffer, clientIvcVkBuffer } = clientIvcProof;
37
- const fileData = [
38
- [CLIENT_IVC_PROOF_FILE_NAME, clientIvcProofBuffer],
39
- [CLIENT_IVC_VK_FILE_NAME, clientIvcVkBuffer],
40
- ] as const;
41
- await Promise.all(fileData.map(([fileName, buffer]) => fs.writeFile(join(directory, fileName), buffer)));
26
+ const { clientIvcProofBuffer } = clientIvcProof;
27
+ await fs.writeFile(join(directory, CLIENT_IVC_PROOF_FILE_NAME), clientIvcProofBuffer);
42
28
  }
@@ -11,7 +11,6 @@ import { sleep } from '@aztec/foundation/sleep';
11
11
  import { Timer } from '@aztec/foundation/timer';
12
12
  import {
13
13
  type ServerProtocolArtifact,
14
- SimulatedServerCircuitArtifacts,
15
14
  convertBaseParityInputsToWitnessMap,
16
15
  convertBaseParityOutputsFromWitnessMap,
17
16
  convertBlockMergeRollupInputsToWitnessMap,
@@ -32,6 +31,8 @@ import {
32
31
  convertSimulatedPublicBaseRollupOutputsFromWitnessMap,
33
32
  convertSimulatedSingleTxBlockRootRollupInputsToWitnessMap,
34
33
  convertSimulatedSingleTxBlockRootRollupOutputsFromWitnessMap,
34
+ foreignCallHandler,
35
+ getSimulatedServerCircuitArtifact,
35
36
  } from '@aztec/noir-protocol-circuits-types/server';
36
37
  import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
37
38
  import type { WitnessMap } from '@aztec/noir-types';
@@ -347,16 +348,26 @@ export class TestCircuitProver implements ServerCircuitProver {
347
348
  const witnessMap = convertInput(input);
348
349
  const circuitName = mapProtocolArtifactNameToCircuitName(artifactName);
349
350
 
350
- let simulationProvider = this.simulationProvider ?? this.wasmSimulator;
351
- if (['BlockRootRollupArtifact', 'SingleTxBlockRootRollupArtifact'].includes(artifactName)) {
352
- // TODO(#10323): temporarily force block root to use wasm while we simulate
353
- // the blob operations with an oracle. Appears to be no way to provide nativeACVM with a foreign call hander.
354
- simulationProvider = this.wasmSimulator;
351
+ let witness: WitnessMap;
352
+ if (
353
+ ['BlockRootRollupArtifact', 'SingleTxBlockRootRollupArtifact'].includes(artifactName) ||
354
+ this.simulationProvider == undefined
355
+ ) {
356
+ // TODO(#10323): Native ACVM simulator does not support foreign call handler so we use the wasm simulator
357
+ // when simulating block root rollup and single tx block root rollup circuits or when the native ACVM simulator
358
+ // is not provided.
359
+ witness = await this.wasmSimulator.executeProtocolCircuit(
360
+ witnessMap,
361
+ getSimulatedServerCircuitArtifact(artifactName),
362
+ foreignCallHandler,
363
+ );
364
+ } else {
365
+ witness = await this.simulationProvider.executeProtocolCircuit(
366
+ witnessMap,
367
+ getSimulatedServerCircuitArtifact(artifactName),
368
+ undefined, // Native ACM simulator does not support foreign call handler
369
+ );
355
370
  }
356
- const witness = await simulationProvider.executeProtocolCircuit(
357
- witnessMap,
358
- SimulatedServerCircuitArtifacts[artifactName],
359
- );
360
371
 
361
372
  const result = convertOutput(witness);
362
373