@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.cd76b27

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 (262) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +13 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +74 -20
  8. package/dest/config/index.d.ts +3 -1
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -34
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +197 -79
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/index.d.ts +2 -2
  22. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/index.js +1 -1
  24. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  30. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  31. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  33. package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
  34. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  36. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  38. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  40. package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
  41. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/oracle.js +67 -44
  43. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  44. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
  46. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +45 -47
  47. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +92 -53
  49. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +67 -33
  50. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +132 -108
  52. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  53. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  54. package/dest/contract_sync/contract_sync_service.js +97 -0
  55. package/dest/contract_sync/helpers.d.ts +29 -0
  56. package/dest/contract_sync/helpers.d.ts.map +1 -0
  57. package/dest/contract_sync/helpers.js +55 -0
  58. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  59. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  60. package/dest/debug/pxe_debug_utils.js +28 -17
  61. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  62. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  63. package/dest/entrypoints/client/bundle/index.js +2 -0
  64. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  65. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  66. package/dest/entrypoints/client/bundle/utils.js +31 -8
  67. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  68. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  69. package/dest/entrypoints/client/lazy/index.js +2 -0
  70. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  71. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  72. package/dest/entrypoints/client/lazy/utils.js +32 -9
  73. package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
  74. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  75. package/dest/entrypoints/server/index.d.ts +5 -1
  76. package/dest/entrypoints/server/index.d.ts.map +1 -1
  77. package/dest/entrypoints/server/index.js +4 -0
  78. package/dest/entrypoints/server/utils.d.ts +1 -1
  79. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  80. package/dest/entrypoints/server/utils.js +39 -16
  81. package/dest/events/event_service.d.ts +6 -6
  82. package/dest/events/event_service.d.ts.map +1 -1
  83. package/dest/events/event_service.js +19 -22
  84. package/dest/events/private_event_filter_validator.d.ts +5 -5
  85. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  86. package/dest/events/private_event_filter_validator.js +5 -6
  87. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  88. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  89. package/dest/job_coordinator/job_coordinator.js +94 -0
  90. package/dest/logs/log_service.d.ts +8 -5
  91. package/dest/logs/log_service.d.ts.map +1 -1
  92. package/dest/logs/log_service.js +28 -30
  93. package/dest/notes/note_service.d.ts +10 -9
  94. package/dest/notes/note_service.d.ts.map +1 -1
  95. package/dest/notes/note_service.js +34 -38
  96. package/dest/notes_filter.d.ts +25 -0
  97. package/dest/notes_filter.d.ts.map +1 -0
  98. package/dest/notes_filter.js +4 -0
  99. package/dest/oracle_version.d.ts +3 -3
  100. package/dest/oracle_version.d.ts.map +1 -1
  101. package/dest/oracle_version.js +4 -3
  102. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  103. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  104. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  105. package/dest/private_kernel/hints/index.d.ts +3 -3
  106. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  107. package/dest/private_kernel/hints/index.js +2 -2
  108. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  109. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  110. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +16 -10
  111. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  112. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  113. package/dest/private_kernel/private_kernel_execution_prover.js +12 -13
  114. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  115. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  116. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  117. package/dest/pxe.d.ts +76 -58
  118. package/dest/pxe.d.ts.map +1 -1
  119. package/dest/pxe.js +135 -125
  120. package/dest/storage/address_store/address_store.d.ts +1 -1
  121. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  122. package/dest/storage/address_store/address_store.js +12 -11
  123. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  124. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  125. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  126. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  127. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  128. package/dest/storage/capsule_store/capsule_store.js +130 -23
  129. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  130. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  131. package/dest/storage/contract_store/contract_store.js +27 -18
  132. package/dest/storage/metadata.d.ts +1 -1
  133. package/dest/storage/metadata.js +1 -1
  134. package/dest/storage/note_store/note_store.d.ts +50 -51
  135. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  136. package/dest/storage/note_store/note_store.js +284 -263
  137. package/dest/storage/note_store/stored_note.d.ts +16 -0
  138. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  139. package/dest/storage/note_store/stored_note.js +43 -0
  140. package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
  141. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  142. package/dest/storage/private_event_store/private_event_store.js +231 -73
  143. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  144. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  145. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  146. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  147. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  148. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  149. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  150. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  151. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  152. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  153. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  154. package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
  155. package/dest/tagging/constants.d.ts +2 -0
  156. package/dest/tagging/constants.d.ts.map +1 -0
  157. package/dest/tagging/constants.js +10 -0
  158. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  159. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  160. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  161. package/dest/tagging/index.d.ts +3 -2
  162. package/dest/tagging/index.d.ts.map +1 -1
  163. package/dest/tagging/index.js +2 -10
  164. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  165. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  166. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +12 -12
  167. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  168. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  169. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  170. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  171. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  172. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  173. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
  174. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  175. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  176. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  177. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  178. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  179. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  180. package/package.json +27 -18
  181. package/src/access_scopes.ts +9 -0
  182. package/src/bin/check_oracle_version.ts +1 -0
  183. package/src/block_synchronizer/block_synchronizer.ts +93 -32
  184. package/src/config/index.ts +14 -0
  185. package/src/config/package_info.ts +1 -1
  186. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  187. package/src/contract_function_simulator/contract_function_simulator.ts +351 -137
  188. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  189. package/src/contract_function_simulator/index.ts +1 -1
  190. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  191. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  192. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  193. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  194. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  195. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  196. package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
  197. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +129 -132
  198. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +197 -115
  199. package/src/contract_sync/contract_sync_service.ts +152 -0
  200. package/src/contract_sync/helpers.ts +98 -0
  201. package/src/debug/pxe_debug_utils.ts +63 -18
  202. package/src/entrypoints/client/bundle/index.ts +2 -0
  203. package/src/entrypoints/client/bundle/utils.ts +23 -16
  204. package/src/entrypoints/client/lazy/index.ts +2 -0
  205. package/src/entrypoints/client/lazy/utils.ts +24 -17
  206. package/src/entrypoints/pxe_creation_options.ts +4 -2
  207. package/src/entrypoints/server/index.ts +4 -0
  208. package/src/entrypoints/server/utils.ts +33 -41
  209. package/src/events/event_service.ts +19 -25
  210. package/src/events/private_event_filter_validator.ts +3 -5
  211. package/src/job_coordinator/job_coordinator.ts +150 -0
  212. package/src/logs/log_service.ts +40 -34
  213. package/src/notes/note_service.ts +41 -45
  214. package/src/notes_filter.ts +26 -0
  215. package/src/oracle_version.ts +4 -3
  216. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  217. package/src/private_kernel/hints/index.ts +2 -2
  218. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +39 -28
  219. package/src/private_kernel/private_kernel_execution_prover.ts +15 -14
  220. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  221. package/src/pxe.ts +266 -189
  222. package/src/storage/address_store/address_store.ts +15 -15
  223. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  224. package/src/storage/capsule_store/capsule_store.ts +159 -23
  225. package/src/storage/contract_store/contract_store.ts +26 -15
  226. package/src/storage/metadata.ts +1 -1
  227. package/src/storage/note_store/note_store.ts +326 -320
  228. package/src/storage/note_store/stored_note.ts +48 -0
  229. package/src/storage/private_event_store/private_event_store.ts +301 -79
  230. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  231. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  232. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  233. package/src/storage/tagging_store/sender_tagging_store.ts +294 -109
  234. package/src/tagging/constants.ts +10 -0
  235. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  236. package/src/tagging/index.ts +2 -11
  237. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +25 -11
  238. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  239. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  240. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
  241. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
  242. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  243. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  244. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  245. package/dest/contract_function_simulator/proxied_node.js +0 -27
  246. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  247. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.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
  250. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  251. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  252. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  253. package/dest/public_storage/public_storage_service.d.ts +0 -24
  254. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  255. package/dest/public_storage/public_storage_service.js +0 -26
  256. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  257. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  258. package/dest/tree_membership/tree_membership_service.js +0 -84
  259. package/src/contract_function_simulator/proxied_node.ts +0 -33
  260. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  261. package/src/public_storage/public_storage_service.ts +0 -33
  262. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
21
  import {
21
22
  CompleteAddress,
22
- type ContractClassWithId,
23
23
  type ContractInstanceWithAddress,
24
24
  type PartialAddress,
25
25
  computeContractAddressFromInstance,
26
26
  getContractClassFromArtifact,
27
27
  } from '@aztec/stdlib/contract';
28
28
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
30
  import type {
32
31
  PrivateExecutionStep,
@@ -34,6 +33,7 @@ import type {
34
33
  PrivateKernelTailCircuitPublicInputs,
35
34
  } from '@aztec/stdlib/kernel';
36
35
  import {
36
+ BlockHeader,
37
37
  type ContractOverrides,
38
38
  type InTx,
39
39
  PrivateExecutionResult,
@@ -47,27 +47,31 @@ import {
47
47
  TxProfileResult,
48
48
  TxProvingResult,
49
49
  TxSimulationResult,
50
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
51
51
  } from '@aztec/stdlib/tx';
52
52
 
53
53
  import { inspect } from 'util';
54
54
 
55
+ import type { AccessScopes } from './access_scopes.js';
55
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
57
  import type { PXEConfig } from './config/index.js';
58
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
59
  import {
58
60
  ContractFunctionSimulator,
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
66
70
  import {
67
71
  PrivateKernelExecutionProver,
68
72
  type PrivateKernelExecutionProverConfig,
69
73
  } from './private_kernel/private_kernel_execution_prover.js';
70
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
74
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
71
75
  import { AddressStore } from './storage/address_store/address_store.js';
72
76
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
77
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -83,6 +87,56 @@ export type PackedPrivateEvent = InTx & {
83
87
  eventSelector: EventSelector;
84
88
  };
85
89
 
90
+ /** Options for PXE.profileTx. */
91
+ export type ProfileTxOpts = {
92
+ /** The profiling mode to use. */
93
+ profileMode: 'full' | 'execution-steps' | 'gates';
94
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
95
+ skipProofGeneration?: boolean;
96
+ /** Addresses whose private state and keys are accessible during private execution. */
97
+ scopes: AccessScopes;
98
+ };
99
+
100
+ /** Options for PXE.simulateTx. */
101
+ export type SimulateTxOpts = {
102
+ /** Whether to simulate the public part of the transaction. */
103
+ simulatePublic: boolean;
104
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
105
+ skipTxValidation?: boolean;
106
+ /** If false, fees are enforced. */
107
+ skipFeeEnforcement?: boolean;
108
+ /** State overrides for the simulation, such as contract instances and artifacts. */
109
+ overrides?: SimulationOverrides;
110
+ /** Addresses whose private state and keys are accessible during private execution */
111
+ scopes: AccessScopes;
112
+ };
113
+
114
+ /** Options for PXE.executeUtility. */
115
+ export type ExecuteUtilityOpts = {
116
+ /** The authentication witnesses required for the function call. */
117
+ authwits?: AuthWitness[];
118
+ /** The accounts whose notes we can access in this call */
119
+ scopes: AccessScopes;
120
+ };
121
+
122
+ /** Args for PXE.create. */
123
+ export type PXECreateArgs = {
124
+ /** The Aztec node to connect to. */
125
+ node: AztecNode;
126
+ /** The key-value store for persisting PXE state. */
127
+ store: AztecAsyncKVStore;
128
+ /** The prover for generating private kernel proofs. */
129
+ proofCreator: PrivateKernelProver;
130
+ /** The circuit simulator for executing ACIR circuits. */
131
+ simulator: CircuitSimulator;
132
+ /** Provider for protocol contract artifacts and instances. */
133
+ protocolContractsProvider: ProtocolContractsProvider;
134
+ /** PXE configuration options. */
135
+ config: PXEConfig;
136
+ /** Optional logger instance or string suffix for the logger name. */
137
+ loggerOrSuffix?: string | Logger;
138
+ };
139
+
86
140
  /**
87
141
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
88
142
  * manage private state of users.
@@ -101,12 +155,14 @@ export class PXE {
101
155
  private recipientTaggingStore: RecipientTaggingStore,
102
156
  private addressStore: AddressStore,
103
157
  private privateEventStore: PrivateEventStore,
158
+ private contractSyncService: ContractSyncService,
104
159
  private simulator: CircuitSimulator,
105
160
  private proverEnabled: boolean,
106
161
  private proofCreator: PrivateKernelProver,
107
162
  private protocolContractsProvider: ProtocolContractsProvider,
108
163
  private log: Logger,
109
164
  private jobQueue: SerialQueue,
165
+ private jobCoordinator: JobCoordinator,
110
166
  public debug: PXEDebugUtils,
111
167
  ) {}
112
168
 
@@ -117,25 +173,31 @@ export class PXE {
117
173
  *
118
174
  * @returns A promise that resolves PXE is ready to be used.
119
175
  */
120
- public static async create(
121
- node: AztecNode,
122
- store: AztecAsyncKVStore,
123
- proofCreator: PrivateKernelProver,
124
- simulator: CircuitSimulator,
125
- protocolContractsProvider: ProtocolContractsProvider,
126
- config: PXEConfig,
127
- loggerOrSuffix?: string | Logger,
128
- ) {
176
+ public static async create({
177
+ node,
178
+ store,
179
+ proofCreator,
180
+ simulator,
181
+ protocolContractsProvider,
182
+ config,
183
+ loggerOrSuffix,
184
+ }: PXECreateArgs) {
185
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
186
+ const bindings: LoggerBindings | undefined =
187
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
188
+
129
189
  const log =
130
190
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
131
191
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
132
192
  : loggerOrSuffix;
133
193
 
134
- const proverEnabled = !!config.proverEnabled;
194
+ const info = await node.getNodeInfo();
195
+
196
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
135
197
  const addressStore = new AddressStore(store);
136
198
  const privateEventStore = new PrivateEventStore(store);
137
199
  const contractStore = new ContractStore(store);
138
- const noteStore = await NoteStore.create(store);
200
+ const noteStore = new NoteStore(store);
139
201
  const anchorBlockStore = new AnchorBlockStore(store);
140
202
  const senderTaggingStore = new SenderTaggingStore(store);
141
203
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -143,9 +205,35 @@ export class PXE {
143
205
  const capsuleStore = new CapsuleStore(store);
144
206
  const keyStore = new KeyStore(store);
145
207
  const tipsStore = new L2TipsKVStore(store, 'pxe');
146
- const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, tipsStore, config, loggerOrSuffix);
208
+ const contractSyncService = new ContractSyncService(
209
+ node,
210
+ contractStore,
211
+ noteStore,
212
+ createLogger('pxe:contract_sync', bindings),
213
+ );
214
+ const synchronizer = new BlockSynchronizer(
215
+ node,
216
+ store,
217
+ anchorBlockStore,
218
+ noteStore,
219
+ privateEventStore,
220
+ tipsStore,
221
+ contractSyncService,
222
+ config,
223
+ bindings,
224
+ );
225
+
226
+ const jobCoordinator = new JobCoordinator(store, bindings);
227
+ jobCoordinator.registerStores([
228
+ capsuleStore,
229
+ senderTaggingStore,
230
+ recipientTaggingStore,
231
+ privateEventStore,
232
+ noteStore,
233
+ contractSyncService,
234
+ ]);
147
235
 
148
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
236
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
149
237
 
150
238
  const jobQueue = new SerialQueue();
151
239
 
@@ -162,21 +250,26 @@ export class PXE {
162
250
  recipientTaggingStore,
163
251
  addressStore,
164
252
  privateEventStore,
253
+ contractSyncService,
165
254
  simulator,
166
255
  proverEnabled,
167
256
  proofCreator,
168
257
  protocolContractsProvider,
169
258
  log,
170
259
  jobQueue,
260
+ jobCoordinator,
171
261
  debugUtils,
172
262
  );
173
263
 
174
- debugUtils.setPXE(pxe);
264
+ debugUtils.setPXEHelpers(
265
+ pxe.#putInJobQueue.bind(pxe),
266
+ pxe.#getSimulatorForTx.bind(pxe),
267
+ pxe.#executeUtility.bind(pxe),
268
+ );
175
269
 
176
270
  pxe.jobQueue.start();
177
271
 
178
272
  await pxe.#registerProtocolContracts();
179
- const info = await node.getNodeInfo();
180
273
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
181
274
  return pxe;
182
275
  }
@@ -186,20 +279,20 @@ export class PXE {
186
279
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
187
280
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
188
281
 
189
- return new ContractFunctionSimulator(
190
- proxyContractStore,
191
- this.noteStore,
192
- this.keyStore,
193
- this.addressStore,
194
- this.node,
195
- this.anchorBlockStore,
196
- this.senderTaggingStore,
197
- this.recipientTaggingStore,
198
- this.senderAddressBookStore,
199
- this.capsuleStore,
200
- this.privateEventStore,
201
- this.simulator,
202
- );
282
+ return new ContractFunctionSimulator({
283
+ contractStore: proxyContractStore,
284
+ noteStore: this.noteStore,
285
+ keyStore: this.keyStore,
286
+ addressStore: this.addressStore,
287
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
288
+ senderTaggingStore: this.senderTaggingStore,
289
+ recipientTaggingStore: this.recipientTaggingStore,
290
+ senderAddressBookStore: this.senderAddressBookStore,
291
+ capsuleStore: this.capsuleStore,
292
+ privateEventStore: this.privateEventStore,
293
+ simulator: this.simulator,
294
+ contractSyncService: this.contractSyncService,
295
+ });
203
296
  }
204
297
 
205
298
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -222,7 +315,7 @@ export class PXE {
222
315
  *
223
316
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
224
317
  */
225
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
318
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
226
319
  // TODO(#12636): relax the conditions under which we forbid concurrency.
227
320
  if (this.jobQueue.length() != 0) {
228
321
  this.log.warn(
@@ -230,7 +323,22 @@ export class PXE {
230
323
  );
231
324
  }
232
325
 
233
- return this.jobQueue.put(fn);
326
+ return this.jobQueue.put(async () => {
327
+ const jobId = this.jobCoordinator.beginJob();
328
+ this.log.verbose(`Beginning job ${jobId}`);
329
+
330
+ try {
331
+ const result = await fn(jobId);
332
+ this.log.verbose(`Committing job ${jobId}`);
333
+
334
+ await this.jobCoordinator.commitJob(jobId);
335
+ return result;
336
+ } catch (err) {
337
+ this.log.verbose(`Aborting job ${jobId}`);
338
+ await this.jobCoordinator.abortJob(jobId);
339
+ throw err;
340
+ }
341
+ });
234
342
  }
235
343
 
236
344
  async #registerProtocolContracts() {
@@ -245,42 +353,36 @@ export class PXE {
245
353
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
246
354
  }
247
355
 
248
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
249
- return !!(await this.node.getContractClass(id));
250
- }
251
-
252
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
253
- return !!(await this.node.getContract(address));
254
- }
255
-
256
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
257
- const initNullifier = await siloNullifier(address, address.toField());
258
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
259
- }
260
-
261
356
  // Executes the entrypoint private function, as well as all nested private
262
357
  // functions that might arise.
263
358
  async #executePrivate(
264
359
  contractFunctionSimulator: ContractFunctionSimulator,
265
360
  txRequest: TxExecutionRequest,
266
- scopes?: AztecAddress[],
361
+ scopes: AccessScopes,
362
+ jobId: string,
267
363
  ): Promise<PrivateExecutionResult> {
268
364
  const { origin: contractAddress, functionSelector } = txRequest;
269
365
 
270
366
  try {
271
367
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
272
368
 
273
- const result = await contractFunctionSimulator.run(
274
- txRequest,
369
+ await this.contractSyncService.ensureContractSynced(
275
370
  contractAddress,
276
371
  functionSelector,
277
- undefined,
372
+ (privateSyncCall, execScopes) =>
373
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
278
374
  anchorBlockHeader,
279
- // The sender for tags is set by contracts, typically by an account
280
- // contract entrypoint
281
- undefined, // senderForTags
375
+ jobId,
282
376
  scopes,
283
377
  );
378
+
379
+ const result = await contractFunctionSimulator.run(txRequest, {
380
+ contractAddress,
381
+ selector: functionSelector,
382
+ anchorBlockHeader,
383
+ scopes,
384
+ jobId,
385
+ });
284
386
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
285
387
  return result;
286
388
  } catch (err) {
@@ -292,23 +394,25 @@ export class PXE {
292
394
  }
293
395
 
294
396
  /**
295
- * Simulate a utility function call on the given contract.
397
+ * Execute a utility function call on the given contract.
296
398
  * @param contractFunctionSimulator - The simulator to use for the function call.
297
399
  * @param call - The function call to execute.
298
400
  * @param authWitnesses - Authentication witnesses required for the function call.
299
401
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
300
402
  * accounts if not specified.
301
- * @returns The simulation result containing the outputs of the utility function.
403
+ * @param jobId - The job ID for staged writes.
404
+ * @returns The execution result containing the outputs of the utility function.
302
405
  */
303
- async #simulateUtility(
406
+ async #executeUtility(
304
407
  contractFunctionSimulator: ContractFunctionSimulator,
305
408
  call: FunctionCall,
306
- authWitnesses?: AuthWitness[],
307
- scopes?: AztecAddress[],
409
+ authWitnesses: AuthWitness[] | undefined,
410
+ scopes: AccessScopes,
411
+ jobId: string,
308
412
  ) {
309
413
  try {
310
414
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
311
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
415
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
312
416
  } catch (err) {
313
417
  if (err instanceof SimulationError) {
314
418
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -361,85 +465,45 @@ export class PXE {
361
465
  privateExecutionResult: PrivateExecutionResult,
362
466
  config: PrivateKernelExecutionProverConfig,
363
467
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
364
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
365
- const kernelOracle = new PrivateKernelOracleImpl(
366
- this.contractStore,
367
- this.keyStore,
368
- this.node,
369
- simulationAnchorBlock,
468
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
469
+ const anchorBlockHash = await anchorBlockHeader.hash();
470
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
471
+ const kernelTraceProver = new PrivateKernelExecutionProver(
472
+ kernelOracle,
473
+ proofCreator,
474
+ !this.proverEnabled,
475
+ this.log.getBindings(),
370
476
  );
371
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
372
477
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
373
478
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
374
479
  }
375
480
 
376
481
  // Public API
377
482
 
378
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
379
- return this.contractStore.getContractInstance(address);
483
+ /**
484
+ * Returns the block header up to which the PXE has synced.
485
+ * @returns The synced block header
486
+ */
487
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
488
+ return this.anchorBlockStore.getBlockHeader();
380
489
  }
381
490
 
382
491
  /**
383
- * Returns the contract class metadata given a contract class id.
384
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
385
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
386
- * @param id - Identifier of the class.
387
- * @param includeArtifact - Identifier of the class.
388
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
389
- * for `includeArtifact`
390
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
391
- * should the pxe query the node for contract public info, and merge it with its own definitions?
392
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
393
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
394
- * do for the time being.
492
+ * Returns the contract instance for a given address, if it's registered in the PXE.
493
+ * @param address - The contract address.
494
+ * @returns The contract instance if found, undefined otherwise.
395
495
  */
396
- public async getContractClassMetadata(
397
- id: Fr,
398
- includeArtifact: boolean = false,
399
- ): Promise<{
400
- contractClass: ContractClassWithId | undefined;
401
- isContractClassPubliclyRegistered: boolean;
402
- artifact: ContractArtifact | undefined;
403
- }> {
404
- const artifact = await this.contractStore.getContractArtifact(id);
405
- if (!artifact) {
406
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
407
- }
408
-
409
- return {
410
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
411
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
412
- artifact: includeArtifact ? artifact : undefined,
413
- };
496
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
497
+ return this.contractStore.getContractInstance(address);
414
498
  }
415
499
 
416
500
  /**
417
- * Returns the contract metadata given an address.
418
- * The metadata consists of its contract instance, which includes the contract class identifier,
419
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
420
- * and whether the contract instance with the given address has been publicly deployed.
421
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
422
- * This query is not dependent on the PXE.
423
- * @param address - The address that the contract instance resides at.
424
- * @returns - It returns the contract metadata
425
- * TODO(@spalladino): Should we return the public keys in plain as well here?
501
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
502
+ * @param id - Identifier of the contract class.
503
+ * @returns The contract artifact if found, undefined otherwise.
426
504
  */
427
- public async getContractMetadata(address: AztecAddress): Promise<{
428
- contractInstance: ContractInstanceWithAddress | undefined;
429
- isContractInitialized: boolean;
430
- isContractPublished: boolean;
431
- }> {
432
- let instance;
433
- try {
434
- instance = await this.contractStore.getContractInstance(address);
435
- } catch {
436
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
437
- }
438
- return {
439
- contractInstance: instance,
440
- isContractInitialized: await this.#isContractInitialized(address),
441
- isContractPublished: await this.#isContractPublished(address),
442
- };
505
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
506
+ return await this.contractStore.getContractArtifact(id);
443
507
  }
444
508
 
445
509
  /**
@@ -464,7 +528,6 @@ export class PXE {
464
528
  }
465
529
 
466
530
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
467
- await this.noteStore.addScope(accountCompleteAddress.address);
468
531
  return accountCompleteAddress;
469
532
  }
470
533
 
@@ -612,13 +675,7 @@ export class PXE {
612
675
 
613
676
  const header = await this.anchorBlockStore.getBlockHeader();
614
677
 
615
- const currentClassId = await readCurrentClassId(
616
- contractAddress,
617
- currentInstance,
618
- this.node,
619
- header.globalVariables.blockNumber,
620
- header.globalVariables.timestamp,
621
- );
678
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
622
679
  if (!contractClass.id.equals(currentClassId)) {
623
680
  throw new Error('Could not update contract to a class different from the current one.');
624
681
  }
@@ -649,22 +706,23 @@ export class PXE {
649
706
  * (where validators prove the public portion).
650
707
  *
651
708
  * @param txRequest - An authenticated tx request ready for proving
709
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
652
710
  * @returns A result containing the proof and public inputs of the tail circuit.
653
711
  * @throws If contract code not found, or public simulation reverts.
654
712
  * Also throws if simulatePublic is true and public simulation reverts.
655
713
  */
656
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
714
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
657
715
  let privateExecutionResult: PrivateExecutionResult;
658
716
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
659
717
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
660
- return this.#putInJobQueue(async () => {
718
+ return this.#putInJobQueue(async jobId => {
661
719
  const totalTimer = new Timer();
662
720
  try {
663
721
  const syncTimer = new Timer();
664
722
  await this.blockStateSynchronizer.sync();
665
723
  const syncTime = syncTimer.ms();
666
724
  const contractFunctionSimulator = this.#getSimulatorForTx();
667
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
725
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
668
726
 
669
727
  const {
670
728
  publicInputs,
@@ -711,7 +769,7 @@ export class PXE {
711
769
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
712
770
  const txHash = (await txProvingResult.toTx()).txHash;
713
771
 
714
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
772
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
715
773
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
716
774
  preTagsUsedInTheTx,
717
775
  });
@@ -728,20 +786,16 @@ export class PXE {
728
786
 
729
787
  /**
730
788
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
731
- *
732
- * @param txRequest - An authenticated tx request ready for simulation
733
- * @param msgSender - (Optional) The message sender to use for the simulation.
734
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
789
+ * @param txRequest - An authenticated tx request ready for simulation.
735
790
  * @returns A trace of the program execution with gate counts.
736
791
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
737
792
  */
738
793
  public profileTx(
739
794
  txRequest: TxExecutionRequest,
740
- profileMode: 'full' | 'execution-steps' | 'gates',
741
- skipProofGeneration: boolean = true,
795
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
742
796
  ): Promise<TxProfileResult> {
743
797
  // We disable concurrent profiles for consistency with simulateTx.
744
- return this.#putInJobQueue(async () => {
798
+ return this.#putInJobQueue(async jobId => {
745
799
  const totalTimer = new Timer();
746
800
  try {
747
801
  const txInfo = {
@@ -761,7 +815,7 @@ export class PXE {
761
815
  const syncTime = syncTimer.ms();
762
816
 
763
817
  const contractFunctionSimulator = this.#getSimulatorForTx();
764
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
818
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
765
819
 
766
820
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
767
821
  txRequest,
@@ -818,12 +872,7 @@ export class PXE {
818
872
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
819
873
  *
820
874
  *
821
- * @param txRequest - An authenticated tx request ready for simulation
822
- * @param simulatePublic - Whether to simulate the public part of the transaction.
823
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
824
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
825
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
826
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
875
+ * @param txRequest - An authenticated tx request ready for simulation.
827
876
  * @returns A simulated transaction result object that includes public and private return values.
828
877
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
829
878
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -832,16 +881,12 @@ export class PXE {
832
881
  */
833
882
  public simulateTx(
834
883
  txRequest: TxExecutionRequest,
835
- simulatePublic: boolean,
836
- skipTxValidation: boolean = false,
837
- skipFeeEnforcement: boolean = false,
838
- overrides?: SimulationOverrides,
839
- scopes?: AztecAddress[],
884
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
840
885
  ): Promise<TxSimulationResult> {
841
886
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
842
887
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
843
888
  // delete the same read value, or reading values that another simulation is currently modifying).
844
- return this.#putInJobQueue(async () => {
889
+ return this.#putInJobQueue(async jobId => {
845
890
  try {
846
891
  const totalTimer = new Timer();
847
892
  const txInfo = {
@@ -864,24 +909,26 @@ export class PXE {
864
909
  // Temporary: in case there are overrides, we have to skip the kernels or validations
865
910
  // will fail. Consider handing control to the user/wallet on whether they want to run them
866
911
  // or not.
867
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
912
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
913
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
914
+ const skipKernels = hasOverriddenContracts;
915
+
916
+ // Set overridden contracts on the sync service so it knows to skip syncing them
917
+ if (hasOverriddenContracts) {
918
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
919
+ }
868
920
 
869
921
  // Execution of private functions only; no proving, and no kernel logic.
870
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
922
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
871
923
 
872
924
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
873
925
  let executionSteps: PrivateExecutionStep[] = [];
874
926
 
875
927
  if (skipKernels) {
876
- // According to the protocol rules, the nonce generator for the note hashes
877
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
878
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
879
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
880
- : privateExecutionResult.firstNullifier;
881
928
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
882
929
  privateExecutionResult,
883
- nonceGenerator,
884
- this.contractStore,
930
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
931
+ this.node,
885
932
  ));
886
933
  } else {
887
934
  // Kernel logic, plus proving of all private functions and kernels.
@@ -959,30 +1006,24 @@ export class PXE {
959
1006
  inspect(txRequest),
960
1007
  `simulatePublic=${simulatePublic}`,
961
1008
  `skipTxValidation=${skipTxValidation}`,
962
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1009
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
963
1010
  );
964
1011
  }
965
1012
  });
966
1013
  }
967
1014
 
968
1015
  /**
969
- * Simulate the execution of a contract utility function.
970
- *
1016
+ * Executes a contract utility function.
971
1017
  * @param call - The function call containing the function details, arguments, and target contract address.
972
- * @param authwits - (Optional) The authentication witnesses required for the function call.
973
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
974
- * default to all.
975
- * @returns The result of the utility function call, structured based on the function ABI.
976
1018
  */
977
- public simulateUtility(
1019
+ public executeUtility(
978
1020
  call: FunctionCall,
979
- authwits?: AuthWitness[],
980
- scopes?: AztecAddress[],
981
- ): Promise<UtilitySimulationResult> {
982
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1021
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1022
+ ): Promise<UtilityExecutionResult> {
1023
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
983
1024
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
984
- // delete the same read value, or reading values that another simulation is currently modifying).
985
- return this.#putInJobQueue(async () => {
1025
+ // delete the same read value, or reading values that another execution is currently modifying).
1026
+ return this.#putInJobQueue(async jobId => {
986
1027
  try {
987
1028
  const totalTimer = new Timer();
988
1029
  const syncTimer = new Timer();
@@ -990,7 +1031,25 @@ export class PXE {
990
1031
  const syncTime = syncTimer.ms();
991
1032
  const functionTimer = new Timer();
992
1033
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
1034
+
1035
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1036
+ await this.contractSyncService.ensureContractSynced(
1037
+ call.to,
1038
+ call.selector,
1039
+ (privateSyncCall, execScopes) =>
1040
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1041
+ anchorBlockHeader,
1042
+ jobId,
1043
+ scopes,
1044
+ );
1045
+
1046
+ const executionResult = await this.#executeUtility(
1047
+ contractFunctionSimulator,
1048
+ call,
1049
+ authwits ?? [],
1050
+ scopes,
1051
+ jobId,
1052
+ );
994
1053
  const functionTime = functionTimer.ms();
995
1054
 
996
1055
  const totalTime = totalTimer.ms();
@@ -1011,8 +1070,8 @@ export class PXE {
1011
1070
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1012
1071
  throw this.#contextualizeError(
1013
1072
  err,
1014
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1015
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1073
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1074
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1016
1075
  );
1017
1076
  }
1018
1077
  });
@@ -1035,11 +1094,29 @@ export class PXE {
1035
1094
  eventSelector: EventSelector,
1036
1095
  filter: PrivateEventFilter,
1037
1096
  ): Promise<PackedPrivateEvent[]> {
1038
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
1039
- const call = await this.contractStore.getFunctionCall('sync_private_state', [], filter.contractAddress);
1040
- await this.simulateUtility(call);
1097
+ let anchorBlockNumber: BlockNumber;
1098
+
1099
+ await this.#putInJobQueue(async jobId => {
1100
+ await this.blockStateSynchronizer.sync();
1101
+
1102
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1103
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1104
+
1105
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1106
+
1107
+ await this.contractSyncService.ensureContractSynced(
1108
+ filter.contractAddress,
1109
+ null,
1110
+ async (privateSyncCall, execScopes) =>
1111
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1112
+ anchorBlockHeader,
1113
+ jobId,
1114
+ filter.scopes,
1115
+ );
1116
+ });
1041
1117
 
1042
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1118
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1119
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1043
1120
 
1044
1121
  this.log.debug(
1045
1122
  `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,