@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.e2b2873ed

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 (179) 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 +50 -28
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.js +71 -40
  11. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  12. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  13. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  14. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  15. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
  16. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
  18. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/oracle/oracle.js +51 -29
  20. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
  21. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
  23. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +43 -36
  24. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +87 -23
  26. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +61 -30
  27. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +108 -86
  29. package/dest/contract_sync/contract_sync_service.d.ts +42 -0
  30. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  31. package/dest/contract_sync/contract_sync_service.js +97 -0
  32. package/dest/contract_sync/helpers.d.ts +28 -0
  33. package/dest/contract_sync/helpers.d.ts.map +1 -0
  34. package/dest/contract_sync/helpers.js +55 -0
  35. package/dest/debug/pxe_debug_utils.d.ts +22 -9
  36. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  37. package/dest/debug/pxe_debug_utils.js +28 -17
  38. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  39. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  40. package/dest/entrypoints/client/bundle/utils.js +21 -7
  41. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  42. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  43. package/dest/entrypoints/client/lazy/utils.js +22 -8
  44. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  45. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  46. package/dest/entrypoints/server/index.d.ts +2 -1
  47. package/dest/entrypoints/server/index.d.ts.map +1 -1
  48. package/dest/entrypoints/server/index.js +1 -0
  49. package/dest/entrypoints/server/utils.d.ts +1 -1
  50. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  51. package/dest/entrypoints/server/utils.js +28 -9
  52. package/dest/events/event_service.d.ts +5 -6
  53. package/dest/events/event_service.d.ts.map +1 -1
  54. package/dest/events/event_service.js +6 -7
  55. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  56. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  57. package/dest/job_coordinator/job_coordinator.js +3 -2
  58. package/dest/logs/log_service.d.ts +6 -5
  59. package/dest/logs/log_service.d.ts.map +1 -1
  60. package/dest/logs/log_service.js +24 -28
  61. package/dest/notes/note_service.d.ts +6 -6
  62. package/dest/notes/note_service.d.ts.map +1 -1
  63. package/dest/notes/note_service.js +14 -14
  64. package/dest/oracle_version.d.ts +3 -3
  65. package/dest/oracle_version.d.ts.map +1 -1
  66. package/dest/oracle_version.js +4 -3
  67. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  68. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  69. package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
  70. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
  71. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  72. package/dest/pxe.d.ts +68 -23
  73. package/dest/pxe.d.ts.map +1 -1
  74. package/dest/pxe.js +78 -48
  75. package/dest/storage/address_store/address_store.d.ts +1 -1
  76. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  77. package/dest/storage/address_store/address_store.js +12 -11
  78. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  79. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  80. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  81. package/dest/storage/capsule_store/capsule_store.js +6 -8
  82. package/dest/storage/contract_store/contract_store.d.ts +1 -2
  83. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  84. package/dest/storage/contract_store/contract_store.js +27 -30
  85. package/dest/storage/metadata.d.ts +1 -1
  86. package/dest/storage/metadata.js +1 -1
  87. package/dest/storage/note_store/note_store.d.ts +47 -50
  88. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  89. package/dest/storage/note_store/note_store.js +278 -252
  90. package/dest/storage/note_store/stored_note.d.ts +16 -0
  91. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  92. package/dest/storage/note_store/stored_note.js +43 -0
  93. package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
  94. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  95. package/dest/storage/private_event_store/private_event_store.js +198 -147
  96. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  97. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  98. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  99. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  100. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  101. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  102. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  103. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  104. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  105. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  106. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  107. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  108. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  109. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  110. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  111. package/dest/tagging/index.d.ts +2 -1
  112. package/dest/tagging/index.d.ts.map +1 -1
  113. package/dest/tagging/index.js +1 -0
  114. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  115. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  116. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
  117. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  118. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  119. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  120. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  121. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  122. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
  123. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  124. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  125. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  126. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
  127. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  128. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +7 -4
  129. package/package.json +25 -16
  130. package/src/bin/check_oracle_version.ts +1 -0
  131. package/src/block_synchronizer/block_synchronizer.ts +76 -33
  132. package/src/config/index.ts +14 -0
  133. package/src/contract_function_simulator/contract_function_simulator.ts +117 -87
  134. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  135. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  136. package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
  137. package/src/contract_function_simulator/oracle/oracle.ts +56 -26
  138. package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
  139. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +122 -101
  140. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +170 -95
  141. package/src/contract_sync/contract_sync_service.ts +145 -0
  142. package/src/contract_sync/helpers.ts +93 -0
  143. package/src/debug/pxe_debug_utils.ts +61 -17
  144. package/src/entrypoints/client/bundle/utils.ts +16 -15
  145. package/src/entrypoints/client/lazy/utils.ts +17 -15
  146. package/src/entrypoints/pxe_creation_options.ts +2 -1
  147. package/src/entrypoints/server/index.ts +1 -0
  148. package/src/entrypoints/server/utils.ts +22 -26
  149. package/src/events/event_service.ts +5 -7
  150. package/src/job_coordinator/job_coordinator.ts +4 -3
  151. package/src/logs/log_service.ts +35 -28
  152. package/src/notes/note_service.ts +21 -20
  153. package/src/oracle_version.ts +4 -3
  154. package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
  155. package/src/private_kernel/private_kernel_oracle.ts +2 -2
  156. package/src/pxe.ts +178 -85
  157. package/src/storage/address_store/address_store.ts +15 -15
  158. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  159. package/src/storage/capsule_store/capsule_store.ts +8 -8
  160. package/src/storage/contract_store/contract_store.ts +26 -35
  161. package/src/storage/metadata.ts +1 -1
  162. package/src/storage/note_store/note_store.ts +317 -318
  163. package/src/storage/note_store/stored_note.ts +48 -0
  164. package/src/storage/private_event_store/private_event_store.ts +250 -190
  165. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  166. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  167. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  168. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  169. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  170. package/src/tagging/index.ts +1 -0
  171. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
  172. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  173. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
  174. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  175. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
  176. package/dest/tree_membership/tree_membership_service.d.ts +0 -50
  177. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  178. package/dest/tree_membership/tree_membership_service.js +0 -75
  179. 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 = 12;
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 = '8fb18d1fa560c4844b22c55a3e79c32ffcb71ded9ac409911470ee0296a84d72';
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 = '666a8a7fc697f72b29dbf0ae7464db269cf5afa019acac8861f814543147dbb4';
@@ -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';
@@ -85,6 +86,56 @@ export type PackedPrivateEvent = InTx & {
85
86
  eventSelector: EventSelector;
86
87
  };
87
88
 
89
+ /** Options for PXE.profileTx. */
90
+ export type ProfileTxOpts = {
91
+ /** The profiling mode to use. */
92
+ profileMode: 'full' | 'execution-steps' | 'gates';
93
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
94
+ skipProofGeneration?: boolean;
95
+ /** Addresses whose private state and keys are accessible during private execution. */
96
+ scopes?: AztecAddress[];
97
+ };
98
+
99
+ /** Options for PXE.simulateTx. */
100
+ export type SimulateTxOpts = {
101
+ /** Whether to simulate the public part of the transaction. */
102
+ simulatePublic: boolean;
103
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
104
+ skipTxValidation?: boolean;
105
+ /** If false, fees are enforced. */
106
+ skipFeeEnforcement?: boolean;
107
+ /** State overrides for the simulation, such as contract instances and artifacts. */
108
+ overrides?: SimulationOverrides;
109
+ /** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
110
+ scopes?: AztecAddress[];
111
+ };
112
+
113
+ /** Options for PXE.simulateUtility. */
114
+ export type SimulateUtilityOpts = {
115
+ /** The authentication witnesses required for the function call. */
116
+ authwits?: AuthWitness[];
117
+ /** The accounts whose notes we can access in this call. Defaults to all. */
118
+ scopes?: AztecAddress[];
119
+ };
120
+
121
+ /** Args for PXE.create. */
122
+ export type PXECreateArgs = {
123
+ /** The Aztec node to connect to. */
124
+ node: AztecNode;
125
+ /** The key-value store for persisting PXE state. */
126
+ store: AztecAsyncKVStore;
127
+ /** The prover for generating private kernel proofs. */
128
+ proofCreator: PrivateKernelProver;
129
+ /** The circuit simulator for executing ACIR circuits. */
130
+ simulator: CircuitSimulator;
131
+ /** Provider for protocol contract artifacts and instances. */
132
+ protocolContractsProvider: ProtocolContractsProvider;
133
+ /** PXE configuration options. */
134
+ config: PXEConfig;
135
+ /** Optional logger instance or string suffix for the logger name. */
136
+ loggerOrSuffix?: string | Logger;
137
+ };
138
+
88
139
  /**
89
140
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
141
  * manage private state of users.
@@ -103,6 +154,7 @@ export class PXE {
103
154
  private recipientTaggingStore: RecipientTaggingStore,
104
155
  private addressStore: AddressStore,
105
156
  private privateEventStore: PrivateEventStore,
157
+ private contractSyncService: ContractSyncService,
106
158
  private simulator: CircuitSimulator,
107
159
  private proverEnabled: boolean,
108
160
  private proofCreator: PrivateKernelProver,
@@ -120,25 +172,31 @@ export class PXE {
120
172
  *
121
173
  * @returns A promise that resolves PXE is ready to be used.
122
174
  */
123
- public static async create(
124
- node: AztecNode,
125
- store: AztecAsyncKVStore,
126
- proofCreator: PrivateKernelProver,
127
- simulator: CircuitSimulator,
128
- protocolContractsProvider: ProtocolContractsProvider,
129
- config: PXEConfig,
130
- loggerOrSuffix?: string | Logger,
131
- ) {
175
+ public static async create({
176
+ node,
177
+ store,
178
+ proofCreator,
179
+ simulator,
180
+ protocolContractsProvider,
181
+ config,
182
+ loggerOrSuffix,
183
+ }: PXECreateArgs) {
184
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
185
+ const bindings: LoggerBindings | undefined =
186
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
187
+
132
188
  const log =
133
189
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
190
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
191
  : loggerOrSuffix;
136
192
 
137
- const proverEnabled = !!config.proverEnabled;
193
+ const info = await node.getNodeInfo();
194
+
195
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
196
  const addressStore = new AddressStore(store);
139
197
  const privateEventStore = new PrivateEventStore(store);
140
198
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
199
+ const noteStore = new NoteStore(store);
142
200
  const anchorBlockStore = new AnchorBlockStore(store);
143
201
  const senderTaggingStore = new SenderTaggingStore(store);
144
202
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,6 +204,12 @@ export class PXE {
146
204
  const capsuleStore = new CapsuleStore(store);
147
205
  const keyStore = new KeyStore(store);
148
206
  const tipsStore = new L2TipsKVStore(store, 'pxe');
207
+ const contractSyncService = new ContractSyncService(
208
+ node,
209
+ contractStore,
210
+ noteStore,
211
+ createLogger('pxe:contract_sync', bindings),
212
+ );
149
213
  const synchronizer = new BlockSynchronizer(
150
214
  node,
151
215
  store,
@@ -153,14 +217,22 @@ export class PXE {
153
217
  noteStore,
154
218
  privateEventStore,
155
219
  tipsStore,
220
+ contractSyncService,
156
221
  config,
157
- loggerOrSuffix,
222
+ bindings,
158
223
  );
159
224
 
160
- const jobCoordinator = new JobCoordinator(store);
161
- jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
225
+ const jobCoordinator = new JobCoordinator(store, bindings);
226
+ jobCoordinator.registerStores([
227
+ capsuleStore,
228
+ senderTaggingStore,
229
+ recipientTaggingStore,
230
+ privateEventStore,
231
+ noteStore,
232
+ contractSyncService,
233
+ ]);
162
234
 
163
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
235
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
164
236
 
165
237
  const jobQueue = new SerialQueue();
166
238
 
@@ -177,6 +249,7 @@ export class PXE {
177
249
  recipientTaggingStore,
178
250
  addressStore,
179
251
  privateEventStore,
252
+ contractSyncService,
180
253
  simulator,
181
254
  proverEnabled,
182
255
  proofCreator,
@@ -187,12 +260,15 @@ export class PXE {
187
260
  debugUtils,
188
261
  );
189
262
 
190
- debugUtils.setPXE(pxe);
263
+ debugUtils.setPXEHelpers(
264
+ pxe.#putInJobQueue.bind(pxe),
265
+ pxe.#getSimulatorForTx.bind(pxe),
266
+ pxe.#simulateUtility.bind(pxe),
267
+ );
191
268
 
192
269
  pxe.jobQueue.start();
193
270
 
194
271
  await pxe.#registerProtocolContracts();
195
- const info = await node.getNodeInfo();
196
272
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
197
273
  return pxe;
198
274
  }
@@ -202,20 +278,20 @@ export class PXE {
202
278
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
203
279
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
204
280
 
205
- return new ContractFunctionSimulator(
206
- proxyContractStore,
207
- this.noteStore,
208
- this.keyStore,
209
- this.addressStore,
210
- BenchmarkedNodeFactory.create(this.node),
211
- this.anchorBlockStore,
212
- this.senderTaggingStore,
213
- this.recipientTaggingStore,
214
- this.senderAddressBookStore,
215
- this.capsuleStore,
216
- this.privateEventStore,
217
- this.simulator,
218
- );
281
+ return new ContractFunctionSimulator({
282
+ contractStore: proxyContractStore,
283
+ noteStore: this.noteStore,
284
+ keyStore: this.keyStore,
285
+ addressStore: this.addressStore,
286
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
287
+ senderTaggingStore: this.senderTaggingStore,
288
+ recipientTaggingStore: this.recipientTaggingStore,
289
+ senderAddressBookStore: this.senderAddressBookStore,
290
+ capsuleStore: this.capsuleStore,
291
+ privateEventStore: this.privateEventStore,
292
+ simulator: this.simulator,
293
+ contractSyncService: this.contractSyncService,
294
+ });
219
295
  }
220
296
 
221
297
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -289,18 +365,23 @@ export class PXE {
289
365
  try {
290
366
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
291
367
 
292
- const result = await contractFunctionSimulator.run(
293
- txRequest,
368
+ await this.contractSyncService.ensureContractSynced(
294
369
  contractAddress,
295
370
  functionSelector,
296
- undefined,
371
+ (privateSyncCall, execScopes) =>
372
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
297
373
  anchorBlockHeader,
298
- // The sender for tags is set by contracts, typically by an account
299
- // contract entrypoint
300
- undefined, // senderForTags
301
- scopes,
302
374
  jobId,
375
+ scopes,
303
376
  );
377
+
378
+ const result = await contractFunctionSimulator.run(txRequest, {
379
+ contractAddress,
380
+ selector: functionSelector,
381
+ anchorBlockHeader,
382
+ scopes,
383
+ jobId,
384
+ });
304
385
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
305
386
  return result;
306
387
  } catch (err) {
@@ -384,15 +465,33 @@ export class PXE {
384
465
  config: PrivateKernelExecutionProverConfig,
385
466
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
386
467
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
387
- const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
468
+ const anchorBlockHash = await anchorBlockHeader.hash();
388
469
  const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
389
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
470
+ const kernelTraceProver = new PrivateKernelExecutionProver(
471
+ kernelOracle,
472
+ proofCreator,
473
+ !this.proverEnabled,
474
+ this.log.getBindings(),
475
+ );
390
476
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
391
477
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
392
478
  }
393
479
 
394
480
  // Public API
395
481
 
482
+ /**
483
+ * Returns the block header up to which the PXE has synced.
484
+ * @returns The synced block header
485
+ */
486
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
487
+ return this.anchorBlockStore.getBlockHeader();
488
+ }
489
+
490
+ /**
491
+ * Returns the contract instance for a given address, if it's registered in the PXE.
492
+ * @param address - The contract address.
493
+ * @returns The contract instance if found, undefined otherwise.
494
+ */
396
495
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
397
496
  return this.contractStore.getContractInstance(address);
398
497
  }
@@ -428,7 +527,6 @@ export class PXE {
428
527
  }
429
528
 
430
529
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
431
- await this.noteStore.addScope(accountCompleteAddress.address);
432
530
  return accountCompleteAddress;
433
531
  }
434
532
 
@@ -607,11 +705,12 @@ export class PXE {
607
705
  * (where validators prove the public portion).
608
706
  *
609
707
  * @param txRequest - An authenticated tx request ready for proving
708
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
610
709
  * @returns A result containing the proof and public inputs of the tail circuit.
611
710
  * @throws If contract code not found, or public simulation reverts.
612
711
  * Also throws if simulatePublic is true and public simulation reverts.
613
712
  */
614
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
713
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
615
714
  let privateExecutionResult: PrivateExecutionResult;
616
715
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
617
716
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -622,7 +721,7 @@ export class PXE {
622
721
  await this.blockStateSynchronizer.sync();
623
722
  const syncTime = syncTimer.ms();
624
723
  const contractFunctionSimulator = this.#getSimulatorForTx();
625
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
724
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
626
725
 
627
726
  const {
628
727
  publicInputs,
@@ -686,17 +785,13 @@ export class PXE {
686
785
 
687
786
  /**
688
787
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
689
- *
690
- * @param txRequest - An authenticated tx request ready for simulation
691
- * @param msgSender - (Optional) The message sender to use for the simulation.
692
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
788
+ * @param txRequest - An authenticated tx request ready for simulation.
693
789
  * @returns A trace of the program execution with gate counts.
694
790
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
695
791
  */
696
792
  public profileTx(
697
793
  txRequest: TxExecutionRequest,
698
- profileMode: 'full' | 'execution-steps' | 'gates',
699
- skipProofGeneration: boolean = true,
794
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
700
795
  ): Promise<TxProfileResult> {
701
796
  // We disable concurrent profiles for consistency with simulateTx.
702
797
  return this.#putInJobQueue(async jobId => {
@@ -719,12 +814,7 @@ export class PXE {
719
814
  const syncTime = syncTimer.ms();
720
815
 
721
816
  const contractFunctionSimulator = this.#getSimulatorForTx();
722
- const privateExecutionResult = await this.#executePrivate(
723
- contractFunctionSimulator,
724
- txRequest,
725
- undefined,
726
- jobId,
727
- );
817
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
728
818
 
729
819
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
730
820
  txRequest,
@@ -781,12 +871,7 @@ export class PXE {
781
871
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
782
872
  *
783
873
  *
784
- * @param txRequest - An authenticated tx request ready for simulation
785
- * @param simulatePublic - Whether to simulate the public part of the transaction.
786
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
787
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
788
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
789
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
874
+ * @param txRequest - An authenticated tx request ready for simulation.
790
875
  * @returns A simulated transaction result object that includes public and private return values.
791
876
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
792
877
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -795,11 +880,7 @@ export class PXE {
795
880
  */
796
881
  public simulateTx(
797
882
  txRequest: TxExecutionRequest,
798
- simulatePublic: boolean,
799
- skipTxValidation: boolean = false,
800
- skipFeeEnforcement: boolean = false,
801
- overrides?: SimulationOverrides,
802
- scopes?: AztecAddress[],
883
+ { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
803
884
  ): Promise<TxSimulationResult> {
804
885
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
805
886
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -827,7 +908,14 @@ export class PXE {
827
908
  // Temporary: in case there are overrides, we have to skip the kernels or validations
828
909
  // will fail. Consider handing control to the user/wallet on whether they want to run them
829
910
  // or not.
830
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
911
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
912
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
913
+ const skipKernels = hasOverriddenContracts;
914
+
915
+ // Set overridden contracts on the sync service so it knows to skip syncing them
916
+ if (hasOverriddenContracts) {
917
+ this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
918
+ }
831
919
 
832
920
  // Execution of private functions only; no proving, and no kernel logic.
833
921
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -838,7 +926,7 @@ export class PXE {
838
926
  if (skipKernels) {
839
927
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
840
928
  privateExecutionResult,
841
- this.contractStore,
929
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
842
930
  ));
843
931
  } else {
844
932
  // Kernel logic, plus proving of all private functions and kernels.
@@ -923,18 +1011,12 @@ export class PXE {
923
1011
  }
924
1012
 
925
1013
  /**
926
- * Simulate the execution of a contract utility function.
927
- *
1014
+ * Simulates the execution of a contract utility function.
928
1015
  * @param call - The function call containing the function details, arguments, and target contract address.
929
- * @param authwits - (Optional) The authentication witnesses required for the function call.
930
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
931
- * default to all.
932
- * @returns The result of the utility function call, structured based on the function ABI.
933
1016
  */
934
1017
  public simulateUtility(
935
1018
  call: FunctionCall,
936
- authwits?: AuthWitness[],
937
- scopes?: AztecAddress[],
1019
+ { authwits, scopes }: SimulateUtilityOpts = {},
938
1020
  ): Promise<UtilitySimulationResult> {
939
1021
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
940
1022
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -948,8 +1030,15 @@ export class PXE {
948
1030
  const functionTimer = new Timer();
949
1031
  const contractFunctionSimulator = this.#getSimulatorForTx();
950
1032
 
951
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
952
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1033
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1034
+ await this.contractSyncService.ensureContractSynced(
1035
+ call.to,
1036
+ call.selector,
1037
+ (privateSyncCall, execScopes) =>
1038
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1039
+ anchorBlockHeader,
1040
+ jobId,
1041
+ scopes,
953
1042
  );
954
1043
 
955
1044
  const executionResult = await this.#simulateUtility(
@@ -1008,15 +1097,19 @@ export class PXE {
1008
1097
  await this.#putInJobQueue(async jobId => {
1009
1098
  await this.blockStateSynchronizer.sync();
1010
1099
 
1011
- anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
1100
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1101
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1012
1102
 
1013
1103
  const contractFunctionSimulator = this.#getSimulatorForTx();
1014
1104
 
1015
- await this.contractStore.syncPrivateState(
1105
+ await this.contractSyncService.ensureContractSynced(
1016
1106
  filter.contractAddress,
1017
1107
  null,
1018
- async privateSyncCall =>
1019
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1108
+ async (privateSyncCall, execScopes) =>
1109
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1110
+ anchorBlockHeader,
1111
+ jobId,
1112
+ filter.scopes,
1020
1113
  );
1021
1114
  });
1022
1115