@aztec/pxe 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c

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 (266) 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 -82
  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 +44 -50
  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 +83 -54
  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 +131 -110
  52. package/dest/contract_logging.d.ts +22 -0
  53. package/dest/contract_logging.d.ts.map +1 -0
  54. package/dest/contract_logging.js +23 -0
  55. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  56. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  57. package/dest/contract_sync/contract_sync_service.js +97 -0
  58. package/dest/contract_sync/helpers.d.ts +29 -0
  59. package/dest/contract_sync/helpers.d.ts.map +1 -0
  60. package/dest/contract_sync/helpers.js +55 -0
  61. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  62. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  63. package/dest/debug/pxe_debug_utils.js +28 -17
  64. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  65. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  66. package/dest/entrypoints/client/bundle/index.js +3 -0
  67. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  68. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  69. package/dest/entrypoints/client/bundle/utils.js +31 -8
  70. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  71. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  72. package/dest/entrypoints/client/lazy/index.js +3 -0
  73. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  74. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  75. package/dest/entrypoints/client/lazy/utils.js +32 -9
  76. package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
  77. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  78. package/dest/entrypoints/server/index.d.ts +5 -1
  79. package/dest/entrypoints/server/index.d.ts.map +1 -1
  80. package/dest/entrypoints/server/index.js +4 -0
  81. package/dest/entrypoints/server/utils.d.ts +1 -1
  82. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/server/utils.js +39 -16
  84. package/dest/events/event_service.d.ts +6 -6
  85. package/dest/events/event_service.d.ts.map +1 -1
  86. package/dest/events/event_service.js +19 -22
  87. package/dest/events/private_event_filter_validator.d.ts +5 -5
  88. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  89. package/dest/events/private_event_filter_validator.js +5 -6
  90. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  91. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  92. package/dest/job_coordinator/job_coordinator.js +94 -0
  93. package/dest/logs/log_service.d.ts +8 -5
  94. package/dest/logs/log_service.d.ts.map +1 -1
  95. package/dest/logs/log_service.js +28 -30
  96. package/dest/notes/note_service.d.ts +10 -9
  97. package/dest/notes/note_service.d.ts.map +1 -1
  98. package/dest/notes/note_service.js +34 -38
  99. package/dest/notes_filter.d.ts +25 -0
  100. package/dest/notes_filter.d.ts.map +1 -0
  101. package/dest/notes_filter.js +4 -0
  102. package/dest/oracle_version.d.ts +3 -3
  103. package/dest/oracle_version.d.ts.map +1 -1
  104. package/dest/oracle_version.js +4 -3
  105. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  106. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  107. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  108. package/dest/private_kernel/hints/index.d.ts +3 -3
  109. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  110. package/dest/private_kernel/hints/index.js +2 -2
  111. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  112. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  113. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +16 -10
  114. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  115. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  116. package/dest/private_kernel/private_kernel_execution_prover.js +12 -13
  117. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -24
  118. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  119. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  120. package/dest/pxe.d.ts +76 -58
  121. package/dest/pxe.d.ts.map +1 -1
  122. package/dest/pxe.js +149 -138
  123. package/dest/storage/address_store/address_store.d.ts +1 -1
  124. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  125. package/dest/storage/address_store/address_store.js +12 -11
  126. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  127. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  128. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  129. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  130. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  131. package/dest/storage/capsule_store/capsule_store.js +130 -23
  132. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  133. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  134. package/dest/storage/contract_store/contract_store.js +157 -84
  135. package/dest/storage/metadata.d.ts +1 -1
  136. package/dest/storage/metadata.js +1 -1
  137. package/dest/storage/note_store/note_store.d.ts +50 -51
  138. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  139. package/dest/storage/note_store/note_store.js +284 -263
  140. package/dest/storage/note_store/stored_note.d.ts +16 -0
  141. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  142. package/dest/storage/note_store/stored_note.js +43 -0
  143. package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
  144. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  145. package/dest/storage/private_event_store/private_event_store.js +231 -73
  146. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  147. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  148. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  149. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  150. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  151. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  152. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  153. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  154. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  155. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  156. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  157. package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
  158. package/dest/tagging/constants.d.ts +2 -0
  159. package/dest/tagging/constants.d.ts.map +1 -0
  160. package/dest/tagging/constants.js +10 -0
  161. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  162. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  163. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  164. package/dest/tagging/index.d.ts +3 -2
  165. package/dest/tagging/index.d.ts.map +1 -1
  166. package/dest/tagging/index.js +2 -10
  167. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  168. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  169. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +12 -12
  170. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  171. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  172. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  173. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  174. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  175. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  176. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
  177. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  178. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  179. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  180. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  181. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  182. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  183. package/package.json +27 -18
  184. package/src/access_scopes.ts +9 -0
  185. package/src/bin/check_oracle_version.ts +1 -0
  186. package/src/block_synchronizer/block_synchronizer.ts +93 -32
  187. package/src/config/index.ts +14 -0
  188. package/src/config/package_info.ts +1 -1
  189. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  190. package/src/contract_function_simulator/contract_function_simulator.ts +350 -143
  191. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  192. package/src/contract_function_simulator/index.ts +1 -1
  193. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  194. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  195. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  196. package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
  197. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  198. package/src/contract_function_simulator/oracle/oracle.ts +79 -47
  199. package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
  200. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +119 -137
  201. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +198 -115
  202. package/src/contract_logging.ts +39 -0
  203. package/src/contract_sync/contract_sync_service.ts +152 -0
  204. package/src/contract_sync/helpers.ts +98 -0
  205. package/src/debug/pxe_debug_utils.ts +63 -18
  206. package/src/entrypoints/client/bundle/index.ts +3 -0
  207. package/src/entrypoints/client/bundle/utils.ts +23 -16
  208. package/src/entrypoints/client/lazy/index.ts +3 -0
  209. package/src/entrypoints/client/lazy/utils.ts +24 -17
  210. package/src/entrypoints/pxe_creation_options.ts +4 -2
  211. package/src/entrypoints/server/index.ts +4 -0
  212. package/src/entrypoints/server/utils.ts +33 -41
  213. package/src/events/event_service.ts +19 -25
  214. package/src/events/private_event_filter_validator.ts +3 -5
  215. package/src/job_coordinator/job_coordinator.ts +150 -0
  216. package/src/logs/log_service.ts +40 -34
  217. package/src/notes/note_service.ts +41 -45
  218. package/src/notes_filter.ts +26 -0
  219. package/src/oracle_version.ts +4 -3
  220. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  221. package/src/private_kernel/hints/index.ts +2 -2
  222. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +39 -28
  223. package/src/private_kernel/private_kernel_execution_prover.ts +15 -14
  224. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  225. package/src/pxe.ts +280 -209
  226. package/src/storage/address_store/address_store.ts +15 -15
  227. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  228. package/src/storage/capsule_store/capsule_store.ts +159 -23
  229. package/src/storage/contract_store/contract_store.ts +186 -96
  230. package/src/storage/metadata.ts +1 -1
  231. package/src/storage/note_store/note_store.ts +326 -320
  232. package/src/storage/note_store/stored_note.ts +48 -0
  233. package/src/storage/private_event_store/private_event_store.ts +301 -79
  234. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  235. package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
  236. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  237. package/src/storage/tagging_store/sender_tagging_store.ts +294 -109
  238. package/src/tagging/constants.ts +10 -0
  239. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  240. package/src/tagging/index.ts +2 -11
  241. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +25 -11
  242. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  243. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  244. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
  245. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
  246. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  247. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  248. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  249. package/dest/contract_function_simulator/proxied_node.js +0 -27
  250. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  251. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  252. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  253. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  254. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  255. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  256. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  257. package/dest/public_storage/public_storage_service.d.ts +0 -24
  258. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  259. package/dest/public_storage/public_storage_service.js +0 -26
  260. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  261. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  262. package/dest/tree_membership/tree_membership_service.js +0 -84
  263. package/src/contract_function_simulator/proxied_node.ts +0 -33
  264. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  265. package/src/public_storage/public_storage_service.ts +0 -33
  266. 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,32 @@ 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 { displayDebugLogs } from './contract_logging.js';
65
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
66
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
70
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
66
71
  import {
67
72
  PrivateKernelExecutionProver,
68
73
  type PrivateKernelExecutionProverConfig,
69
74
  } from './private_kernel/private_kernel_execution_prover.js';
70
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
75
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
71
76
  import { AddressStore } from './storage/address_store/address_store.js';
72
77
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
78
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -83,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
83
88
  eventSelector: EventSelector;
84
89
  };
85
90
 
91
+ /** Options for PXE.profileTx. */
92
+ export type ProfileTxOpts = {
93
+ /** The profiling mode to use. */
94
+ profileMode: 'full' | 'execution-steps' | 'gates';
95
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
96
+ skipProofGeneration?: boolean;
97
+ /** Addresses whose private state and keys are accessible during private execution. */
98
+ scopes: AccessScopes;
99
+ };
100
+
101
+ /** Options for PXE.simulateTx. */
102
+ export type SimulateTxOpts = {
103
+ /** Whether to simulate the public part of the transaction. */
104
+ simulatePublic: boolean;
105
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
106
+ skipTxValidation?: boolean;
107
+ /** If false, fees are enforced. */
108
+ skipFeeEnforcement?: boolean;
109
+ /** State overrides for the simulation, such as contract instances and artifacts. */
110
+ overrides?: SimulationOverrides;
111
+ /** Addresses whose private state and keys are accessible during private execution */
112
+ scopes: AccessScopes;
113
+ };
114
+
115
+ /** Options for PXE.executeUtility. */
116
+ export type ExecuteUtilityOpts = {
117
+ /** The authentication witnesses required for the function call. */
118
+ authwits?: AuthWitness[];
119
+ /** The accounts whose notes we can access in this call */
120
+ scopes: AccessScopes;
121
+ };
122
+
123
+ /** Args for PXE.create. */
124
+ export type PXECreateArgs = {
125
+ /** The Aztec node to connect to. */
126
+ node: AztecNode;
127
+ /** The key-value store for persisting PXE state. */
128
+ store: AztecAsyncKVStore;
129
+ /** The prover for generating private kernel proofs. */
130
+ proofCreator: PrivateKernelProver;
131
+ /** The circuit simulator for executing ACIR circuits. */
132
+ simulator: CircuitSimulator;
133
+ /** Provider for protocol contract artifacts and instances. */
134
+ protocolContractsProvider: ProtocolContractsProvider;
135
+ /** PXE configuration options. */
136
+ config: PXEConfig;
137
+ /** Optional logger instance or string suffix for the logger name. */
138
+ loggerOrSuffix?: string | Logger;
139
+ };
140
+
86
141
  /**
87
142
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
88
143
  * manage private state of users.
@@ -101,12 +156,14 @@ export class PXE {
101
156
  private recipientTaggingStore: RecipientTaggingStore,
102
157
  private addressStore: AddressStore,
103
158
  private privateEventStore: PrivateEventStore,
159
+ private contractSyncService: ContractSyncService,
104
160
  private simulator: CircuitSimulator,
105
161
  private proverEnabled: boolean,
106
162
  private proofCreator: PrivateKernelProver,
107
163
  private protocolContractsProvider: ProtocolContractsProvider,
108
164
  private log: Logger,
109
165
  private jobQueue: SerialQueue,
166
+ private jobCoordinator: JobCoordinator,
110
167
  public debug: PXEDebugUtils,
111
168
  ) {}
112
169
 
@@ -117,25 +174,31 @@ export class PXE {
117
174
  *
118
175
  * @returns A promise that resolves PXE is ready to be used.
119
176
  */
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
- ) {
177
+ public static async create({
178
+ node,
179
+ store,
180
+ proofCreator,
181
+ simulator,
182
+ protocolContractsProvider,
183
+ config,
184
+ loggerOrSuffix,
185
+ }: PXECreateArgs) {
186
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
187
+ const bindings: LoggerBindings | undefined =
188
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
189
+
129
190
  const log =
130
191
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
131
192
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
132
193
  : loggerOrSuffix;
133
194
 
134
- const proverEnabled = !!config.proverEnabled;
195
+ const info = await node.getNodeInfo();
196
+
197
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
135
198
  const addressStore = new AddressStore(store);
136
199
  const privateEventStore = new PrivateEventStore(store);
137
200
  const contractStore = new ContractStore(store);
138
- const noteStore = await NoteStore.create(store);
201
+ const noteStore = new NoteStore(store);
139
202
  const anchorBlockStore = new AnchorBlockStore(store);
140
203
  const senderTaggingStore = new SenderTaggingStore(store);
141
204
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -143,9 +206,35 @@ export class PXE {
143
206
  const capsuleStore = new CapsuleStore(store);
144
207
  const keyStore = new KeyStore(store);
145
208
  const tipsStore = new L2TipsKVStore(store, 'pxe');
146
- const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, tipsStore, config, loggerOrSuffix);
209
+ const contractSyncService = new ContractSyncService(
210
+ node,
211
+ contractStore,
212
+ noteStore,
213
+ createLogger('pxe:contract_sync', bindings),
214
+ );
215
+ const synchronizer = new BlockSynchronizer(
216
+ node,
217
+ store,
218
+ anchorBlockStore,
219
+ noteStore,
220
+ privateEventStore,
221
+ tipsStore,
222
+ contractSyncService,
223
+ config,
224
+ bindings,
225
+ );
147
226
 
148
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
227
+ const jobCoordinator = new JobCoordinator(store, bindings);
228
+ jobCoordinator.registerStores([
229
+ capsuleStore,
230
+ senderTaggingStore,
231
+ recipientTaggingStore,
232
+ privateEventStore,
233
+ noteStore,
234
+ contractSyncService,
235
+ ]);
236
+
237
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
149
238
 
150
239
  const jobQueue = new SerialQueue();
151
240
 
@@ -162,21 +251,26 @@ export class PXE {
162
251
  recipientTaggingStore,
163
252
  addressStore,
164
253
  privateEventStore,
254
+ contractSyncService,
165
255
  simulator,
166
256
  proverEnabled,
167
257
  proofCreator,
168
258
  protocolContractsProvider,
169
259
  log,
170
260
  jobQueue,
261
+ jobCoordinator,
171
262
  debugUtils,
172
263
  );
173
264
 
174
- debugUtils.setPXE(pxe);
265
+ debugUtils.setPXEHelpers(
266
+ pxe.#putInJobQueue.bind(pxe),
267
+ pxe.#getSimulatorForTx.bind(pxe),
268
+ pxe.#executeUtility.bind(pxe),
269
+ );
175
270
 
176
271
  pxe.jobQueue.start();
177
272
 
178
273
  await pxe.#registerProtocolContracts();
179
- const info = await node.getNodeInfo();
180
274
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
181
275
  return pxe;
182
276
  }
@@ -186,20 +280,20 @@ export class PXE {
186
280
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
187
281
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
188
282
 
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
- );
283
+ return new ContractFunctionSimulator({
284
+ contractStore: proxyContractStore,
285
+ noteStore: this.noteStore,
286
+ keyStore: this.keyStore,
287
+ addressStore: this.addressStore,
288
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
289
+ senderTaggingStore: this.senderTaggingStore,
290
+ recipientTaggingStore: this.recipientTaggingStore,
291
+ senderAddressBookStore: this.senderAddressBookStore,
292
+ capsuleStore: this.capsuleStore,
293
+ privateEventStore: this.privateEventStore,
294
+ simulator: this.simulator,
295
+ contractSyncService: this.contractSyncService,
296
+ });
203
297
  }
204
298
 
205
299
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -222,7 +316,7 @@ export class PXE {
222
316
  *
223
317
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
224
318
  */
225
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
319
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
226
320
  // TODO(#12636): relax the conditions under which we forbid concurrency.
227
321
  if (this.jobQueue.length() != 0) {
228
322
  this.log.warn(
@@ -230,57 +324,65 @@ export class PXE {
230
324
  );
231
325
  }
232
326
 
233
- return this.jobQueue.put(fn);
327
+ return this.jobQueue.put(async () => {
328
+ const jobId = this.jobCoordinator.beginJob();
329
+ this.log.verbose(`Beginning job ${jobId}`);
330
+
331
+ try {
332
+ const result = await fn(jobId);
333
+ this.log.verbose(`Committing job ${jobId}`);
334
+
335
+ await this.jobCoordinator.commitJob(jobId);
336
+ return result;
337
+ } catch (err) {
338
+ this.log.verbose(`Aborting job ${jobId}`);
339
+ await this.jobCoordinator.abortJob(jobId);
340
+ throw err;
341
+ }
342
+ });
234
343
  }
235
344
 
236
345
  async #registerProtocolContracts() {
237
346
  const registered: Record<string, string> = {};
238
347
  for (const name of protocolContractNames) {
239
- const { address, contractClass, instance, artifact } =
240
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
241
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
348
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
349
+ await this.contractStore.addContractArtifact(artifact);
242
350
  await this.contractStore.addContractInstance(instance);
243
351
  registered[name] = address.toString();
244
352
  }
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
 
@@ -538,8 +601,7 @@ export class PXE {
538
601
  * @param artifact - The build artifact for the contract class.
539
602
  */
540
603
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
541
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
542
- await this.contractStore.addContractArtifact(contractClassId, artifact);
604
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
543
605
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
544
606
  }
545
607
 
@@ -558,17 +620,17 @@ export class PXE {
558
620
  if (artifact) {
559
621
  // If the user provides an artifact, validate it against the expected class id and register it
560
622
  const contractClass = await getContractClassFromArtifact(artifact);
561
- const contractClassId = contractClass.id;
562
- if (!contractClassId.equals(instance.currentContractClassId)) {
623
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
563
624
  throw new Error(
564
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
625
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
565
626
  );
566
627
  }
567
628
  const computedAddress = await computeContractAddressFromInstance(instance);
568
629
  if (!computedAddress.equals(instance.address)) {
569
630
  throw new Error('Added a contract in which the address does not match the contract instance.');
570
631
  }
571
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
632
+
633
+ await this.contractStore.addContractArtifact(artifact, contractClass);
572
634
 
573
635
  const publicFunctionSignatures = artifact.functions
574
636
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -612,26 +674,21 @@ export class PXE {
612
674
 
613
675
  const header = await this.anchorBlockStore.getBlockHeader();
614
676
 
615
- const currentClassId = await readCurrentClassId(
616
- contractAddress,
617
- currentInstance,
618
- this.node,
619
- header.globalVariables.blockNumber,
620
- header.globalVariables.timestamp,
621
- );
677
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
622
678
  if (!contractClass.id.equals(currentClassId)) {
623
679
  throw new Error('Could not update contract to a class different from the current one.');
624
680
  }
625
681
 
626
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
627
-
628
682
  const publicFunctionSignatures = artifact.functions
629
683
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
630
684
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
631
685
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
632
686
 
633
687
  currentInstance.currentContractClassId = contractClass.id;
634
- await this.contractStore.addContractInstance(currentInstance);
688
+ await Promise.all([
689
+ this.contractStore.addContractArtifact(artifact, contractClass),
690
+ this.contractStore.addContractInstance(currentInstance),
691
+ ]);
635
692
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
636
693
  });
637
694
  }
@@ -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.
@@ -900,6 +947,9 @@ export class PXE {
900
947
  const publicSimulationTimer = new Timer();
901
948
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
902
949
  publicSimulationTime = publicSimulationTimer.ms();
950
+ if (publicOutput?.debugLogs?.length) {
951
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
952
+ }
903
953
  }
904
954
 
905
955
  let validationTime: number | undefined;
@@ -959,30 +1009,24 @@ export class PXE {
959
1009
  inspect(txRequest),
960
1010
  `simulatePublic=${simulatePublic}`,
961
1011
  `skipTxValidation=${skipTxValidation}`,
962
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1012
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
963
1013
  );
964
1014
  }
965
1015
  });
966
1016
  }
967
1017
 
968
1018
  /**
969
- * Simulate the execution of a contract utility function.
970
- *
1019
+ * Executes a contract utility function.
971
1020
  * @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
1021
  */
977
- public simulateUtility(
1022
+ public executeUtility(
978
1023
  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.
1024
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1025
+ ): Promise<UtilityExecutionResult> {
1026
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
983
1027
  // 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 () => {
1028
+ // delete the same read value, or reading values that another execution is currently modifying).
1029
+ return this.#putInJobQueue(async jobId => {
986
1030
  try {
987
1031
  const totalTimer = new Timer();
988
1032
  const syncTimer = new Timer();
@@ -991,11 +1035,24 @@ export class PXE {
991
1035
  const functionTimer = new Timer();
992
1036
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
1037
 
994
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
995
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
1038
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1039
+ await this.contractSyncService.ensureContractSynced(
1040
+ call.to,
1041
+ call.selector,
1042
+ (privateSyncCall, execScopes) =>
1043
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1044
+ anchorBlockHeader,
1045
+ jobId,
1046
+ scopes,
996
1047
  );
997
1048
 
998
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
1049
+ const executionResult = await this.#executeUtility(
1050
+ contractFunctionSimulator,
1051
+ call,
1052
+ authwits ?? [],
1053
+ scopes,
1054
+ jobId,
1055
+ );
999
1056
  const functionTime = functionTimer.ms();
1000
1057
 
1001
1058
  const totalTime = totalTimer.ms();
@@ -1016,8 +1073,8 @@ export class PXE {
1016
1073
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1017
1074
  throw this.#contextualizeError(
1018
1075
  err,
1019
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1020
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1076
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1077
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1021
1078
  );
1022
1079
  }
1023
1080
  });
@@ -1036,25 +1093,39 @@ export class PXE {
1036
1093
  * Defaults to the latest known block to PXE + 1.
1037
1094
  * @returns - The packed events with block and tx metadata.
1038
1095
  */
1039
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1040
- return this.#putInJobQueue(async () => {
1096
+ public async getPrivateEvents(
1097
+ eventSelector: EventSelector,
1098
+ filter: PrivateEventFilter,
1099
+ ): Promise<PackedPrivateEvent[]> {
1100
+ let anchorBlockNumber: BlockNumber;
1101
+
1102
+ await this.#putInJobQueue(async jobId => {
1041
1103
  await this.blockStateSynchronizer.sync();
1104
+
1105
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1106
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1107
+
1042
1108
  const contractFunctionSimulator = this.#getSimulatorForTx();
1043
1109
 
1044
- await this.contractStore.syncPrivateState(
1110
+ await this.contractSyncService.ensureContractSynced(
1045
1111
  filter.contractAddress,
1046
1112
  null,
1047
- async privateSyncCall => await this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
1113
+ async (privateSyncCall, execScopes) =>
1114
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1115
+ anchorBlockHeader,
1116
+ jobId,
1117
+ filter.scopes,
1048
1118
  );
1119
+ });
1049
1120
 
1050
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1121
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1122
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1051
1123
 
1052
- this.log.debug(
1053
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1054
- );
1124
+ this.log.debug(
1125
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1126
+ );
1055
1127
 
1056
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1057
- });
1128
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1058
1129
  }
1059
1130
 
1060
1131
  /**