@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.71324e566

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 (242) hide show
  1. package/dest/bin/check_oracle_version.js +4 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +19 -1
  5. package/dest/config/index.d.ts +2 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +8 -15
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +62 -30
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.js +205 -74
  12. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  13. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  16. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  18. package/dest/contract_function_simulator/index.d.ts +2 -1
  19. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/index.js +1 -0
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +61 -45
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  35. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/oracle.js +282 -97
  40. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -80
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +110 -87
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +118 -64
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +312 -128
  47. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  48. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/pick_notes.js +20 -3
  50. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  51. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  53. package/dest/contract_logging.d.ts +27 -0
  54. package/dest/contract_logging.d.ts.map +1 -0
  55. package/dest/contract_logging.js +38 -0
  56. package/dest/contract_sync/contract_sync_service.d.ts +7 -4
  57. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
  58. package/dest/contract_sync/contract_sync_service.js +69 -35
  59. package/dest/contract_sync/helpers.d.ts +2 -2
  60. package/dest/contract_sync/helpers.d.ts.map +1 -1
  61. package/dest/contract_sync/helpers.js +9 -4
  62. package/dest/debug/pxe_debug_utils.d.ts +5 -6
  63. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  64. package/dest/debug/pxe_debug_utils.js +4 -7
  65. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  66. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/index.js +2 -0
  68. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  69. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/utils.js +11 -3
  71. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  72. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/index.js +2 -0
  74. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  75. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/utils.js +11 -3
  77. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  78. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  79. package/dest/entrypoints/pxe_creation_options.js +3 -1
  80. package/dest/entrypoints/server/index.d.ts +3 -2
  81. package/dest/entrypoints/server/index.d.ts.map +1 -1
  82. package/dest/entrypoints/server/index.js +2 -1
  83. package/dest/entrypoints/server/utils.d.ts +2 -2
  84. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  85. package/dest/entrypoints/server/utils.js +11 -3
  86. package/dest/events/event_service.d.ts +3 -2
  87. package/dest/events/event_service.d.ts.map +1 -1
  88. package/dest/events/event_service.js +16 -4
  89. package/dest/events/private_event_filter_validator.d.ts +3 -2
  90. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  91. package/dest/events/private_event_filter_validator.js +15 -0
  92. package/dest/logs/log_service.d.ts +7 -7
  93. package/dest/logs/log_service.d.ts.map +1 -1
  94. package/dest/logs/log_service.js +33 -48
  95. package/dest/messages/message_context_service.d.ts +17 -0
  96. package/dest/messages/message_context_service.d.ts.map +1 -0
  97. package/dest/messages/message_context_service.js +36 -0
  98. package/dest/notes/note_service.d.ts +4 -4
  99. package/dest/notes/note_service.d.ts.map +1 -1
  100. package/dest/notes/note_service.js +17 -7
  101. package/dest/notes_filter.d.ts +24 -0
  102. package/dest/notes_filter.d.ts.map +1 -0
  103. package/dest/notes_filter.js +4 -0
  104. package/dest/oracle_version.d.ts +4 -3
  105. package/dest/oracle_version.d.ts.map +1 -1
  106. package/dest/oracle_version.js +20 -10
  107. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  108. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  109. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  110. package/dest/private_kernel/hints/index.d.ts +1 -1
  111. package/dest/private_kernel/hints/index.js +1 -1
  112. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  113. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  114. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  115. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  116. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  117. package/dest/private_kernel/hints/test_utils.js +203 -0
  118. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  119. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  120. package/dest/private_kernel/private_kernel_execution_prover.js +18 -13
  121. package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
  122. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  123. package/dest/private_kernel/private_kernel_oracle.js +19 -18
  124. package/dest/pxe.d.ts +73 -24
  125. package/dest/pxe.d.ts.map +1 -1
  126. package/dest/pxe.js +122 -75
  127. package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
  128. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  129. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  130. package/dest/storage/capsule_store/capsule_service.js +50 -0
  131. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  132. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  133. package/dest/storage/capsule_store/capsule_store.js +36 -28
  134. package/dest/storage/capsule_store/index.d.ts +2 -1
  135. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  136. package/dest/storage/capsule_store/index.js +1 -0
  137. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  138. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  139. package/dest/storage/contract_store/contract_store.js +148 -70
  140. package/dest/storage/metadata.d.ts +1 -1
  141. package/dest/storage/metadata.js +1 -1
  142. package/dest/storage/note_store/note_store.d.ts +3 -3
  143. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  144. package/dest/storage/note_store/note_store.js +6 -4
  145. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  146. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  147. package/dest/storage/private_event_store/private_event_store.js +3 -0
  148. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  149. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  150. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  151. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  152. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  153. package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
  154. package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
  155. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  156. package/dest/tagging/get_all_logs_by_tags.js +17 -3
  157. package/dest/tagging/index.d.ts +3 -3
  158. package/dest/tagging/index.d.ts.map +1 -1
  159. package/dest/tagging/index.js +1 -1
  160. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
  161. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  162. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -22
  163. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  164. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
  165. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  166. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
  167. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
  168. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  169. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  170. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  171. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  172. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
  173. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
  174. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  175. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  176. package/package.json +16 -16
  177. package/src/bin/check_oracle_version.ts +4 -4
  178. package/src/block_synchronizer/block_synchronizer.ts +22 -2
  179. package/src/config/index.ts +3 -9
  180. package/src/config/package_info.ts +1 -1
  181. package/src/contract_function_simulator/contract_function_simulator.ts +365 -136
  182. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  183. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  184. package/src/contract_function_simulator/index.ts +1 -0
  185. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  186. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  187. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  188. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  189. package/src/contract_function_simulator/oracle/interfaces.ts +82 -54
  190. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  191. package/src/contract_function_simulator/oracle/oracle.ts +364 -140
  192. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  193. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +138 -178
  194. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +527 -158
  195. package/src/contract_function_simulator/pick_notes.ts +22 -3
  196. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  197. package/src/contract_logging.ts +52 -0
  198. package/src/contract_sync/contract_sync_service.ts +102 -55
  199. package/src/contract_sync/helpers.ts +8 -3
  200. package/src/debug/pxe_debug_utils.ts +11 -14
  201. package/src/entrypoints/client/bundle/index.ts +2 -0
  202. package/src/entrypoints/client/bundle/utils.ts +11 -4
  203. package/src/entrypoints/client/lazy/index.ts +2 -0
  204. package/src/entrypoints/client/lazy/utils.ts +11 -4
  205. package/src/entrypoints/pxe_creation_options.ts +7 -0
  206. package/src/entrypoints/server/index.ts +2 -1
  207. package/src/entrypoints/server/utils.ts +9 -10
  208. package/src/events/event_service.ts +17 -4
  209. package/src/events/private_event_filter_validator.ts +21 -1
  210. package/src/logs/log_service.ts +63 -91
  211. package/src/messages/message_context_service.ts +44 -0
  212. package/src/notes/note_service.ts +19 -8
  213. package/src/notes_filter.ts +24 -0
  214. package/src/oracle_version.ts +20 -10
  215. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  216. package/src/private_kernel/hints/index.ts +1 -1
  217. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  218. package/src/private_kernel/hints/test_utils.ts +325 -0
  219. package/src/private_kernel/private_kernel_execution_prover.ts +18 -16
  220. package/src/private_kernel/private_kernel_oracle.ts +21 -21
  221. package/src/pxe.ts +214 -119
  222. package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
  223. package/src/storage/capsule_store/capsule_service.ts +90 -0
  224. package/src/storage/capsule_store/capsule_store.ts +44 -26
  225. package/src/storage/capsule_store/index.ts +1 -0
  226. package/src/storage/contract_store/contract_store.ts +181 -80
  227. package/src/storage/metadata.ts +1 -1
  228. package/src/storage/note_store/note_store.ts +9 -5
  229. package/src/storage/private_event_store/private_event_store.ts +4 -0
  230. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  231. package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
  232. package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
  233. package/src/tagging/get_all_logs_by_tags.ts +28 -4
  234. package/src/tagging/index.ts +2 -2
  235. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +12 -25
  236. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  237. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
  238. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
  239. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
  240. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
  241. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  242. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from '@aztec/stdlib/abi';
19
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
21
22
  import {
22
23
  CompleteAddress,
23
24
  type ContractInstanceWithAddress,
@@ -33,6 +34,7 @@ import type {
33
34
  PrivateKernelTailCircuitPublicInputs,
34
35
  } from '@aztec/stdlib/kernel';
35
36
  import {
37
+ BlockHeader,
36
38
  type ContractOverrides,
37
39
  type InTx,
38
40
  PrivateExecutionResult,
@@ -46,7 +48,7 @@ import {
46
48
  TxProfileResult,
47
49
  TxProvingResult,
48
50
  TxSimulationResult,
49
- UtilitySimulationResult,
51
+ UtilityExecutionResult,
50
52
  } from '@aztec/stdlib/tx';
51
53
 
52
54
  import { inspect } from 'util';
@@ -59,12 +61,14 @@ import {
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
62
65
  import { ContractSyncService } from './contract_sync/contract_sync_service.js';
63
66
  import { readCurrentClassId } from './contract_sync/helpers.js';
64
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
68
72
  import {
69
73
  PrivateKernelExecutionProver,
70
74
  type PrivateKernelExecutionProverConfig,
@@ -85,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
85
89
  eventSelector: EventSelector;
86
90
  };
87
91
 
92
+ /** Options for PXE.profileTx. */
93
+ export type ProfileTxOpts = {
94
+ /** The profiling mode to use. */
95
+ profileMode: 'full' | 'execution-steps' | 'gates';
96
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
97
+ skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AztecAddress[];
100
+ };
101
+
102
+ /** Options for PXE.simulateTx. */
103
+ export type SimulateTxOpts = {
104
+ /** Whether to simulate the public part of the transaction. */
105
+ simulatePublic: boolean;
106
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
107
+ skipTxValidation?: boolean;
108
+ /** If false, fees are enforced. */
109
+ skipFeeEnforcement?: boolean;
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
113
+ overrides?: SimulationOverrides;
114
+ /** Addresses whose private state and keys are accessible during private execution */
115
+ scopes: AztecAddress[];
116
+ };
117
+
118
+ /** Options for PXE.executeUtility. */
119
+ export type ExecuteUtilityOpts = {
120
+ /** The authentication witnesses required for the function call. */
121
+ authwits?: AuthWitness[];
122
+ /** The accounts whose notes we can access in this call */
123
+ scopes: AztecAddress[];
124
+ };
125
+
126
+ /** Args for PXE.create. */
127
+ export type PXECreateArgs = {
128
+ /** The Aztec node to connect to. */
129
+ node: AztecNode;
130
+ /** The key-value store for persisting PXE state. */
131
+ store: AztecAsyncKVStore;
132
+ /** The prover for generating private kernel proofs. */
133
+ proofCreator: PrivateKernelProver;
134
+ /** The circuit simulator for executing ACIR circuits. */
135
+ simulator: CircuitSimulator;
136
+ /** Provider for protocol contract artifacts and instances. */
137
+ protocolContractsProvider: ProtocolContractsProvider;
138
+ /** PXE configuration options. */
139
+ config: PXEConfig;
140
+ /** Optional logger instance or string suffix for the logger name. */
141
+ loggerOrSuffix?: string | Logger;
142
+ };
143
+
88
144
  /**
89
145
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
146
  * manage private state of users.
@@ -92,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
92
148
  export class PXE {
93
149
  private constructor(
94
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
95
152
  private blockStateSynchronizer: BlockSynchronizer,
96
153
  private keyStore: KeyStore,
97
154
  private contractStore: ContractStore,
@@ -104,6 +161,8 @@ export class PXE {
104
161
  private addressStore: AddressStore,
105
162
  private privateEventStore: PrivateEventStore,
106
163
  private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
107
166
  private simulator: CircuitSimulator,
108
167
  private proverEnabled: boolean,
109
168
  private proofCreator: PrivateKernelProver,
@@ -121,15 +180,15 @@ export class PXE {
121
180
  *
122
181
  * @returns A promise that resolves PXE is ready to be used.
123
182
  */
124
- public static async create(
125
- node: AztecNode,
126
- store: AztecAsyncKVStore,
127
- proofCreator: PrivateKernelProver,
128
- simulator: CircuitSimulator,
129
- protocolContractsProvider: ProtocolContractsProvider,
130
- config: PXEConfig,
131
- loggerOrSuffix?: string | Logger,
132
- ) {
183
+ public static async create({
184
+ node,
185
+ store,
186
+ proofCreator,
187
+ simulator,
188
+ protocolContractsProvider,
189
+ config,
190
+ loggerOrSuffix,
191
+ }: PXECreateArgs) {
133
192
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
134
193
  const bindings: LoggerBindings | undefined =
135
194
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -139,7 +198,9 @@ export class PXE {
139
198
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
140
199
  : loggerOrSuffix;
141
200
 
142
- const proverEnabled = !!config.proverEnabled;
201
+ const info = await node.getNodeInfo();
202
+
203
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
143
204
  const addressStore = new AddressStore(store);
144
205
  const privateEventStore = new PrivateEventStore(store);
145
206
  const contractStore = new ContractStore(store);
@@ -157,6 +218,8 @@ export class PXE {
157
218
  noteStore,
158
219
  createLogger('pxe:contract_sync', bindings),
159
220
  );
221
+ const messageContextService = new MessageContextService(node);
222
+
160
223
  const synchronizer = new BlockSynchronizer(
161
224
  node,
162
225
  store,
@@ -185,6 +248,7 @@ export class PXE {
185
248
 
186
249
  const pxe = new PXE(
187
250
  node,
251
+ store,
188
252
  synchronizer,
189
253
  keyStore,
190
254
  contractStore,
@@ -197,6 +261,8 @@ export class PXE {
197
261
  addressStore,
198
262
  privateEventStore,
199
263
  contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
200
266
  simulator,
201
267
  proverEnabled,
202
268
  proofCreator,
@@ -210,13 +276,12 @@ export class PXE {
210
276
  debugUtils.setPXEHelpers(
211
277
  pxe.#putInJobQueue.bind(pxe),
212
278
  pxe.#getSimulatorForTx.bind(pxe),
213
- pxe.#simulateUtility.bind(pxe),
279
+ pxe.#executeUtility.bind(pxe),
214
280
  );
215
281
 
216
282
  pxe.jobQueue.start();
217
283
 
218
284
  await pxe.#registerProtocolContracts();
219
- const info = await node.getNodeInfo();
220
285
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
221
286
  return pxe;
222
287
  }
@@ -226,20 +291,22 @@ export class PXE {
226
291
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
227
292
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
228
293
 
229
- return new ContractFunctionSimulator(
230
- proxyContractStore,
231
- this.noteStore,
232
- this.keyStore,
233
- this.addressStore,
234
- BenchmarkedNodeFactory.create(this.node),
235
- this.senderTaggingStore,
236
- this.recipientTaggingStore,
237
- this.senderAddressBookStore,
238
- this.capsuleStore,
239
- this.privateEventStore,
240
- this.simulator,
241
- this.contractSyncService,
242
- );
294
+ return new ContractFunctionSimulator({
295
+ contractStore: proxyContractStore,
296
+ noteStore: this.noteStore,
297
+ keyStore: this.keyStore,
298
+ addressStore: this.addressStore,
299
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
300
+ l2TipsStore: this.l2TipsStore,
301
+ senderTaggingStore: this.senderTaggingStore,
302
+ recipientTaggingStore: this.recipientTaggingStore,
303
+ senderAddressBookStore: this.senderAddressBookStore,
304
+ capsuleStore: this.capsuleStore,
305
+ privateEventStore: this.privateEventStore,
306
+ simulator: this.simulator,
307
+ contractSyncService: this.contractSyncService,
308
+ messageContextService: this.messageContextService,
309
+ });
243
310
  }
244
311
 
245
312
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -291,9 +358,8 @@ export class PXE {
291
358
  async #registerProtocolContracts() {
292
359
  const registered: Record<string, string> = {};
293
360
  for (const name of protocolContractNames) {
294
- const { address, contractClass, instance, artifact } =
295
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
296
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
361
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
362
+ await this.contractStore.addContractArtifact(artifact);
297
363
  await this.contractStore.addContractInstance(instance);
298
364
  registered[name] = address.toString();
299
365
  }
@@ -305,7 +371,7 @@ export class PXE {
305
371
  async #executePrivate(
306
372
  contractFunctionSimulator: ContractFunctionSimulator,
307
373
  txRequest: TxExecutionRequest,
308
- scopes: AztecAddress[] | undefined,
374
+ scopes: AztecAddress[],
309
375
  jobId: string,
310
376
  ): Promise<PrivateExecutionResult> {
311
377
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -316,23 +382,20 @@ export class PXE {
316
382
  await this.contractSyncService.ensureContractSynced(
317
383
  contractAddress,
318
384
  functionSelector,
319
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
385
+ (privateSyncCall, execScopes) =>
386
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
320
387
  anchorBlockHeader,
321
388
  jobId,
389
+ scopes,
322
390
  );
323
391
 
324
- const result = await contractFunctionSimulator.run(
325
- txRequest,
392
+ const result = await contractFunctionSimulator.run(txRequest, {
326
393
  contractAddress,
327
- functionSelector,
328
- undefined,
394
+ selector: functionSelector,
329
395
  anchorBlockHeader,
330
- // The sender for tags is set by contracts, typically by an account
331
- // contract entrypoint
332
- undefined, // senderForTags
333
396
  scopes,
334
397
  jobId,
335
- );
398
+ });
336
399
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
337
400
  return result;
338
401
  } catch (err) {
@@ -344,25 +407,32 @@ export class PXE {
344
407
  }
345
408
 
346
409
  /**
347
- * Simulate a utility function call on the given contract.
410
+ * Execute a utility function call on the given contract.
348
411
  * @param contractFunctionSimulator - The simulator to use for the function call.
349
412
  * @param call - The function call to execute.
350
413
  * @param authWitnesses - Authentication witnesses required for the function call.
351
414
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
352
415
  * accounts if not specified.
353
416
  * @param jobId - The job ID for staged writes.
354
- * @returns The simulation result containing the outputs of the utility function.
417
+ * @returns The execution result containing the outputs of the utility function.
355
418
  */
356
- async #simulateUtility(
419
+ async #executeUtility(
357
420
  contractFunctionSimulator: ContractFunctionSimulator,
358
421
  call: FunctionCall,
359
422
  authWitnesses: AuthWitness[] | undefined,
360
- scopes: AztecAddress[] | undefined,
423
+ scopes: AztecAddress[],
361
424
  jobId: string,
362
425
  ) {
363
426
  try {
364
427
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
365
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
428
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
429
+ call,
430
+ authWitnesses ?? [],
431
+ anchorBlockHeader,
432
+ scopes,
433
+ jobId,
434
+ );
435
+ return { result, offchainEffects };
366
436
  } catch (err) {
367
437
  if (err instanceof SimulationError) {
368
438
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -416,8 +486,7 @@ export class PXE {
416
486
  config: PrivateKernelExecutionProverConfig,
417
487
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
418
488
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
419
- const anchorBlockHash = await anchorBlockHeader.hash();
420
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
489
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
421
490
  const kernelTraceProver = new PrivateKernelExecutionProver(
422
491
  kernelOracle,
423
492
  proofCreator,
@@ -430,6 +499,21 @@ export class PXE {
430
499
 
431
500
  // Public API
432
501
 
502
+ /**
503
+ * Returns the block header up to which the PXE has synced.
504
+ * @returns The synced block header
505
+ */
506
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
507
+ return this.#putInJobQueue(() => {
508
+ return this.anchorBlockStore.getBlockHeader();
509
+ });
510
+ }
511
+
512
+ /**
513
+ * Returns the contract instance for a given address, if it's registered in the PXE.
514
+ * @param address - The contract address.
515
+ * @returns The contract instance if found, undefined otherwise.
516
+ */
433
517
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
434
518
  return this.contractStore.getContractInstance(address);
435
519
  }
@@ -479,6 +563,12 @@ export class PXE {
479
563
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
480
564
  */
481
565
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
566
+ if (!(await sender.isValid())) {
567
+ throw new Error(
568
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
569
+ );
570
+ }
571
+
482
572
  const accounts = await this.keyStore.getAccounts();
483
573
  if (accounts.includes(sender)) {
484
574
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -489,6 +579,9 @@ export class PXE {
489
579
 
490
580
  if (wasAdded) {
491
581
  this.log.info(`Added sender:\n ${sender.toString()}`);
582
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
583
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
584
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
492
585
  } else {
493
586
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
494
587
  }
@@ -538,8 +631,7 @@ export class PXE {
538
631
  * @param artifact - The build artifact for the contract class.
539
632
  */
540
633
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
541
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
542
- await this.contractStore.addContractArtifact(contractClassId, artifact);
634
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
543
635
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
544
636
  }
545
637
 
@@ -558,17 +650,17 @@ export class PXE {
558
650
  if (artifact) {
559
651
  // If the user provides an artifact, validate it against the expected class id and register it
560
652
  const contractClass = await getContractClassFromArtifact(artifact);
561
- const contractClassId = contractClass.id;
562
- if (!contractClassId.equals(instance.currentContractClassId)) {
653
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
563
654
  throw new Error(
564
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
655
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
565
656
  );
566
657
  }
567
658
  const computedAddress = await computeContractAddressFromInstance(instance);
568
659
  if (!computedAddress.equals(instance.address)) {
569
660
  throw new Error('Added a contract in which the address does not match the contract instance.');
570
661
  }
571
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
662
+
663
+ await this.contractStore.addContractArtifact(artifact, contractClass);
572
664
 
573
665
  const publicFunctionSignatures = artifact.functions
574
666
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -617,15 +709,16 @@ export class PXE {
617
709
  throw new Error('Could not update contract to a class different from the current one.');
618
710
  }
619
711
 
620
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
621
-
622
712
  const publicFunctionSignatures = artifact.functions
623
713
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
624
714
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
625
715
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
626
716
 
627
717
  currentInstance.currentContractClassId = contractClass.id;
628
- await this.contractStore.addContractInstance(currentInstance);
718
+ await Promise.all([
719
+ this.contractStore.addContractArtifact(artifact, contractClass),
720
+ this.contractStore.addContractInstance(currentInstance),
721
+ ]);
629
722
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
630
723
  });
631
724
  }
@@ -643,11 +736,12 @@ export class PXE {
643
736
  * (where validators prove the public portion).
644
737
  *
645
738
  * @param txRequest - An authenticated tx request ready for proving
739
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
646
740
  * @returns A result containing the proof and public inputs of the tail circuit.
647
741
  * @throws If contract code not found, or public simulation reverts.
648
742
  * Also throws if simulatePublic is true and public simulation reverts.
649
743
  */
650
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
744
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
651
745
  let privateExecutionResult: PrivateExecutionResult;
652
746
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
653
747
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -658,7 +752,7 @@ export class PXE {
658
752
  await this.blockStateSynchronizer.sync();
659
753
  const syncTime = syncTimer.ms();
660
754
  const contractFunctionSimulator = this.#getSimulatorForTx();
661
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
755
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
662
756
 
663
757
  const {
664
758
  publicInputs,
@@ -700,17 +794,17 @@ export class PXE {
700
794
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
701
795
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
702
796
  // storing the tags here prevents linkage of txs sent from the same PXE.
703
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
704
- if (preTagsUsedInTheTx.length > 0) {
797
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
798
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
705
799
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
706
800
  const txHash = (await txProvingResult.toTx()).txHash;
707
801
 
708
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
709
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
710
- preTagsUsedInTheTx,
802
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
803
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
804
+ taggingIndexRangesUsedInTheTx,
711
805
  });
712
806
  } else {
713
- this.log.debug(`No pre-tags used in the tx`);
807
+ this.log.debug(`No tagging index ranges used in the tx`);
714
808
  }
715
809
 
716
810
  return txProvingResult;
@@ -722,17 +816,13 @@ export class PXE {
722
816
 
723
817
  /**
724
818
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
725
- *
726
- * @param txRequest - An authenticated tx request ready for simulation
727
- * @param msgSender - (Optional) The message sender to use for the simulation.
728
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
819
+ * @param txRequest - An authenticated tx request ready for simulation.
729
820
  * @returns A trace of the program execution with gate counts.
730
821
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
731
822
  */
732
823
  public profileTx(
733
824
  txRequest: TxExecutionRequest,
734
- profileMode: 'full' | 'execution-steps' | 'gates',
735
- skipProofGeneration: boolean = true,
825
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
736
826
  ): Promise<TxProfileResult> {
737
827
  // We disable concurrent profiles for consistency with simulateTx.
738
828
  return this.#putInJobQueue(async jobId => {
@@ -755,12 +845,7 @@ export class PXE {
755
845
  const syncTime = syncTimer.ms();
756
846
 
757
847
  const contractFunctionSimulator = this.#getSimulatorForTx();
758
- const privateExecutionResult = await this.#executePrivate(
759
- contractFunctionSimulator,
760
- txRequest,
761
- undefined,
762
- jobId,
763
- );
848
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
764
849
 
765
850
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
766
851
  txRequest,
@@ -817,12 +902,7 @@ export class PXE {
817
902
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
818
903
  *
819
904
  *
820
- * @param txRequest - An authenticated tx request ready for simulation
821
- * @param simulatePublic - Whether to simulate the public part of the transaction.
822
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
823
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
824
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
825
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
905
+ * @param txRequest - An authenticated tx request ready for simulation.
826
906
  * @returns A simulated transaction result object that includes public and private return values.
827
907
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
828
908
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -831,11 +911,14 @@ export class PXE {
831
911
  */
832
912
  public simulateTx(
833
913
  txRequest: TxExecutionRequest,
834
- simulatePublic: boolean,
835
- skipTxValidation: boolean = false,
836
- skipFeeEnforcement: boolean = false,
837
- overrides?: SimulationOverrides,
838
- scopes?: AztecAddress[],
914
+ {
915
+ simulatePublic,
916
+ skipTxValidation = false,
917
+ skipFeeEnforcement = false,
918
+ skipKernels = true,
919
+ overrides,
920
+ scopes,
921
+ }: SimulateTxOpts,
839
922
  ): Promise<TxSimulationResult> {
840
923
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
841
924
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -859,17 +942,20 @@ export class PXE {
859
942
  await this.blockStateSynchronizer.sync();
860
943
  const syncTime = syncTimer.ms();
861
944
 
862
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
863
- // Temporary: in case there are overrides, we have to skip the kernels or validations
864
- // will fail. Consider handing control to the user/wallet on whether they want to run them
865
- // or not.
866
945
  const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
867
946
  const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
868
- const skipKernels = hasOverriddenContracts;
869
947
 
870
- // Set overridden contracts on the sync service so it knows to skip syncing them
948
+ if (hasOverriddenContracts && !skipKernels) {
949
+ throw new Error(
950
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
951
+ );
952
+ }
953
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
954
+
871
955
  if (hasOverriddenContracts) {
872
- this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
956
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
957
+ // We exclude them so the sync service skips them entirely.
958
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
873
959
  }
874
960
 
875
961
  // Execution of private functions only; no proving, and no kernel logic.
@@ -881,7 +967,8 @@ export class PXE {
881
967
  if (skipKernels) {
882
968
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
883
969
  privateExecutionResult,
884
- this.contractStore,
970
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
971
+ this.node,
885
972
  ));
886
973
  } else {
887
974
  // Kernel logic, plus proving of all private functions and kernels.
@@ -900,6 +987,9 @@ export class PXE {
900
987
  const publicSimulationTimer = new Timer();
901
988
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
902
989
  publicSimulationTime = publicSimulationTimer.ms();
990
+ if (publicOutput?.debugLogs?.length) {
991
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
992
+ }
903
993
  }
904
994
 
905
995
  let validationTime: number | undefined;
@@ -908,7 +998,8 @@ export class PXE {
908
998
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
909
999
  validationTime = validationTimer.ms();
910
1000
  if (validationResult.result === 'invalid') {
911
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1001
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1002
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
912
1003
  }
913
1004
  }
914
1005
 
@@ -959,29 +1050,23 @@ export class PXE {
959
1050
  inspect(txRequest),
960
1051
  `simulatePublic=${simulatePublic}`,
961
1052
  `skipTxValidation=${skipTxValidation}`,
962
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1053
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
963
1054
  );
964
1055
  }
965
1056
  });
966
1057
  }
967
1058
 
968
1059
  /**
969
- * Simulate the execution of a contract utility function.
970
- *
1060
+ * Executes a contract utility function.
971
1061
  * @param call - The function call containing the function details, arguments, and target contract address.
972
- * @param authwits - (Optional) The authentication witnesses required for the function call.
973
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
974
- * default to all.
975
- * @returns The result of the utility function call, structured based on the function ABI.
976
1062
  */
977
- public simulateUtility(
1063
+ public executeUtility(
978
1064
  call: FunctionCall,
979
- authwits?: AuthWitness[],
980
- scopes?: AztecAddress[],
981
- ): Promise<UtilitySimulationResult> {
982
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1065
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1066
+ ): Promise<UtilityExecutionResult> {
1067
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
983
1068
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
984
- // delete the same read value, or reading values that another simulation is currently modifying).
1069
+ // delete the same read value, or reading values that another execution is currently modifying).
985
1070
  return this.#putInJobQueue(async jobId => {
986
1071
  try {
987
1072
  const totalTimer = new Timer();
@@ -995,12 +1080,14 @@ export class PXE {
995
1080
  await this.contractSyncService.ensureContractSynced(
996
1081
  call.to,
997
1082
  call.selector,
998
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1083
+ (privateSyncCall, execScopes) =>
1084
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
999
1085
  anchorBlockHeader,
1000
1086
  jobId,
1087
+ scopes,
1001
1088
  );
1002
1089
 
1003
- const executionResult = await this.#simulateUtility(
1090
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1004
1091
  contractFunctionSimulator,
1005
1092
  call,
1006
1093
  authwits ?? [],
@@ -1021,14 +1108,19 @@ export class PXE {
1021
1108
  };
1022
1109
 
1023
1110
  const simulationStats = contractFunctionSimulator.getStats();
1024
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1111
+ return {
1112
+ result: executionResult,
1113
+ offchainEffects,
1114
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1115
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1116
+ };
1025
1117
  } catch (err: any) {
1026
1118
  const { to, name, args } = call;
1027
1119
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1028
1120
  throw this.#contextualizeError(
1029
1121
  err,
1030
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1031
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1122
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1123
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1032
1124
  );
1033
1125
  }
1034
1126
  });
@@ -1064,10 +1156,11 @@ export class PXE {
1064
1156
  await this.contractSyncService.ensureContractSynced(
1065
1157
  filter.contractAddress,
1066
1158
  null,
1067
- async privateSyncCall =>
1068
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1159
+ async (privateSyncCall, execScopes) =>
1160
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1069
1161
  anchorBlockHeader,
1070
1162
  jobId,
1163
+ filter.scopes,
1071
1164
  );
1072
1165
  });
1073
1166
 
@@ -1082,9 +1175,11 @@ export class PXE {
1082
1175
  }
1083
1176
 
1084
1177
  /**
1085
- * Stops the PXE's job queue.
1178
+ * Stops the PXE's job queue and closes the backing store.
1086
1179
  */
1087
- public stop(): Promise<void> {
1088
- return this.jobQueue.end();
1180
+ public async stop(): Promise<void> {
1181
+ await this.jobQueue.end();
1182
+ await this.blockStateSynchronizer.stop();
1183
+ await this.db.close();
1089
1184
  }
1090
1185
  }