@aztec/pxe 0.0.1-commit.f295ac2 → 0.0.1-commit.f2ce05ee

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 (187) 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 +62 -16
  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/contract_function_simulator.d.ts +5 -5
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +12 -15
  11. package/dest/contract_function_simulator/index.d.ts +2 -2
  12. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/index.js +1 -1
  14. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  16. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  18. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
  21. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/note_packing_utils.js +4 -4
  23. package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
  24. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/oracle.js +56 -34
  26. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
  27. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -3
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +20 -9
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +38 -24
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +84 -65
  35. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  36. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  37. package/dest/contract_sync/contract_sync_service.js +82 -0
  38. package/dest/contract_sync/helpers.d.ts +28 -0
  39. package/dest/contract_sync/helpers.d.ts.map +1 -0
  40. package/dest/contract_sync/helpers.js +55 -0
  41. package/dest/debug/pxe_debug_utils.d.ts +22 -9
  42. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  43. package/dest/debug/pxe_debug_utils.js +28 -17
  44. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  45. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  46. package/dest/entrypoints/client/bundle/utils.js +12 -6
  47. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  48. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  49. package/dest/entrypoints/client/lazy/utils.js +13 -7
  50. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  51. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  52. package/dest/entrypoints/server/index.d.ts +2 -1
  53. package/dest/entrypoints/server/index.d.ts.map +1 -1
  54. package/dest/entrypoints/server/index.js +1 -0
  55. package/dest/entrypoints/server/utils.d.ts +1 -1
  56. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/server/utils.js +19 -8
  58. package/dest/events/event_service.d.ts +5 -6
  59. package/dest/events/event_service.d.ts.map +1 -1
  60. package/dest/events/event_service.js +6 -7
  61. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  62. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  63. package/dest/job_coordinator/job_coordinator.js +3 -2
  64. package/dest/logs/log_service.d.ts +6 -5
  65. package/dest/logs/log_service.d.ts.map +1 -1
  66. package/dest/logs/log_service.js +20 -19
  67. package/dest/notes/note_service.d.ts +6 -6
  68. package/dest/notes/note_service.d.ts.map +1 -1
  69. package/dest/notes/note_service.js +14 -14
  70. package/dest/oracle_version.d.ts +3 -3
  71. package/dest/oracle_version.d.ts.map +1 -1
  72. package/dest/oracle_version.js +4 -3
  73. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  74. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  75. package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
  76. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
  77. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  78. package/dest/pxe.d.ts +13 -2
  79. package/dest/pxe.d.ts.map +1 -1
  80. package/dest/pxe.js +45 -20
  81. package/dest/storage/address_store/address_store.d.ts +1 -1
  82. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  83. package/dest/storage/address_store/address_store.js +12 -11
  84. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  85. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  86. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  87. package/dest/storage/capsule_store/capsule_store.js +6 -8
  88. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  89. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  90. package/dest/storage/contract_store/contract_store.js +27 -30
  91. package/dest/storage/metadata.d.ts +1 -1
  92. package/dest/storage/metadata.js +1 -1
  93. package/dest/storage/note_store/note_store.d.ts +48 -50
  94. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  95. package/dest/storage/note_store/note_store.js +279 -252
  96. package/dest/storage/note_store/stored_note.d.ts +16 -0
  97. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  98. package/dest/storage/note_store/stored_note.js +43 -0
  99. package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
  100. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  101. package/dest/storage/private_event_store/private_event_store.js +198 -147
  102. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  103. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  104. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  105. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  106. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  107. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  108. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  109. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  110. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  111. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  112. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  113. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  114. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  115. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  116. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  117. package/dest/tagging/index.d.ts +2 -1
  118. package/dest/tagging/index.d.ts.map +1 -1
  119. package/dest/tagging/index.js +1 -0
  120. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  121. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  122. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
  123. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  124. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  125. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  126. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  127. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  128. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
  129. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  130. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  131. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  132. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
  133. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  134. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +7 -4
  135. package/package.json +25 -16
  136. package/src/bin/check_oracle_version.ts +1 -0
  137. package/src/block_synchronizer/block_synchronizer.ts +76 -33
  138. package/src/config/index.ts +14 -0
  139. package/src/contract_function_simulator/contract_function_simulator.ts +12 -17
  140. package/src/contract_function_simulator/index.ts +1 -1
  141. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  142. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  143. package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
  144. package/src/contract_function_simulator/oracle/note_packing_utils.ts +4 -4
  145. package/src/contract_function_simulator/oracle/oracle.ts +62 -32
  146. package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
  147. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -11
  148. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +107 -74
  149. package/src/contract_sync/contract_sync_service.ts +129 -0
  150. package/src/contract_sync/helpers.ts +93 -0
  151. package/src/debug/pxe_debug_utils.ts +60 -17
  152. package/src/entrypoints/client/bundle/utils.ts +7 -14
  153. package/src/entrypoints/client/lazy/utils.ts +8 -14
  154. package/src/entrypoints/pxe_creation_options.ts +2 -1
  155. package/src/entrypoints/server/index.ts +1 -0
  156. package/src/entrypoints/server/utils.ts +15 -19
  157. package/src/events/event_service.ts +5 -7
  158. package/src/job_coordinator/job_coordinator.ts +4 -3
  159. package/src/logs/log_service.ts +31 -15
  160. package/src/notes/note_service.ts +21 -20
  161. package/src/oracle_version.ts +4 -3
  162. package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
  163. package/src/private_kernel/private_kernel_oracle.ts +2 -2
  164. package/src/pxe.ts +84 -19
  165. package/src/storage/address_store/address_store.ts +15 -15
  166. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  167. package/src/storage/capsule_store/capsule_store.ts +8 -8
  168. package/src/storage/contract_store/contract_store.ts +26 -35
  169. package/src/storage/metadata.ts +1 -1
  170. package/src/storage/note_store/note_store.ts +318 -318
  171. package/src/storage/note_store/stored_note.ts +48 -0
  172. package/src/storage/private_event_store/private_event_store.ts +250 -190
  173. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  174. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  175. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  176. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  177. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  178. package/src/tagging/index.ts +1 -0
  179. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
  180. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  181. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
  182. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  183. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
  184. package/dest/tree_membership/tree_membership_service.d.ts +0 -50
  185. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  186. package/dest/tree_membership/tree_membership_service.js +0 -75
  187. package/src/tree_membership/tree_membership_service.ts +0 -97
@@ -1,21 +1,20 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { DataInBlock } from '@aztec/stdlib/block';
4
- import { L2BlockHash } from '@aztec/stdlib/block';
5
4
  import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
6
5
  import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
7
6
  import { Note, NoteDao, NoteStatus } from '@aztec/stdlib/note';
8
7
  import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import type { TxHash } from '@aztec/stdlib/tx';
8
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
10
9
 
11
- import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
12
10
  import type { NoteStore } from '../storage/note_store/note_store.js';
13
11
 
14
12
  export class NoteService {
15
13
  constructor(
16
14
  private readonly noteStore: NoteStore,
17
15
  private readonly aztecNode: AztecNode,
18
- private readonly anchorBlockStore: AnchorBlockStore,
16
+ private readonly anchorBlockHeader: BlockHeader,
17
+ private readonly jobId: string,
19
18
  ) {}
20
19
 
21
20
  /**
@@ -34,13 +33,16 @@ export class NoteService {
34
33
  status: NoteStatus,
35
34
  scopes?: AztecAddress[],
36
35
  ) {
37
- const noteDaos = await this.noteStore.getNotes({
38
- contractAddress,
39
- owner,
40
- storageSlot,
41
- status,
42
- scopes,
43
- });
36
+ const noteDaos = await this.noteStore.getNotes(
37
+ {
38
+ contractAddress,
39
+ owner,
40
+ storageSlot,
41
+ status,
42
+ scopes,
43
+ },
44
+ this.jobId,
45
+ );
44
46
  return noteDaos.map(
45
47
  ({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier }) => ({
46
48
  contractAddress,
@@ -69,9 +71,9 @@ export class NoteService {
69
71
  * @param contractAddress - The contract whose notes should be checked and nullified.
70
72
  */
71
73
  public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
72
- const anchorBlockHash = L2BlockHash.fromField(await (await this.anchorBlockStore.getBlockHeader()).hash());
74
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
73
75
 
74
- const contractNotes = await this.noteStore.getNotes({ contractAddress });
76
+ const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
75
77
 
76
78
  if (contractNotes.length === 0) {
77
79
  return;
@@ -105,10 +107,10 @@ export class NoteService {
105
107
  })
106
108
  .filter(nullifier => nullifier !== undefined) as DataInBlock<Fr>[];
107
109
 
108
- await this.noteStore.applyNullifiers(foundNullifiers);
110
+ await this.noteStore.applyNullifiers(foundNullifiers, this.jobId);
109
111
  }
110
112
 
111
- public async storeNote(
113
+ public async validateAndStoreNote(
112
114
  contractAddress: AztecAddress,
113
115
  owner: AztecAddress,
114
116
  storageSlot: Fr,
@@ -139,9 +141,8 @@ export class NoteService {
139
141
  // number which *should* be recent enough to be available, even for non-archive nodes.
140
142
  // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
141
143
  // logs up to the synced block making this only an additional safety check.
142
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
143
- const anchorBlockNumber = anchorBlockHeader.getBlockNumber();
144
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
144
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
145
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
145
146
 
146
147
  // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
147
148
  // of other contracts, which would constitute a security breach.
@@ -183,12 +184,12 @@ export class NoteService {
183
184
  );
184
185
 
185
186
  // The note was found by `recipient`, so we use that as the scope when storing the note.
186
- await this.noteStore.addNotes([noteDao], recipient);
187
+ await this.noteStore.addNotes([noteDao], recipient, this.jobId);
187
188
 
188
189
  if (nullifierIndex !== undefined) {
189
190
  // We found nullifier index which implies that the note has already been nullified.
190
191
  const { data: _, ...blockHashAndNum } = nullifierIndex;
191
- await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }]);
192
+ await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }], this.jobId);
192
193
  }
193
194
  }
194
195
  }
@@ -4,8 +4,9 @@
4
4
  ///
5
5
  /// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
6
6
  /// and if the oracle version is incompatible an error is thrown.
7
- export const ORACLE_VERSION = 6;
7
+ export const ORACLE_VERSION = 11;
8
8
 
9
9
  /// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
10
- /// which in turn implies that you need to update the ORACLE_VERSION constant.
11
- export const ORACLE_INTERFACE_HASH = 'cc2a1f26a3b39ef194d710f94683929f63939d725f10b4fe2c82749a47a74c7b';
10
+ /// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
11
+ /// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
12
+ export const ORACLE_INTERFACE_HASH = '20c4d02d8cd5e448c11001a5f72ea2e0927630aeda75e537550872a9627bf40b';
@@ -1,6 +1,6 @@
1
1
  import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { createLogger } from '@aztec/foundation/log';
3
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
4
  import { pushTestData } from '@aztec/foundation/testing';
5
5
  import { Timer } from '@aztec/foundation/timer';
6
6
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
@@ -56,13 +56,16 @@ export interface PrivateKernelExecutionProverConfig {
56
56
  * inform state tree updates.
57
57
  */
58
58
  export class PrivateKernelExecutionProver {
59
- private log = createLogger('pxe:private-kernel-execution-prover');
59
+ private log: Logger;
60
60
 
61
61
  constructor(
62
62
  private oracle: PrivateKernelOracle,
63
63
  private proofCreator: PrivateKernelProver,
64
64
  private fakeProofs = false,
65
- ) {}
65
+ bindings?: LoggerBindings,
66
+ ) {
67
+ this.log = createLogger('pxe:private-kernel-execution-prover', bindings);
68
+ }
66
69
 
67
70
  /**
68
71
  * Generate a proof for a given transaction request and execution result.
@@ -7,7 +7,7 @@ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-type
7
7
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
8
8
  import type { FunctionSelector } from '@aztec/stdlib/abi';
9
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { L2BlockHash } from '@aztec/stdlib/block';
10
+ import { BlockHash } from '@aztec/stdlib/block';
11
11
  import {
12
12
  type ContractInstanceWithAddress,
13
13
  computeContractClassIdPreimage,
@@ -30,7 +30,7 @@ export class PrivateKernelOracle {
30
30
  private contractStore: ContractStore,
31
31
  private keyStore: KeyStore,
32
32
  private node: AztecNode,
33
- private blockHash: L2BlockHash,
33
+ private blockHash: BlockHash,
34
34
  ) {}
35
35
 
36
36
  /** Retrieves the preimage of a contract address from the registered contract instances db. */
package/src/pxe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
@@ -18,7 +18,6 @@ import {
18
18
  } from '@aztec/stdlib/abi';
19
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
- import { L2BlockHash } from '@aztec/stdlib/block';
22
21
  import {
23
22
  CompleteAddress,
24
23
  type ContractInstanceWithAddress,
@@ -34,6 +33,7 @@ import type {
34
33
  PrivateKernelTailCircuitPublicInputs,
35
34
  } from '@aztec/stdlib/kernel';
36
35
  import {
36
+ BlockHeader,
37
37
  type ContractOverrides,
38
38
  type InTx,
39
39
  PrivateExecutionResult,
@@ -59,8 +59,9 @@ import {
59
59
  ContractFunctionSimulator,
60
60
  generateSimulatedProvingResult,
61
61
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
63
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
65
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
66
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
67
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
@@ -103,6 +104,7 @@ export class PXE {
103
104
  private recipientTaggingStore: RecipientTaggingStore,
104
105
  private addressStore: AddressStore,
105
106
  private privateEventStore: PrivateEventStore,
107
+ private contractSyncService: ContractSyncService,
106
108
  private simulator: CircuitSimulator,
107
109
  private proverEnabled: boolean,
108
110
  private proofCreator: PrivateKernelProver,
@@ -129,6 +131,10 @@ export class PXE {
129
131
  config: PXEConfig,
130
132
  loggerOrSuffix?: string | Logger,
131
133
  ) {
134
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
135
+ const bindings: LoggerBindings | undefined =
136
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
137
+
132
138
  const log =
133
139
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
140
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
@@ -138,7 +144,7 @@ export class PXE {
138
144
  const addressStore = new AddressStore(store);
139
145
  const privateEventStore = new PrivateEventStore(store);
140
146
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
147
+ const noteStore = new NoteStore(store);
142
148
  const anchorBlockStore = new AnchorBlockStore(store);
143
149
  const senderTaggingStore = new SenderTaggingStore(store);
144
150
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,6 +152,12 @@ export class PXE {
146
152
  const capsuleStore = new CapsuleStore(store);
147
153
  const keyStore = new KeyStore(store);
148
154
  const tipsStore = new L2TipsKVStore(store, 'pxe');
155
+ const contractSyncService = new ContractSyncService(
156
+ node,
157
+ contractStore,
158
+ noteStore,
159
+ createLogger('pxe:contract_sync', bindings),
160
+ );
149
161
  const synchronizer = new BlockSynchronizer(
150
162
  node,
151
163
  store,
@@ -153,14 +165,22 @@ export class PXE {
153
165
  noteStore,
154
166
  privateEventStore,
155
167
  tipsStore,
168
+ contractSyncService,
156
169
  config,
157
- loggerOrSuffix,
170
+ bindings,
158
171
  );
159
172
 
160
- const jobCoordinator = new JobCoordinator(store);
161
- jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
173
+ const jobCoordinator = new JobCoordinator(store, bindings);
174
+ jobCoordinator.registerStores([
175
+ capsuleStore,
176
+ senderTaggingStore,
177
+ recipientTaggingStore,
178
+ privateEventStore,
179
+ noteStore,
180
+ contractSyncService,
181
+ ]);
162
182
 
163
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
183
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
164
184
 
165
185
  const jobQueue = new SerialQueue();
166
186
 
@@ -177,6 +197,7 @@ export class PXE {
177
197
  recipientTaggingStore,
178
198
  addressStore,
179
199
  privateEventStore,
200
+ contractSyncService,
180
201
  simulator,
181
202
  proverEnabled,
182
203
  proofCreator,
@@ -187,7 +208,11 @@ export class PXE {
187
208
  debugUtils,
188
209
  );
189
210
 
190
- debugUtils.setPXE(pxe);
211
+ debugUtils.setPXEHelpers(
212
+ pxe.#putInJobQueue.bind(pxe),
213
+ pxe.#getSimulatorForTx.bind(pxe),
214
+ pxe.#simulateUtility.bind(pxe),
215
+ );
191
216
 
192
217
  pxe.jobQueue.start();
193
218
 
@@ -208,13 +233,13 @@ export class PXE {
208
233
  this.keyStore,
209
234
  this.addressStore,
210
235
  BenchmarkedNodeFactory.create(this.node),
211
- this.anchorBlockStore,
212
236
  this.senderTaggingStore,
213
237
  this.recipientTaggingStore,
214
238
  this.senderAddressBookStore,
215
239
  this.capsuleStore,
216
240
  this.privateEventStore,
217
241
  this.simulator,
242
+ this.contractSyncService,
218
243
  );
219
244
  }
220
245
 
@@ -289,6 +314,14 @@ export class PXE {
289
314
  try {
290
315
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
291
316
 
317
+ await this.contractSyncService.ensureContractSynced(
318
+ contractAddress,
319
+ functionSelector,
320
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
321
+ anchorBlockHeader,
322
+ jobId,
323
+ );
324
+
292
325
  const result = await contractFunctionSimulator.run(
293
326
  txRequest,
294
327
  contractAddress,
@@ -384,15 +417,33 @@ export class PXE {
384
417
  config: PrivateKernelExecutionProverConfig,
385
418
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
386
419
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
387
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
420
+ const anchorBlockHash = await anchorBlockHeader.hash();
388
421
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
389
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
422
+ const kernelTraceProver = new PrivateKernelExecutionProver(
423
+ kernelOracle,
424
+ proofCreator,
425
+ !this.proverEnabled,
426
+ this.log.getBindings(),
427
+ );
390
428
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
391
429
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
392
430
  }
393
431
 
394
432
  // Public API
395
433
 
434
+ /**
435
+ * Returns the block header up to which the PXE has synced.
436
+ * @returns The synced block header
437
+ */
438
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
439
+ return this.anchorBlockStore.getBlockHeader();
440
+ }
441
+
442
+ /**
443
+ * Returns the contract instance for a given address, if it's registered in the PXE.
444
+ * @param address - The contract address.
445
+ * @returns The contract instance if found, undefined otherwise.
446
+ */
396
447
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
397
448
  return this.contractStore.getContractInstance(address);
398
449
  }
@@ -428,7 +479,6 @@ export class PXE {
428
479
  }
429
480
 
430
481
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
431
- await this.noteStore.addScope(accountCompleteAddress.address);
432
482
  return accountCompleteAddress;
433
483
  }
434
484
 
@@ -827,7 +877,14 @@ export class PXE {
827
877
  // Temporary: in case there are overrides, we have to skip the kernels or validations
828
878
  // will fail. Consider handing control to the user/wallet on whether they want to run them
829
879
  // or not.
830
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
880
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
881
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
882
+ const skipKernels = hasOverriddenContracts;
883
+
884
+ // Set overridden contracts on the sync service so it knows to skip syncing them
885
+ if (hasOverriddenContracts) {
886
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
887
+ }
831
888
 
832
889
  // Execution of private functions only; no proving, and no kernel logic.
833
890
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -838,7 +895,7 @@ export class PXE {
838
895
  if (skipKernels) {
839
896
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
840
897
  privateExecutionResult,
841
- this.contractStore,
898
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
842
899
  ));
843
900
  } else {
844
901
  // Kernel logic, plus proving of all private functions and kernels.
@@ -948,8 +1005,13 @@ export class PXE {
948
1005
  const functionTimer = new Timer();
949
1006
  const contractFunctionSimulator = this.#getSimulatorForTx();
950
1007
 
951
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
952
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1008
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1009
+ await this.contractSyncService.ensureContractSynced(
1010
+ call.to,
1011
+ call.selector,
1012
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1013
+ anchorBlockHeader,
1014
+ jobId,
953
1015
  );
954
1016
 
955
1017
  const executionResult = await this.#simulateUtility(
@@ -1008,15 +1070,18 @@ export class PXE {
1008
1070
  await this.#putInJobQueue(async jobId => {
1009
1071
  await this.blockStateSynchronizer.sync();
1010
1072
 
1011
- anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
1073
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1074
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1012
1075
 
1013
1076
  const contractFunctionSimulator = this.#getSimulatorForTx();
1014
1077
 
1015
- await this.contractStore.syncPrivateState(
1078
+ await this.contractSyncService.ensureContractSynced(
1016
1079
  filter.contractAddress,
1017
1080
  null,
1018
1081
  async privateSyncCall =>
1019
1082
  await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1083
+ anchorBlockHeader,
1084
+ jobId,
1020
1085
  );
1021
1086
  });
1022
1087
 
@@ -43,23 +43,23 @@ export class AddressStore {
43
43
  });
44
44
  }
45
45
 
46
- async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
47
- const index = await this.#completeAddressIndex.getAsync(address.toString());
48
- if (index === undefined) {
49
- return undefined;
50
- }
51
-
52
- const value = await this.#completeAddresses.atAsync(index);
53
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
54
- }
55
-
56
46
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
57
- return this.#getCompleteAddress(account);
47
+ return this.#store.transactionAsync(async () => {
48
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
49
+ if (index === undefined) {
50
+ return undefined;
51
+ }
52
+
53
+ const value = await this.#completeAddresses.atAsync(index);
54
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
55
+ });
58
56
  }
59
57
 
60
- async getCompleteAddresses(): Promise<CompleteAddress[]> {
61
- return await Promise.all(
62
- (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
63
- );
58
+ getCompleteAddresses(): Promise<CompleteAddress[]> {
59
+ return this.#store.transactionAsync(async () => {
60
+ return await Promise.all(
61
+ (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
62
+ );
63
+ });
64
64
  }
65
65
  }
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
10
10
  this.#synchronizedHeader = this.#store.openSingleton('header');
11
11
  }
12
12
 
13
+ /**
14
+ * Sets the currently synchronized block
15
+ *
16
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
17
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
18
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
19
+ *
20
+ */
13
21
  async setHeader(header: BlockHeader): Promise<void> {
14
22
  await this.#synchronizedHeader.set(header.toBuffer());
15
23
  }
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
57
57
  */
58
58
  async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
59
59
  const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
60
- let staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
- // Note that if staged === null, we marked it for deletion, so we don't want to
62
- // re-read it from DB
63
- if (staged === undefined) {
64
- // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
65
- staged = await this.#loadCapsuleFromDb(dbSlotKey);
66
- }
67
- return staged;
60
+ const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
61
+
62
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
63
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
64
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
65
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
66
+
67
+ return staged !== undefined ? staged : dbValue;
68
68
  }
69
69
 
70
70
  /**
@@ -3,7 +3,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { toArray } from '@aztec/foundation/iterable';
4
4
  import type { MembershipWitness } from '@aztec/foundation/trees';
5
5
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
6
- import { isProtocolContract } from '@aztec/protocol-contracts';
7
6
  import {
8
7
  type ContractArtifact,
9
8
  type FunctionAbi,
@@ -43,10 +42,12 @@ export class ContractStore {
43
42
  /** Map from contract address to contract class id */
44
43
  #contractClassIdMap: Map<string, Fr> = new Map();
45
44
 
45
+ #store: AztecAsyncKVStore;
46
46
  #contractArtifacts: AztecAsyncMap<string, Buffer>;
47
47
  #contractInstances: AztecAsyncMap<string, Buffer>;
48
48
 
49
49
  constructor(store: AztecAsyncKVStore) {
50
+ this.#store = store;
50
51
  this.#contractArtifacts = store.openMap('contract_artifacts');
51
52
  this.#contractInstances = store.openMap('contracts_instances');
52
53
  }
@@ -54,6 +55,7 @@ export class ContractStore {
54
55
  // Setters
55
56
 
56
57
  public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
58
+ // Validation outside transactionAsync - these are not DB operations
57
59
  const privateFunctions = contract.functions.filter(
58
60
  functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
59
61
  );
@@ -70,7 +72,9 @@ export class ContractStore {
70
72
  throw new Error('Repeated function selectors of private functions');
71
73
  }
72
74
 
73
- await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
75
+ await this.#store.transactionAsync(() =>
76
+ this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract)),
77
+ );
74
78
  }
75
79
 
76
80
  async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
@@ -124,21 +128,27 @@ export class ContractStore {
124
128
 
125
129
  // Public getters
126
130
 
127
- async getContractsAddresses(): Promise<AztecAddress[]> {
128
- const keys = await toArray(this.#contractInstances.keysAsync());
129
- return keys.map(AztecAddress.fromString);
131
+ getContractsAddresses(): Promise<AztecAddress[]> {
132
+ return this.#store.transactionAsync(async () => {
133
+ const keys = await toArray(this.#contractInstances.keysAsync());
134
+ return keys.map(AztecAddress.fromString);
135
+ });
130
136
  }
131
137
 
132
138
  /** Returns a contract instance for a given address. Throws if not found. */
133
- public async getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
134
- const contract = await this.#contractInstances.getAsync(contractAddress.toString());
135
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
139
+ public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
140
+ return this.#store.transactionAsync(async () => {
141
+ const contract = await this.#contractInstances.getAsync(contractAddress.toString());
142
+ return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
143
+ });
136
144
  }
137
145
 
138
- public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
139
- const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
140
- // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
141
- return contract && contractArtifactFromBuffer(Buffer.from(contract));
146
+ public getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
147
+ return this.#store.transactionAsync(async () => {
148
+ const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
149
+ // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
150
+ return contract && contractArtifactFromBuffer(Buffer.from(contract));
151
+ });
142
152
  }
143
153
 
144
154
  /** Returns a contract class for a given class id. Throws if not found. */
@@ -306,34 +316,15 @@ export class ContractStore {
306
316
  throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
307
317
  }
308
318
 
309
- return {
319
+ return FunctionCall.from({
310
320
  name: functionDao.name,
311
- args: encodeArguments(functionDao, args),
321
+ to,
312
322
  selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
313
323
  type: functionDao.functionType,
314
- to,
315
324
  hideMsgSender: false,
316
325
  isStatic: functionDao.isStatic,
326
+ args: encodeArguments(functionDao, args),
317
327
  returnTypes: functionDao.returnTypes,
318
- };
319
- }
320
-
321
- // Synchronize target contract data
322
- public async syncPrivateState(
323
- contractAddress: AztecAddress,
324
- functionToInvokeAfterSync: FunctionSelector | null,
325
- utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
326
- ) {
327
- // Protocol contracts don't have private state to sync
328
- if (!isProtocolContract(contractAddress)) {
329
- const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
330
- if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
331
- throw new Error(
332
- 'Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
333
- );
334
- }
335
-
336
- return utilityExecutor(syncPrivateStateFunctionCall);
337
- }
328
+ });
338
329
  }
339
330
  }
@@ -1 +1 @@
1
- export const PXE_DATA_SCHEMA_VERSION = 2;
1
+ export const PXE_DATA_SCHEMA_VERSION = 3;