@aztec/pxe 0.0.1-commit.b655e406 → 0.0.1-commit.d3ec352c

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 (157) hide show
  1. package/dest/bin/check_oracle_version.d.ts +1 -1
  2. package/dest/config/index.d.ts +2 -10
  3. package/dest/config/index.d.ts.map +1 -1
  4. package/dest/config/index.js +7 -13
  5. package/dest/config/package_info.d.ts +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.d.ts +4 -4
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.js +9 -10
  9. package/dest/contract_function_simulator/execution_data_provider.d.ts +11 -18
  10. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/execution_note_cache.d.ts +8 -6
  12. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/execution_note_cache.js +20 -12
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  15. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/hashed_values_cache.d.ts +1 -1
  17. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/index.d.ts +1 -1
  19. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  22. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -3
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  28. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +1 -1
  29. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/index.d.ts +1 -1
  31. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -9
  32. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +1 -3
  34. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +5 -3
  36. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/oracle/note_packing_utils.js +4 -3
  38. package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -4
  39. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/oracle.js +18 -12
  41. package/dest/contract_function_simulator/oracle/private_execution.d.ts +3 -2
  42. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +7 -11
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +19 -6
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +11 -10
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +3 -2
  49. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  50. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  51. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  53. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +12 -11
  55. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/pxe_oracle_interface.js +15 -20
  57. package/dest/entrypoints/client/bundle/index.d.ts +1 -1
  58. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  59. package/dest/entrypoints/client/bundle/utils.js +2 -2
  60. package/dest/entrypoints/client/lazy/index.d.ts +1 -1
  61. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  62. package/dest/entrypoints/client/lazy/utils.js +2 -2
  63. package/dest/entrypoints/pxe_creation_options.d.ts +1 -1
  64. package/dest/entrypoints/server/index.d.ts +1 -1
  65. package/dest/entrypoints/server/utils.d.ts +1 -1
  66. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/server/utils.js +4 -15
  68. package/dest/error_enriching.d.ts +1 -1
  69. package/dest/oracle_version.d.ts +3 -3
  70. package/dest/oracle_version.js +2 -2
  71. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  72. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  73. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  74. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  75. package/dest/private_kernel/hints/index.d.ts +1 -1
  76. package/dest/private_kernel/index.d.ts +1 -1
  77. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  78. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  79. package/dest/private_kernel/private_kernel_execution_prover.js +7 -6
  80. package/dest/private_kernel/private_kernel_oracle.d.ts +1 -1
  81. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +4 -4
  82. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  83. package/dest/pxe.d.ts +20 -13
  84. package/dest/pxe.d.ts.map +1 -1
  85. package/dest/pxe.js +19 -37
  86. package/dest/storage/address_data_provider/address_data_provider.d.ts +1 -1
  87. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  88. package/dest/storage/address_data_provider/index.d.ts +1 -1
  89. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +1 -1
  90. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  91. package/dest/storage/capsule_data_provider/index.d.ts +1 -1
  92. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +2 -12
  93. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  94. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -12
  95. package/dest/storage/contract_data_provider/index.d.ts +1 -1
  96. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +1 -1
  97. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  98. package/dest/storage/index.d.ts +1 -1
  99. package/dest/storage/metadata.d.ts +1 -1
  100. package/dest/storage/note_data_provider/index.d.ts +2 -2
  101. package/dest/storage/note_data_provider/index.d.ts.map +1 -1
  102. package/dest/storage/note_data_provider/index.js +1 -1
  103. package/dest/storage/note_data_provider/note_data_provider.d.ts +5 -5
  104. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  105. package/dest/storage/note_data_provider/note_data_provider.js +17 -11
  106. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +2 -8
  107. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -1
  108. package/dest/storage/private_event_data_provider/private_event_data_provider.js +3 -2
  109. package/dest/storage/sync_data_provider/index.d.ts +1 -1
  110. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +3 -2
  111. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  112. package/dest/storage/tagging_data_provider/index.d.ts +1 -1
  113. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +1 -1
  114. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  115. package/dest/synchronizer/index.d.ts +1 -1
  116. package/dest/synchronizer/synchronizer.d.ts +3 -2
  117. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  118. package/dest/synchronizer/synchronizer.js +2 -1
  119. package/dest/tagging/constants.d.ts +1 -1
  120. package/dest/tagging/index.d.ts +1 -1
  121. package/dest/tagging/siloed_tag.d.ts +1 -1
  122. package/dest/tagging/siloed_tag.d.ts.map +1 -1
  123. package/dest/tagging/tag.d.ts +1 -1
  124. package/dest/tagging/tag.d.ts.map +1 -1
  125. package/dest/tagging/utils.d.ts +1 -1
  126. package/package.json +20 -19
  127. package/src/config/index.ts +8 -23
  128. package/src/contract_function_simulator/contract_function_simulator.ts +17 -12
  129. package/src/contract_function_simulator/execution_data_provider.ts +16 -17
  130. package/src/contract_function_simulator/execution_note_cache.ts +18 -10
  131. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  132. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +13 -1
  133. package/src/contract_function_simulator/oracle/interfaces.ts +22 -7
  134. package/src/contract_function_simulator/oracle/note_packing_utils.ts +5 -3
  135. package/src/contract_function_simulator/oracle/oracle.ts +24 -8
  136. package/src/contract_function_simulator/oracle/private_execution.ts +2 -1
  137. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +16 -3
  138. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +19 -7
  139. package/src/contract_function_simulator/pxe_oracle_interface.ts +54 -50
  140. package/src/entrypoints/client/bundle/utils.ts +2 -2
  141. package/src/entrypoints/client/lazy/utils.ts +2 -2
  142. package/src/entrypoints/server/utils.ts +4 -18
  143. package/src/oracle_version.ts +2 -2
  144. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +4 -8
  145. package/src/private_kernel/private_kernel_execution_prover.ts +8 -12
  146. package/src/private_kernel/private_kernel_oracle_impl.ts +2 -2
  147. package/src/pxe.ts +36 -64
  148. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -17
  149. package/src/storage/note_data_provider/index.ts +1 -1
  150. package/src/storage/note_data_provider/note_data_provider.ts +22 -12
  151. package/src/storage/private_event_data_provider/private_event_data_provider.ts +4 -9
  152. package/src/storage/sync_data_provider/sync_data_provider.ts +2 -1
  153. package/src/synchronizer/synchronizer.ts +2 -1
  154. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  155. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  156. package/dest/storage/note_data_provider/note_dao.js +0 -102
  157. package/src/storage/note_data_provider/note_dao.ts +0 -154
package/src/pxe.ts CHANGED
@@ -9,16 +9,16 @@ import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/pr
9
9
  import type { CircuitSimulator } from '@aztec/simulator/client';
10
10
  import {
11
11
  type ContractArtifact,
12
- type EventMetadataDefinition,
12
+ EventSelector,
13
13
  FunctionCall,
14
14
  FunctionSelector,
15
15
  FunctionType,
16
- decodeFromAbi,
17
16
  decodeFunctionSignature,
18
17
  encodeArguments,
19
18
  } from '@aztec/stdlib/abi';
20
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
21
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2BlockHash } from '@aztec/stdlib/block';
22
22
  import {
23
23
  CompleteAddress,
24
24
  type ContractClassWithId,
@@ -28,14 +28,15 @@ import {
28
28
  getContractClassFromArtifact,
29
29
  } from '@aztec/stdlib/contract';
30
30
  import { SimulationError } from '@aztec/stdlib/errors';
31
- import { siloNullifier } from '@aztec/stdlib/hash';
31
+ import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
32
32
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
33
33
  import type {
34
34
  PrivateExecutionStep,
35
35
  PrivateKernelExecutionProofOutput,
36
36
  PrivateKernelTailCircuitPublicInputs,
37
37
  } from '@aztec/stdlib/kernel';
38
- import { type NotesFilter, UniqueNote } from '@aztec/stdlib/note';
38
+ import type { NotesFilter } from '@aztec/stdlib/note';
39
+ import { NoteDao } from '@aztec/stdlib/note';
39
40
  import {
40
41
  type ContractOverrides,
41
42
  PrivateExecutionResult,
@@ -46,6 +47,7 @@ import {
46
47
  type SimulationTimings,
47
48
  Tx,
48
49
  TxExecutionRequest,
50
+ TxHash,
49
51
  TxProfileResult,
50
52
  TxProvingResult,
51
53
  TxSimulationResult,
@@ -73,14 +75,20 @@ import { AddressDataProvider } from './storage/address_data_provider/address_dat
73
75
  import { CapsuleDataProvider } from './storage/capsule_data_provider/capsule_data_provider.js';
74
76
  import { ContractDataProvider } from './storage/contract_data_provider/contract_data_provider.js';
75
77
  import { NoteDataProvider } from './storage/note_data_provider/note_data_provider.js';
76
- import {
77
- type PrivateEvent,
78
- PrivateEventDataProvider,
79
- } from './storage/private_event_data_provider/private_event_data_provider.js';
78
+ import { PrivateEventDataProvider } from './storage/private_event_data_provider/private_event_data_provider.js';
80
79
  import { SyncDataProvider } from './storage/sync_data_provider/sync_data_provider.js';
81
80
  import { TaggingDataProvider } from './storage/tagging_data_provider/tagging_data_provider.js';
82
81
  import { Synchronizer } from './synchronizer/index.js';
83
82
 
83
+ export type PrivateEvent = {
84
+ packedEvent: Fr[];
85
+ blockNumber: number;
86
+ blockHash: L2BlockHash;
87
+ txHash: TxHash;
88
+ recipient: AztecAddress;
89
+ eventSelector: EventSelector;
90
+ };
91
+
84
92
  /**
85
93
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
86
94
  * manage private state of users.
@@ -665,25 +673,12 @@ export class PXE {
665
673
  * @param filter - The filter to apply to the notes.
666
674
  * @returns The requested notes.
667
675
  */
668
- public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
676
+ public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
669
677
  // We need to manually trigger private state sync to have a guarantee that all the notes are available.
670
- await this.simulateUtility('sync_private_state', [], filter.contractAddress);
671
-
672
- const noteDaos = await this.noteDataProvider.getNotes(filter);
678
+ const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
679
+ await this.simulateUtility(call);
673
680
 
674
- const uniqueNotes = noteDaos.map(async dao => {
675
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
676
- const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
677
- completeAddress.address.equals(dao.recipient),
678
- );
679
- const completeAddress = completeAddresses[completeAddressIndex];
680
- if (completeAddress === undefined) {
681
- throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
682
- }
683
- const recipient = completeAddress.address;
684
- return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
685
- });
686
- return Promise.all(uniqueNotes);
681
+ return this.noteDataProvider.getNotes(filter);
687
682
  }
688
683
 
689
684
  /**
@@ -908,10 +903,9 @@ export class PXE {
908
903
 
909
904
  if (skipKernels) {
910
905
  // According to the protocol rules, the nonce generator for the note hashes
911
- // can either be the first nullifier in the tx or the hash of the initial tx request
912
- // if there are none.
906
+ // can either be the first nullifier in the tx or the protocol nullifier if there are none.
913
907
  const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
914
- ? await txRequest.toTxRequest().hash()
908
+ ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
915
909
  : privateExecutionResult.firstNullifier;
916
910
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
917
911
  privateExecutionResult,
@@ -1003,21 +997,15 @@ export class PXE {
1003
997
  /**
1004
998
  * Simulate the execution of a contract utility function.
1005
999
  *
1006
- * @param functionName - The name of the utility contract function to be called.
1007
- * @param args - The arguments to be provided to the function.
1008
- * @param to - The address of the contract to be called.
1000
+ * @param call - The function call containing the function details, arguments, and target contract address.
1009
1001
  * @param authwits - (Optional) The authentication witnesses required for the function call.
1010
- * @param from - (Optional) The msg sender to set for the call.
1011
1002
  * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
1003
  * default to all.
1013
1004
  * @returns The result of the utility function call, structured based on the function ABI.
1014
1005
  */
1015
1006
  public simulateUtility(
1016
- functionName: string,
1017
- args: any[],
1018
- to: AztecAddress,
1007
+ call: FunctionCall,
1019
1008
  authwits?: AuthWitness[],
1020
- _from?: AztecAddress,
1021
1009
  scopes?: AztecAddress[],
1022
1010
  ): Promise<UtilitySimulationResult> {
1023
1011
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
@@ -1029,20 +1017,14 @@ export class PXE {
1029
1017
  const syncTimer = new Timer();
1030
1018
  await this.synchronizer.sync();
1031
1019
  const syncTime = syncTimer.ms();
1032
- const functionCall = await this.#getFunctionCall(functionName, args, to);
1033
1020
  const functionTimer = new Timer();
1034
1021
  const contractFunctionSimulator = this.#getSimulatorForTx();
1035
- const executionResult = await this.#simulateUtility(
1036
- contractFunctionSimulator,
1037
- functionCall,
1038
- authwits ?? [],
1039
- scopes,
1040
- );
1022
+ const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
1041
1023
  const functionTime = functionTimer.ms();
1042
1024
 
1043
1025
  const totalTime = totalTimer.ms();
1044
1026
 
1045
- const perFunction = [{ functionName, time: functionTime }];
1027
+ const perFunction = [{ functionName: call.name, time: functionTime }];
1046
1028
 
1047
1029
  const timings: SimulationTimings = {
1048
1030
  total: totalTime,
@@ -1054,10 +1036,11 @@ export class PXE {
1054
1036
  const simulationStats = contractFunctionSimulator.getStats();
1055
1037
  return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1056
1038
  } catch (err: any) {
1039
+ const { to, name, args } = call;
1057
1040
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1058
1041
  throw this.#contextualizeError(
1059
1042
  err,
1060
- `simulateUtility ${to}:${functionName}(${stringifiedArgs})`,
1043
+ `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1061
1044
  `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1062
1045
  );
1063
1046
  }
@@ -1067,19 +1050,19 @@ export class PXE {
1067
1050
  /**
1068
1051
  * Returns the private events given search parameters.
1069
1052
  * @param contractAddress - The address of the contract to get events from.
1070
- * @param eventMetadata - Metadata of the event. This should be the class generated from the contract. e.g. Contract.events.Event
1053
+ * @param eventSelector - Event selector to search for.
1071
1054
  * @param from - The block number to search from.
1072
1055
  * @param numBlocks - The amount of blocks to search.
1073
1056
  * @param recipients - The addresses that decrypted the logs.
1074
- * @returns - The deserialized events.
1057
+ * @returns - The packed events with block and tx metadata.
1075
1058
  */
1076
- public async getPrivateEvents<T>(
1059
+ public async getPrivateEvents(
1077
1060
  contractAddress: AztecAddress,
1078
- eventMetadataDef: EventMetadataDefinition,
1061
+ eventSelector: EventSelector,
1079
1062
  from: number,
1080
1063
  numBlocks: number,
1081
1064
  recipients: AztecAddress[],
1082
- ): Promise<T[]> {
1065
+ ): Promise<PrivateEvent[]> {
1083
1066
  if (recipients.length === 0) {
1084
1067
  throw new Error('Recipients are required to get private events');
1085
1068
  }
@@ -1087,21 +1070,10 @@ export class PXE {
1087
1070
  this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
1088
1071
 
1089
1072
  // We need to manually trigger private state sync to have a guarantee that all the events are available.
1090
- await this.simulateUtility('sync_private_state', [], contractAddress);
1091
-
1092
- const events = await this.privateEventDataProvider.getPrivateEvents(
1093
- contractAddress,
1094
- from,
1095
- numBlocks,
1096
- recipients,
1097
- eventMetadataDef.eventSelector,
1098
- );
1099
-
1100
- const decodedEvents = events.map(
1101
- (event: PrivateEvent): T => decodeFromAbi([eventMetadataDef.abiType], event.msgContent) as T,
1102
- );
1073
+ const call = await this.#getFunctionCall('sync_private_state', [], contractAddress);
1074
+ await this.simulateUtility(call);
1103
1075
 
1104
- return decodedEvents;
1076
+ return this.privateEventDataProvider.getPrivateEvents(contractAddress, from, numBlocks, recipients, eventSelector);
1105
1077
  }
1106
1078
 
1107
1079
  /**
@@ -184,23 +184,6 @@ export class ContractDataProvider {
184
184
  return fnArtifact && { ...fnArtifact, contractName: artifact.name };
185
185
  }
186
186
 
187
- /**
188
- * Retrieves the artifact of a specified function within a given contract.
189
- * The function is identified by its name, which is unique within a contract.
190
- * Throws if the contract has not been added to the database.
191
- *
192
- * @param contractAddress - The AztecAddress representing the contract containing the function.
193
- * @param functionName - The name of the function.
194
- * @returns The corresponding function's artifact as an object
195
- */
196
- public async getFunctionArtifactByName(
197
- contractAddress: AztecAddress,
198
- functionName: string,
199
- ): Promise<FunctionArtifact | undefined> {
200
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
201
- return artifact?.functions.find(fn => fn.name === functionName);
202
- }
203
-
204
187
  public async getFunctionAbi(
205
188
  contractAddress: AztecAddress,
206
189
  selector: FunctionSelector,
@@ -1,2 +1,2 @@
1
- export { NoteDao } from './note_dao.js';
1
+ export { NoteDao } from '@aztec/stdlib/note';
2
2
  export { NoteDataProvider } from './note_data_provider.js';
@@ -3,10 +3,9 @@ import type { Fr } from '@aztec/foundation/fields';
3
3
  import { toArray } from '@aztec/foundation/iterable';
4
4
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import type { InBlock } from '@aztec/stdlib/block';
6
+ import type { DataInBlock } from '@aztec/stdlib/block';
7
7
  import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
8
-
9
- import { NoteDao } from './note_dao.js';
8
+ import { NoteDao } from '@aztec/stdlib/note';
10
9
 
11
10
  /**
12
11
  * NoteDataProvider manages the storage and retrieval of notes.
@@ -194,10 +193,12 @@ export class NoteDataProvider {
194
193
  await this.#notes.set(noteIndex, dao.toBuffer());
195
194
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
196
195
 
197
- let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
196
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
198
197
 
199
198
  if (scopes.length === 0) {
200
- scopes = [dao.recipient.toString()];
199
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
200
+ // insertion via `addNotes` or when removing their nullifiers.
201
+ throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
201
202
  }
202
203
 
203
204
  for (const scope of scopes) {
@@ -223,7 +224,7 @@ export class NoteDataProvider {
223
224
  * parameters.
224
225
  *
225
226
  * @param filter - Filter criteria including contractAddress (required), and optional
226
- * storageSlot, status, scopes and siloedNullifier.
227
+ * owner, storageSlot, status, scopes, and siloedNullifier.
227
228
  * @returns Promise resolving to array of NoteDao objects matching the filter
228
229
  * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
229
230
  */
@@ -306,6 +307,10 @@ export class NoteDataProvider {
306
307
  continue;
307
308
  }
308
309
 
310
+ if (filter.owner && !note.owner.equals(filter.owner)) {
311
+ continue;
312
+ }
313
+
309
314
  if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
310
315
  continue;
311
316
  }
@@ -332,7 +337,7 @@ export class NoteDataProvider {
332
337
  * @returns Promise resolving to array of nullified NoteDao objects
333
338
  * @throws Error if any nullifier is not found in the active notes
334
339
  */
335
- applyNullifiers(nullifiers: InBlock<Fr>[]): Promise<NoteDao[]> {
340
+ applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]> {
336
341
  if (nullifiers.length === 0) {
337
342
  return Promise.resolve([]);
338
343
  }
@@ -359,7 +364,14 @@ export class NoteDataProvider {
359
364
  if (!noteBuffer) {
360
365
  throw new Error('Note not found in applyNullifiers');
361
366
  }
362
- const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
367
+
368
+ const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
369
+ if (noteScopes.length === 0) {
370
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
371
+ // insertion via `addNotes` or when removing their nullifiers.
372
+ throw new Error('Note scopes are missing in applyNullifiers');
373
+ }
374
+
363
375
  const note = NoteDao.fromBuffer(noteBuffer);
364
376
 
365
377
  nullifiedNotes.push(note);
@@ -374,10 +386,8 @@ export class NoteDataProvider {
374
386
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
375
387
  }
376
388
 
377
- if (noteScopes !== undefined) {
378
- for (const scope of noteScopes) {
379
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
380
- }
389
+ for (const scope of noteScopes) {
390
+ await this.#nullifiedNotesToScope.set(noteIndex, scope);
381
391
  }
382
392
  await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
383
393
  await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
@@ -7,6 +7,8 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { L2BlockHash } from '@aztec/stdlib/block';
8
8
  import { TxHash } from '@aztec/stdlib/tx';
9
9
 
10
+ import type { PrivateEvent } from '../../pxe.js';
11
+
10
12
  interface PrivateEventEntry {
11
13
  msgContent: Buffer;
12
14
  blockNumber: number;
@@ -15,14 +17,6 @@ interface PrivateEventEntry {
15
17
  txHash: Buffer;
16
18
  }
17
19
 
18
- export type PrivateEvent = {
19
- msgContent: Fr[];
20
- blockNumber: number;
21
- blockHash: L2BlockHash;
22
- txHash: TxHash;
23
- recipient: AztecAddress;
24
- };
25
-
26
20
  /**
27
21
  * Stores decrypted private event logs.
28
22
  */
@@ -131,11 +125,12 @@ export class PrivateEventDataProvider {
131
125
  events.push({
132
126
  eventCommitmentIndex: entry.eventCommitmentIndex,
133
127
  event: {
134
- msgContent,
128
+ packedEvent: msgContent,
135
129
  blockNumber: entry.blockNumber,
136
130
  recipient,
137
131
  txHash,
138
132
  blockHash,
133
+ eventSelector,
139
134
  },
140
135
  });
141
136
  }
@@ -1,3 +1,4 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
2
3
  import { BlockHeader } from '@aztec/stdlib/tx';
3
4
 
@@ -14,7 +15,7 @@ export class SyncDataProvider {
14
15
  await this.#synchronizedHeader.set(header.toBuffer());
15
16
  }
16
17
 
17
- async getBlockNumber(): Promise<number> {
18
+ async getBlockNumber(): Promise<BlockNumber> {
18
19
  const headerBuffer = await this.#synchronizedHeader.getAsync();
19
20
  if (!headerBuffer) {
20
21
  throw new Error(`Trying to get block number with a not-yet-synchronized PXE - this should never happen`);
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
3
  import type { L2TipsKVStore } from '@aztec/kv-store/stores';
3
4
  import { L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
@@ -109,7 +110,7 @@ export class Synchronizer implements L2BlockStreamEventHandler {
109
110
  }
110
111
  if (!currentHeader) {
111
112
  // REFACTOR: We should know the header of the genesis block without having to request it from the node.
112
- await this.syncDataProvider.setHeader((await this.node.getBlockHeader(0))!);
113
+ await this.syncDataProvider.setHeader((await this.node.getBlockHeader(BlockNumber.ZERO))!);
113
114
  }
114
115
  await this.blockStream.sync();
115
116
  }
@@ -1,100 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { BufferReader } from '@aztec/foundation/serialize';
3
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { Note } from '@aztec/stdlib/note';
5
- import { TxHash } from '@aztec/stdlib/tx';
6
- import type { NoteData } from '../../contract_function_simulator/oracle/interfaces.js';
7
- /**
8
- * A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
9
- * information required to use it during execution and manage its state.
10
- */
11
- export declare class NoteDao implements NoteData {
12
- /** The packed content of the note, as will be returned in the getNotes oracle. */
13
- note: Note;
14
- /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
15
- contractAddress: AztecAddress;
16
- /**
17
- * The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
18
- * since contracts typically make queries based on it.
19
- */
20
- storageSlot: Fr;
21
- /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
22
- noteNonce: Fr;
23
- /**
24
- * The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
25
- * be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
26
- */
27
- noteHash: Fr;
28
- /**
29
- * The nullifier of the note, siloed by contract address.
30
- * Note: Might be set as 0 if the note was added to PXE as nullified.
31
- */
32
- siloedNullifier: Fr;
33
- /** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
34
- * when searching for txEffects.
35
- */
36
- txHash: TxHash;
37
- /** The L2 block number in which the tx with this note was included. Used for note management while processing
38
- * reorgs.*/
39
- l2BlockNumber: number;
40
- /** The L2 block hash in which the tx with this note was included. Used for note management while processing
41
- * reorgs.*/
42
- l2BlockHash: string;
43
- /** The index of the leaf in the global note hash tree the note is stored at */
44
- index: bigint;
45
- /**
46
- * The address whose public key was used to encrypt the note log during delivery.
47
- * (This is the x-coordinate of the public key.)
48
- */
49
- recipient: AztecAddress;
50
- constructor(
51
- /** The packed content of the note, as will be returned in the getNotes oracle. */
52
- note: Note,
53
- /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
54
- contractAddress: AztecAddress,
55
- /**
56
- * The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
57
- * since contracts typically make queries based on it.
58
- */
59
- storageSlot: Fr,
60
- /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
61
- noteNonce: Fr,
62
- /**
63
- * The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
64
- * be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
65
- */
66
- noteHash: Fr,
67
- /**
68
- * The nullifier of the note, siloed by contract address.
69
- * Note: Might be set as 0 if the note was added to PXE as nullified.
70
- */
71
- siloedNullifier: Fr,
72
- /** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
73
- * when searching for txEffects.
74
- */
75
- txHash: TxHash,
76
- /** The L2 block number in which the tx with this note was included. Used for note management while processing
77
- * reorgs.*/
78
- l2BlockNumber: number,
79
- /** The L2 block hash in which the tx with this note was included. Used for note management while processing
80
- * reorgs.*/
81
- l2BlockHash: string,
82
- /** The index of the leaf in the global note hash tree the note is stored at */
83
- index: bigint,
84
- /**
85
- * The address whose public key was used to encrypt the note log during delivery.
86
- * (This is the x-coordinate of the public key.)
87
- */
88
- recipient: AztecAddress);
89
- toBuffer(): Buffer;
90
- static fromBuffer(buffer: Buffer | BufferReader): NoteDao;
91
- toString(): string;
92
- static fromString(str: string): NoteDao;
93
- /**
94
- * Returns the size in bytes of the Note Dao.
95
- * @returns - Its size in bytes.
96
- */
97
- getSize(): number;
98
- static random({ note, contractAddress, storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient, }?: Partial<NoteDao>): Promise<NoteDao>;
99
- }
100
- //# sourceMappingURL=note_dao.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../../src/storage/note_data_provider/note_dao.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAS,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wDAAwD,CAAC;AAEvF;;;GAGG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IAIpC,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB;;;OAGG;IACI,SAAS,EAAE,YAAY;;IAzC9B,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB;;;OAGG;IACI,SAAS,EAAE,YAAY;IAGhC,QAAQ,IAAI,MAAM;IAgBlB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IA8B/C,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAK7B;;;OAGG;IACI,OAAO;WAMD,MAAM,CAAC,EAClB,IAAoB,EACpB,eAA2B,EAC3B,WAAyB,EACzB,SAAuB,EACvB,QAAsB,EACtB,eAA6B,EAC7B,MAAwB,EACxB,aAAgD,EAChD,WAAoC,EACpC,KAA8B,EAC9B,SAAqB,GACtB,GAAE,OAAO,CAAC,OAAO,CAAM;CAezB"}
@@ -1,102 +0,0 @@
1
- import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
2
- import { Fr, Point } from '@aztec/foundation/fields';
3
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { Note } from '@aztec/stdlib/note';
6
- import { TxHash } from '@aztec/stdlib/tx';
7
- /**
8
- * A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
9
- * information required to use it during execution and manage its state.
10
- */ export class NoteDao {
11
- note;
12
- contractAddress;
13
- storageSlot;
14
- noteNonce;
15
- noteHash;
16
- siloedNullifier;
17
- txHash;
18
- l2BlockNumber;
19
- l2BlockHash;
20
- index;
21
- recipient;
22
- constructor(// Note information
23
- /** The packed content of the note, as will be returned in the getNotes oracle. */ note, /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */ contractAddress, /**
24
- * The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
25
- * since contracts typically make queries based on it.
26
- */ storageSlot, /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */ noteNonce, // Computed values
27
- /**
28
- * The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
29
- * be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
30
- */ noteHash, /**
31
- * The nullifier of the note, siloed by contract address.
32
- * Note: Might be set as 0 if the note was added to PXE as nullified.
33
- */ siloedNullifier, // Metadata
34
- /** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
35
- * when searching for txEffects.
36
- */ txHash, /** The L2 block number in which the tx with this note was included. Used for note management while processing
37
- * reorgs.*/ l2BlockNumber, /** The L2 block hash in which the tx with this note was included. Used for note management while processing
38
- * reorgs.*/ l2BlockHash, /** The index of the leaf in the global note hash tree the note is stored at */ index, /**
39
- * The address whose public key was used to encrypt the note log during delivery.
40
- * (This is the x-coordinate of the public key.)
41
- */ recipient){
42
- this.note = note;
43
- this.contractAddress = contractAddress;
44
- this.storageSlot = storageSlot;
45
- this.noteNonce = noteNonce;
46
- this.noteHash = noteHash;
47
- this.siloedNullifier = siloedNullifier;
48
- this.txHash = txHash;
49
- this.l2BlockNumber = l2BlockNumber;
50
- this.l2BlockHash = l2BlockHash;
51
- this.index = index;
52
- this.recipient = recipient;
53
- }
54
- toBuffer() {
55
- return serializeToBuffer([
56
- this.note,
57
- this.contractAddress,
58
- this.storageSlot,
59
- this.noteNonce,
60
- this.noteHash,
61
- this.siloedNullifier,
62
- this.txHash,
63
- this.l2BlockNumber,
64
- Fr.fromHexString(this.l2BlockHash),
65
- this.index,
66
- this.recipient
67
- ]);
68
- }
69
- static fromBuffer(buffer) {
70
- const reader = BufferReader.asReader(buffer);
71
- const note = Note.fromBuffer(reader);
72
- const contractAddress = AztecAddress.fromBuffer(reader);
73
- const storageSlot = Fr.fromBuffer(reader);
74
- const noteNonce = Fr.fromBuffer(reader);
75
- const noteHash = Fr.fromBuffer(reader);
76
- const siloedNullifier = Fr.fromBuffer(reader);
77
- const txHash = reader.readObject(TxHash);
78
- const l2BlockNumber = reader.readNumber();
79
- const l2BlockHash = Fr.fromBuffer(reader).toString();
80
- const index = toBigIntBE(reader.readBytes(32));
81
- const recipient = AztecAddress.fromBuffer(reader);
82
- return new NoteDao(note, contractAddress, storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient);
83
- }
84
- toString() {
85
- return '0x' + this.toBuffer().toString('hex');
86
- }
87
- static fromString(str) {
88
- const hex = str.replace(/^0x/, '');
89
- return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
90
- }
91
- /**
92
- * Returns the size in bytes of the Note Dao.
93
- * @returns - Its size in bytes.
94
- */ getSize() {
95
- const indexSize = Math.ceil(Math.log2(Number(this.index)));
96
- const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
97
- return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
98
- }
99
- static async random({ note = Note.random(), contractAddress = undefined, storageSlot = Fr.random(), noteNonce = Fr.random(), noteHash = Fr.random(), siloedNullifier = Fr.random(), txHash = TxHash.random(), l2BlockNumber = Math.floor(Math.random() * 1000), l2BlockHash = Fr.random().toString(), index = Fr.random().toBigInt(), recipient = undefined } = {}) {
100
- return new NoteDao(note, contractAddress ?? await AztecAddress.random(), storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient ?? await AztecAddress.random());
101
- }
102
- }