@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa

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 (269) hide show
  1. package/dest/bin/check_oracle_version.js +5 -5
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +68 -16
  5. package/dest/config/index.d.ts +4 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +12 -2
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +63 -31
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.js +206 -78
  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 +5 -7
  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 +9 -11
  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 +5 -8
  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 +7 -12
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts +65 -46
  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 -42
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/oracle.js +319 -112
  40. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
  41. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution.js +5 -40
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +59 -77
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +120 -86
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +134 -67
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +337 -151
  49. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  50. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/pick_notes.js +9 -2
  52. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  53. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  55. package/dest/contract_logging.d.ts +27 -0
  56. package/dest/contract_logging.d.ts.map +1 -0
  57. package/dest/contract_logging.js +38 -0
  58. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  59. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  60. package/dest/contract_sync/contract_sync_service.js +116 -0
  61. package/dest/contract_sync/helpers.d.ts +28 -0
  62. package/dest/contract_sync/helpers.d.ts.map +1 -0
  63. package/dest/contract_sync/helpers.js +60 -0
  64. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  65. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  66. package/dest/debug/pxe_debug_utils.js +28 -17
  67. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  68. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  69. package/dest/entrypoints/client/bundle/index.js +2 -0
  70. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  71. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  72. package/dest/entrypoints/client/bundle/utils.js +23 -9
  73. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  74. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  75. package/dest/entrypoints/client/lazy/index.js +2 -0
  76. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  77. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  78. package/dest/entrypoints/client/lazy/utils.js +24 -10
  79. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  80. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  81. package/dest/entrypoints/pxe_creation_options.js +3 -1
  82. package/dest/entrypoints/server/index.d.ts +4 -2
  83. package/dest/entrypoints/server/index.d.ts.map +1 -1
  84. package/dest/entrypoints/server/index.js +3 -1
  85. package/dest/entrypoints/server/utils.d.ts +2 -2
  86. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  87. package/dest/entrypoints/server/utils.js +30 -11
  88. package/dest/events/event_service.d.ts +6 -6
  89. package/dest/events/event_service.d.ts.map +1 -1
  90. package/dest/events/event_service.js +21 -10
  91. package/dest/events/private_event_filter_validator.d.ts +3 -2
  92. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  93. package/dest/events/private_event_filter_validator.js +15 -0
  94. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  95. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  96. package/dest/job_coordinator/job_coordinator.js +3 -2
  97. package/dest/logs/log_service.d.ts +10 -9
  98. package/dest/logs/log_service.d.ts.map +1 -1
  99. package/dest/logs/log_service.js +50 -64
  100. package/dest/messages/message_context_service.d.ts +17 -0
  101. package/dest/messages/message_context_service.d.ts.map +1 -0
  102. package/dest/messages/message_context_service.js +36 -0
  103. package/dest/notes/note_service.d.ts +8 -8
  104. package/dest/notes/note_service.d.ts.map +1 -1
  105. package/dest/notes/note_service.js +29 -19
  106. package/dest/notes_filter.d.ts +24 -0
  107. package/dest/notes_filter.d.ts.map +1 -0
  108. package/dest/notes_filter.js +4 -0
  109. package/dest/oracle_version.d.ts +4 -3
  110. package/dest/oracle_version.d.ts.map +1 -1
  111. package/dest/oracle_version.js +20 -9
  112. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  113. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  114. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  115. package/dest/private_kernel/hints/index.d.ts +1 -1
  116. package/dest/private_kernel/hints/index.js +1 -1
  117. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  118. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  119. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  120. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  121. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  122. package/dest/private_kernel/hints/test_utils.js +203 -0
  123. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  124. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  125. package/dest/private_kernel/private_kernel_execution_prover.js +20 -15
  126. package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
  127. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  128. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  129. package/dest/pxe.d.ts +74 -24
  130. package/dest/pxe.d.ts.map +1 -1
  131. package/dest/pxe.js +142 -80
  132. package/dest/storage/address_store/address_store.d.ts +1 -1
  133. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  134. package/dest/storage/address_store/address_store.js +12 -11
  135. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  136. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  137. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  138. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  139. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  140. package/dest/storage/capsule_store/capsule_service.js +50 -0
  141. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  142. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  143. package/dest/storage/capsule_store/capsule_store.js +39 -36
  144. package/dest/storage/capsule_store/index.d.ts +2 -1
  145. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  146. package/dest/storage/capsule_store/index.js +1 -0
  147. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  148. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  149. package/dest/storage/contract_store/contract_store.js +157 -84
  150. package/dest/storage/metadata.d.ts +1 -1
  151. package/dest/storage/metadata.js +1 -1
  152. package/dest/storage/note_store/note_store.d.ts +47 -49
  153. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  154. package/dest/storage/note_store/note_store.js +278 -252
  155. package/dest/storage/note_store/stored_note.d.ts +16 -0
  156. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  157. package/dest/storage/note_store/stored_note.js +43 -0
  158. package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
  159. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  160. package/dest/storage/private_event_store/private_event_store.js +198 -147
  161. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  162. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  163. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  164. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  165. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  166. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  167. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  168. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  169. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  170. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  171. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  172. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  173. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  174. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  175. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  176. package/dest/tagging/index.d.ts +4 -3
  177. package/dest/tagging/index.d.ts.map +1 -1
  178. package/dest/tagging/index.js +2 -1
  179. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
  180. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  181. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -21
  182. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  183. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  184. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  185. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  186. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
  187. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  188. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
  189. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  190. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  191. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +23 -16
  192. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -7
  193. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  194. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +42 -27
  195. package/package.json +25 -16
  196. package/src/bin/check_oracle_version.ts +5 -4
  197. package/src/block_synchronizer/block_synchronizer.ts +82 -33
  198. package/src/config/index.ts +9 -1
  199. package/src/config/package_info.ts +1 -1
  200. package/src/contract_function_simulator/contract_function_simulator.ts +366 -142
  201. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  202. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  203. package/src/contract_function_simulator/index.ts +1 -0
  204. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -10
  205. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  206. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  207. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +5 -11
  208. package/src/contract_function_simulator/oracle/interfaces.ts +95 -58
  209. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  210. package/src/contract_function_simulator/oracle/oracle.ts +404 -150
  211. package/src/contract_function_simulator/oracle/private_execution.ts +5 -64
  212. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +160 -182
  213. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +564 -182
  214. package/src/contract_function_simulator/pick_notes.ts +9 -2
  215. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  216. package/src/contract_logging.ts +52 -0
  217. package/src/contract_sync/contract_sync_service.ts +176 -0
  218. package/src/contract_sync/helpers.ts +98 -0
  219. package/src/debug/pxe_debug_utils.ts +63 -18
  220. package/src/entrypoints/client/bundle/index.ts +2 -0
  221. package/src/entrypoints/client/bundle/utils.ts +18 -18
  222. package/src/entrypoints/client/lazy/index.ts +2 -0
  223. package/src/entrypoints/client/lazy/utils.ts +19 -18
  224. package/src/entrypoints/pxe_creation_options.ts +9 -1
  225. package/src/entrypoints/server/index.ts +3 -1
  226. package/src/entrypoints/server/utils.ts +24 -29
  227. package/src/events/event_service.ts +22 -11
  228. package/src/events/private_event_filter_validator.ts +21 -1
  229. package/src/job_coordinator/job_coordinator.ts +4 -3
  230. package/src/logs/log_service.ts +93 -105
  231. package/src/messages/message_context_service.ts +44 -0
  232. package/src/notes/note_service.ts +38 -26
  233. package/src/notes_filter.ts +24 -0
  234. package/src/oracle_version.ts +20 -9
  235. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  236. package/src/private_kernel/hints/index.ts +1 -1
  237. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  238. package/src/private_kernel/hints/test_utils.ts +325 -0
  239. package/src/private_kernel/private_kernel_execution_prover.ts +24 -19
  240. package/src/private_kernel/private_kernel_oracle.ts +9 -9
  241. package/src/pxe.ts +272 -126
  242. package/src/storage/address_store/address_store.ts +15 -15
  243. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  244. package/src/storage/capsule_store/capsule_service.ts +90 -0
  245. package/src/storage/capsule_store/capsule_store.ts +42 -34
  246. package/src/storage/capsule_store/index.ts +1 -0
  247. package/src/storage/contract_store/contract_store.ts +186 -96
  248. package/src/storage/metadata.ts +1 -1
  249. package/src/storage/note_store/note_store.ts +318 -318
  250. package/src/storage/note_store/stored_note.ts +48 -0
  251. package/src/storage/private_event_store/private_event_store.ts +250 -190
  252. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  253. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  254. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  255. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  256. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  257. package/src/tagging/index.ts +3 -2
  258. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +19 -24
  259. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  260. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  261. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -10
  262. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +29 -26
  263. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +39 -29
  264. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  265. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  266. package/dest/tree_membership/tree_membership_service.d.ts +0 -50
  267. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  268. package/dest/tree_membership/tree_membership_service.js +0 -75
  269. package/src/tree_membership/tree_membership_service.ts +0 -97
package/src/pxe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
@@ -18,7 +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 { L2BlockHash } from '@aztec/stdlib/block';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
22
22
  import {
23
23
  CompleteAddress,
24
24
  type ContractInstanceWithAddress,
@@ -34,6 +34,7 @@ import type {
34
34
  PrivateKernelTailCircuitPublicInputs,
35
35
  } from '@aztec/stdlib/kernel';
36
36
  import {
37
+ BlockHeader,
37
38
  type ContractOverrides,
38
39
  type InTx,
39
40
  PrivateExecutionResult,
@@ -47,7 +48,7 @@ import {
47
48
  TxProfileResult,
48
49
  TxProvingResult,
49
50
  TxSimulationResult,
50
- UtilitySimulationResult,
51
+ UtilityExecutionResult,
51
52
  } from '@aztec/stdlib/tx';
52
53
 
53
54
  import { inspect } from 'util';
@@ -59,12 +60,15 @@ import {
59
60
  ContractFunctionSimulator,
60
61
  generateSimulatedProvingResult,
61
62
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
63
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.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';
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,
@@ -103,6 +160,9 @@ export class PXE {
103
160
  private recipientTaggingStore: RecipientTaggingStore,
104
161
  private addressStore: AddressStore,
105
162
  private privateEventStore: PrivateEventStore,
163
+ private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
106
166
  private simulator: CircuitSimulator,
107
167
  private proverEnabled: boolean,
108
168
  private proofCreator: PrivateKernelProver,
@@ -120,25 +180,31 @@ export class PXE {
120
180
  *
121
181
  * @returns A promise that resolves PXE is ready to be used.
122
182
  */
123
- public static async create(
124
- node: AztecNode,
125
- store: AztecAsyncKVStore,
126
- proofCreator: PrivateKernelProver,
127
- simulator: CircuitSimulator,
128
- protocolContractsProvider: ProtocolContractsProvider,
129
- config: PXEConfig,
130
- loggerOrSuffix?: string | Logger,
131
- ) {
183
+ public static async create({
184
+ node,
185
+ store,
186
+ proofCreator,
187
+ simulator,
188
+ protocolContractsProvider,
189
+ config,
190
+ loggerOrSuffix,
191
+ }: PXECreateArgs) {
192
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
193
+ const bindings: LoggerBindings | undefined =
194
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
195
+
132
196
  const log =
133
197
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
198
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
199
  : loggerOrSuffix;
136
200
 
137
- const proverEnabled = !!config.proverEnabled;
201
+ const info = await node.getNodeInfo();
202
+
203
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
204
  const addressStore = new AddressStore(store);
139
205
  const privateEventStore = new PrivateEventStore(store);
140
206
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
207
+ const noteStore = new NoteStore(store);
142
208
  const anchorBlockStore = new AnchorBlockStore(store);
143
209
  const senderTaggingStore = new SenderTaggingStore(store);
144
210
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,6 +212,14 @@ export class PXE {
146
212
  const capsuleStore = new CapsuleStore(store);
147
213
  const keyStore = new KeyStore(store);
148
214
  const tipsStore = new L2TipsKVStore(store, 'pxe');
215
+ const contractSyncService = new ContractSyncService(
216
+ node,
217
+ contractStore,
218
+ noteStore,
219
+ createLogger('pxe:contract_sync', bindings),
220
+ );
221
+ const messageContextService = new MessageContextService(node);
222
+
149
223
  const synchronizer = new BlockSynchronizer(
150
224
  node,
151
225
  store,
@@ -153,19 +227,28 @@ export class PXE {
153
227
  noteStore,
154
228
  privateEventStore,
155
229
  tipsStore,
230
+ contractSyncService,
156
231
  config,
157
- loggerOrSuffix,
232
+ bindings,
158
233
  );
159
234
 
160
- const jobCoordinator = new JobCoordinator(store);
161
- jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
235
+ const jobCoordinator = new JobCoordinator(store, bindings);
236
+ jobCoordinator.registerStores([
237
+ capsuleStore,
238
+ senderTaggingStore,
239
+ recipientTaggingStore,
240
+ privateEventStore,
241
+ noteStore,
242
+ contractSyncService,
243
+ ]);
162
244
 
163
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
245
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
164
246
 
165
247
  const jobQueue = new SerialQueue();
166
248
 
167
249
  const pxe = new PXE(
168
250
  node,
251
+ store,
169
252
  synchronizer,
170
253
  keyStore,
171
254
  contractStore,
@@ -177,6 +260,9 @@ export class PXE {
177
260
  recipientTaggingStore,
178
261
  addressStore,
179
262
  privateEventStore,
263
+ contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
180
266
  simulator,
181
267
  proverEnabled,
182
268
  proofCreator,
@@ -187,12 +273,15 @@ export class PXE {
187
273
  debugUtils,
188
274
  );
189
275
 
190
- debugUtils.setPXE(pxe);
276
+ debugUtils.setPXEHelpers(
277
+ pxe.#putInJobQueue.bind(pxe),
278
+ pxe.#getSimulatorForTx.bind(pxe),
279
+ pxe.#executeUtility.bind(pxe),
280
+ );
191
281
 
192
282
  pxe.jobQueue.start();
193
283
 
194
284
  await pxe.#registerProtocolContracts();
195
- const info = await node.getNodeInfo();
196
285
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
197
286
  return pxe;
198
287
  }
@@ -202,20 +291,22 @@ export class PXE {
202
291
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
203
292
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
204
293
 
205
- return new ContractFunctionSimulator(
206
- proxyContractStore,
207
- this.noteStore,
208
- this.keyStore,
209
- this.addressStore,
210
- BenchmarkedNodeFactory.create(this.node),
211
- this.anchorBlockStore,
212
- this.senderTaggingStore,
213
- this.recipientTaggingStore,
214
- this.senderAddressBookStore,
215
- this.capsuleStore,
216
- this.privateEventStore,
217
- this.simulator,
218
- );
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
+ });
219
310
  }
220
311
 
221
312
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -267,9 +358,8 @@ export class PXE {
267
358
  async #registerProtocolContracts() {
268
359
  const registered: Record<string, string> = {};
269
360
  for (const name of protocolContractNames) {
270
- const { address, contractClass, instance, artifact } =
271
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
272
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
361
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
362
+ await this.contractStore.addContractArtifact(artifact);
273
363
  await this.contractStore.addContractInstance(instance);
274
364
  registered[name] = address.toString();
275
365
  }
@@ -281,7 +371,7 @@ export class PXE {
281
371
  async #executePrivate(
282
372
  contractFunctionSimulator: ContractFunctionSimulator,
283
373
  txRequest: TxExecutionRequest,
284
- scopes: AztecAddress[] | undefined,
374
+ scopes: AztecAddress[],
285
375
  jobId: string,
286
376
  ): Promise<PrivateExecutionResult> {
287
377
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -289,18 +379,23 @@ export class PXE {
289
379
  try {
290
380
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
291
381
 
292
- const result = await contractFunctionSimulator.run(
293
- txRequest,
382
+ await this.contractSyncService.ensureContractSynced(
294
383
  contractAddress,
295
384
  functionSelector,
296
- undefined,
385
+ (privateSyncCall, execScopes) =>
386
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
297
387
  anchorBlockHeader,
298
- // The sender for tags is set by contracts, typically by an account
299
- // contract entrypoint
300
- undefined, // senderForTags
301
- scopes,
302
388
  jobId,
389
+ scopes,
303
390
  );
391
+
392
+ const result = await contractFunctionSimulator.run(txRequest, {
393
+ contractAddress,
394
+ selector: functionSelector,
395
+ anchorBlockHeader,
396
+ scopes,
397
+ jobId,
398
+ });
304
399
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
305
400
  return result;
306
401
  } catch (err) {
@@ -312,25 +407,32 @@ export class PXE {
312
407
  }
313
408
 
314
409
  /**
315
- * Simulate a utility function call on the given contract.
410
+ * Execute a utility function call on the given contract.
316
411
  * @param contractFunctionSimulator - The simulator to use for the function call.
317
412
  * @param call - The function call to execute.
318
413
  * @param authWitnesses - Authentication witnesses required for the function call.
319
414
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
320
415
  * accounts if not specified.
321
416
  * @param jobId - The job ID for staged writes.
322
- * @returns The simulation result containing the outputs of the utility function.
417
+ * @returns The execution result containing the outputs of the utility function.
323
418
  */
324
- async #simulateUtility(
419
+ async #executeUtility(
325
420
  contractFunctionSimulator: ContractFunctionSimulator,
326
421
  call: FunctionCall,
327
422
  authWitnesses: AuthWitness[] | undefined,
328
- scopes: AztecAddress[] | undefined,
423
+ scopes: AztecAddress[],
329
424
  jobId: string,
330
425
  ) {
331
426
  try {
332
427
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
333
- 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 };
334
436
  } catch (err) {
335
437
  if (err instanceof SimulationError) {
336
438
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -384,15 +486,35 @@ export class PXE {
384
486
  config: PrivateKernelExecutionProverConfig,
385
487
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
386
488
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
387
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
489
+ const anchorBlockHash = await anchorBlockHeader.hash();
388
490
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
389
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
491
+ const kernelTraceProver = new PrivateKernelExecutionProver(
492
+ kernelOracle,
493
+ proofCreator,
494
+ !this.proverEnabled,
495
+ this.log.getBindings(),
496
+ );
390
497
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
391
498
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
392
499
  }
393
500
 
394
501
  // Public API
395
502
 
503
+ /**
504
+ * Returns the block header up to which the PXE has synced.
505
+ * @returns The synced block header
506
+ */
507
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
508
+ return this.#putInJobQueue(() => {
509
+ return this.anchorBlockStore.getBlockHeader();
510
+ });
511
+ }
512
+
513
+ /**
514
+ * Returns the contract instance for a given address, if it's registered in the PXE.
515
+ * @param address - The contract address.
516
+ * @returns The contract instance if found, undefined otherwise.
517
+ */
396
518
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
397
519
  return this.contractStore.getContractInstance(address);
398
520
  }
@@ -428,7 +550,6 @@ export class PXE {
428
550
  }
429
551
 
430
552
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
431
- await this.noteStore.addScope(accountCompleteAddress.address);
432
553
  return accountCompleteAddress;
433
554
  }
434
555
 
@@ -443,6 +564,12 @@ export class PXE {
443
564
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
444
565
  */
445
566
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
567
+ if (!(await sender.isValid())) {
568
+ throw new Error(
569
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
570
+ );
571
+ }
572
+
446
573
  const accounts = await this.keyStore.getAccounts();
447
574
  if (accounts.includes(sender)) {
448
575
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -453,6 +580,9 @@ export class PXE {
453
580
 
454
581
  if (wasAdded) {
455
582
  this.log.info(`Added sender:\n ${sender.toString()}`);
583
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
584
+ // all contracts must re-sync to discover them.
585
+ this.contractSyncService.wipe();
456
586
  } else {
457
587
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
458
588
  }
@@ -502,8 +632,7 @@ export class PXE {
502
632
  * @param artifact - The build artifact for the contract class.
503
633
  */
504
634
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
505
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
506
- await this.contractStore.addContractArtifact(contractClassId, artifact);
635
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
507
636
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
508
637
  }
509
638
 
@@ -522,17 +651,17 @@ export class PXE {
522
651
  if (artifact) {
523
652
  // If the user provides an artifact, validate it against the expected class id and register it
524
653
  const contractClass = await getContractClassFromArtifact(artifact);
525
- const contractClassId = contractClass.id;
526
- if (!contractClassId.equals(instance.currentContractClassId)) {
654
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
527
655
  throw new Error(
528
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
656
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
529
657
  );
530
658
  }
531
659
  const computedAddress = await computeContractAddressFromInstance(instance);
532
660
  if (!computedAddress.equals(instance.address)) {
533
661
  throw new Error('Added a contract in which the address does not match the contract instance.');
534
662
  }
535
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
663
+
664
+ await this.contractStore.addContractArtifact(artifact, contractClass);
536
665
 
537
666
  const publicFunctionSignatures = artifact.functions
538
667
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -581,15 +710,16 @@ export class PXE {
581
710
  throw new Error('Could not update contract to a class different from the current one.');
582
711
  }
583
712
 
584
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
585
-
586
713
  const publicFunctionSignatures = artifact.functions
587
714
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
588
715
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
589
716
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
590
717
 
591
718
  currentInstance.currentContractClassId = contractClass.id;
592
- await this.contractStore.addContractInstance(currentInstance);
719
+ await Promise.all([
720
+ this.contractStore.addContractArtifact(artifact, contractClass),
721
+ this.contractStore.addContractInstance(currentInstance),
722
+ ]);
593
723
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
594
724
  });
595
725
  }
@@ -607,11 +737,12 @@ export class PXE {
607
737
  * (where validators prove the public portion).
608
738
  *
609
739
  * @param txRequest - An authenticated tx request ready for proving
740
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
610
741
  * @returns A result containing the proof and public inputs of the tail circuit.
611
742
  * @throws If contract code not found, or public simulation reverts.
612
743
  * Also throws if simulatePublic is true and public simulation reverts.
613
744
  */
614
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
745
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
615
746
  let privateExecutionResult: PrivateExecutionResult;
616
747
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
617
748
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -622,7 +753,7 @@ export class PXE {
622
753
  await this.blockStateSynchronizer.sync();
623
754
  const syncTime = syncTimer.ms();
624
755
  const contractFunctionSimulator = this.#getSimulatorForTx();
625
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
756
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
626
757
 
627
758
  const {
628
759
  publicInputs,
@@ -664,17 +795,17 @@ export class PXE {
664
795
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
665
796
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
666
797
  // storing the tags here prevents linkage of txs sent from the same PXE.
667
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
668
- if (preTagsUsedInTheTx.length > 0) {
798
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
799
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
669
800
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
670
801
  const txHash = (await txProvingResult.toTx()).txHash;
671
802
 
672
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
673
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
674
- preTagsUsedInTheTx,
803
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
804
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
805
+ taggingIndexRangesUsedInTheTx,
675
806
  });
676
807
  } else {
677
- this.log.debug(`No pre-tags used in the tx`);
808
+ this.log.debug(`No tagging index ranges used in the tx`);
678
809
  }
679
810
 
680
811
  return txProvingResult;
@@ -686,17 +817,13 @@ export class PXE {
686
817
 
687
818
  /**
688
819
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
689
- *
690
- * @param txRequest - An authenticated tx request ready for simulation
691
- * @param msgSender - (Optional) The message sender to use for the simulation.
692
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
820
+ * @param txRequest - An authenticated tx request ready for simulation.
693
821
  * @returns A trace of the program execution with gate counts.
694
822
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
695
823
  */
696
824
  public profileTx(
697
825
  txRequest: TxExecutionRequest,
698
- profileMode: 'full' | 'execution-steps' | 'gates',
699
- skipProofGeneration: boolean = true,
826
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
700
827
  ): Promise<TxProfileResult> {
701
828
  // We disable concurrent profiles for consistency with simulateTx.
702
829
  return this.#putInJobQueue(async jobId => {
@@ -719,12 +846,7 @@ export class PXE {
719
846
  const syncTime = syncTimer.ms();
720
847
 
721
848
  const contractFunctionSimulator = this.#getSimulatorForTx();
722
- const privateExecutionResult = await this.#executePrivate(
723
- contractFunctionSimulator,
724
- txRequest,
725
- undefined,
726
- jobId,
727
- );
849
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
728
850
 
729
851
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
730
852
  txRequest,
@@ -781,12 +903,7 @@ export class PXE {
781
903
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
782
904
  *
783
905
  *
784
- * @param txRequest - An authenticated tx request ready for simulation
785
- * @param simulatePublic - Whether to simulate the public part of the transaction.
786
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
787
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
788
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
789
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
906
+ * @param txRequest - An authenticated tx request ready for simulation.
790
907
  * @returns A simulated transaction result object that includes public and private return values.
791
908
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
792
909
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -795,11 +912,14 @@ export class PXE {
795
912
  */
796
913
  public simulateTx(
797
914
  txRequest: TxExecutionRequest,
798
- simulatePublic: boolean,
799
- skipTxValidation: boolean = false,
800
- skipFeeEnforcement: boolean = false,
801
- overrides?: SimulationOverrides,
802
- scopes?: AztecAddress[],
915
+ {
916
+ simulatePublic,
917
+ skipTxValidation = false,
918
+ skipFeeEnforcement = false,
919
+ skipKernels = true,
920
+ overrides,
921
+ scopes,
922
+ }: SimulateTxOpts,
803
923
  ): Promise<TxSimulationResult> {
804
924
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
805
925
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -823,11 +943,21 @@ export class PXE {
823
943
  await this.blockStateSynchronizer.sync();
824
944
  const syncTime = syncTimer.ms();
825
945
 
946
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
947
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
948
+
949
+ if (hasOverriddenContracts && !skipKernels) {
950
+ throw new Error(
951
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
952
+ );
953
+ }
826
954
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
827
- // Temporary: in case there are overrides, we have to skip the kernels or validations
828
- // will fail. Consider handing control to the user/wallet on whether they want to run them
829
- // or not.
830
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
955
+
956
+ if (hasOverriddenContracts) {
957
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
958
+ // We exclude them so the sync service skips them entirely.
959
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
960
+ }
831
961
 
832
962
  // Execution of private functions only; no proving, and no kernel logic.
833
963
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -838,7 +968,8 @@ export class PXE {
838
968
  if (skipKernels) {
839
969
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
840
970
  privateExecutionResult,
841
- this.contractStore,
971
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
972
+ this.node,
842
973
  ));
843
974
  } else {
844
975
  // Kernel logic, plus proving of all private functions and kernels.
@@ -857,6 +988,9 @@ export class PXE {
857
988
  const publicSimulationTimer = new Timer();
858
989
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
859
990
  publicSimulationTime = publicSimulationTimer.ms();
991
+ if (publicOutput?.debugLogs?.length) {
992
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
993
+ }
860
994
  }
861
995
 
862
996
  let validationTime: number | undefined;
@@ -865,7 +999,8 @@ export class PXE {
865
999
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
866
1000
  validationTime = validationTimer.ms();
867
1001
  if (validationResult.result === 'invalid') {
868
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1002
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1003
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
869
1004
  }
870
1005
  }
871
1006
 
@@ -916,29 +1051,23 @@ export class PXE {
916
1051
  inspect(txRequest),
917
1052
  `simulatePublic=${simulatePublic}`,
918
1053
  `skipTxValidation=${skipTxValidation}`,
919
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1054
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
920
1055
  );
921
1056
  }
922
1057
  });
923
1058
  }
924
1059
 
925
1060
  /**
926
- * Simulate the execution of a contract utility function.
927
- *
1061
+ * Executes a contract utility function.
928
1062
  * @param call - The function call containing the function details, arguments, and target contract address.
929
- * @param authwits - (Optional) The authentication witnesses required for the function call.
930
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
931
- * default to all.
932
- * @returns The result of the utility function call, structured based on the function ABI.
933
1063
  */
934
- public simulateUtility(
1064
+ public executeUtility(
935
1065
  call: FunctionCall,
936
- authwits?: AuthWitness[],
937
- scopes?: AztecAddress[],
938
- ): Promise<UtilitySimulationResult> {
939
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1066
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1067
+ ): Promise<UtilityExecutionResult> {
1068
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
940
1069
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
941
- // delete the same read value, or reading values that another simulation is currently modifying).
1070
+ // delete the same read value, or reading values that another execution is currently modifying).
942
1071
  return this.#putInJobQueue(async jobId => {
943
1072
  try {
944
1073
  const totalTimer = new Timer();
@@ -948,11 +1077,18 @@ export class PXE {
948
1077
  const functionTimer = new Timer();
949
1078
  const contractFunctionSimulator = this.#getSimulatorForTx();
950
1079
 
951
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
952
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1080
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1081
+ await this.contractSyncService.ensureContractSynced(
1082
+ call.to,
1083
+ call.selector,
1084
+ (privateSyncCall, execScopes) =>
1085
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1086
+ anchorBlockHeader,
1087
+ jobId,
1088
+ scopes,
953
1089
  );
954
1090
 
955
- const executionResult = await this.#simulateUtility(
1091
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
956
1092
  contractFunctionSimulator,
957
1093
  call,
958
1094
  authwits ?? [],
@@ -973,14 +1109,19 @@ export class PXE {
973
1109
  };
974
1110
 
975
1111
  const simulationStats = contractFunctionSimulator.getStats();
976
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1112
+ return {
1113
+ result: executionResult,
1114
+ offchainEffects,
1115
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1116
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1117
+ };
977
1118
  } catch (err: any) {
978
1119
  const { to, name, args } = call;
979
1120
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
980
1121
  throw this.#contextualizeError(
981
1122
  err,
982
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
983
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1123
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1124
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
984
1125
  );
985
1126
  }
986
1127
  });
@@ -1008,15 +1149,19 @@ export class PXE {
1008
1149
  await this.#putInJobQueue(async jobId => {
1009
1150
  await this.blockStateSynchronizer.sync();
1010
1151
 
1011
- anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
1152
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1153
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1012
1154
 
1013
1155
  const contractFunctionSimulator = this.#getSimulatorForTx();
1014
1156
 
1015
- await this.contractStore.syncPrivateState(
1157
+ await this.contractSyncService.ensureContractSynced(
1016
1158
  filter.contractAddress,
1017
1159
  null,
1018
- async privateSyncCall =>
1019
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1160
+ async (privateSyncCall, execScopes) =>
1161
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1162
+ anchorBlockHeader,
1163
+ jobId,
1164
+ filter.scopes,
1020
1165
  );
1021
1166
  });
1022
1167
 
@@ -1031,9 +1176,10 @@ export class PXE {
1031
1176
  }
1032
1177
 
1033
1178
  /**
1034
- * Stops the PXE's job queue.
1179
+ * Stops the PXE's job queue and closes the backing store.
1035
1180
  */
1036
- public stop(): Promise<void> {
1037
- return this.jobQueue.end();
1181
+ public async stop(): Promise<void> {
1182
+ await this.jobQueue.end();
1183
+ await this.db.close();
1038
1184
  }
1039
1185
  }