@aztec/pxe 5.0.0-rc.2 → 5.0.1

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 (229) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +5 -3
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +7 -1
  4. package/dest/contract/contract_class_service.d.ts +31 -0
  5. package/dest/contract/contract_class_service.d.ts.map +1 -0
  6. package/dest/contract/contract_class_service.js +68 -0
  7. package/dest/{contract_sync → contract}/contract_sync_service.d.ts +7 -6
  8. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  9. package/dest/{contract_sync → contract}/contract_sync_service.js +10 -30
  10. package/dest/contract/helpers.d.ts +7 -0
  11. package/dest/contract/helpers.d.ts.map +1 -0
  12. package/dest/contract/helpers.js +20 -0
  13. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  14. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  15. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  16. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
  17. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
  19. package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
  20. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/contract_function_simulator.js +31 -14
  22. package/dest/contract_function_simulator/execution_note_cache.d.ts +3 -9
  23. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/execution_note_cache.js +8 -28
  25. package/dest/contract_function_simulator/index.d.ts +4 -2
  26. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/index.js +2 -1
  28. package/dest/contract_function_simulator/noir-structs/fact.d.ts +5 -5
  29. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/noir-structs/fact.js +2 -2
  31. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +3 -3
  32. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/fact_collection.js +3 -1
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +7 -1
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  37. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  38. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  39. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +2 -2
  40. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -1
  42. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +8 -1
  43. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +17 -0
  45. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +7 -2
  46. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/acir_callback.js +55 -11
  48. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  49. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  50. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
  51. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +11 -7
  52. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/oracle_registry.js +50 -10
  54. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +48 -9
  55. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +51 -30
  57. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -2
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -32
  60. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +23 -16
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +105 -60
  63. package/dest/debug/pxe_debug_utils.d.ts +2 -2
  64. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  65. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  66. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/index.js +1 -0
  68. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  69. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/utils.js +11 -5
  71. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  72. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/index.js +1 -0
  74. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  75. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/utils.js +11 -5
  77. package/dest/entrypoints/client/store.d.ts +14 -0
  78. package/dest/entrypoints/client/store.d.ts.map +1 -0
  79. package/dest/entrypoints/client/store.js +28 -0
  80. package/dest/entrypoints/server/index.d.ts +6 -2
  81. package/dest/entrypoints/server/index.d.ts.map +1 -1
  82. package/dest/entrypoints/server/index.js +4 -1
  83. package/dest/entrypoints/server/store.d.ts +18 -0
  84. package/dest/entrypoints/server/store.d.ts.map +1 -0
  85. package/dest/entrypoints/server/store.js +28 -0
  86. package/dest/entrypoints/server/utils.d.ts +1 -1
  87. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  88. package/dest/entrypoints/server/utils.js +8 -2
  89. package/dest/error_enriching.d.ts +5 -3
  90. package/dest/error_enriching.d.ts.map +1 -1
  91. package/dest/error_enriching.js +12 -10
  92. package/dest/hooks/execution_hooks.d.ts +15 -4
  93. package/dest/hooks/execution_hooks.d.ts.map +1 -1
  94. package/dest/hooks/index.d.ts +3 -2
  95. package/dest/hooks/index.d.ts.map +1 -1
  96. package/dest/hooks/index.js +1 -0
  97. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  98. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  99. package/dest/hooks/resolve_custom_request.js +3 -0
  100. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +10 -1
  101. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -1
  102. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -3
  103. package/dest/logs/log_service.d.ts +5 -3
  104. package/dest/logs/log_service.d.ts.map +1 -1
  105. package/dest/logs/log_service.js +38 -17
  106. package/dest/notes/note_service.d.ts +1 -1
  107. package/dest/notes/note_service.js +1 -1
  108. package/dest/oracle_version.d.ts +2 -2
  109. package/dest/oracle_version.js +2 -2
  110. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
  111. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  112. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +6 -2
  113. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  114. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  115. package/dest/private_kernel/private_kernel_execution_prover.js +17 -36
  116. package/dest/private_kernel/private_kernel_oracle.d.ts +4 -2
  117. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  118. package/dest/private_kernel/private_kernel_oracle.js +17 -5
  119. package/dest/pxe.d.ts +81 -46
  120. package/dest/pxe.d.ts.map +1 -1
  121. package/dest/pxe.js +138 -104
  122. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
  123. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
  124. package/dest/storage/backwards_compatibility_tests/schema_tests.js +31 -7
  125. package/dest/storage/contract_store/contract_store.d.ts +27 -24
  126. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  127. package/dest/storage/contract_store/contract_store.js +63 -74
  128. package/dest/storage/fact_store/fact_service.d.ts +6 -4
  129. package/dest/storage/fact_store/fact_service.d.ts.map +1 -1
  130. package/dest/storage/fact_store/fact_service.js +19 -4
  131. package/dest/storage/fact_store/fact_store.d.ts +1 -1
  132. package/dest/storage/fact_store/fact_store.js +1 -1
  133. package/dest/storage/fact_store/index.d.ts +2 -1
  134. package/dest/storage/fact_store/index.d.ts.map +1 -1
  135. package/dest/storage/fact_store/index.js +1 -0
  136. package/dest/storage/fact_store/origin_state.d.ts +57 -0
  137. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  138. package/dest/storage/fact_store/origin_state.js +53 -0
  139. package/dest/storage/metadata.d.ts +2 -2
  140. package/dest/storage/metadata.d.ts.map +1 -1
  141. package/dest/storage/metadata.js +1 -1
  142. package/dest/storage/store_identity.d.ts +35 -0
  143. package/dest/storage/store_identity.d.ts.map +1 -0
  144. package/dest/storage/store_identity.js +44 -0
  145. package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -3
  146. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  147. package/dest/storage/tagging_store/sender_tagging_store.js +48 -11
  148. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +17 -6
  149. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -1
  150. package/dest/storage/tagging_store/tagging_secret_sources_store.js +24 -11
  151. package/dest/tagging/constants.d.ts +2 -2
  152. package/dest/tagging/constants.d.ts.map +1 -1
  153. package/dest/tagging/constants.js +18 -9
  154. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +1 -1
  155. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +1 -1
  156. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  157. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +6 -2
  158. package/package.json +17 -17
  159. package/src/block_synchronizer/block_synchronizer.ts +9 -1
  160. package/src/contract/contract_class_service.ts +83 -0
  161. package/src/{contract_sync → contract}/contract_sync_service.ts +18 -37
  162. package/src/contract/helpers.ts +35 -0
  163. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  164. package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
  165. package/src/contract_function_simulator/contract_function_simulator.ts +56 -14
  166. package/src/contract_function_simulator/execution_note_cache.ts +7 -28
  167. package/src/contract_function_simulator/index.ts +7 -1
  168. package/src/contract_function_simulator/noir-structs/fact.ts +4 -4
  169. package/src/contract_function_simulator/noir-structs/fact_collection.ts +9 -4
  170. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +6 -0
  171. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  172. package/src/contract_function_simulator/noir-structs/provided_secret.ts +1 -1
  173. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +21 -0
  174. package/src/contract_function_simulator/oracle/acir_callback.ts +58 -12
  175. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  176. package/src/contract_function_simulator/oracle/oracle_registry.ts +37 -7
  177. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +49 -32
  178. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +92 -41
  179. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +149 -71
  180. package/src/debug/pxe_debug_utils.ts +1 -1
  181. package/src/entrypoints/client/bundle/index.ts +1 -0
  182. package/src/entrypoints/client/bundle/utils.ts +16 -4
  183. package/src/entrypoints/client/lazy/index.ts +1 -0
  184. package/src/entrypoints/client/lazy/utils.ts +16 -4
  185. package/src/entrypoints/client/store.ts +38 -0
  186. package/src/entrypoints/server/index.ts +6 -1
  187. package/src/entrypoints/server/store.ts +47 -0
  188. package/src/entrypoints/server/utils.ts +21 -7
  189. package/src/error_enriching.ts +26 -10
  190. package/src/hooks/execution_hooks.ts +14 -3
  191. package/src/hooks/index.ts +2 -0
  192. package/src/hooks/resolve_custom_request.ts +24 -0
  193. package/src/hooks/resolve_tagging_secret_strategy.ts +14 -0
  194. package/src/logs/log_service.ts +35 -11
  195. package/src/notes/note_service.ts +1 -1
  196. package/src/oracle_version.ts +2 -2
  197. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -1
  198. package/src/private_kernel/private_kernel_execution_prover.ts +22 -52
  199. package/src/private_kernel/private_kernel_oracle.ts +23 -4
  200. package/src/pxe.ts +212 -143
  201. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +6 -6
  202. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +1 -1
  203. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +12 -12
  204. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
  205. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
  206. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +3 -3
  207. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +1 -1
  208. package/src/storage/backwards_compatibility_tests/schema_tests.ts +38 -4
  209. package/src/storage/contract_store/contract_store.ts +85 -92
  210. package/src/storage/fact_store/fact_service.ts +29 -5
  211. package/src/storage/fact_store/fact_store.ts +1 -1
  212. package/src/storage/fact_store/index.ts +10 -0
  213. package/src/storage/fact_store/origin_state.ts +75 -0
  214. package/src/storage/metadata.ts +1 -1
  215. package/src/storage/store_identity.ts +72 -0
  216. package/src/storage/tagging_store/sender_tagging_store.ts +62 -15
  217. package/src/storage/tagging_store/tagging_secret_sources_store.ts +36 -15
  218. package/src/tagging/constants.ts +19 -9
  219. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -1
  220. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +6 -2
  221. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  222. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  223. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -51
  224. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  225. package/dest/contract_sync/helpers.d.ts +0 -28
  226. package/dest/contract_sync/helpers.d.ts.map +0 -1
  227. package/dest/contract_sync/helpers.js +0 -48
  228. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
  229. package/src/contract_sync/helpers.ts +0 -79
@@ -1,48 +0,0 @@
1
- import { isProtocolContract } from '@aztec/protocol-contracts';
2
- /**
3
- * Read the current class id of a contract as of the given block, as seen by the AztecNode. The node resolves it from
4
- * the same scheduled value change the AVM enforces against the public data tree. If the node has no record of the
5
- * instance (e.g. it was never publicly deployed), the original class id from the local instance is used.
6
- * @param contractAddress - The address of the contract to read the class id for.
7
- * @param instance - The local instance of the contract, used as a fallback when the node doesn't know it.
8
- * @param aztecNode - The Aztec node to query.
9
- * @param header - The header of the block at which to resolve the current class id.
10
- * @returns The current class id.
11
- */ export async function readCurrentClassId(contractAddress, instance, aztecNode, header) {
12
- const nodeInstance = await aztecNode.getContract(contractAddress, await header.hash());
13
- // If the contract was upgraded then the node WILL know of that and return a non-undefined instance. An undefined
14
- // result therefore means that no upgrade has happened, and therefore that the original class is the current one.
15
- return nodeInstance?.currentContractClassId ?? instance.originalContractClassId;
16
- }
17
- export async function syncScope(contractAddress, contractStore, functionToInvokeAfterSync, utilityExecutor, scope) {
18
- // Protocol contracts don't have private state to sync
19
- if (isProtocolContract(contractAddress)) {
20
- return;
21
- }
22
- const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [
23
- scope
24
- ], contractAddress);
25
- if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
26
- throw new Error('Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.');
27
- }
28
- await utilityExecutor(syncStateFunctionCall, [
29
- scope
30
- ]);
31
- }
32
- /**
33
- * Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
34
- * provider (i.e. PXE's own storage).
35
- * @param contractAddress - The address of the contract to verify.
36
- * @param aztecNode - The Aztec node to query for storage.
37
- * @param contractStore - The contract store to fetch the local instance from.
38
- * @param header - The header of the block at which to verify the current class id.
39
- */ export async function verifyCurrentClassId(contractAddress, aztecNode, contractStore, header) {
40
- const instance = await contractStore.getContractInstance(contractAddress);
41
- if (!instance) {
42
- throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
43
- }
44
- const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
45
- if (!instance.currentContractClassId.equals(currentClassId)) {
46
- throw new Error(`Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`);
47
- }
48
- }
@@ -1,60 +0,0 @@
1
- import { type FunctionSelector, findFunctionArtifactBySelector } from '@aztec/stdlib/abi';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { ContractOverrides } from '@aztec/stdlib/tx';
4
-
5
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
6
-
7
- /*
8
- * Proxy generator for a ContractStore that allows overriding contract instances at given addresses,
9
- * so the contract function simulator can execute different bytecode on certain addresses. An example
10
- * use case would be overriding your own account contract so that valid signatures don't have to be
11
- * provided while simulating.
12
- *
13
- * Function artifact lookups for an overridden address are routed via the override-instance's
14
- * `currentContractClassId` rather than the underlying ContractStore's address→class mapping —
15
- * `ContractStore.getFunctionArtifact` calls `this.getContractInstance` internally, which the proxy
16
- * cannot intercept (the binding sees the raw target, not the proxy). The target class must be
17
- * registered ahead of time via `pxe.registerContractClass(...)`.
18
- */
19
- export class ProxiedContractStoreFactory {
20
- static create(contractStore: ContractStore, overrides?: ContractOverrides) {
21
- if (!overrides) {
22
- return contractStore;
23
- }
24
-
25
- return new Proxy(contractStore, {
26
- get(target, prop: keyof ContractStore) {
27
- if (prop === 'getContractInstance') {
28
- return (address: AztecAddress) => {
29
- const override = overrides[address.toString()];
30
- return override ? Promise.resolve(override.instance) : target.getContractInstance(address);
31
- };
32
- }
33
- if (prop === 'getFunctionArtifact' || prop === 'getFunctionArtifactWithDebugMetadata') {
34
- return async (contractAddress: AztecAddress, selector: FunctionSelector) => {
35
- const override = overrides[contractAddress.toString()];
36
- if (!override) {
37
- return (target[prop] as Function).call(target, contractAddress, selector);
38
- }
39
- const artifact = await target.getContractArtifact(override.instance.currentContractClassId);
40
- if (!artifact) {
41
- throw new Error(
42
- `No artifact registered for override class ${override.instance.currentContractClassId} ` +
43
- `at ${contractAddress}. Register it via pxe.registerContractClass(...) before simulating.`,
44
- );
45
- }
46
- const fn = await findFunctionArtifactBySelector(artifact, selector);
47
- if (!fn) {
48
- throw new Error(
49
- `Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}.`,
50
- );
51
- }
52
- return { ...fn, contractName: artifact.name };
53
- };
54
- }
55
- const value = Reflect.get(target, prop);
56
- return typeof value === 'function' ? value.bind(target) : value;
57
- },
58
- }) satisfies ContractStore;
59
- }
60
- }
@@ -1,79 +0,0 @@
1
- import { isProtocolContract } from '@aztec/protocol-contracts';
2
- import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { ContractInstance } from '@aztec/stdlib/contract';
5
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
6
- import type { BlockHeader } from '@aztec/stdlib/tx';
7
-
8
- import type { ContractStore } from '../storage/contract_store/contract_store.js';
9
-
10
- /**
11
- * Read the current class id of a contract as of the given block, as seen by the AztecNode. The node resolves it from
12
- * the same scheduled value change the AVM enforces against the public data tree. If the node has no record of the
13
- * instance (e.g. it was never publicly deployed), the original class id from the local instance is used.
14
- * @param contractAddress - The address of the contract to read the class id for.
15
- * @param instance - The local instance of the contract, used as a fallback when the node doesn't know it.
16
- * @param aztecNode - The Aztec node to query.
17
- * @param header - The header of the block at which to resolve the current class id.
18
- * @returns The current class id.
19
- */
20
- export async function readCurrentClassId(
21
- contractAddress: AztecAddress,
22
- instance: ContractInstance,
23
- aztecNode: AztecNode,
24
- header: BlockHeader,
25
- ) {
26
- const nodeInstance = await aztecNode.getContract(contractAddress, await header.hash());
27
- // If the contract was upgraded then the node WILL know of that and return a non-undefined instance. An undefined
28
- // result therefore means that no upgrade has happened, and therefore that the original class is the current one.
29
- return nodeInstance?.currentContractClassId ?? instance.originalContractClassId;
30
- }
31
-
32
- export async function syncScope(
33
- contractAddress: AztecAddress,
34
- contractStore: ContractStore,
35
- functionToInvokeAfterSync: FunctionSelector | null,
36
- utilityExecutor: (privateSyncCall: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
37
- scope: AztecAddress,
38
- ) {
39
- // Protocol contracts don't have private state to sync
40
- if (isProtocolContract(contractAddress)) {
41
- return;
42
- }
43
-
44
- const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [scope], contractAddress);
45
- if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
46
- throw new Error(
47
- 'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
48
- );
49
- }
50
-
51
- await utilityExecutor(syncStateFunctionCall, [scope]);
52
- }
53
-
54
- /**
55
- * Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
56
- * provider (i.e. PXE's own storage).
57
- * @param contractAddress - The address of the contract to verify.
58
- * @param aztecNode - The Aztec node to query for storage.
59
- * @param contractStore - The contract store to fetch the local instance from.
60
- * @param header - The header of the block at which to verify the current class id.
61
- */
62
- export async function verifyCurrentClassId(
63
- contractAddress: AztecAddress,
64
- aztecNode: AztecNode,
65
- contractStore: ContractStore,
66
- header: BlockHeader,
67
- ) {
68
- const instance = await contractStore.getContractInstance(contractAddress);
69
- if (!instance) {
70
- throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
71
- }
72
-
73
- const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
74
- if (!instance.currentContractClassId.equals(currentClassId)) {
75
- throw new Error(
76
- `Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`,
77
- );
78
- }
79
- }