@aztec/pxe 0.0.1-commit.1142ef1 → 0.0.1-commit.18ccd8f0

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 (211) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +66 -21
  5. package/dest/config/index.d.ts +3 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +17 -0
  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 +5 -7
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +30 -20
  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 +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  22. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  23. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  24. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  25. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  27. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -11
  28. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  30. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  32. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +43 -32
  37. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  38. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/oracle/private_execution.js +0 -35
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +19 -7
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +25 -16
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +69 -71
  46. package/dest/contract_sync/index.d.ts +23 -0
  47. package/dest/contract_sync/index.d.ts.map +1 -0
  48. package/dest/contract_sync/index.js +54 -0
  49. package/dest/debug/pxe_debug_utils.d.ts +16 -6
  50. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  51. package/dest/debug/pxe_debug_utils.js +20 -10
  52. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  53. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  54. package/dest/entrypoints/client/bundle/utils.js +10 -5
  55. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  56. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/client/lazy/utils.js +11 -6
  58. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  59. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  60. package/dest/entrypoints/server/index.d.ts +3 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +2 -0
  63. package/dest/entrypoints/server/utils.d.ts +1 -1
  64. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  65. package/dest/entrypoints/server/utils.js +19 -8
  66. package/dest/events/event_service.d.ts +4 -3
  67. package/dest/events/event_service.d.ts.map +1 -1
  68. package/dest/events/event_service.js +17 -19
  69. package/dest/events/private_event_filter_validator.d.ts +5 -5
  70. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  71. package/dest/events/private_event_filter_validator.js +5 -6
  72. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  73. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  74. package/dest/job_coordinator/job_coordinator.js +3 -2
  75. package/dest/logs/log_service.d.ts +4 -2
  76. package/dest/logs/log_service.d.ts.map +1 -1
  77. package/dest/logs/log_service.js +22 -14
  78. package/dest/notes/note_service.d.ts +5 -4
  79. package/dest/notes/note_service.d.ts.map +1 -1
  80. package/dest/notes/note_service.js +30 -34
  81. package/dest/oracle_version.d.ts +3 -3
  82. package/dest/oracle_version.d.ts.map +1 -1
  83. package/dest/oracle_version.js +4 -3
  84. package/dest/private_kernel/hints/index.d.ts +2 -2
  85. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  86. package/dest/private_kernel/hints/index.js +1 -1
  87. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  88. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  89. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +12 -6
  90. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  91. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  92. package/dest/private_kernel/private_kernel_execution_prover.js +3 -3
  93. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -28
  94. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  95. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  96. package/dest/pxe.d.ts +7 -36
  97. package/dest/pxe.d.ts.map +1 -1
  98. package/dest/pxe.js +43 -83
  99. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  100. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  101. package/dest/storage/capsule_store/capsule_store.js +132 -23
  102. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  103. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  104. package/dest/storage/contract_store/contract_store.js +0 -12
  105. package/dest/storage/note_store/note_store.d.ts +45 -56
  106. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  107. package/dest/storage/note_store/note_store.js +241 -262
  108. package/dest/storage/note_store/stored_note.d.ts +16 -0
  109. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  110. package/dest/storage/note_store/stored_note.js +43 -0
  111. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  112. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  113. package/dest/storage/private_event_store/private_event_store.js +199 -109
  114. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  115. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  116. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  117. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
  118. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  119. package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
  120. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
  121. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  122. package/dest/storage/tagging_store/sender_tagging_store.js +109 -27
  123. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  124. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  125. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  126. package/dest/tagging/index.d.ts +2 -1
  127. package/dest/tagging/index.d.ts.map +1 -1
  128. package/dest/tagging/index.js +1 -0
  129. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  130. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  131. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +6 -6
  132. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  133. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  134. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  135. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  136. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  137. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +7 -7
  138. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  139. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  140. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  141. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
  142. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  143. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
  144. package/package.json +18 -18
  145. package/src/bin/check_oracle_version.ts +1 -0
  146. package/src/block_synchronizer/block_synchronizer.ts +85 -33
  147. package/src/config/index.ts +14 -0
  148. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  149. package/src/contract_function_simulator/contract_function_simulator.ts +34 -24
  150. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  151. package/src/contract_function_simulator/index.ts +1 -1
  152. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  153. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  154. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  155. package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
  156. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  157. package/src/contract_function_simulator/oracle/oracle.ts +56 -41
  158. package/src/contract_function_simulator/oracle/private_execution.ts +1 -67
  159. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +35 -8
  160. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +90 -76
  161. package/src/contract_sync/index.ts +98 -0
  162. package/src/debug/pxe_debug_utils.ts +26 -11
  163. package/src/entrypoints/client/bundle/utils.ts +4 -13
  164. package/src/entrypoints/client/lazy/utils.ts +5 -13
  165. package/src/entrypoints/pxe_creation_options.ts +2 -1
  166. package/src/entrypoints/server/index.ts +2 -0
  167. package/src/entrypoints/server/utils.ts +15 -19
  168. package/src/events/event_service.ts +15 -21
  169. package/src/events/private_event_filter_validator.ts +3 -5
  170. package/src/job_coordinator/job_coordinator.ts +4 -3
  171. package/src/logs/log_service.ts +33 -12
  172. package/src/notes/note_service.ts +37 -40
  173. package/src/oracle_version.ts +4 -3
  174. package/src/private_kernel/hints/index.ts +1 -1
  175. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +32 -20
  176. package/src/private_kernel/private_kernel_execution_prover.ts +7 -4
  177. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  178. package/src/pxe.ts +77 -117
  179. package/src/storage/capsule_store/capsule_store.ts +159 -23
  180. package/src/storage/contract_store/contract_store.ts +0 -20
  181. package/src/storage/note_store/note_store.ts +283 -319
  182. package/src/storage/note_store/stored_note.ts +48 -0
  183. package/src/storage/private_event_store/private_event_store.ts +270 -125
  184. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  185. package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
  186. package/src/storage/tagging_store/sender_tagging_store.ts +128 -27
  187. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  188. package/src/tagging/index.ts +1 -0
  189. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +16 -5
  190. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  191. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +9 -6
  192. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  193. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
  194. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  195. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  196. package/dest/contract_function_simulator/proxied_node.js +0 -27
  197. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  198. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  199. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  200. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  201. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  202. package/dest/public_storage/public_storage_service.d.ts +0 -24
  203. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  204. package/dest/public_storage/public_storage_service.js +0 -26
  205. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  206. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  207. package/dest/tree_membership/tree_membership_service.js +0 -84
  208. package/src/contract_function_simulator/proxied_node.ts +0 -33
  209. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  210. package/src/public_storage/public_storage_service.ts +0 -33
  211. package/src/tree_membership/tree_membership_service.ts +0 -112
@@ -1,73 +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 { BlockHash } 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: BlockHash,
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
- */
47
- getNoteHashMembershipWitness(noteHash: Fr): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined>;
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
+ }
48
86
 
49
- /**
50
- * Returns a membership witness with the sibling path and leaf index in our nullifier indexed merkle tree.
51
- */
52
- getNullifierMembershipWitness(nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
53
- /**
54
- * Returns the root of our note hash merkle tree.
55
- */
56
- 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
+ }
57
100
 
58
101
  /**
59
102
  * Retrieves the sk_m corresponding to the pk_m.
60
103
  * @throws If the provided public key is not associated with any of the registered accounts.
61
- * @param pkM - The master public key to get secret key for.
104
+ * @param masterPublicKey - The master public key to get secret key for.
62
105
  * @returns A Promise that resolves to sk_m.
63
106
  * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
64
107
  */
65
- getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar>;
108
+ public getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar> {
109
+ return this.keyStore.getMasterSecretKey(masterPublicKey);
110
+ }
66
111
 
67
112
  /** Use debug data to get the function name corresponding to a selector. */
68
- 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
+ );
69
141
 
70
- /** Returns a membership witness and leaf index to our public data indexed merkle tree,
71
- * along with an associated DelayedPublicMutable containing the class ID to update. */
72
- 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
+ }
73
152
  }
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,
@@ -54,13 +53,13 @@ import { inspect } from 'util';
54
53
 
55
54
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
55
  import type { PXEConfig } from './config/index.js';
56
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
57
  import {
58
58
  ContractFunctionSimulator,
59
59
  generateSimulatedProvingResult,
60
60
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
61
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
62
+ import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
64
63
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
64
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
65
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -69,7 +68,7 @@ import {
69
68
  PrivateKernelExecutionProver,
70
69
  type PrivateKernelExecutionProverConfig,
71
70
  } from './private_kernel/private_kernel_execution_prover.js';
72
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
71
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
73
72
  import { AddressStore } from './storage/address_store/address_store.js';
74
73
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
75
74
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -129,6 +128,10 @@ export class PXE {
129
128
  config: PXEConfig,
130
129
  loggerOrSuffix?: string | Logger,
131
130
  ) {
131
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
+ const bindings: LoggerBindings | undefined =
133
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
134
+
132
135
  const log =
133
136
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
137
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
@@ -138,7 +141,7 @@ export class PXE {
138
141
  const addressStore = new AddressStore(store);
139
142
  const privateEventStore = new PrivateEventStore(store);
140
143
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
144
+ const noteStore = new NoteStore(store);
142
145
  const anchorBlockStore = new AnchorBlockStore(store);
143
146
  const senderTaggingStore = new SenderTaggingStore(store);
144
147
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -148,17 +151,25 @@ export class PXE {
148
151
  const tipsStore = new L2TipsKVStore(store, 'pxe');
149
152
  const synchronizer = new BlockSynchronizer(
150
153
  node,
154
+ store,
151
155
  anchorBlockStore,
152
156
  noteStore,
153
157
  privateEventStore,
154
158
  tipsStore,
155
159
  config,
156
- loggerOrSuffix,
160
+ bindings,
157
161
  );
158
162
 
159
- const jobCoordinator = new JobCoordinator(store);
163
+ const jobCoordinator = new JobCoordinator(store, bindings);
164
+ jobCoordinator.registerStores([
165
+ capsuleStore,
166
+ senderTaggingStore,
167
+ recipientTaggingStore,
168
+ privateEventStore,
169
+ noteStore,
170
+ ]);
160
171
 
161
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
172
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
162
173
 
163
174
  const jobQueue = new SerialQueue();
164
175
 
@@ -185,7 +196,7 @@ export class PXE {
185
196
  debugUtils,
186
197
  );
187
198
 
188
- debugUtils.setPXE(pxe);
199
+ debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
189
200
 
190
201
  pxe.jobQueue.start();
191
202
 
@@ -205,7 +216,7 @@ export class PXE {
205
216
  this.noteStore,
206
217
  this.keyStore,
207
218
  this.addressStore,
208
- ProxiedNodeFactory.create(this.node),
219
+ BenchmarkedNodeFactory.create(this.node),
209
220
  this.anchorBlockStore,
210
221
  this.senderTaggingStore,
211
222
  this.recipientTaggingStore,
@@ -274,19 +285,6 @@ export class PXE {
274
285
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
275
286
  }
276
287
 
277
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
278
- return !!(await this.node.getContractClass(id));
279
- }
280
-
281
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
282
- return !!(await this.node.getContract(address));
283
- }
284
-
285
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
286
- const initNullifier = await siloNullifier(address, address.toField());
287
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
288
- }
289
-
290
288
  // Executes the entrypoint private function, as well as all nested private
291
289
  // functions that might arise.
292
290
  async #executePrivate(
@@ -300,6 +298,15 @@ export class PXE {
300
298
  try {
301
299
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
302
300
 
301
+ await ensureContractSynced(
302
+ contractAddress,
303
+ functionSelector,
304
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
305
+ this.node,
306
+ this.contractStore,
307
+ anchorBlockHeader,
308
+ );
309
+
303
310
  const result = await contractFunctionSimulator.run(
304
311
  txRequest,
305
312
  contractAddress,
@@ -394,14 +401,15 @@ export class PXE {
394
401
  privateExecutionResult: PrivateExecutionResult,
395
402
  config: PrivateKernelExecutionProverConfig,
396
403
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
397
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
398
- const kernelOracle = new PrivateKernelOracleImpl(
399
- this.contractStore,
400
- this.keyStore,
401
- this.node,
402
- simulationAnchorBlock,
404
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
405
+ const anchorBlockHash = await anchorBlockHeader.hash();
406
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
407
+ const kernelTraceProver = new PrivateKernelExecutionProver(
408
+ kernelOracle,
409
+ proofCreator,
410
+ !this.proverEnabled,
411
+ this.log.getBindings(),
403
412
  );
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
405
413
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
414
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
415
  }
@@ -413,66 +421,12 @@ export class PXE {
413
421
  }
414
422
 
415
423
  /**
416
- * Returns the contract class metadata given a contract class id.
417
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
418
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
419
- * @param id - Identifier of the class.
420
- * @param includeArtifact - Identifier of the class.
421
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
422
- * for `includeArtifact`
423
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
424
- * should the pxe query the node for contract public info, and merge it with its own definitions?
425
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
426
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
427
- * do for the time being.
428
- */
429
- public async getContractClassMetadata(
430
- id: Fr,
431
- includeArtifact: boolean = false,
432
- ): Promise<{
433
- contractClass: ContractClassWithId | undefined;
434
- isContractClassPubliclyRegistered: boolean;
435
- artifact: ContractArtifact | undefined;
436
- }> {
437
- const artifact = await this.contractStore.getContractArtifact(id);
438
- if (!artifact) {
439
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
440
- }
441
-
442
- return {
443
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
444
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
445
- artifact: includeArtifact ? artifact : undefined,
446
- };
447
- }
448
-
449
- /**
450
- * Returns the contract metadata given an address.
451
- * The metadata consists of its contract instance, which includes the contract class identifier,
452
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
453
- * and whether the contract instance with the given address has been publicly deployed.
454
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
455
- * This query is not dependent on the PXE.
456
- * @param address - The address that the contract instance resides at.
457
- * @returns - It returns the contract metadata
458
- * TODO(@spalladino): Should we return the public keys in plain as well here?
424
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
425
+ * @param id - Identifier of the contract class.
426
+ * @returns The contract artifact if found, undefined otherwise.
459
427
  */
460
- public async getContractMetadata(address: AztecAddress): Promise<{
461
- contractInstance: ContractInstanceWithAddress | undefined;
462
- isContractInitialized: boolean;
463
- isContractPublished: boolean;
464
- }> {
465
- let instance;
466
- try {
467
- instance = await this.contractStore.getContractInstance(address);
468
- } catch {
469
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
470
- }
471
- return {
472
- contractInstance: instance,
473
- isContractInitialized: await this.#isContractInitialized(address),
474
- isContractPublished: await this.#isContractPublished(address),
475
- };
428
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
429
+ return await this.contractStore.getContractArtifact(id);
476
430
  }
477
431
 
478
432
  /**
@@ -497,7 +451,6 @@ export class PXE {
497
451
  }
498
452
 
499
453
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
500
- await this.noteStore.addScope(accountCompleteAddress.address);
501
454
  return accountCompleteAddress;
502
455
  }
503
456
 
@@ -645,13 +598,7 @@ export class PXE {
645
598
 
646
599
  const header = await this.anchorBlockStore.getBlockHeader();
647
600
 
648
- const currentClassId = await readCurrentClassId(
649
- contractAddress,
650
- currentInstance,
651
- this.node,
652
- header.globalVariables.blockNumber,
653
- header.globalVariables.timestamp,
654
- );
601
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
655
602
  if (!contractClass.id.equals(currentClassId)) {
656
603
  throw new Error('Could not update contract to a class different from the current one.');
657
604
  }
@@ -744,7 +691,7 @@ export class PXE {
744
691
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
745
692
  const txHash = (await txProvingResult.toTx()).txHash;
746
693
 
747
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
694
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
748
695
  this.log.debug(`Stored used pre-tags as sender for the tx`, {
749
696
  preTagsUsedInTheTx,
750
697
  });
@@ -911,14 +858,8 @@ export class PXE {
911
858
  let executionSteps: PrivateExecutionStep[] = [];
912
859
 
913
860
  if (skipKernels) {
914
- // According to the protocol rules, the nonce generator for the note hashes
915
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
916
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
917
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
918
- : privateExecutionResult.firstNullifier;
919
861
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
920
862
  privateExecutionResult,
921
- nonceGenerator,
922
863
  this.contractStore,
923
864
  ));
924
865
  } else {
@@ -1029,8 +970,14 @@ export class PXE {
1029
970
  const functionTimer = new Timer();
1030
971
  const contractFunctionSimulator = this.#getSimulatorForTx();
1031
972
 
1032
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1033
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
973
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
974
+ await ensureContractSynced(
975
+ call.to,
976
+ call.selector,
977
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
978
+ this.node,
979
+ this.contractStore,
980
+ anchorBlockHeader,
1034
981
  );
1035
982
 
1036
983
  const executionResult = await this.#simulateUtility(
@@ -1080,26 +1027,39 @@ export class PXE {
1080
1027
  * Defaults to the latest known block to PXE + 1.
1081
1028
  * @returns - The packed events with block and tx metadata.
1082
1029
  */
1083
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1084
- return this.#putInJobQueue(async jobId => {
1030
+ public async getPrivateEvents(
1031
+ eventSelector: EventSelector,
1032
+ filter: PrivateEventFilter,
1033
+ ): Promise<PackedPrivateEvent[]> {
1034
+ let anchorBlockNumber: BlockNumber;
1035
+
1036
+ await this.#putInJobQueue(async jobId => {
1085
1037
  await this.blockStateSynchronizer.sync();
1038
+
1039
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1040
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1041
+
1086
1042
  const contractFunctionSimulator = this.#getSimulatorForTx();
1087
1043
 
1088
- await this.contractStore.syncPrivateState(
1044
+ await ensureContractSynced(
1089
1045
  filter.contractAddress,
1090
1046
  null,
1091
1047
  async privateSyncCall =>
1092
1048
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1049
+ this.node,
1050
+ this.contractStore,
1051
+ anchorBlockHeader,
1093
1052
  );
1053
+ });
1094
1054
 
1095
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1055
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1056
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1096
1057
 
1097
- this.log.debug(
1098
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1099
- );
1058
+ this.log.debug(
1059
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1060
+ );
1100
1061
 
1101
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1102
- });
1062
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1063
  }
1104
1064
 
1105
1065
  /**