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

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 (209) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +10 -4
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +66 -18
  4. package/dest/config/index.d.ts +3 -1
  5. package/dest/config/index.d.ts.map +1 -1
  6. package/dest/config/index.js +17 -0
  7. package/dest/config/package_info.js +1 -1
  8. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  10. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -9
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +33 -19
  14. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  17. package/dest/contract_function_simulator/index.d.ts +2 -2
  18. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/index.js +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -2
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -2
  23. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  24. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  26. package/dest/contract_function_simulator/oracle/interfaces.d.ts +14 -10
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  29. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  31. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  33. package/dest/contract_function_simulator/oracle/oracle.d.ts +9 -7
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/oracle.js +41 -30
  36. package/dest/contract_function_simulator/oracle/private_execution.d.ts +8 -13
  37. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/private_execution.js +21 -11
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +16 -18
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +25 -38
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +26 -16
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +71 -71
  45. package/dest/debug/pxe_debug_utils.d.ts +1 -1
  46. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  47. package/dest/debug/pxe_debug_utils.js +2 -1
  48. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/utils.js +10 -1
  51. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  52. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  53. package/dest/entrypoints/client/lazy/utils.js +10 -1
  54. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  55. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  56. package/dest/entrypoints/server/index.d.ts +2 -1
  57. package/dest/entrypoints/server/index.d.ts.map +1 -1
  58. package/dest/entrypoints/server/index.js +1 -0
  59. package/dest/entrypoints/server/utils.d.ts +1 -1
  60. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/server/utils.js +11 -7
  62. package/dest/events/event_service.d.ts +4 -3
  63. package/dest/events/event_service.d.ts.map +1 -1
  64. package/dest/events/event_service.js +17 -19
  65. package/dest/events/private_event_filter_validator.d.ts +5 -5
  66. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  67. package/dest/events/private_event_filter_validator.js +5 -6
  68. package/dest/job_coordinator/job_coordinator.d.ts +74 -0
  69. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  70. package/dest/job_coordinator/job_coordinator.js +93 -0
  71. package/dest/logs/log_service.d.ts +3 -2
  72. package/dest/logs/log_service.d.ts.map +1 -1
  73. package/dest/logs/log_service.js +22 -13
  74. package/dest/notes/note_service.d.ts +5 -4
  75. package/dest/notes/note_service.d.ts.map +1 -1
  76. package/dest/notes/note_service.js +31 -34
  77. package/dest/oracle_version.d.ts +3 -3
  78. package/dest/oracle_version.d.ts.map +1 -1
  79. package/dest/oracle_version.js +4 -3
  80. package/dest/private_kernel/hints/index.d.ts +2 -2
  81. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  82. package/dest/private_kernel/hints/index.js +1 -1
  83. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  84. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  85. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  86. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  87. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  88. package/dest/private_kernel/private_kernel_execution_prover.js +4 -5
  89. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  90. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  91. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  92. package/dest/pxe.d.ts +8 -36
  93. package/dest/pxe.d.ts.map +1 -1
  94. package/dest/pxe.js +71 -90
  95. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  96. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  97. package/dest/storage/capsule_store/capsule_store.js +132 -23
  98. package/dest/storage/contract_store/contract_store.d.ts +2 -1
  99. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  100. package/dest/storage/contract_store/contract_store.js +12 -0
  101. package/dest/storage/note_store/note_store.d.ts +45 -56
  102. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  103. package/dest/storage/note_store/note_store.js +244 -263
  104. package/dest/storage/note_store/stored_note.d.ts +16 -0
  105. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  106. package/dest/storage/note_store/stored_note.js +43 -0
  107. package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
  108. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  109. package/dest/storage/private_event_store/private_event_store.js +203 -68
  110. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  111. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  112. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  113. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  114. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  115. package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
  116. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  117. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  118. package/dest/storage/tagging_store/sender_tagging_store.js +110 -28
  119. package/dest/tagging/constants.d.ts +2 -0
  120. package/dest/tagging/constants.d.ts.map +1 -0
  121. package/dest/tagging/constants.js +10 -0
  122. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  123. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  124. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  125. package/dest/tagging/index.d.ts +3 -2
  126. package/dest/tagging/index.d.ts.map +1 -1
  127. package/dest/tagging/index.js +2 -10
  128. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  129. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  130. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -8
  131. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  132. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  133. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  134. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  135. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  136. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
  137. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  138. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  139. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  140. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  141. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  142. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  143. package/package.json +18 -18
  144. package/src/block_synchronizer/block_synchronizer.ts +77 -20
  145. package/src/config/index.ts +14 -0
  146. package/src/config/package_info.ts +1 -1
  147. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  148. package/src/contract_function_simulator/contract_function_simulator.ts +39 -21
  149. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  150. package/src/contract_function_simulator/index.ts +1 -1
  151. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +4 -0
  152. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  153. package/src/contract_function_simulator/oracle/interfaces.ts +19 -9
  154. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  155. package/src/contract_function_simulator/oracle/oracle.ts +54 -39
  156. package/src/contract_function_simulator/oracle/private_execution.ts +30 -20
  157. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +44 -42
  158. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +89 -75
  159. package/src/debug/pxe_debug_utils.ts +2 -1
  160. package/src/entrypoints/client/bundle/utils.ts +7 -1
  161. package/src/entrypoints/client/lazy/utils.ts +7 -2
  162. package/src/entrypoints/pxe_creation_options.ts +2 -1
  163. package/src/entrypoints/server/index.ts +1 -0
  164. package/src/entrypoints/server/utils.ts +11 -15
  165. package/src/events/event_service.ts +17 -21
  166. package/src/events/private_event_filter_validator.ts +3 -5
  167. package/src/job_coordinator/job_coordinator.ts +149 -0
  168. package/src/logs/log_service.ts +28 -9
  169. package/src/notes/note_service.ts +38 -40
  170. package/src/oracle_version.ts +4 -3
  171. package/src/private_kernel/hints/index.ts +1 -1
  172. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
  173. package/src/private_kernel/private_kernel_execution_prover.ts +3 -5
  174. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  175. package/src/pxe.ts +125 -119
  176. package/src/storage/capsule_store/capsule_store.ts +159 -23
  177. package/src/storage/contract_store/contract_store.ts +20 -0
  178. package/src/storage/note_store/note_store.ts +286 -317
  179. package/src/storage/note_store/stored_note.ts +48 -0
  180. package/src/storage/private_event_store/private_event_store.ts +277 -76
  181. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  182. package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
  183. package/src/storage/tagging_store/sender_tagging_store.ts +129 -28
  184. package/src/tagging/constants.ts +10 -0
  185. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  186. package/src/tagging/index.ts +2 -11
  187. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +21 -7
  188. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  189. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
  190. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
  191. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  192. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  193. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  194. package/dest/contract_function_simulator/proxied_node.js +0 -27
  195. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  196. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  197. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  198. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  199. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  200. package/dest/public_storage/public_storage_service.d.ts +0 -24
  201. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  202. package/dest/public_storage/public_storage_service.js +0 -26
  203. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  204. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  205. package/dest/tree_membership/tree_membership_service.js +0 -84
  206. package/src/contract_function_simulator/proxied_node.ts +0 -33
  207. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  208. package/src/public_storage/public_storage_service.ts +0 -33
  209. package/src/tree_membership/tree_membership_service.ts +0 -112
@@ -1,72 +1,152 @@
1
- import { FUNCTION_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
1
+ import { FUNCTION_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
2
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
4
4
  import { MembershipWitness } from '@aztec/foundation/trees';
5
+ import type { KeyStore } from '@aztec/key-store';
6
+ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
7
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
8
  import type { FunctionSelector } from '@aztec/stdlib/abi';
6
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { L2BlockHash } from '@aztec/stdlib/block';
11
+ import {
12
+ type ContractInstanceWithAddress,
13
+ computeContractClassIdPreimage,
14
+ computeSaltedInitializationHash,
15
+ } from '@aztec/stdlib/contract';
16
+ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
17
+ import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
18
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
7
19
  import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
8
- import type { PublicKeys } from '@aztec/stdlib/keys';
9
20
  import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
10
21
  import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
11
22
 
23
+ import type { ContractStore } from '../storage/contract_store/contract_store.js';
24
+
12
25
  /**
13
26
  * Provides functionality needed by the private kernel for interacting with our state trees.
14
- * This is either PrivateKernelOracleImpl, or a mocked test implementation.
15
27
  */
16
- export interface PrivateKernelOracle {
28
+ export class PrivateKernelOracle {
29
+ constructor(
30
+ private contractStore: ContractStore,
31
+ private keyStore: KeyStore,
32
+ private node: AztecNode,
33
+ private blockHash: L2BlockHash,
34
+ ) {}
35
+
17
36
  /** Retrieves the preimage of a contract address from the registered contract instances db. */
18
- getContractAddressPreimage(address: AztecAddress): Promise<{
19
- saltedInitializationHash: Fr;
20
- publicKeys: PublicKeys;
21
- currentContractClassId: Fr;
22
- originalContractClassId: Fr;
23
- }>;
37
+ public async getContractAddressPreimage(
38
+ address: AztecAddress,
39
+ ): Promise<ContractInstanceWithAddress & { saltedInitializationHash: Fr }> {
40
+ const instance = await this.contractStore.getContractInstance(address);
41
+ if (!instance) {
42
+ throw new Error(`Contract instance not found when getting address preimage. Contract address: ${address}.`);
43
+ }
44
+ return {
45
+ saltedInitializationHash: await computeSaltedInitializationHash(instance),
46
+ ...instance,
47
+ };
48
+ }
24
49
 
25
50
  /** Retrieves the preimage of a contract class id from the contract classes db. */
26
- getContractClassIdPreimage(
27
- contractClassId: Fr,
28
- ): Promise<{ artifactHash: Fr; publicBytecodeCommitment: Fr; privateFunctionsRoot: Fr }>;
51
+ public async getContractClassIdPreimage(contractClassId: Fr) {
52
+ const contractClass = await this.contractStore.getContractClass(contractClassId);
53
+ if (!contractClass) {
54
+ throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
55
+ }
56
+ return computeContractClassIdPreimage(contractClass);
57
+ }
29
58
 
30
- /**
31
- * Returns a membership witness with the sibling path and leaf index in our private functions tree.
32
- */
33
- getFunctionMembershipWitness(
59
+ /** Returns a membership witness with the sibling path and leaf index in our private functions tree. */
60
+ public async getFunctionMembershipWitness(
34
61
  contractClassId: Fr,
35
62
  selector: FunctionSelector,
36
- ): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>>;
63
+ ): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>> {
64
+ const membershipWitness = await this.contractStore.getFunctionMembershipWitness(contractClassId, selector);
65
+ if (!membershipWitness) {
66
+ throw new Error(
67
+ `Membership witness not found for contract class id ${contractClassId} and selector ${selector}.`,
68
+ );
69
+ }
70
+ return membershipWitness;
71
+ }
37
72
 
38
73
  /**
39
74
  * Returns a membership witness with the sibling path and leaf index in our protocol VK indexed merkle tree.
40
75
  * Used to validate the previous kernel's verification key.
41
76
  */
42
- getVkMembershipWitness(vk: VerificationKeyAsFields): Promise<MembershipWitness<typeof VK_TREE_HEIGHT>>;
77
+ public getVkMembershipWitness(vk: VerificationKeyAsFields): Promise<MembershipWitness<typeof VK_TREE_HEIGHT>> {
78
+ const leafIndex = getVKIndex(vk);
79
+ return Promise.resolve(new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)));
80
+ }
43
81
 
44
- /**
45
- * Returns a membership witness with the sibling path and leaf index in our private function indexed merkle tree.
46
- */ getNoteHashMembershipWitness(leafIndex: bigint): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>>;
82
+ /** Returns a membership witness with the sibling path and leaf index in our note hash tree. */
83
+ getNoteHashMembershipWitness(noteHash: Fr): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
84
+ return this.node.getNoteHashMembershipWitness(this.blockHash, noteHash);
85
+ }
47
86
 
48
- /**
49
- * Returns a membership witness with the sibling path and leaf index in our nullifier indexed merkle tree.
50
- */
51
- getNullifierMembershipWitness(nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
52
- /**
53
- * Returns the root of our note hash merkle tree.
54
- */
55
- getNoteHashTreeRoot(): Promise<Fr>;
87
+ /** Returns a membership witness with the sibling path and leaf index in our nullifier indexed merkle tree. */
88
+ getNullifierMembershipWitness(nullifier: Fr): Promise<NullifierMembershipWitness | undefined> {
89
+ return this.node.getNullifierMembershipWitness(this.blockHash, nullifier);
90
+ }
91
+
92
+ /** Returns the root of our note hash merkle tree. */
93
+ async getNoteHashTreeRoot(): Promise<Fr> {
94
+ const header = await this.node.getBlockHeader(this.blockHash);
95
+ if (!header) {
96
+ throw new Error(`No block header found for block hash ${this.blockHash}`);
97
+ }
98
+ return header.state.partial.noteHashTree.root;
99
+ }
56
100
 
57
101
  /**
58
102
  * Retrieves the sk_m corresponding to the pk_m.
59
103
  * @throws If the provided public key is not associated with any of the registered accounts.
60
- * @param pkM - The master public key to get secret key for.
104
+ * @param masterPublicKey - The master public key to get secret key for.
61
105
  * @returns A Promise that resolves to sk_m.
62
106
  * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
63
107
  */
64
- getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar>;
108
+ public getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar> {
109
+ return this.keyStore.getMasterSecretKey(masterPublicKey);
110
+ }
65
111
 
66
112
  /** Use debug data to get the function name corresponding to a selector. */
67
- getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
113
+ public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
114
+ return this.contractStore.getDebugFunctionName(contractAddress, selector);
115
+ }
116
+
117
+ /**
118
+ * Returns a membership witness and leaf index to our public data indexed merkle tree,
119
+ * along with an associated DelayedPublicMutable containing the class ID to update.
120
+ */
121
+ public async getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints> {
122
+ const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } =
123
+ await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
124
+
125
+ const hashLeafSlot = await computePublicDataTreeLeafSlot(
126
+ ProtocolContractAddress.ContractInstanceRegistry,
127
+ delayedPublicMutableHashSlot,
128
+ );
129
+ const updatedClassIdWitness = await this.node.getPublicDataWitness(this.blockHash, hashLeafSlot);
130
+
131
+ if (!updatedClassIdWitness) {
132
+ throw new Error(`No public data tree witness found for ${hashLeafSlot}`);
133
+ }
134
+
135
+ const readStorage = (storageSlot: Fr) =>
136
+ this.node.getPublicStorageAt(this.blockHash, ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
137
+ const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
138
+ delayedPublicMutableSlot,
139
+ readStorage,
140
+ );
68
141
 
69
- /** Returns a membership witness and leaf index to our public data indexed merkle tree,
70
- * along with an associated DelayedPublicMutable containing the class ID to update. */
71
- getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints>;
142
+ return new UpdatedClassIdHints(
143
+ new MembershipWitness(
144
+ PUBLIC_DATA_TREE_HEIGHT,
145
+ updatedClassIdWitness.index,
146
+ updatedClassIdWitness.siblingPath.toTuple(),
147
+ ),
148
+ updatedClassIdWitness.leafPreimage,
149
+ delayedPublicMutableValues,
150
+ );
151
+ }
72
152
  }
package/src/pxe.ts CHANGED
@@ -1,4 +1,5 @@
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
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
@@ -17,16 +18,15 @@ import {
17
18
  } from '@aztec/stdlib/abi';
18
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import { L2BlockHash } from '@aztec/stdlib/block';
20
22
  import {
21
23
  CompleteAddress,
22
- type ContractClassWithId,
23
24
  type ContractInstanceWithAddress,
24
25
  type PartialAddress,
25
26
  computeContractAddressFromInstance,
26
27
  getContractClassFromArtifact,
27
28
  } from '@aztec/stdlib/contract';
28
29
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
30
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
31
  import type {
32
32
  PrivateExecutionStep,
@@ -54,20 +54,22 @@ import { inspect } from 'util';
54
54
 
55
55
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
56
  import type { PXEConfig } from './config/index.js';
57
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
58
  import {
58
59
  ContractFunctionSimulator,
59
60
  generateSimulatedProvingResult,
60
61
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
+ import { ensureContractSynced, readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
64
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
65
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
66
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
66
68
  import {
67
69
  PrivateKernelExecutionProver,
68
70
  type PrivateKernelExecutionProverConfig,
69
71
  } from './private_kernel/private_kernel_execution_prover.js';
70
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
72
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
71
73
  import { AddressStore } from './storage/address_store/address_store.js';
72
74
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
75
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -107,6 +109,7 @@ export class PXE {
107
109
  private protocolContractsProvider: ProtocolContractsProvider,
108
110
  private log: Logger,
109
111
  private jobQueue: SerialQueue,
112
+ private jobCoordinator: JobCoordinator,
110
113
  public debug: PXEDebugUtils,
111
114
  ) {}
112
115
 
@@ -135,7 +138,7 @@ export class PXE {
135
138
  const addressStore = new AddressStore(store);
136
139
  const privateEventStore = new PrivateEventStore(store);
137
140
  const contractStore = new ContractStore(store);
138
- const noteStore = await NoteStore.create(store);
141
+ const noteStore = new NoteStore(store);
139
142
  const anchorBlockStore = new AnchorBlockStore(store);
140
143
  const senderTaggingStore = new SenderTaggingStore(store);
141
144
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -143,7 +146,25 @@ export class PXE {
143
146
  const capsuleStore = new CapsuleStore(store);
144
147
  const keyStore = new KeyStore(store);
145
148
  const tipsStore = new L2TipsKVStore(store, 'pxe');
146
- const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, tipsStore, config, loggerOrSuffix);
149
+ const synchronizer = new BlockSynchronizer(
150
+ node,
151
+ store,
152
+ anchorBlockStore,
153
+ noteStore,
154
+ privateEventStore,
155
+ tipsStore,
156
+ config,
157
+ loggerOrSuffix,
158
+ );
159
+
160
+ const jobCoordinator = new JobCoordinator(store);
161
+ jobCoordinator.registerStores([
162
+ capsuleStore,
163
+ senderTaggingStore,
164
+ recipientTaggingStore,
165
+ privateEventStore,
166
+ noteStore,
167
+ ]);
147
168
 
148
169
  const debugUtils = new PXEDebugUtils(contractStore, noteStore);
149
170
 
@@ -168,6 +189,7 @@ export class PXE {
168
189
  protocolContractsProvider,
169
190
  log,
170
191
  jobQueue,
192
+ jobCoordinator,
171
193
  debugUtils,
172
194
  );
173
195
 
@@ -191,7 +213,7 @@ export class PXE {
191
213
  this.noteStore,
192
214
  this.keyStore,
193
215
  this.addressStore,
194
- this.node,
216
+ BenchmarkedNodeFactory.create(this.node),
195
217
  this.anchorBlockStore,
196
218
  this.senderTaggingStore,
197
219
  this.recipientTaggingStore,
@@ -222,7 +244,7 @@ export class PXE {
222
244
  *
223
245
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
224
246
  */
225
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
247
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
226
248
  // TODO(#12636): relax the conditions under which we forbid concurrency.
227
249
  if (this.jobQueue.length() != 0) {
228
250
  this.log.warn(
@@ -230,7 +252,22 @@ export class PXE {
230
252
  );
231
253
  }
232
254
 
233
- return this.jobQueue.put(fn);
255
+ return this.jobQueue.put(async () => {
256
+ const jobId = this.jobCoordinator.beginJob();
257
+ this.log.verbose(`Beginning job ${jobId}`);
258
+
259
+ try {
260
+ const result = await fn(jobId);
261
+ this.log.verbose(`Committing job ${jobId}`);
262
+
263
+ await this.jobCoordinator.commitJob(jobId);
264
+ return result;
265
+ } catch (err) {
266
+ this.log.verbose(`Aborting job ${jobId}`);
267
+ await this.jobCoordinator.abortJob(jobId);
268
+ throw err;
269
+ }
270
+ });
234
271
  }
235
272
 
236
273
  async #registerProtocolContracts() {
@@ -245,31 +282,28 @@ export class PXE {
245
282
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
246
283
  }
247
284
 
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
285
  // Executes the entrypoint private function, as well as all nested private
262
286
  // functions that might arise.
263
287
  async #executePrivate(
264
288
  contractFunctionSimulator: ContractFunctionSimulator,
265
289
  txRequest: TxExecutionRequest,
266
- scopes?: AztecAddress[],
290
+ scopes: AztecAddress[] | undefined,
291
+ jobId: string,
267
292
  ): Promise<PrivateExecutionResult> {
268
293
  const { origin: contractAddress, functionSelector } = txRequest;
269
294
 
270
295
  try {
271
296
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
272
297
 
298
+ await ensureContractSynced(
299
+ contractAddress,
300
+ functionSelector,
301
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
302
+ this.node,
303
+ this.contractStore,
304
+ anchorBlockHeader,
305
+ );
306
+
273
307
  const result = await contractFunctionSimulator.run(
274
308
  txRequest,
275
309
  contractAddress,
@@ -280,6 +314,7 @@ export class PXE {
280
314
  // contract entrypoint
281
315
  undefined, // senderForTags
282
316
  scopes,
317
+ jobId,
283
318
  );
284
319
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
285
320
  return result;
@@ -298,17 +333,19 @@ export class PXE {
298
333
  * @param authWitnesses - Authentication witnesses required for the function call.
299
334
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
300
335
  * accounts if not specified.
336
+ * @param jobId - The job ID for staged writes.
301
337
  * @returns The simulation result containing the outputs of the utility function.
302
338
  */
303
339
  async #simulateUtility(
304
340
  contractFunctionSimulator: ContractFunctionSimulator,
305
341
  call: FunctionCall,
306
- authWitnesses?: AuthWitness[],
307
- scopes?: AztecAddress[],
342
+ authWitnesses: AuthWitness[] | undefined,
343
+ scopes: AztecAddress[] | undefined,
344
+ jobId: string,
308
345
  ) {
309
346
  try {
310
347
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
311
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
348
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
312
349
  } catch (err) {
313
350
  if (err instanceof SimulationError) {
314
351
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -361,13 +398,9 @@ export class PXE {
361
398
  privateExecutionResult: PrivateExecutionResult,
362
399
  config: PrivateKernelExecutionProverConfig,
363
400
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
364
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
365
- const kernelOracle = new PrivateKernelOracleImpl(
366
- this.contractStore,
367
- this.keyStore,
368
- this.node,
369
- simulationAnchorBlock,
370
- );
401
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
402
+ const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
403
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
371
404
  const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
372
405
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
373
406
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
@@ -380,66 +413,12 @@ export class PXE {
380
413
  }
381
414
 
382
415
  /**
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.
416
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
417
+ * @param id - Identifier of the contract class.
418
+ * @returns The contract artifact if found, undefined otherwise.
395
419
  */
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
- };
414
- }
415
-
416
- /**
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?
426
- */
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
- };
420
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
421
+ return await this.contractStore.getContractArtifact(id);
443
422
  }
444
423
 
445
424
  /**
@@ -464,7 +443,6 @@ export class PXE {
464
443
  }
465
444
 
466
445
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
467
- await this.noteStore.addScope(accountCompleteAddress.address);
468
446
  return accountCompleteAddress;
469
447
  }
470
448
 
@@ -612,13 +590,7 @@ export class PXE {
612
590
 
613
591
  const header = await this.anchorBlockStore.getBlockHeader();
614
592
 
615
- const currentClassId = await readCurrentClassId(
616
- contractAddress,
617
- currentInstance,
618
- this.node,
619
- header.globalVariables.blockNumber,
620
- header.globalVariables.timestamp,
621
- );
593
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
622
594
  if (!contractClass.id.equals(currentClassId)) {
623
595
  throw new Error('Could not update contract to a class different from the current one.');
624
596
  }
@@ -657,14 +629,14 @@ export class PXE {
657
629
  let privateExecutionResult: PrivateExecutionResult;
658
630
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
659
631
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
660
- return this.#putInJobQueue(async () => {
632
+ return this.#putInJobQueue(async jobId => {
661
633
  const totalTimer = new Timer();
662
634
  try {
663
635
  const syncTimer = new Timer();
664
636
  await this.blockStateSynchronizer.sync();
665
637
  const syncTime = syncTimer.ms();
666
638
  const contractFunctionSimulator = this.#getSimulatorForTx();
667
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
639
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
668
640
 
669
641
  const {
670
642
  publicInputs,
@@ -711,7 +683,7 @@ export class PXE {
711
683
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
712
684
  const txHash = (await txProvingResult.toTx()).txHash;
713
685
 
714
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
686
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
715
687
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
716
688
  preTagsUsedInTheTx,
717
689
  });
@@ -741,7 +713,7 @@ export class PXE {
741
713
  skipProofGeneration: boolean = true,
742
714
  ): Promise<TxProfileResult> {
743
715
  // We disable concurrent profiles for consistency with simulateTx.
744
- return this.#putInJobQueue(async () => {
716
+ return this.#putInJobQueue(async jobId => {
745
717
  const totalTimer = new Timer();
746
718
  try {
747
719
  const txInfo = {
@@ -761,7 +733,12 @@ export class PXE {
761
733
  const syncTime = syncTimer.ms();
762
734
 
763
735
  const contractFunctionSimulator = this.#getSimulatorForTx();
764
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
736
+ const privateExecutionResult = await this.#executePrivate(
737
+ contractFunctionSimulator,
738
+ txRequest,
739
+ undefined,
740
+ jobId,
741
+ );
765
742
 
766
743
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
767
744
  txRequest,
@@ -841,7 +818,7 @@ export class PXE {
841
818
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
842
819
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
843
820
  // delete the same read value, or reading values that another simulation is currently modifying).
844
- return this.#putInJobQueue(async () => {
821
+ return this.#putInJobQueue(async jobId => {
845
822
  try {
846
823
  const totalTimer = new Timer();
847
824
  const txInfo = {
@@ -867,20 +844,14 @@ export class PXE {
867
844
  const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
868
845
 
869
846
  // Execution of private functions only; no proving, and no kernel logic.
870
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
847
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
871
848
 
872
849
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
873
850
  let executionSteps: PrivateExecutionStep[] = [];
874
851
 
875
852
  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
853
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
882
854
  privateExecutionResult,
883
- nonceGenerator,
884
855
  this.contractStore,
885
856
  ));
886
857
  } else {
@@ -982,7 +953,7 @@ export class PXE {
982
953
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
983
954
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
984
955
  // delete the same read value, or reading values that another simulation is currently modifying).
985
- return this.#putInJobQueue(async () => {
956
+ return this.#putInJobQueue(async jobId => {
986
957
  try {
987
958
  const totalTimer = new Timer();
988
959
  const syncTimer = new Timer();
@@ -990,7 +961,24 @@ export class PXE {
990
961
  const syncTime = syncTimer.ms();
991
962
  const functionTimer = new Timer();
992
963
  const contractFunctionSimulator = this.#getSimulatorForTx();
993
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
964
+
965
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
966
+ await ensureContractSynced(
967
+ call.to,
968
+ call.selector,
969
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
970
+ this.node,
971
+ this.contractStore,
972
+ anchorBlockHeader,
973
+ );
974
+
975
+ const executionResult = await this.#simulateUtility(
976
+ contractFunctionSimulator,
977
+ call,
978
+ authwits ?? [],
979
+ scopes,
980
+ jobId,
981
+ );
994
982
  const functionTime = functionTimer.ms();
995
983
 
996
984
  const totalTime = totalTimer.ms();
@@ -1035,11 +1023,29 @@ export class PXE {
1035
1023
  eventSelector: EventSelector,
1036
1024
  filter: PrivateEventFilter,
1037
1025
  ): 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);
1026
+ let anchorBlockNumber: BlockNumber;
1027
+
1028
+ await this.#putInJobQueue(async jobId => {
1029
+ await this.blockStateSynchronizer.sync();
1030
+
1031
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1032
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1033
+
1034
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1035
+
1036
+ await ensureContractSynced(
1037
+ filter.contractAddress,
1038
+ null,
1039
+ async privateSyncCall =>
1040
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1041
+ this.node,
1042
+ this.contractStore,
1043
+ anchorBlockHeader,
1044
+ );
1045
+ });
1041
1046
 
1042
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1047
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1048
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1043
1049
 
1044
1050
  this.log.debug(
1045
1051
  `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,