@aztec/simulator 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 (144) hide show
  1. package/dest/common/db_interfaces.d.ts +30 -17
  2. package/dest/common/db_interfaces.d.ts.map +1 -1
  3. package/dest/common/db_interfaces.js +1 -1
  4. package/dest/common/debug_fn_name.d.ts +2 -2
  5. package/dest/common/debug_fn_name.d.ts.map +1 -1
  6. package/dest/common/message_load_oracle_inputs.d.ts +4 -0
  7. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -1
  8. package/dest/common/message_load_oracle_inputs.js +9 -0
  9. package/dest/private/acvm/acvm.d.ts +6 -1
  10. package/dest/private/acvm/acvm.d.ts.map +1 -1
  11. package/dest/private/acvm/acvm.js +7 -13
  12. package/dest/private/acvm/deserialize.d.ts +19 -18
  13. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  14. package/dest/private/acvm/deserialize.js +31 -23
  15. package/dest/private/acvm/oracle/oracle.d.ts +36 -34
  16. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  17. package/dest/private/acvm/oracle/oracle.js +134 -79
  18. package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -2
  19. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  20. package/dest/private/acvm/oracle/typed_oracle.js +5 -2
  21. package/dest/private/acvm/serialize.d.ts +11 -0
  22. package/dest/private/acvm/serialize.d.ts.map +1 -1
  23. package/dest/private/acvm/serialize.js +27 -0
  24. package/dest/private/execution_data_provider.d.ts +15 -13
  25. package/dest/private/execution_data_provider.d.ts.map +1 -1
  26. package/dest/private/private_execution.d.ts +2 -2
  27. package/dest/private/private_execution.d.ts.map +1 -1
  28. package/dest/private/private_execution.js +4 -5
  29. package/dest/private/private_execution_oracle.d.ts.map +1 -1
  30. package/dest/private/private_execution_oracle.js +1 -1
  31. package/dest/private/providers/acvm_native.d.ts +6 -4
  32. package/dest/private/providers/acvm_native.d.ts.map +1 -1
  33. package/dest/private/providers/acvm_native.js +6 -3
  34. package/dest/private/providers/acvm_wasm.d.ts +6 -7
  35. package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
  36. package/dest/private/providers/acvm_wasm.js +13 -15
  37. package/dest/private/providers/acvm_wasm_with_blobs.d.ts +5 -5
  38. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
  39. package/dest/private/providers/acvm_wasm_with_blobs.js +7 -9
  40. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +90 -0
  41. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -0
  42. package/dest/private/providers/circuit_recording/circuit_recorder.js +246 -0
  43. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +18 -0
  44. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -0
  45. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.js +39 -0
  46. package/dest/private/providers/simulation_provider.d.ts +21 -7
  47. package/dest/private/providers/simulation_provider.d.ts.map +1 -1
  48. package/dest/private/simulator.d.ts +3 -2
  49. package/dest/private/simulator.d.ts.map +1 -1
  50. package/dest/private/simulator.js +2 -2
  51. package/dest/private/unconstrained_execution.d.ts +2 -2
  52. package/dest/private/unconstrained_execution.d.ts.map +1 -1
  53. package/dest/private/unconstrained_execution.js +1 -2
  54. package/dest/private/unconstrained_execution_oracle.d.ts +5 -3
  55. package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
  56. package/dest/private/unconstrained_execution_oracle.js +9 -5
  57. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  58. package/dest/public/avm/avm_simulator.js +0 -2
  59. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  60. package/dest/public/avm/fixtures/avm_simulation_tester.js +5 -5
  61. package/dest/public/avm/fixtures/index.d.ts +4 -4
  62. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  63. package/dest/public/avm/fixtures/index.js +9 -6
  64. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +1 -2
  65. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
  66. package/dest/public/avm/fixtures/simple_contract_data_source.js +0 -3
  67. package/dest/public/avm/journal/journal.d.ts +16 -70
  68. package/dest/public/avm/journal/journal.d.ts.map +1 -1
  69. package/dest/public/avm/journal/journal.js +88 -210
  70. package/dest/public/avm/journal/nullifiers.d.ts +2 -2
  71. package/dest/public/avm/journal/nullifiers.d.ts.map +1 -1
  72. package/dest/public/avm/journal/public_storage.d.ts +2 -2
  73. package/dest/public/avm/journal/public_storage.d.ts.map +1 -1
  74. package/dest/public/avm/test_utils.d.ts +10 -13
  75. package/dest/public/avm/test_utils.d.ts.map +1 -1
  76. package/dest/public/avm/test_utils.js +8 -13
  77. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +3 -3
  78. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  79. package/dest/public/fixtures/public_tx_simulation_tester.js +10 -9
  80. package/dest/public/hinting_db_sources.d.ts +19 -0
  81. package/dest/public/hinting_db_sources.d.ts.map +1 -0
  82. package/dest/public/hinting_db_sources.js +36 -0
  83. package/dest/public/public_db_sources.d.ts +46 -22
  84. package/dest/public/public_db_sources.d.ts.map +1 -1
  85. package/dest/public/public_db_sources.js +82 -27
  86. package/dest/public/public_processor/public_processor.d.ts +5 -5
  87. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  88. package/dest/public/public_processor/public_processor.js +21 -20
  89. package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -14
  90. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  91. package/dest/public/public_tx_simulator/public_tx_context.js +15 -19
  92. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +9 -6
  93. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  94. package/dest/public/public_tx_simulator/public_tx_simulator.js +28 -14
  95. package/dest/public/side_effect_trace.d.ts +6 -22
  96. package/dest/public/side_effect_trace.d.ts.map +1 -1
  97. package/dest/public/side_effect_trace.js +11 -70
  98. package/dest/public/side_effect_trace_interface.d.ts +5 -19
  99. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  100. package/dest/testing.d.ts +2 -0
  101. package/dest/testing.d.ts.map +1 -0
  102. package/dest/testing.js +1 -0
  103. package/package.json +15 -14
  104. package/src/common/db_interfaces.ts +32 -18
  105. package/src/common/debug_fn_name.ts +2 -2
  106. package/src/common/message_load_oracle_inputs.ts +8 -0
  107. package/src/private/acvm/acvm.ts +8 -24
  108. package/src/private/acvm/deserialize.ts +35 -29
  109. package/src/private/acvm/oracle/oracle.ts +171 -129
  110. package/src/private/acvm/oracle/typed_oracle.ts +7 -3
  111. package/src/private/acvm/serialize.ts +28 -0
  112. package/src/private/execution_data_provider.ts +19 -14
  113. package/src/private/private_execution.ts +11 -7
  114. package/src/private/private_execution_oracle.ts +5 -1
  115. package/src/private/providers/acvm_native.ts +17 -6
  116. package/src/private/providers/acvm_wasm.ts +27 -20
  117. package/src/private/providers/acvm_wasm_with_blobs.ts +15 -12
  118. package/src/private/providers/circuit_recording/circuit_recorder.ts +283 -0
  119. package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +82 -0
  120. package/src/private/providers/simulation_provider.ts +30 -5
  121. package/src/private/simulator.ts +5 -3
  122. package/src/private/unconstrained_execution.ts +8 -4
  123. package/src/private/unconstrained_execution_oracle.ts +15 -9
  124. package/src/public/avm/avm_simulator.ts +0 -2
  125. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -5
  126. package/src/public/avm/fixtures/index.ts +16 -10
  127. package/src/public/avm/fixtures/simple_contract_data_source.ts +1 -10
  128. package/src/public/avm/journal/journal.ts +119 -353
  129. package/src/public/avm/journal/nullifiers.ts +2 -2
  130. package/src/public/avm/journal/public_storage.ts +2 -2
  131. package/src/public/avm/test_utils.ts +20 -29
  132. package/src/public/fixtures/public_tx_simulation_tester.ts +9 -12
  133. package/src/public/hinting_db_sources.ts +71 -0
  134. package/src/public/public_db_sources.ts +134 -32
  135. package/src/public/public_processor/public_processor.ts +22 -21
  136. package/src/public/public_tx_simulator/public_tx_context.ts +30 -38
  137. package/src/public/public_tx_simulator/public_tx_simulator.ts +47 -17
  138. package/src/public/side_effect_trace.ts +8 -172
  139. package/src/public/side_effect_trace_interface.ts +4 -55
  140. package/src/testing.ts +1 -0
  141. package/dest/public/avm/bytecode_utils.d.ts +0 -5
  142. package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
  143. package/dest/public/avm/bytecode_utils.js +0 -17
  144. package/src/public/avm/bytecode_utils.ts +0 -17
@@ -6,7 +6,6 @@ import { type Tx } from '@aztec/stdlib/tx';
6
6
  import { GlobalVariables } from '@aztec/stdlib/tx';
7
7
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
8
8
  import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
9
- import { WorldStateDB } from '../public_db_sources.js';
10
9
  import { type PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
11
10
  export declare const DEFAULT_BLOCK_NUMBER = 42;
12
11
  export type TestEnqueuedCall = {
@@ -22,11 +21,12 @@ export type TestEnqueuedCall = {
22
21
  * transactions.
23
22
  */
24
23
  export declare class PublicTxSimulationTester extends BaseAvmSimulationTester {
25
- private worldStateDB;
24
+ private merkleTree;
26
25
  private txCount;
27
- constructor(worldStateDB: WorldStateDB, contractDataSource: SimpleContractDataSource, merkleTrees: MerkleTreeWriteOperations);
26
+ constructor(merkleTree: MerkleTreeWriteOperations, contractDataSource: SimpleContractDataSource);
28
27
  static create(): Promise<PublicTxSimulationTester>;
29
28
  createTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr): Promise<Tx>;
30
29
  simulateTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr, globals?: GlobalVariables): Promise<PublicTxResult>;
31
30
  }
31
+ export declare function defaultGlobals(): GlobalVariables;
32
32
  //# sourceMappingURL=public_tx_simulation_tester.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulation_tester.d.ts","sourceRoot":"","sources":["../../../src/public/fixtures/public_tx_simulation_tester.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,KAAK,gBAAgB,EAAqC,MAAM,mBAAmB,CAAC;AAC7F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAA0B,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAe,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,+CAA+C,CAAC;AAKvG,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,uBAAuB;IAIjE,OAAO,CAAC,YAAY;IAHtB,OAAO,CAAC,OAAO,CAAK;gBAGV,YAAY,EAAE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BAAgB,GAAG;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,uBAAuB;IAGvD,OAAO,CAAC,UAAU;IAF9B,OAAO,CAAC,OAAO,CAAK;gBAEA,UAAU,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,wBAAwB;WAInF,MAAM,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAMlD,QAAQ,CACnB,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,gBAAgB,EAAO,EACnC,QAAQ,GAAE,gBAAgB,EAAO,EACjC,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,GAC/C,OAAO,CAAC,EAAE,CAAC;IAiED,UAAU,CACrB,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,gBAAgB,EAAO,EACnC,QAAQ,GAAE,gBAAgB,EAAO,EACjC,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,EAChD,OAAO,kBAAmB,GACzB,OAAO,CAAC,cAAc,CAAC;CAgB3B;AAwBD,wBAAgB,cAAc,oBAM7B"}
@@ -8,7 +8,7 @@ import { NativeWorldStateService } from '@aztec/world-state';
8
8
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
9
9
  import { getContractFunctionArtifact, getFunctionSelector } from '../avm/fixtures/index.js';
10
10
  import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
11
- import { WorldStateDB } from '../public_db_sources.js';
11
+ import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
12
12
  import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
13
13
  import { createTxForPublicCalls } from './index.js';
14
14
  const TIMESTAMP = new Fr(99833);
@@ -19,16 +19,15 @@ export const DEFAULT_BLOCK_NUMBER = 42;
19
19
  * It provides an interface for simulating one transaction at a time and maintains state between subsequent
20
20
  * transactions.
21
21
  */ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
22
- worldStateDB;
22
+ merkleTree;
23
23
  txCount;
24
- constructor(worldStateDB, contractDataSource, merkleTrees){
25
- super(contractDataSource, merkleTrees), this.worldStateDB = worldStateDB, this.txCount = 0;
24
+ constructor(merkleTree, contractDataSource){
25
+ super(contractDataSource, merkleTree), this.merkleTree = merkleTree, this.txCount = 0;
26
26
  }
27
27
  static async create() {
28
28
  const contractDataSource = new SimpleContractDataSource();
29
- const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
30
- const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
31
- return new PublicTxSimulationTester(worldStateDB, contractDataSource, merkleTrees);
29
+ const merkleTree = await (await NativeWorldStateService.tmp()).fork();
30
+ return new PublicTxSimulationTester(merkleTree, contractDataSource);
32
31
  }
33
32
  async createTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++)) {
34
33
  const setupExecutionRequests = [];
@@ -65,7 +64,9 @@ export const DEFAULT_BLOCK_NUMBER = 42;
65
64
  async simulateTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++), globals = defaultGlobals()) {
66
65
  const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier);
67
66
  await this.setFeePayerBalance(feePayer);
68
- const simulator = new PublicTxSimulator(this.merkleTrees, this.worldStateDB, globals, /*doMerkleOperations=*/ true);
67
+ const treesDB = new PublicTreesDB(this.merkleTree);
68
+ const contractsDB = new PublicContractsDB(this.contractDataSource);
69
+ const simulator = new PublicTxSimulator(treesDB, contractsDB, globals, /*doMerkleOperations=*/ true);
69
70
  const startTime = performance.now();
70
71
  const avmResult = await simulator.simulate(tx);
71
72
  const endTime = performance.now();
@@ -84,7 +85,7 @@ async function executionRequestForCall(contractArtifact, sender, address, fnName
84
85
  const callContext = new CallContext(sender, address, /*selector=*/ new FunctionSelector(PUBLIC_DISPATCH_SELECTOR), isStaticCall);
85
86
  return new PublicExecutionRequest(callContext, calldata);
86
87
  }
87
- function defaultGlobals() {
88
+ export function defaultGlobals() {
88
89
  const globals = GlobalVariables.empty();
89
90
  globals.timestamp = TIMESTAMP;
90
91
  globals.gasFees = DEFAULT_GAS_FEES; // apply some nonzero default gas fees
@@ -0,0 +1,19 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { FunctionSelector } from '@aztec/stdlib/abi';
3
+ import { type AvmExecutionHints } from '@aztec/stdlib/avm';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
+ import type { PublicContractsDBInterface } from '../server.js';
7
+ /**
8
+ * A public contracts database that forwards requests and collects AVM hints.
9
+ */
10
+ export declare class HintingPublicContractsDB implements PublicContractsDBInterface {
11
+ private readonly db;
12
+ readonly hints: AvmExecutionHints;
13
+ constructor(db: PublicContractsDBInterface, hints: AvmExecutionHints);
14
+ getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
15
+ getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
16
+ getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
17
+ getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
18
+ }
19
+ //# sourceMappingURL=hinting_db_sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE/D;;GAEG;AACH,qBAAa,wBAAyB,YAAW,0BAA0B;IAC7D,OAAO,CAAC,QAAQ,CAAC,EAAE;aAA8C,KAAK,EAAE,iBAAiB;gBAAxE,EAAE,EAAE,0BAA0B,EAAkB,KAAK,EAAE,iBAAiB;IAExF,mBAAmB,CAC9B,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAmBtC,gBAAgB,CAAC,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAe/E,qBAAqB,CAAC,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAQnE,oBAAoB,CAC/B,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAG/B"}
@@ -0,0 +1,36 @@
1
+ import { AvmBytecodeCommitmentHint, AvmContractClassHint, AvmContractInstanceHint } from '@aztec/stdlib/avm';
2
+ /**
3
+ * A public contracts database that forwards requests and collects AVM hints.
4
+ */ export class HintingPublicContractsDB {
5
+ db;
6
+ hints;
7
+ constructor(db, hints){
8
+ this.db = db;
9
+ this.hints = hints;
10
+ }
11
+ async getContractInstance(address, blockNumber) {
12
+ const instance = await this.db.getContractInstance(address, blockNumber);
13
+ if (instance) {
14
+ // We don't need to hint the block number because it doesn't change.
15
+ this.hints.contractInstances.push(new AvmContractInstanceHint(instance.address, instance.salt, instance.deployer, instance.currentContractClassId, instance.originalContractClassId, instance.initializationHash, instance.publicKeys));
16
+ }
17
+ return instance;
18
+ }
19
+ async getContractClass(contractClassId) {
20
+ const contractClass = await this.db.getContractClass(contractClassId);
21
+ if (contractClass) {
22
+ this.hints.contractClasses.push(new AvmContractClassHint(contractClass.id, contractClass.artifactHash, contractClass.privateFunctionsRoot, contractClass.packedBytecode));
23
+ }
24
+ return contractClass;
25
+ }
26
+ async getBytecodeCommitment(contractClassId) {
27
+ const commitment = await this.db.getBytecodeCommitment(contractClassId);
28
+ if (commitment) {
29
+ this.hints.bytecodeCommitments.push(new AvmBytecodeCommitmentHint(contractClassId, commitment));
30
+ }
31
+ return commitment;
32
+ }
33
+ async getDebugFunctionName(contractAddress, selector) {
34
+ return await this.db.getDebugFunctionName(contractAddress, selector);
35
+ }
36
+ }
@@ -1,17 +1,21 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
1
3
  import { Fr } from '@aztec/foundation/fields';
4
+ import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
2
5
  import type { FunctionSelector } from '@aztec/stdlib/abi';
3
6
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
7
  import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
5
- import type { MerkleTreeCheckpointOperations, MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
6
- import type { Tx } from '@aztec/stdlib/tx';
7
- import type { PublicContractsDB, PublicStateDB } from '../common/db_interfaces.js';
8
+ import type { BatchInsertionResult, IndexedTreeId, MerkleTreeLeafType, MerkleTreeReadOperations, MerkleTreeWriteOperations, SequentialInsertionResult, TreeInfo } from '@aztec/stdlib/interfaces/server';
9
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
10
+ import type { BlockHeader, StateReference, Tx } from '@aztec/stdlib/tx';
11
+ import type { PublicContractsDBInterface, PublicStateDBInterface } from '../common/db_interfaces.js';
8
12
  /**
9
- * Implements the PublicContractsDB using a ContractDataSource.
13
+ * Implements the PublicContractsDBInterface using a ContractDataSource.
10
14
  * Progressively records contracts in transaction as they are processed in a block.
11
15
  * Separates block-level contract information (from processed/included txs) from the
12
16
  * current tx's contract information (which may be cleared on tx revert/death).
13
17
  */
14
- export declare class ContractsDataSourcePublicDB implements PublicContractsDB {
18
+ export declare class PublicContractsDB implements PublicContractsDBInterface {
15
19
  private dataSource;
16
20
  private currentTxNonRevertibleCache;
17
21
  private currentTxRevertibleCache;
@@ -81,31 +85,50 @@ export declare class ContractsDataSourcePublicDB implements PublicContractsDB {
81
85
  * Then, clears the tx cache.
82
86
  */
83
87
  commitContractsForTx(onlyNonRevertibles?: boolean): void;
84
- getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
88
+ getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
85
89
  getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
86
90
  getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
87
91
  getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
88
92
  }
89
93
  /**
90
- * A public state DB that reads and writes to the world state.
94
+ * Proxy class that forwards all merkle tree operations to the underlying object.
95
+ *
96
+ * NOTE: It might be possible to prune this to just the methods used in public.
97
+ * Then we'd need to define a new interface, instead of MerkleTreeWriteOperations,
98
+ * to be used by all our classes (that could be PublicStateDBInterface).
91
99
  */
92
- export declare class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, MerkleTreeCheckpointOperations {
93
- db: MerkleTreeWriteOperations;
94
- private logger;
95
- constructor(db: MerkleTreeWriteOperations, dataSource: ContractDataSource);
96
- /**
97
- * Checkpoints the current fork state
98
- */
100
+ declare class ForwardMerkleTree implements MerkleTreeWriteOperations {
101
+ private readonly operations;
102
+ constructor(operations: MerkleTreeWriteOperations);
103
+ getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo>;
104
+ getStateReference(): Promise<StateReference>;
105
+ getInitialHeader(): BlockHeader;
106
+ getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
107
+ getPreviousValueIndex<ID extends IndexedTreeId>(treeId: ID, value: bigint): Promise<{
108
+ index: bigint;
109
+ alreadyPresent: boolean;
110
+ } | undefined>;
111
+ getLeafPreimage<ID extends IndexedTreeId>(treeId: ID, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
112
+ findLeafIndices<ID extends MerkleTreeId>(treeId: ID, values: MerkleTreeLeafType<ID>[]): Promise<(bigint | undefined)[]>;
113
+ findLeafIndicesAfter<ID extends MerkleTreeId>(treeId: ID, values: MerkleTreeLeafType<ID>[], startIndex: bigint): Promise<(bigint | undefined)[]>;
114
+ getLeafValue<ID extends MerkleTreeId>(treeId: ID, index: bigint): Promise<MerkleTreeLeafType<typeof treeId> | undefined>;
115
+ getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(treeId: ID, leafIndices: bigint[]): Promise<(bigint | undefined)[]>;
99
116
  createCheckpoint(): Promise<void>;
100
- /**
101
- * Commits the current checkpoint
102
- */
103
117
  commitCheckpoint(): Promise<void>;
104
- /**
105
- * Reverts the current checkpoint
106
- */
107
118
  revertCheckpoint(): Promise<void>;
108
- getMerkleInterface(): MerkleTreeWriteOperations;
119
+ appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void>;
120
+ updateArchive(header: BlockHeader): Promise<void>;
121
+ batchInsert<TreeHeight extends number, SubtreeSiblingPathHeight extends number, ID extends IndexedTreeId>(treeId: ID, leaves: Buffer[], subtreeHeight: number): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>>;
122
+ sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(treeId: ID, leaves: Buffer[]): Promise<SequentialInsertionResult<TreeHeight>>;
123
+ close(): Promise<void>;
124
+ }
125
+ /**
126
+ * A class that provides access to the merkle trees, and other helper methods.
127
+ */
128
+ export declare class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInterface {
129
+ db: MerkleTreeWriteOperations;
130
+ private logger;
131
+ constructor(db: MerkleTreeWriteOperations);
109
132
  /**
110
133
  * Reads a value from public storage, returning zero if none.
111
134
  * @param contract - Owner of the storage.
@@ -122,8 +145,9 @@ export declare class WorldStateDB extends ContractsDataSourcePublicDB implements
122
145
  */
123
146
  storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void>;
124
147
  getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined>;
125
- getCommitmentValue(leafIndex: bigint): Promise<Fr | undefined>;
148
+ getNoteHash(leafIndex: bigint): Promise<Fr | undefined>;
126
149
  getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
127
150
  }
128
151
  export declare function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr>;
152
+ export {};
129
153
  //# sourceMappingURL=public_db_sources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAIzC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,KAAK,E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IAIjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,iBAAkB,YAAW,sBAAsB;IAGjE,EAAE,EAAE,yBAAyB;IAFhD,OAAO,CAAC,MAAM,CAA6C;gBAExC,EAAE,EAAE,yBAAyB;IAIhD;;;;;OAKG;IACU,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IAIvE;;;;;;OAMG;IACU,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3E,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAW9D,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAWvD,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAU3E;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,wBAAwB,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAcjH"}
@@ -9,11 +9,11 @@ import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
9
9
  import { MerkleTreeId } from '@aztec/stdlib/trees';
10
10
  import { TxContractCache } from './tx_contract_cache.js';
11
11
  /**
12
- * Implements the PublicContractsDB using a ContractDataSource.
12
+ * Implements the PublicContractsDBInterface using a ContractDataSource.
13
13
  * Progressively records contracts in transaction as they are processed in a block.
14
14
  * Separates block-level contract information (from processed/included txs) from the
15
15
  * current tx's contract information (which may be cleared on tx revert/death).
16
- */ export class ContractsDataSourcePublicDB {
16
+ */ export class PublicContractsDB {
17
17
  dataSource;
18
18
  // Two caching layers for contract classes and instances.
19
19
  // Tx-level cache:
@@ -139,9 +139,16 @@ import { TxContractCache } from './tx_contract_cache.js';
139
139
  this.currentTxNonRevertibleCache.clear();
140
140
  this.currentTxRevertibleCache.clear();
141
141
  }
142
- async getContractInstance(address) {
142
+ // TODO(fcarreiro/alvaro): This method currently needs a blockNumber. Since this class
143
+ // is only ever used for a given block, it should be possible to construct it with the
144
+ // block number and then forget about it. However, since this class (and interface) is
145
+ // currently more externally exposed than we'd want to, Facundo preferred to not add it
146
+ // to the constructor right now. If we can make this class more private, we should
147
+ // reconsider this. A litmus test is in how many places we need to initialize with a
148
+ // dummy block number (tests or not) and pass block numbers to `super`.
149
+ async getContractInstance(address, blockNumber) {
143
150
  // Check caches in order: tx revertible -> tx non-revertible -> block -> data source
144
- return this.currentTxRevertibleCache.getInstance(address) ?? this.currentTxNonRevertibleCache.getInstance(address) ?? this.blockCache.getInstance(address) ?? await this.dataSource.getContract(address);
151
+ return this.currentTxRevertibleCache.getInstance(address) ?? this.currentTxNonRevertibleCache.getInstance(address) ?? this.blockCache.getInstance(address) ?? await this.dataSource.getContract(address, blockNumber);
145
152
  }
146
153
  async getContractClass(contractClassId) {
147
154
  // Check caches in order: tx revertible -> tx non-revertible -> block -> data source
@@ -174,30 +181,78 @@ import { TxContractCache } from './tx_contract_cache.js';
174
181
  }
175
182
  }
176
183
  /**
177
- * A public state DB that reads and writes to the world state.
178
- */ export class WorldStateDB extends ContractsDataSourcePublicDB {
179
- db;
180
- logger;
181
- constructor(db, dataSource){
182
- super(dataSource), this.db = db, this.logger = createLogger('simulator:world-state-db');
184
+ * Proxy class that forwards all merkle tree operations to the underlying object.
185
+ *
186
+ * NOTE: It might be possible to prune this to just the methods used in public.
187
+ * Then we'd need to define a new interface, instead of MerkleTreeWriteOperations,
188
+ * to be used by all our classes (that could be PublicStateDBInterface).
189
+ */ class ForwardMerkleTree {
190
+ operations;
191
+ constructor(operations){
192
+ this.operations = operations;
183
193
  }
184
- /**
185
- * Checkpoints the current fork state
186
- */ async createCheckpoint() {
187
- await this.db.createCheckpoint();
194
+ getTreeInfo(treeId) {
195
+ return this.operations.getTreeInfo(treeId);
188
196
  }
189
- /**
190
- * Commits the current checkpoint
191
- */ async commitCheckpoint() {
192
- await this.db.commitCheckpoint();
197
+ getStateReference() {
198
+ return this.operations.getStateReference();
193
199
  }
194
- /**
195
- * Reverts the current checkpoint
196
- */ async revertCheckpoint() {
197
- await this.db.revertCheckpoint();
200
+ getInitialHeader() {
201
+ return this.operations.getInitialHeader();
202
+ }
203
+ getSiblingPath(treeId, index) {
204
+ return this.operations.getSiblingPath(treeId, index);
205
+ }
206
+ getPreviousValueIndex(treeId, value) {
207
+ return this.operations.getPreviousValueIndex(treeId, value);
208
+ }
209
+ getLeafPreimage(treeId, index) {
210
+ return this.operations.getLeafPreimage(treeId, index);
211
+ }
212
+ findLeafIndices(treeId, values) {
213
+ return this.operations.findLeafIndices(treeId, values);
214
+ }
215
+ findLeafIndicesAfter(treeId, values, startIndex) {
216
+ return this.operations.findLeafIndicesAfter(treeId, values, startIndex);
217
+ }
218
+ getLeafValue(treeId, index) {
219
+ return this.operations.getLeafValue(treeId, index);
220
+ }
221
+ getBlockNumbersForLeafIndices(treeId, leafIndices) {
222
+ return this.operations.getBlockNumbersForLeafIndices(treeId, leafIndices);
198
223
  }
199
- getMerkleInterface() {
200
- return this.db;
224
+ createCheckpoint() {
225
+ return this.operations.createCheckpoint();
226
+ }
227
+ commitCheckpoint() {
228
+ return this.operations.commitCheckpoint();
229
+ }
230
+ revertCheckpoint() {
231
+ return this.operations.revertCheckpoint();
232
+ }
233
+ appendLeaves(treeId, leaves) {
234
+ return this.operations.appendLeaves(treeId, leaves);
235
+ }
236
+ updateArchive(header) {
237
+ return this.operations.updateArchive(header);
238
+ }
239
+ batchInsert(treeId, leaves, subtreeHeight) {
240
+ return this.operations.batchInsert(treeId, leaves, subtreeHeight);
241
+ }
242
+ sequentialInsert(treeId, leaves) {
243
+ return this.operations.sequentialInsert(treeId, leaves);
244
+ }
245
+ close() {
246
+ return this.operations.close();
247
+ }
248
+ }
249
+ /**
250
+ * A class that provides access to the merkle trees, and other helper methods.
251
+ */ export class PublicTreesDB extends ForwardMerkleTree {
252
+ db;
253
+ logger;
254
+ constructor(db){
255
+ super(db), this.db = db, this.logger = createLogger('simulator:public-trees-db');
201
256
  }
202
257
  /**
203
258
  * Reads a value from public storage, returning zero if none.
@@ -230,13 +285,13 @@ import { TxContractCache } from './tx_contract_cache.js';
230
285
  });
231
286
  return leafValue;
232
287
  }
233
- async getCommitmentValue(leafIndex) {
288
+ async getNoteHash(leafIndex) {
234
289
  const timer = new Timer();
235
290
  const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
236
- this.logger.debug(`[DB] Fetched commitment leaf value`, {
291
+ this.logger.debug(`[DB] Fetched note hash leaf value`, {
237
292
  eventName: 'public-db-access',
238
293
  duration: timer.ms(),
239
- operation: 'get-commitment-leaf-value'
294
+ operation: 'get-note-hash'
240
295
  });
241
296
  return leafValue;
242
297
  }
@@ -6,7 +6,7 @@ import { Gas } from '@aztec/stdlib/gas';
6
6
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
7
7
  import { type FailedTx, GlobalVariables, NestedProcessReturnValues, type ProcessedTx, Tx, type TxValidator } from '@aztec/stdlib/tx';
8
8
  import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
9
- import { WorldStateDB } from '../public_db_sources.js';
9
+ import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
10
10
  import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
11
11
  /**
12
12
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
@@ -24,21 +24,21 @@ export declare class PublicProcessorFactory {
24
24
  * @returns A new instance of a PublicProcessor.
25
25
  */
26
26
  create(merkleTree: MerkleTreeWriteOperations, globalVariables: GlobalVariables, skipFeeEnforcement: boolean): PublicProcessor;
27
- protected createPublicTxSimulator(db: MerkleTreeWriteOperations, worldStateDB: WorldStateDB, globalVariables: GlobalVariables, doMerkleOperations: boolean, skipFeeEnforcement: boolean, telemetryClient: TelemetryClient): PublicTxSimulator;
27
+ protected createPublicTxSimulator(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean, skipFeeEnforcement: boolean, telemetryClient: TelemetryClient): PublicTxSimulator;
28
28
  }
29
29
  /**
30
30
  * Converts Txs lifted from the P2P module into ProcessedTx objects by executing
31
31
  * any public function calls in them. Txs with private calls only are unaffected.
32
32
  */
33
33
  export declare class PublicProcessor implements Traceable {
34
- protected db: MerkleTreeWriteOperations;
35
34
  protected globalVariables: GlobalVariables;
36
- protected worldStateDB: WorldStateDB;
35
+ protected treesDB: PublicTreesDB;
36
+ protected contractsDB: PublicContractsDB;
37
37
  protected publicTxSimulator: PublicTxSimulator;
38
38
  private dateProvider;
39
39
  private log;
40
40
  private metrics;
41
- constructor(db: MerkleTreeWriteOperations, globalVariables: GlobalVariables, worldStateDB: WorldStateDB, publicTxSimulator: PublicTxSimulator, dateProvider: DateProvider, telemetryClient?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
41
+ constructor(globalVariables: GlobalVariables, treesDB: PublicTreesDB, contractsDB: PublicContractsDB, publicTxSimulator: PublicTxSimulator, dateProvider: DateProvider, telemetryClient?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
42
42
  get tracer(): Tracer;
43
43
  /**
44
44
  * Run each tx through the public circuit and the public kernel circuit if needed.
@@ -1 +1 @@
1
- {"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,y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,iBAAiB,EAAE,iBAAiB,EACtC,YAAY,EAAE,YAAY,EAClC,eAAe,GAAE,eAAsC,EAC/C,GAAG,yCAA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;OAKG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE;QACN,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,QAAQ,CAAC,EAAE,IAAI,CAAC;KACZ,EACN,UAAU,GAAE;QACV,mBAAmB,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QACtC,oBAAoB,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAChD,cAAc,CAAC,EAAE;YAAE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;SAAE,CAAC;KAC/D,GACL,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YAwKtD,SAAS;YA2BT,gCAAgC;IAyC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,4BAA4B;YAwB5B,oBAAoB;YA6BpB,wBAAwB;CA8CvC"}
1
+ {"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,E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/C,GAAG,yCAA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;OAKG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE;QACN,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,QAAQ,CAAC,EAAE,IAAI,CAAC;KACZ,EACN,UAAU,GAAE;QACV,mBAAmB,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QACtC,oBAAoB,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAChD,cAAc,CAAC,EAAE;YAAE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;SAAE,CAAC;KAC/D,GACL,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YAwKtD,SAAS;YA2BT,gCAAgC;IAyC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,4BAA4B;YAwB5B,oBAAoB;YA6BpB,wBAAwB;CA8CvC"}
@@ -18,7 +18,7 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
18
18
  import { NestedProcessReturnValues, Tx, TxExecutionPhase, makeProcessedTxFromPrivateOnlyTx, makeProcessedTxFromTxWithPublicCalls } from '@aztec/stdlib/tx';
19
19
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
20
20
  import { ForkCheckpoint } from '@aztec/world-state/native';
21
- import { WorldStateDB } from '../public_db_sources.js';
21
+ import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
22
22
  import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
23
23
  import { PublicProcessorMetrics } from './public_processor_metrics.js';
24
24
  /**
@@ -39,12 +39,13 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
39
39
  * @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
40
40
  * @returns A new instance of a PublicProcessor.
41
41
  */ create(merkleTree, globalVariables, skipFeeEnforcement) {
42
- const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
43
- const publicTxSimulator = this.createPublicTxSimulator(merkleTree, worldStateDB, globalVariables, /*doMerkleOperations=*/ true, skipFeeEnforcement, this.telemetryClient);
44
- return new PublicProcessor(merkleTree, globalVariables, worldStateDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
42
+ const treesDB = new PublicTreesDB(merkleTree);
43
+ const contractsDB = new PublicContractsDB(this.contractDataSource);
44
+ const publicTxSimulator = this.createPublicTxSimulator(treesDB, contractsDB, globalVariables, /*doMerkleOperations=*/ true, skipFeeEnforcement, this.telemetryClient);
45
+ return new PublicProcessor(globalVariables, treesDB, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
45
46
  }
46
- createPublicTxSimulator(db, worldStateDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
47
- return new PublicTxSimulator(db, worldStateDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
47
+ createPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
48
+ return new PublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
48
49
  }
49
50
  }
50
51
  class PublicProcessorTimeoutError extends Error {
@@ -57,17 +58,17 @@ class PublicProcessorTimeoutError extends Error {
57
58
  * Converts Txs lifted from the P2P module into ProcessedTx objects by executing
58
59
  * any public function calls in them. Txs with private calls only are unaffected.
59
60
  */ export class PublicProcessor {
60
- db;
61
61
  globalVariables;
62
- worldStateDB;
62
+ treesDB;
63
+ contractsDB;
63
64
  publicTxSimulator;
64
65
  dateProvider;
65
66
  log;
66
67
  metrics;
67
- constructor(db, globalVariables, worldStateDB, publicTxSimulator, dateProvider, telemetryClient = getTelemetryClient(), log = createLogger('simulator:public-processor')){
68
- this.db = db;
68
+ constructor(globalVariables, treesDB, contractsDB, publicTxSimulator, dateProvider, telemetryClient = getTelemetryClient(), log = createLogger('simulator:public-processor')){
69
69
  this.globalVariables = globalVariables;
70
- this.worldStateDB = worldStateDB;
70
+ this.treesDB = treesDB;
71
+ this.contractsDB = contractsDB;
71
72
  this.publicTxSimulator = publicTxSimulator;
72
73
  this.dateProvider = dateProvider;
73
74
  this.log = log;
@@ -152,7 +153,7 @@ class PublicProcessorTimeoutError extends Error {
152
153
  // We checkpoint the transaction here, then within the try/catch we
153
154
  // 1. Revert the checkpoint if the tx fails or needs to be discarded for any reason
154
155
  // 2. Commit the transaction in the finally block. Note that by using the ForkCheckpoint lifecycle only the first commit/revert takes effect
155
- const checkpoint = await ForkCheckpoint.new(this.worldStateDB);
156
+ const checkpoint = await ForkCheckpoint.new(this.treesDB);
156
157
  try {
157
158
  const [processedTx, returnValues] = await this.processTx(tx, deadline);
158
159
  // If the actual size of this tx would exceed block size, skip it
@@ -196,8 +197,8 @@ class PublicProcessorTimeoutError extends Error {
196
197
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
197
198
  // Add any contracts registered/deployed in this private-only tx to the block-level cache
198
199
  // (add to tx-level cache and then commit to block-level cache)
199
- await this.worldStateDB.addNewContracts(tx);
200
- this.worldStateDB.commitContractsForTx();
200
+ await this.contractsDB.addNewContracts(tx);
201
+ this.contractsDB.commitContractsForTx();
201
202
  }
202
203
  nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map((n)=>n.toBuffer()));
203
204
  result.push(processedTx);
@@ -223,7 +224,7 @@ class PublicProcessorTimeoutError extends Error {
223
224
  // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was reverted
224
225
  await checkpoint.commit();
225
226
  // The tx-level contracts cache should not live on to the next tx
226
- this.worldStateDB.clearContractsForTx();
227
+ this.contractsDB.clearContractsForTx();
227
228
  }
228
229
  }
229
230
  const duration = timer.s();
@@ -272,9 +273,9 @@ class PublicProcessorTimeoutError extends Error {
272
273
  // b) always had a txHandler with the same db passed to it as this.db, which updated the db in buildBaseRollupHints in this loop
273
274
  // To see how this ^ happens, move back to one shared db in test_context and run orchestrator_multi_public_functions.test.ts
274
275
  // The below is taken from buildBaseRollupHints:
275
- await this.db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(processedTx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
276
+ await this.treesDB.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(processedTx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
276
277
  try {
277
- await this.db.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((n)=>n.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
278
+ await this.treesDB.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((n)=>n.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
278
279
  } catch (error) {
279
280
  if (txValidator) {
280
281
  // Ideally the validator has already caught this above, but just in case:
@@ -285,7 +286,7 @@ class PublicProcessorTimeoutError extends Error {
285
286
  }
286
287
  }
287
288
  // The only public data write should be for fee payment
288
- await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, processedTx.txEffect.publicDataWrites.map((x)=>x.toBuffer()));
289
+ await this.treesDB.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, processedTx.txEffect.publicDataWrites.map((x)=>x.toBuffer()));
289
290
  const treeInsertionEnd = process.hrtime.bigint();
290
291
  this.metrics.recordTreeInsertions(Number(treeInsertionEnd - treeInsertionStart) / 1_000);
291
292
  }
@@ -315,12 +316,12 @@ class PublicProcessorTimeoutError extends Error {
315
316
  const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
316
317
  const leafSlot = await computeFeePayerBalanceLeafSlot(feePayer);
317
318
  this.log.debug(`Deducting ${txFee.toBigInt()} balance in Fee Juice for ${feePayer}`);
318
- const balance = await this.worldStateDB.storageRead(feeJuiceAddress, balanceSlot);
319
+ const balance = await this.treesDB.storageRead(feeJuiceAddress, balanceSlot);
319
320
  if (balance.lt(txFee)) {
320
321
  throw new Error(`Not enough balance for fee payer to pay for transaction (got ${balance.toBigInt()} needs ${txFee.toBigInt()})`);
321
322
  }
322
323
  const updatedBalance = balance.sub(txFee);
323
- await this.worldStateDB.storageWrite(feeJuiceAddress, balanceSlot, updatedBalance);
324
+ await this.treesDB.storageWrite(feeJuiceAddress, balanceSlot, updatedBalance);
324
325
  return new PublicDataWrite(leafSlot, updatedBalance);
325
326
  }
326
327
  async processPrivateOnlyTx(tx) {