@aztec/pxe 0.0.1-commit.54489865 → 0.0.1-commit.5914bae

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