@aztec/pxe 0.70.0 → 0.72.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dest/config/index.d.ts.map +1 -1
  2. package/dest/config/index.js +3 -3
  3. package/dest/database/kv_pxe_database.d.ts +7 -5
  4. package/dest/database/kv_pxe_database.d.ts.map +1 -1
  5. package/dest/database/kv_pxe_database.js +33 -11
  6. package/dest/database/note_dao.d.ts +2 -4
  7. package/dest/database/note_dao.d.ts.map +1 -1
  8. package/dest/database/note_dao.js +3 -7
  9. package/dest/database/outgoing_note_dao.d.ts +2 -4
  10. package/dest/database/outgoing_note_dao.d.ts.map +1 -1
  11. package/dest/database/outgoing_note_dao.js +3 -7
  12. package/dest/database/pxe_database.d.ts +29 -12
  13. package/dest/database/pxe_database.d.ts.map +1 -1
  14. package/dest/database/pxe_database_test_suite.d.ts.map +1 -1
  15. package/dest/database/pxe_database_test_suite.js +162 -67
  16. package/dest/note_decryption_utils/add_public_values_to_payload.js +2 -2
  17. package/dest/pxe_service/pxe_service.d.ts +6 -6
  18. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  19. package/dest/pxe_service/pxe_service.js +31 -28
  20. package/dest/pxe_service/test/pxe_test_suite.js +9 -9
  21. package/dest/simulator_oracle/index.d.ts +12 -20
  22. package/dest/simulator_oracle/index.d.ts.map +1 -1
  23. package/dest/simulator_oracle/index.js +123 -69
  24. package/package.json +15 -15
  25. package/src/config/index.ts +2 -1
  26. package/src/database/kv_pxe_database.ts +46 -12
  27. package/src/database/note_dao.ts +6 -34
  28. package/src/database/outgoing_note_dao.ts +6 -33
  29. package/src/database/pxe_database.ts +31 -12
  30. package/src/database/pxe_database_test_suite.ts +189 -75
  31. package/src/note_decryption_utils/add_public_values_to_payload.ts +1 -1
  32. package/src/pxe_service/pxe_service.ts +47 -46
  33. package/src/pxe_service/test/pxe_test_suite.ts +8 -8
  34. package/src/simulator_oracle/index.ts +237 -88
  35. package/dest/note_decryption_utils/brute_force_note_info.d.ts +0 -31
  36. package/dest/note_decryption_utils/brute_force_note_info.d.ts.map +0 -1
  37. package/dest/note_decryption_utils/brute_force_note_info.js +0 -54
  38. package/dest/note_decryption_utils/index.d.ts +0 -3
  39. package/dest/note_decryption_utils/index.d.ts.map +0 -1
  40. package/dest/note_decryption_utils/index.js +0 -2
  41. package/dest/note_decryption_utils/produce_note_daos.d.ts +0 -28
  42. package/dest/note_decryption_utils/produce_note_daos.d.ts.map +0 -1
  43. package/dest/note_decryption_utils/produce_note_daos.js +0 -33
  44. package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts +0 -8
  45. package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts.map +0 -1
  46. package/dest/note_decryption_utils/produce_note_daos_for_key.js +0 -17
  47. package/src/note_decryption_utils/brute_force_note_info.ts +0 -90
  48. package/src/note_decryption_utils/index.ts +0 -2
  49. package/src/note_decryption_utils/produce_note_daos.ts +0 -69
  50. package/src/note_decryption_utils/produce_note_daos_for_key.ts +0 -59
@@ -41,7 +41,7 @@ export async function getOrderedNoteItems(
41
41
  noteFields.sort((a, b) => a.index - b.index);
42
42
 
43
43
  // Now we insert the public fields into the note based on its indices defined in the ABI.
44
- const modifiedNoteItems = privateNoteValues;
44
+ const modifiedNoteItems = [...privateNoteValues];
45
45
  let indexInPublicValues = 0;
46
46
  for (let i = 0; i < noteFields.length; i++) {
47
47
  const noteField = noteFields[i];
@@ -5,7 +5,8 @@ import {
5
5
  type EventMetadataDefinition,
6
6
  type ExtendedNote,
7
7
  type FunctionCall,
8
- type GetUnencryptedLogsResponse,
8
+ type GetContractClassLogsResponse,
9
+ type GetPublicLogsResponse,
9
10
  type InBlock,
10
11
  L1EventPayload,
11
12
  type L2Block,
@@ -234,7 +235,8 @@ export class PXEService implements PXE {
234
235
  `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.contractClassId})`,
235
236
  );
236
237
  }
237
- if (!computeContractAddressFromInstance(instance).equals(instance.address)) {
238
+ const computedAddress = await computeContractAddressFromInstance(instance);
239
+ if (!computedAddress.equals(instance.address)) {
238
240
  throw new Error('Added a contract in which the address does not match the contract instance.');
239
241
  }
240
242
 
@@ -278,13 +280,15 @@ export class PXEService implements PXE {
278
280
  const extendedNotes = noteDaos.map(async dao => {
279
281
  let owner = filter.owner;
280
282
  if (owner === undefined) {
281
- const completeAddresses = (await this.db.getCompleteAddresses()).find(completeAddress =>
282
- completeAddress.address.toAddressPoint().equals(dao.addressPoint),
283
- );
284
- if (completeAddresses === undefined) {
283
+ const completeAddresses = await this.db.getCompleteAddresses();
284
+ const completeAddressIndex = (
285
+ await Promise.all(completeAddresses.map(completeAddresses => completeAddresses.address.toAddressPoint()))
286
+ ).findIndex(addressPoint => addressPoint.equals(dao.addressPoint));
287
+ const completeAddress = completeAddresses[completeAddressIndex];
288
+ if (completeAddress === undefined) {
285
289
  throw new Error(`Cannot find complete address for addressPoint ${dao.addressPoint.toString()}`);
286
290
  }
287
- owner = completeAddresses.address;
291
+ owner = completeAddress.address;
288
292
  }
289
293
  return new UniqueNote(
290
294
  dao.note,
@@ -357,7 +361,7 @@ export class PXEService implements PXE {
357
361
  l2BlockNumber,
358
362
  l2BlockHash,
359
363
  index,
360
- owner.address.toAddressPoint(),
364
+ await owner.address.toAddressPoint(),
361
365
  note.noteTypeId,
362
366
  ),
363
367
  scope,
@@ -402,7 +406,7 @@ export class PXEService implements PXE {
402
406
  l2BlockNumber,
403
407
  l2BlockHash,
404
408
  index,
405
- note.owner.toAddressPoint(),
409
+ await note.owner.toAddressPoint(),
406
410
  note.noteTypeId,
407
411
  ),
408
412
  );
@@ -608,12 +612,12 @@ export class PXEService implements PXE {
608
612
  }
609
613
 
610
614
  /**
611
- * Gets unencrypted logs based on the provided filter.
615
+ * Gets public logs based on the provided filter.
612
616
  * @param filter - The filter to apply to the logs.
613
617
  * @returns The requested logs.
614
618
  */
615
- public getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
616
- return this.node.getUnencryptedLogs(filter);
619
+ public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
620
+ return this.node.getPublicLogs(filter);
617
621
  }
618
622
 
619
623
  /**
@@ -621,7 +625,7 @@ export class PXEService implements PXE {
621
625
  * @param filter - The filter to apply to the logs.
622
626
  * @returns The requested logs.
623
627
  */
624
- public getContractClassLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
628
+ public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
625
629
  return this.node.getContractClassLogs(filter);
626
630
  }
627
631
 
@@ -687,7 +691,7 @@ export class PXEService implements PXE {
687
691
  async #registerProtocolContracts() {
688
692
  const registered: Record<string, string> = {};
689
693
  for (const name of protocolContractNames) {
690
- const { address, contractClass, instance, artifact } = getCanonicalProtocolContract(name);
694
+ const { address, contractClass, instance, artifact } = await getCanonicalProtocolContract(name);
691
695
  await this.db.addContractArtifact(contractClass.id, artifact);
692
696
  await this.db.addContractInstance(instance);
693
697
  registered[name] = address.toString();
@@ -833,7 +837,7 @@ export class PXEService implements PXE {
833
837
  return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
834
838
  }
835
839
 
836
- public async getEncryptedEvents<T>(
840
+ public async getPrivateEvents<T>(
837
841
  eventMetadataDef: EventMetadataDefinition,
838
842
  from: number,
839
843
  limit: number,
@@ -864,25 +868,29 @@ export class PXEService implements PXE {
864
868
 
865
869
  const preaddress = registeredAccount.getPreaddress();
866
870
 
867
- secretKey = computeAddressSecret(preaddress, secretKey);
871
+ secretKey = await computeAddressSecret(preaddress, secretKey);
868
872
  }
869
873
 
870
874
  return secretKey;
871
875
  }),
872
876
  );
873
877
 
874
- const visibleEvents = privateLogs.flatMap(log => {
875
- for (const sk of vsks) {
876
- // TODO: Verify that the first field of the log is the tag siloed with contract address.
877
- // Or use tags to query logs, like we do with notes.
878
- const decryptedEvent = L1EventPayload.decryptAsIncoming(log, sk);
879
- if (decryptedEvent !== undefined) {
880
- return [decryptedEvent];
881
- }
882
- }
878
+ const visibleEvents = (
879
+ await Promise.all(
880
+ privateLogs.map(async log => {
881
+ for (const sk of vsks) {
882
+ // TODO: Verify that the first field of the log is the tag siloed with contract address.
883
+ // Or use tags to query logs, like we do with notes.
884
+ const decryptedEvent = await L1EventPayload.decryptAsIncoming(log, sk);
885
+ if (decryptedEvent !== undefined) {
886
+ return [decryptedEvent];
887
+ }
888
+ }
883
889
 
884
- return [];
885
- });
890
+ return [];
891
+ }),
892
+ )
893
+ ).flat();
886
894
 
887
895
  const decodedEvents = visibleEvents
888
896
  .map(visibleEvent => {
@@ -892,11 +900,6 @@ export class PXEService implements PXE {
892
900
  if (!visibleEvent.eventTypeId.equals(eventMetadata.eventSelector)) {
893
901
  return undefined;
894
902
  }
895
- if (visibleEvent.event.items.length !== eventMetadata.fieldNames.length) {
896
- throw new Error(
897
- 'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length',
898
- );
899
- }
900
903
 
901
904
  return eventMetadata.decode(visibleEvent);
902
905
  })
@@ -905,34 +908,32 @@ export class PXEService implements PXE {
905
908
  return decodedEvents;
906
909
  }
907
910
 
908
- async getUnencryptedEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
911
+ async getPublicEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
909
912
  const eventMetadata = new EventMetadata<T>(eventMetadataDef);
910
- const { logs: unencryptedLogs } = await this.node.getUnencryptedLogs({
913
+ const { logs } = await this.node.getPublicLogs({
911
914
  fromBlock: from,
912
915
  toBlock: from + limit,
913
916
  });
914
917
 
915
- const decodedEvents = unencryptedLogs
916
- .map(unencryptedLog => {
917
- const unencryptedLogBuf = unencryptedLog.log.data;
918
+ const decodedEvents = logs
919
+ .map(log => {
920
+ // +1 for the event selector
921
+ const expectedLength = eventMetadata.fieldNames.length + 1;
922
+ const logFields = log.log.log.slice(0, expectedLength);
918
923
  // We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission.
919
- if (
920
- !EventSelector.fromBuffer(unencryptedLogBuf.subarray(unencryptedLogBuf.byteLength - 4)).equals(
921
- eventMetadata.eventSelector,
922
- )
923
- ) {
924
+ if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadata.eventSelector)) {
924
925
  return undefined;
925
926
  }
926
-
927
- if (unencryptedLogBuf.byteLength !== eventMetadata.fieldNames.length * 32 + 32) {
927
+ // If any of the remaining fields, are non-zero, the payload does match expected:
928
+ if (log.log.log.slice(expectedLength + 1).find(f => !f.isZero())) {
928
929
  throw new Error(
929
930
  'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length',
930
931
  );
931
932
  }
932
933
 
933
- return eventMetadata.decode(unencryptedLog.log);
934
+ return eventMetadata.decode(log.log);
934
935
  })
935
- .filter(unencryptedLog => unencryptedLog !== undefined) as T[];
936
+ .filter(log => log !== undefined) as T[];
936
937
 
937
938
  return decodedEvents;
938
939
  }
@@ -35,7 +35,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
35
35
  });
36
36
 
37
37
  it('successfully adds a contract', async () => {
38
- const contracts = [randomDeployedContract(), randomDeployedContract()];
38
+ const contracts = await Promise.all([randomDeployedContract(), randomDeployedContract()]);
39
39
  for (const contract of contracts) {
40
40
  await pxe.registerContract(contract);
41
41
  }
@@ -49,7 +49,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
49
49
  const artifact = randomContractArtifact();
50
50
  const contractClass = getContractClassFromArtifact(artifact);
51
51
  const contractClassId = contractClass.id;
52
- const instance = randomContractInstanceWithAddress({ contractClassId });
52
+ const instance = await randomContractInstanceWithAddress({ contractClassId });
53
53
 
54
54
  await pxe.registerContractClass(artifact);
55
55
  expect(await pxe.getContractClass(contractClassId)).toMatchObject(
@@ -64,12 +64,12 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
64
64
  const artifact = randomContractArtifact();
65
65
  const contractClass = getContractClassFromArtifact(artifact);
66
66
  const contractClassId = contractClass.id;
67
- const instance = randomContractInstanceWithAddress({ contractClassId });
67
+ const instance = await randomContractInstanceWithAddress({ contractClassId });
68
68
  await expect(
69
69
  pxe.registerContract({
70
70
  instance: {
71
71
  ...instance,
72
- address: AztecAddress.random(),
72
+ address: await AztecAddress.random(),
73
73
  },
74
74
  artifact,
75
75
  }),
@@ -77,13 +77,13 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
77
77
  });
78
78
 
79
79
  it('refuses to register a contract with a class that has not been registered', async () => {
80
- const instance = randomContractInstanceWithAddress();
80
+ const instance = await randomContractInstanceWithAddress();
81
81
  await expect(pxe.registerContract({ instance })).rejects.toThrow(/Missing contract artifact/i);
82
82
  });
83
83
 
84
84
  it('refuses to register a contract with an artifact with mismatching class id', async () => {
85
85
  const artifact = randomContractArtifact();
86
- const instance = randomContractInstanceWithAddress();
86
+ const instance = await randomContractInstanceWithAddress();
87
87
  await expect(pxe.registerContract({ instance, artifact })).rejects.toThrow(/Artifact does not match/i);
88
88
  });
89
89
 
@@ -91,13 +91,13 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
91
91
  // a larger setup and it's sufficiently tested in the e2e tests.
92
92
 
93
93
  it('throws when getting public storage for non-existent contract', async () => {
94
- const contract = AztecAddress.random();
94
+ const contract = await AztecAddress.random();
95
95
  await expect(async () => await pxe.getPublicStorageAt(contract, new Fr(0n))).rejects.toThrow(
96
96
  `Contract ${contract.toString()} is not deployed`,
97
97
  );
98
98
  });
99
99
 
100
- // Note: Not testing `getContractData` and `getUnencryptedLogs` here as these
100
+ // Note: Not testing `getContractData` and `getPublicLogs` here as these
101
101
  // functions only call AztecNode and these methods are frequently used by the e2e tests.
102
102
 
103
103
  it('successfully gets a block number', async () => {