@aztec/simulator 0.85.0-alpha-testnet.2 → 0.85.0-nightly.20250417

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 (72) hide show
  1. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  2. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  3. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
  4. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -1
  5. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  6. package/dest/public/avm/index.d.ts +1 -1
  7. package/dest/public/avm/index.d.ts.map +1 -1
  8. package/dest/public/avm/index.js +1 -1
  9. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  10. package/dest/public/avm/opcodes/accrued_substate.js +1 -1
  11. package/dest/{common → public}/debug_fn_name.d.ts +1 -1
  12. package/dest/{common → public}/debug_fn_name.d.ts.map +1 -1
  13. package/dest/public/fixtures/index.d.ts +1 -0
  14. package/dest/public/fixtures/index.d.ts.map +1 -1
  15. package/dest/public/fixtures/index.js +1 -0
  16. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  17. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  18. package/dest/public/fixtures/public_tx_simulation_tester.js +3 -4
  19. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
  20. package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +1 -1
  21. package/dest/public/hinting_db_sources.d.ts +15 -5
  22. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  23. package/dest/public/hinting_db_sources.js +65 -27
  24. package/dest/public/index.d.ts +3 -5
  25. package/dest/public/index.d.ts.map +1 -1
  26. package/dest/public/index.js +3 -5
  27. package/dest/public/public_db_sources.d.ts +19 -52
  28. package/dest/public/public_db_sources.d.ts.map +1 -1
  29. package/dest/public/public_db_sources.js +96 -107
  30. package/dest/public/public_processor/public_processor.d.ts +6 -6
  31. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  32. package/dest/public/public_processor/public_processor.js +24 -26
  33. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -2
  34. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  35. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +2 -2
  36. package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -4
  37. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  38. package/dest/public/public_tx_simulator/public_tx_context.js +11 -21
  39. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +5 -4
  40. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  41. package/dest/public/public_tx_simulator/public_tx_simulator.js +21 -10
  42. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +3 -2
  43. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  44. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
  45. package/dest/public/side_effect_trace.d.ts +1 -3
  46. package/dest/public/side_effect_trace.d.ts.map +1 -1
  47. package/dest/public/side_effect_trace.js +3 -2
  48. package/dest/public/state_manager/state_manager.d.ts +6 -4
  49. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  50. package/dest/public/state_manager/state_manager.js +20 -41
  51. package/package.json +14 -16
  52. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  53. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  54. package/src/public/avm/index.ts +1 -1
  55. package/src/public/avm/opcodes/accrued_substate.ts +1 -5
  56. package/src/{common → public}/debug_fn_name.ts +1 -1
  57. package/src/public/fixtures/index.ts +1 -0
  58. package/src/public/fixtures/public_tx_simulation_tester.ts +3 -5
  59. package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +1 -1
  60. package/src/public/hinting_db_sources.ts +104 -39
  61. package/src/public/index.ts +3 -5
  62. package/src/public/public_db_sources.ts +111 -164
  63. package/src/public/public_processor/public_processor.ts +27 -29
  64. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +4 -3
  65. package/src/public/public_tx_simulator/public_tx_context.ts +10 -47
  66. package/src/public/public_tx_simulator/public_tx_simulator.ts +25 -10
  67. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -3
  68. package/src/public/side_effect_trace.ts +2 -4
  69. package/src/public/state_manager/state_manager.ts +24 -50
  70. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
  71. /package/dest/{common → public}/debug_fn_name.js +0 -0
  72. /package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.85.0-alpha-testnet.2",
3
+ "version": "0.85.0-nightly.20250417",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -19,8 +19,6 @@
19
19
  "build": "yarn clean && tsc -b",
20
20
  "build:dev": "tsc -b --watch",
21
21
  "clean": "rm -rf ./dest .tsbuildinfo",
22
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
23
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
24
22
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
25
23
  },
26
24
  "inherits": [
@@ -60,24 +58,24 @@
60
58
  ]
61
59
  },
62
60
  "dependencies": {
63
- "@aztec/constants": "0.85.0-alpha-testnet.2",
64
- "@aztec/foundation": "0.85.0-alpha-testnet.2",
65
- "@aztec/noir-acvm_js": "0.85.0-alpha-testnet.2",
66
- "@aztec/noir-noirc_abi": "0.85.0-alpha-testnet.2",
67
- "@aztec/noir-protocol-circuits-types": "0.85.0-alpha-testnet.2",
68
- "@aztec/noir-types": "0.85.0-alpha-testnet.2",
69
- "@aztec/protocol-contracts": "0.85.0-alpha-testnet.2",
70
- "@aztec/stdlib": "0.85.0-alpha-testnet.2",
71
- "@aztec/telemetry-client": "0.85.0-alpha-testnet.2",
72
- "@aztec/world-state": "0.85.0-alpha-testnet.2",
61
+ "@aztec/constants": "0.85.0-nightly.20250417",
62
+ "@aztec/foundation": "0.85.0-nightly.20250417",
63
+ "@aztec/noir-acvm_js": "0.85.0-nightly.20250417",
64
+ "@aztec/noir-noirc_abi": "0.85.0-nightly.20250417",
65
+ "@aztec/noir-protocol-circuits-types": "0.85.0-nightly.20250417",
66
+ "@aztec/noir-types": "0.85.0-nightly.20250417",
67
+ "@aztec/protocol-contracts": "0.85.0-nightly.20250417",
68
+ "@aztec/stdlib": "0.85.0-nightly.20250417",
69
+ "@aztec/telemetry-client": "0.85.0-nightly.20250417",
70
+ "@aztec/world-state": "0.85.0-nightly.20250417",
73
71
  "lodash.clonedeep": "^4.5.0",
74
72
  "lodash.merge": "^4.6.2",
75
73
  "tslib": "^2.4.0"
76
74
  },
77
75
  "devDependencies": {
78
- "@aztec/kv-store": "0.85.0-alpha-testnet.2",
79
- "@aztec/merkle-tree": "0.85.0-alpha-testnet.2",
80
- "@aztec/noir-contracts.js": "0.85.0-alpha-testnet.2",
76
+ "@aztec/kv-store": "0.85.0-nightly.20250417",
77
+ "@aztec/merkle-tree": "0.85.0-nightly.20250417",
78
+ "@aztec/noir-contracts.js": "0.85.0-nightly.20250417",
81
79
  "@jest/globals": "^29.5.0",
82
80
  "@types/jest": "^29.5.0",
83
81
  "@types/lodash.clonedeep": "^4.5.7",
@@ -16,11 +16,11 @@ import {
16
16
  initExecutionEnvironment,
17
17
  resolveContractAssertionMessage,
18
18
  } from '../../avm/fixtures/index.js';
19
+ import { SimpleContractDataSource } from '../../fixtures/simple_contract_data_source.js';
19
20
  import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
20
21
  import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
21
22
  import { AvmSimulator } from '../avm_simulator.js';
22
23
  import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
23
- import { SimpleContractDataSource } from './simple_contract_data_source.js';
24
24
 
25
25
  const TIMESTAMP = new Fr(99833);
26
26
  const DEFAULT_GAS_FEES = new GasFees(2, 3);
@@ -11,8 +11,8 @@ import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash
11
11
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
12
12
  import { MerkleTreeId } from '@aztec/stdlib/trees';
13
13
 
14
+ import type { SimpleContractDataSource } from '../../fixtures/simple_contract_data_source.js';
14
15
  import { createContractClassAndInstance } from './index.js';
15
- import type { SimpleContractDataSource } from './simple_contract_data_source.js';
16
16
 
17
17
  /**
18
18
  * An abstract test class that enables tests of real apps in the AVM without requiring e2e tests.
@@ -1,2 +1,2 @@
1
1
  export * from './avm_simulator.js';
2
- export * from './fixtures/simple_contract_data_source.js';
2
+ export * from '../fixtures/simple_contract_data_source.js';
@@ -181,11 +181,7 @@ export class L1ToL2MessageExists extends Instruction {
181
181
 
182
182
  const msgHash = memory.get(msgHashOffset).toFr();
183
183
  const msgLeafIndex = memory.get(msgLeafIndexOffset).toFr();
184
- const exists = await context.persistableState.checkL1ToL2MessageExists(
185
- context.environment.address,
186
- msgHash,
187
- msgLeafIndex,
188
- );
184
+ const exists = await context.persistableState.checkL1ToL2MessageExists(msgHash, msgLeafIndex);
189
185
  memory.set(existsOffset, exists ? new Uint1(1) : new Uint1(0));
190
186
  }
191
187
  }
@@ -2,7 +2,7 @@ import type { Fr } from '@aztec/foundation/fields';
2
2
  import { FunctionSelector } from '@aztec/stdlib/abi';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
 
5
- import type { PublicContractsDBInterface } from '../public/db_interfaces.js';
5
+ import type { PublicContractsDBInterface } from './db_interfaces.js';
6
6
 
7
7
  export async function getPublicFunctionDebugName(
8
8
  db: PublicContractsDBInterface,
@@ -1,2 +1,3 @@
1
1
  export * from './public_tx_simulation_tester.js';
2
2
  export * from './utils.js';
3
+ export * from './simple_contract_data_source.js';
@@ -10,11 +10,11 @@ import { NativeWorldStateService } from '@aztec/world-state';
10
10
 
11
11
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
12
12
  import { DEFAULT_BLOCK_NUMBER, getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
13
- import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
14
- import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
13
+ import { PublicContractsDB } from '../public_db_sources.js';
15
14
  import { MeasuredPublicTxSimulator } from '../public_tx_simulator/measured_public_tx_simulator.js';
16
15
  import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
17
16
  import { TestExecutorMetrics } from '../test_executor_metrics.js';
17
+ import { SimpleContractDataSource } from './simple_contract_data_source.js';
18
18
  import { createTxForPublicCalls } from './utils.js';
19
19
 
20
20
  const TIMESTAMP = new Fr(99833);
@@ -47,11 +47,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
47
47
  ) {
48
48
  super(contractDataSource, merkleTree);
49
49
 
50
- const treesDB = new PublicTreesDB(merkleTree);
51
50
  const contractsDB = new PublicContractsDB(contractDataSource);
52
-
53
51
  this.simulator = new MeasuredPublicTxSimulator(
54
- treesDB,
52
+ merkleTree,
55
53
  contractsDB,
56
54
  globals,
57
55
  /*doMerkleOperations=*/ true,
@@ -4,7 +4,7 @@ import type { ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
6
 
7
- import { getFunctionSelector } from './index.js';
7
+ import { getFunctionSelector } from '../avm/fixtures/index.js';
8
8
 
9
9
  /**
10
10
  * This class is used during public/avm testing to function as a database of
@@ -24,9 +24,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
24
24
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
25
25
  import {
26
26
  AppendOnlyTreeSnapshot,
27
+ type BatchInsertionResult,
27
28
  type IndexedTreeId,
28
29
  MerkleTreeId,
29
30
  type MerkleTreeLeafType,
31
+ type MerkleTreeWriteOperations,
30
32
  NullifierLeaf,
31
33
  NullifierLeafPreimage,
32
34
  PublicDataTreeLeaf,
@@ -35,11 +37,11 @@ import {
35
37
  getTreeName,
36
38
  merkleTreeIds,
37
39
  } from '@aztec/stdlib/trees';
40
+ import { TreeSnapshots } from '@aztec/stdlib/tx';
38
41
 
39
42
  import { strict as assert } from 'assert';
40
43
 
41
44
  import type { PublicContractsDBInterface } from './db_interfaces.js';
42
- import { PublicTreesDB } from './public_db_sources.js';
43
45
 
44
46
  /**
45
47
  * A public contracts database that forwards requests and collects AVM hints.
@@ -101,10 +103,10 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
101
103
  }
102
104
 
103
105
  /**
104
- * A public trees database that forwards requests and collects AVM hints.
106
+ * A low-level merkle DB that collects hints.
105
107
  */
106
- export class HintingPublicTreesDB extends PublicTreesDB {
107
- private static readonly log: Logger = createLogger('HintingPublicTreesDB');
108
+ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
109
+ private static readonly log: Logger = createLogger('simulator:hinting-merkle-db');
108
110
  // This stack is only for debugging purposes.
109
111
  // The top of the stack is the current checkpoint id.
110
112
  // We need the stack to be non-empty and use 0 as an arbitrary initial checkpoint id.
@@ -113,19 +115,31 @@ export class HintingPublicTreesDB extends PublicTreesDB {
113
115
  private nextCheckpointId: number = 1;
114
116
  private checkpointActionCounter: number = 0; // yes, a side-effect counter.
115
117
 
116
- constructor(db: PublicTreesDB, private hints: AvmExecutionHints) {
117
- super(db);
118
+ public static async create(db: MerkleTreeWriteOperations, hints: AvmExecutionHints) {
119
+ const hintingTreesDB = new HintingMerkleWriteOperations(db, hints);
120
+ const startStateReference = await db.getStateReference();
121
+ hints.startingTreeRoots = new TreeSnapshots(
122
+ startStateReference.l1ToL2MessageTree,
123
+ startStateReference.partial.noteHashTree,
124
+ startStateReference.partial.nullifierTree,
125
+ startStateReference.partial.publicDataTree,
126
+ );
127
+
128
+ return hintingTreesDB;
118
129
  }
119
130
 
131
+ // Use create() to instantiate.
132
+ private constructor(private db: MerkleTreeWriteOperations, private hints: AvmExecutionHints) {}
133
+
120
134
  // Getters.
121
- public override async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
122
- const path = await super.getSiblingPath<N>(treeId, index);
135
+ public async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
136
+ const path = await this.db.getSiblingPath<N>(treeId, index);
123
137
  const key = await this.getHintKey(treeId);
124
138
  this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
125
139
  return Promise.resolve(path);
126
140
  }
127
141
 
128
- public override async getPreviousValueIndex<ID extends IndexedTreeId>(
142
+ public async getPreviousValueIndex<ID extends IndexedTreeId>(
129
143
  treeId: ID,
130
144
  value: bigint,
131
145
  ): Promise<
@@ -135,7 +149,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
135
149
  }
136
150
  | undefined
137
151
  > {
138
- const result = await super.getPreviousValueIndex(treeId, value);
152
+ const result = await this.db.getPreviousValueIndex(treeId, value);
139
153
  if (result === undefined) {
140
154
  throw new Error(
141
155
  `getPreviousValueIndex(${getTreeName(
@@ -150,11 +164,11 @@ export class HintingPublicTreesDB extends PublicTreesDB {
150
164
  return result;
151
165
  }
152
166
 
153
- public override async getLeafPreimage<ID extends IndexedTreeId>(
167
+ public async getLeafPreimage<ID extends IndexedTreeId>(
154
168
  treeId: ID,
155
169
  index: bigint,
156
170
  ): Promise<IndexedTreeLeafPreimage | undefined> {
157
- const preimage = await super.getLeafPreimage<ID>(treeId, index);
171
+ const preimage = await this.db.getLeafPreimage<ID>(treeId, index);
158
172
  if (preimage) {
159
173
  const key = await this.getHintKey(treeId);
160
174
 
@@ -179,14 +193,14 @@ export class HintingPublicTreesDB extends PublicTreesDB {
179
193
  return preimage;
180
194
  }
181
195
 
182
- public override async getLeafValue<ID extends MerkleTreeId>(
196
+ public async getLeafValue<ID extends MerkleTreeId>(
183
197
  treeId: ID,
184
198
  index: bigint,
185
199
  ): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
186
200
  // Use getLeafPreimage for PublicDataTree and NullifierTree.
187
201
  assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
188
202
 
189
- const value = await super.getLeafValue<ID>(treeId, index);
203
+ const value = await this.db.getLeafValue<ID>(treeId, index);
190
204
  if (value) {
191
205
  const key = await this.getHintKey(treeId);
192
206
  // We can cast to Fr because we know the type of the tree.
@@ -199,7 +213,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
199
213
  // State modification.
200
214
  // FIXME(fcarreiro): This is a horrible interface (in the merkle ops). It's receiving the leaves as buffers,
201
215
  // from a leaf class that is NOT the one that will be used to write. Make this type safe.
202
- public override async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
216
+ public async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
203
217
  treeId: ID,
204
218
  leaves: Buffer[],
205
219
  ): Promise<SequentialInsertionResult<TreeHeight>> {
@@ -210,11 +224,10 @@ export class HintingPublicTreesDB extends PublicTreesDB {
210
224
 
211
225
  const beforeState = await this.getHintKey(treeId);
212
226
 
213
- const result = await super.sequentialInsert<TreeHeight, ID>(treeId, leaves);
227
+ const result = await this.db.sequentialInsert<TreeHeight, ID>(treeId, leaves);
214
228
 
215
229
  const afterState = await this.getHintKey(treeId);
216
- HintingPublicTreesDB.log.debug('[sequentialInsert] Evolved tree state.');
217
- HintingPublicTreesDB.logTreeChange(beforeState, afterState, treeId);
230
+ HintingMerkleWriteOperations.logTreeChange('sequentialInsert', beforeState, afterState, treeId);
218
231
 
219
232
  switch (treeId) {
220
233
  case MerkleTreeId.PUBLIC_DATA_TREE:
@@ -265,10 +278,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
265
278
  return result;
266
279
  }
267
280
 
268
- public override async appendLeaves<ID extends MerkleTreeId>(
269
- treeId: ID,
270
- leaves: MerkleTreeLeafType<ID>[],
271
- ): Promise<void> {
281
+ public async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
272
282
  // Use sequentialInsert for PublicDataTree and NullifierTree.
273
283
  assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
274
284
 
@@ -279,39 +289,39 @@ export class HintingPublicTreesDB extends PublicTreesDB {
279
289
  }
280
290
  }
281
291
 
282
- public override async createCheckpoint(): Promise<void> {
292
+ public async createCheckpoint(): Promise<void> {
283
293
  const actionCounter = this.checkpointActionCounter++;
284
294
  const oldCheckpointId = this.getCurrentCheckpointId();
285
295
  const treesStateHash = await this.getTreesStateHash();
286
296
 
287
- await super.createCheckpoint();
297
+ await this.db.createCheckpoint();
288
298
  this.checkpointStack.push(this.nextCheckpointId++);
289
299
  const newCheckpointId = this.getCurrentCheckpointId();
290
300
 
291
301
  this.hints.createCheckpointHints.push(new AvmCreateCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
292
302
 
293
- HintingPublicTreesDB.log.debug(
303
+ HintingMerkleWriteOperations.log.trace(
294
304
  `[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
295
305
  );
296
306
  }
297
307
 
298
- public override async commitCheckpoint(): Promise<void> {
308
+ public async commitCheckpoint(): Promise<void> {
299
309
  const actionCounter = this.checkpointActionCounter++;
300
310
  const oldCheckpointId = this.getCurrentCheckpointId();
301
311
  const treesStateHash = await this.getTreesStateHash();
302
312
 
303
- await super.commitCheckpoint();
313
+ await this.db.commitCheckpoint();
304
314
  this.checkpointStack.pop();
305
315
  const newCheckpointId = this.getCurrentCheckpointId();
306
316
 
307
317
  this.hints.commitCheckpointHints.push(new AvmCommitCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
308
318
 
309
- HintingPublicTreesDB.log.debug(
319
+ HintingMerkleWriteOperations.log.trace(
310
320
  `[commitCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
311
321
  );
312
322
  }
313
323
 
314
- public override async revertCheckpoint(): Promise<void> {
324
+ public async revertCheckpoint(): Promise<void> {
315
325
  const actionCounter = this.checkpointActionCounter++;
316
326
  const oldCheckpointId = this.getCurrentCheckpointId();
317
327
  const treesStateHash = await this.getTreesStateHash();
@@ -324,7 +334,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
324
334
  [MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
325
335
  };
326
336
 
327
- await super.revertCheckpoint();
337
+ await this.db.revertCheckpoint();
328
338
  this.checkpointStack.pop();
329
339
  const newCheckpointId = this.getCurrentCheckpointId();
330
340
 
@@ -340,17 +350,17 @@ export class HintingPublicTreesDB extends PublicTreesDB {
340
350
  AvmRevertCheckpointHint.create(actionCounter, oldCheckpointId, newCheckpointId, beforeState, afterState),
341
351
  );
342
352
 
343
- HintingPublicTreesDB.log.debug(
353
+ HintingMerkleWriteOperations.log.trace(
344
354
  `[revertCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
345
355
  );
346
356
  for (const treeId of merkleTreeIds()) {
347
- HintingPublicTreesDB.logTreeChange(beforeState[treeId], afterState[treeId], treeId);
357
+ HintingMerkleWriteOperations.logTreeChange('revertCheckpoint', beforeState[treeId], afterState[treeId], treeId);
348
358
  }
349
359
  }
350
360
 
351
361
  // Private methods.
352
362
  private async getHintKey(treeId: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
353
- const treeInfo = await super.getTreeInfo(treeId);
363
+ const treeInfo = await this.db.getTreeInfo(treeId);
354
364
  return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
355
365
  }
356
366
 
@@ -360,18 +370,19 @@ export class HintingPublicTreesDB extends PublicTreesDB {
360
370
 
361
371
  // For logging/debugging purposes.
362
372
  private async getTreesStateHash(): Promise<Fr> {
363
- const stateReferenceFields = (await super.getStateReference()).toFields();
373
+ const stateReferenceFields = (await this.db.getStateReference()).toFields();
364
374
  return Fr.fromBuffer(sha256Trunc(Buffer.concat(stateReferenceFields.map(field => field.toBuffer()))));
365
375
  }
366
376
 
367
377
  private static logTreeChange(
378
+ action: string,
368
379
  beforeState: AppendOnlyTreeSnapshot,
369
380
  afterState: AppendOnlyTreeSnapshot,
370
381
  treeId: MerkleTreeId,
371
382
  ) {
372
383
  const treeName = getTreeName(treeId);
373
- HintingPublicTreesDB.log.debug(
374
- `[${treeName}] Evolved tree state: ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`,
384
+ HintingMerkleWriteOperations.log.trace(
385
+ `[${action}] ${treeName} tree state: ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`,
375
386
  );
376
387
  }
377
388
 
@@ -384,15 +395,69 @@ export class HintingPublicTreesDB extends PublicTreesDB {
384
395
 
385
396
  const beforeState = await this.getHintKey(treeId);
386
397
 
387
- await super.appendLeaves<ID>(treeId, [leaf]);
398
+ await this.db.appendLeaves<ID>(treeId, [leaf]);
388
399
 
389
400
  const afterState = await this.getHintKey(treeId);
390
401
 
391
- HintingPublicTreesDB.log.debug('[appendLeaves] Evolved tree state.');
392
- HintingPublicTreesDB.logTreeChange(beforeState, afterState, treeId);
402
+ HintingMerkleWriteOperations.logTreeChange('appendLeaves', beforeState, afterState, treeId);
393
403
 
394
404
  this.hints.appendLeavesHints.push(new AvmAppendLeavesHint(beforeState, afterState, treeId, [leaf as Fr]));
395
405
 
396
406
  return await this.getSiblingPath<N>(treeId, BigInt(beforeState.nextAvailableLeafIndex));
397
407
  }
408
+
409
+ // Non-hinted required methods from MerkleTreeWriteOperations interface
410
+ public async getTreeInfo(treeId: MerkleTreeId) {
411
+ return await this.db.getTreeInfo(treeId);
412
+ }
413
+
414
+ public async getStateReference() {
415
+ return await this.db.getStateReference();
416
+ }
417
+
418
+ public getInitialHeader() {
419
+ return this.db.getInitialHeader();
420
+ }
421
+
422
+ public async updateArchive(header: any): Promise<void> {
423
+ return await this.db.updateArchive(header);
424
+ }
425
+
426
+ public async batchInsert<
427
+ TreeHeight extends number,
428
+ SubtreeSiblingPathHeight extends number,
429
+ ID extends IndexedTreeId,
430
+ >(
431
+ treeId: ID,
432
+ leaves: Buffer[],
433
+ subtreeHeight: number,
434
+ ): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
435
+ return await this.db.batchInsert<TreeHeight, SubtreeSiblingPathHeight, ID>(treeId, leaves, subtreeHeight);
436
+ }
437
+
438
+ public async close(): Promise<void> {
439
+ return await this.db.close();
440
+ }
441
+
442
+ public async findLeafIndices<ID extends MerkleTreeId>(
443
+ treeId: ID,
444
+ values: MerkleTreeLeafType<ID>[],
445
+ ): Promise<(bigint | undefined)[]> {
446
+ return await this.db.findLeafIndices(treeId, values);
447
+ }
448
+
449
+ public async findLeafIndicesAfter<ID extends MerkleTreeId>(
450
+ treeId: ID,
451
+ values: MerkleTreeLeafType<ID>[],
452
+ startIndex: bigint,
453
+ ): Promise<(bigint | undefined)[]> {
454
+ return await this.db.findLeafIndicesAfter(treeId, values, startIndex);
455
+ }
456
+
457
+ public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
458
+ treeId: ID,
459
+ leafIndices: bigint[],
460
+ ): Promise<(bigint | undefined)[]> {
461
+ return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
462
+ }
398
463
  }
@@ -1,8 +1,6 @@
1
- export * from './db_interfaces.js';
2
- export * from './public_tx_simulator/index.js';
3
- export * from './public_db_sources.js';
1
+ export { PublicContractsDB } from './public_db_sources.js';
2
+ export { type PublicTxResult, PublicTxSimulator, TelemetryPublicTxSimulator } from './public_tx_simulator/index.js';
4
3
  export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
5
- export { SideEffectTrace } from './side_effect_trace.js';
6
4
  export { PublicTxSimulationTester } from './fixtures/index.js';
7
- export * from './avm/index.js';
8
5
  export { getCallRequestsWithCalldataByPhase } from './utils.js';
6
+ export { SimpleContractDataSource } from './fixtures/simple_contract_data_source.js';