@aztec/pxe 0.76.1 → 0.76.3

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.
@@ -35,20 +35,6 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
35
35
  */
36
36
  getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
37
37
 
38
- /**
39
- * Adding a capsule to the capsule dispenser.
40
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
41
- * @param capsule - An array of field elements representing the capsule.
42
- */
43
- addCapsule(capsule: Fr[]): Promise<void>;
44
-
45
- /**
46
- * Get the next capsule from the capsule dispenser.
47
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
48
- * @returns A promise that resolves to an array of field elements representing the capsule.
49
- */
50
- popCapsule(): Promise<Fr[] | undefined>;
51
-
52
38
  /**
53
39
  * Gets notes based on the provided filter.
54
40
  * @param filter - The filter to apply to the notes.
@@ -215,32 +201,35 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
215
201
  resetNoteSyncData(): Promise<void>;
216
202
 
217
203
  /**
218
- * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `dbLoad`.
219
- * If data was already stored at this slot, it is overwrriten.
204
+ * Stores arbitrary information in a per-contract non-volatile database (called capsules), which can later
205
+ * be retrieved with `loadCapsule`. If data was already stored at this slot, it is overwritten.
220
206
  * @param contractAddress - The contract address to scope the data under.
221
207
  * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
222
- * @param values - The data to store.
208
+ * @param capsule - An array of field elements representing the capsule.
209
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
210
+ * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
211
+ * network state it's backed by local PXE db.
223
212
  */
224
- dbStore(contractAddress: AztecAddress, slot: Fr, values: Fr[]): Promise<void>;
213
+ storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void>;
225
214
 
226
215
  /**
227
- * Returns data previously stored via `dbStore` in the per-contract non-volatile database.
216
+ * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database (called capsules).
228
217
  * @param contractAddress - The contract address under which the data is scoped.
229
218
  * @param slot - The slot in the database to read.
230
219
  * @returns The stored data or `null` if no data is stored under the slot.
231
220
  */
232
- dbLoad(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
221
+ loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
233
222
 
234
223
  /**
235
- * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
224
+ * Deletes data in the per-contract non-volatile database (called capsules). Does nothing if no data was present.
236
225
  * @param contractAddress - The contract address under which the data is scoped.
237
226
  * @param slot - The slot in the database to delete.
238
227
  */
239
- dbDelete(contractAddress: AztecAddress, slot: Fr): Promise<void>;
228
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void>;
240
229
 
241
230
  /**
242
- * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
243
- * structures by avoiding repeated calls to `dbLoad` and `dbStore`.
231
+ * Copies a number of contiguous entries in the per-contract non-volatile database (called capsules). This allows for
232
+ * efficient data structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
244
233
  * Supports overlapping source and destination regions (which will result in the overlapped source values being
245
234
  * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
246
235
  *
@@ -249,5 +238,5 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
249
238
  * @param dstSlot - The first slot to copy to.
250
239
  * @param numEntries - The number of entries to copy.
251
240
  */
252
- dbCopy(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
241
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
253
242
  }
@@ -54,29 +54,6 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
54
54
  });
55
55
  });
56
56
 
57
- describe('capsules', () => {
58
- it('stores and retrieves capsules', async () => {
59
- const capsule = [Fr.random(), Fr.random()];
60
-
61
- await database.addCapsule(capsule);
62
- await expect(database.popCapsule()).resolves.toEqual(capsule);
63
- });
64
-
65
- it("returns undefined if it doesn't have capsules", async () => {
66
- await expect(database.popCapsule()).resolves.toBeUndefined();
67
- });
68
-
69
- it('behaves like a stack when storing capsules', async () => {
70
- const capsule1 = [Fr.random(), Fr.random()];
71
- const capsule2 = [Fr.random(), Fr.random()];
72
-
73
- await database.addCapsule(capsule1);
74
- await database.addCapsule(capsule2);
75
- await expect(database.popCapsule()).resolves.toEqual(capsule2);
76
- await expect(database.popCapsule()).resolves.toEqual(capsule1);
77
- });
78
- });
79
-
80
57
  describe('incoming notes', () => {
81
58
  let owners: CompleteAddress[];
82
59
  let contractAddresses: AztecAddress[];
@@ -433,8 +410,8 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
433
410
  const slot = new Fr(1);
434
411
  const values = [new Fr(42)];
435
412
 
436
- await database.dbStore(contract, slot, values);
437
- const result = await database.dbLoad(contract, slot);
413
+ await database.storeCapsule(contract, slot, values);
414
+ const result = await database.loadCapsule(contract, slot);
438
415
  expect(result).toEqual(values);
439
416
  });
440
417
 
@@ -442,8 +419,8 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
442
419
  const slot = new Fr(1);
443
420
  const values = [new Fr(42), new Fr(43), new Fr(44)];
444
421
 
445
- await database.dbStore(contract, slot, values);
446
- const result = await database.dbLoad(contract, slot);
422
+ await database.storeCapsule(contract, slot, values);
423
+ const result = await database.loadCapsule(contract, slot);
447
424
  expect(result).toEqual(values);
448
425
  });
449
426
 
@@ -452,10 +429,10 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
452
429
  const initialValues = [new Fr(42)];
453
430
  const newValues = [new Fr(100)];
454
431
 
455
- await database.dbStore(contract, slot, initialValues);
456
- await database.dbStore(contract, slot, newValues);
432
+ await database.storeCapsule(contract, slot, initialValues);
433
+ await database.storeCapsule(contract, slot, newValues);
457
434
 
458
- const result = await database.dbLoad(contract, slot);
435
+ const result = await database.loadCapsule(contract, slot);
459
436
  expect(result).toEqual(newValues);
460
437
  });
461
438
 
@@ -465,11 +442,11 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
465
442
  const values1 = [new Fr(42)];
466
443
  const values2 = [new Fr(100)];
467
444
 
468
- await database.dbStore(contract, slot, values1);
469
- await database.dbStore(anotherContract, slot, values2);
445
+ await database.storeCapsule(contract, slot, values1);
446
+ await database.storeCapsule(anotherContract, slot, values2);
470
447
 
471
- const result1 = await database.dbLoad(contract, slot);
472
- const result2 = await database.dbLoad(anotherContract, slot);
448
+ const result1 = await database.loadCapsule(contract, slot);
449
+ const result2 = await database.loadCapsule(anotherContract, slot);
473
450
 
474
451
  expect(result1).toEqual(values1);
475
452
  expect(result2).toEqual(values2);
@@ -477,7 +454,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
477
454
 
478
455
  it('returns null for non-existent slots', async () => {
479
456
  const slot = Fr.random();
480
- const result = await database.dbLoad(contract, slot);
457
+ const result = await database.loadCapsule(contract, slot);
481
458
  expect(result).toBeNull();
482
459
  });
483
460
 
@@ -485,99 +462,99 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
485
462
  const slot = new Fr(1);
486
463
  const values = [new Fr(42)];
487
464
 
488
- await database.dbStore(contract, slot, values);
489
- await database.dbDelete(contract, slot);
465
+ await database.storeCapsule(contract, slot, values);
466
+ await database.deleteCapsule(contract, slot);
490
467
 
491
- expect(await database.dbLoad(contract, slot)).toBeNull();
468
+ expect(await database.loadCapsule(contract, slot)).toBeNull();
492
469
  });
493
470
 
494
471
  it('deletes an empty slot', async () => {
495
472
  const slot = new Fr(1);
496
- await database.dbDelete(contract, slot);
473
+ await database.deleteCapsule(contract, slot);
497
474
 
498
- expect(await database.dbLoad(contract, slot)).toBeNull();
475
+ expect(await database.loadCapsule(contract, slot)).toBeNull();
499
476
  });
500
477
 
501
478
  it('copies a single value', async () => {
502
479
  const slot = new Fr(1);
503
480
  const values = [new Fr(42)];
504
481
 
505
- await database.dbStore(contract, slot, values);
482
+ await database.storeCapsule(contract, slot, values);
506
483
 
507
484
  const dstSlot = new Fr(5);
508
- await database.dbCopy(contract, slot, dstSlot, 1);
485
+ await database.copyCapsule(contract, slot, dstSlot, 1);
509
486
 
510
- expect(await database.dbLoad(contract, dstSlot)).toEqual(values);
487
+ expect(await database.loadCapsule(contract, dstSlot)).toEqual(values);
511
488
  });
512
489
 
513
490
  it('copies multiple non-overlapping values', async () => {
514
491
  const src = new Fr(1);
515
492
  const valuesArray = [[new Fr(42)], [new Fr(1337)], [new Fr(13)]];
516
493
 
517
- await database.dbStore(contract, src, valuesArray[0]);
518
- await database.dbStore(contract, src.add(new Fr(1)), valuesArray[1]);
519
- await database.dbStore(contract, src.add(new Fr(2)), valuesArray[2]);
494
+ await database.storeCapsule(contract, src, valuesArray[0]);
495
+ await database.storeCapsule(contract, src.add(new Fr(1)), valuesArray[1]);
496
+ await database.storeCapsule(contract, src.add(new Fr(2)), valuesArray[2]);
520
497
 
521
498
  const dst = new Fr(5);
522
- await database.dbCopy(contract, src, dst, 3);
499
+ await database.copyCapsule(contract, src, dst, 3);
523
500
 
524
- expect(await database.dbLoad(contract, dst)).toEqual(valuesArray[0]);
525
- expect(await database.dbLoad(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
526
- expect(await database.dbLoad(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
501
+ expect(await database.loadCapsule(contract, dst)).toEqual(valuesArray[0]);
502
+ expect(await database.loadCapsule(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
503
+ expect(await database.loadCapsule(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
527
504
  });
528
505
 
529
506
  it('copies overlapping values with src ahead', async () => {
530
507
  const src = new Fr(1);
531
508
  const valuesArray = [[new Fr(42)], [new Fr(1337)], [new Fr(13)]];
532
509
 
533
- await database.dbStore(contract, src, valuesArray[0]);
534
- await database.dbStore(contract, src.add(new Fr(1)), valuesArray[1]);
535
- await database.dbStore(contract, src.add(new Fr(2)), valuesArray[2]);
510
+ await database.storeCapsule(contract, src, valuesArray[0]);
511
+ await database.storeCapsule(contract, src.add(new Fr(1)), valuesArray[1]);
512
+ await database.storeCapsule(contract, src.add(new Fr(2)), valuesArray[2]);
536
513
 
537
514
  const dst = new Fr(2);
538
- await database.dbCopy(contract, src, dst, 3);
515
+ await database.copyCapsule(contract, src, dst, 3);
539
516
 
540
- expect(await database.dbLoad(contract, dst)).toEqual(valuesArray[0]);
541
- expect(await database.dbLoad(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
542
- expect(await database.dbLoad(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
517
+ expect(await database.loadCapsule(contract, dst)).toEqual(valuesArray[0]);
518
+ expect(await database.loadCapsule(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
519
+ expect(await database.loadCapsule(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
543
520
 
544
521
  // Slots 2 and 3 (src[1] and src[2]) should have been overwritten since they are also dst[0] and dst[1]
545
- expect(await database.dbLoad(contract, src)).toEqual(valuesArray[0]); // src[0] (unchanged)
546
- expect(await database.dbLoad(contract, src.add(new Fr(1)))).toEqual(valuesArray[0]); // dst[0]
547
- expect(await database.dbLoad(contract, src.add(new Fr(2)))).toEqual(valuesArray[1]); // dst[1]
522
+ expect(await database.loadCapsule(contract, src)).toEqual(valuesArray[0]); // src[0] (unchanged)
523
+ expect(await database.loadCapsule(contract, src.add(new Fr(1)))).toEqual(valuesArray[0]); // dst[0]
524
+ expect(await database.loadCapsule(contract, src.add(new Fr(2)))).toEqual(valuesArray[1]); // dst[1]
548
525
  });
549
526
 
550
527
  it('copies overlapping values with dst ahead', async () => {
551
528
  const src = new Fr(5);
552
529
  const valuesArray = [[new Fr(42)], [new Fr(1337)], [new Fr(13)]];
553
530
 
554
- await database.dbStore(contract, src, valuesArray[0]);
555
- await database.dbStore(contract, src.add(new Fr(1)), valuesArray[1]);
556
- await database.dbStore(contract, src.add(new Fr(2)), valuesArray[2]);
531
+ await database.storeCapsule(contract, src, valuesArray[0]);
532
+ await database.storeCapsule(contract, src.add(new Fr(1)), valuesArray[1]);
533
+ await database.storeCapsule(contract, src.add(new Fr(2)), valuesArray[2]);
557
534
 
558
535
  const dst = new Fr(4);
559
- await database.dbCopy(contract, src, dst, 3);
536
+ await database.copyCapsule(contract, src, dst, 3);
560
537
 
561
- expect(await database.dbLoad(contract, dst)).toEqual(valuesArray[0]);
562
- expect(await database.dbLoad(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
563
- expect(await database.dbLoad(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
538
+ expect(await database.loadCapsule(contract, dst)).toEqual(valuesArray[0]);
539
+ expect(await database.loadCapsule(contract, dst.add(new Fr(1)))).toEqual(valuesArray[1]);
540
+ expect(await database.loadCapsule(contract, dst.add(new Fr(2)))).toEqual(valuesArray[2]);
564
541
 
565
542
  // Slots 5 and 6 (src[0] and src[1]) should have been overwritten since they are also dst[1] and dst[2]
566
- expect(await database.dbLoad(contract, src)).toEqual(valuesArray[1]); // dst[1]
567
- expect(await database.dbLoad(contract, src.add(new Fr(1)))).toEqual(valuesArray[2]); // dst[2]
568
- expect(await database.dbLoad(contract, src.add(new Fr(2)))).toEqual(valuesArray[2]); // src[2] (unchanged)
543
+ expect(await database.loadCapsule(contract, src)).toEqual(valuesArray[1]); // dst[1]
544
+ expect(await database.loadCapsule(contract, src.add(new Fr(1)))).toEqual(valuesArray[2]); // dst[2]
545
+ expect(await database.loadCapsule(contract, src.add(new Fr(2)))).toEqual(valuesArray[2]); // src[2] (unchanged)
569
546
  });
570
547
 
571
548
  it('copying fails if any value is empty', async () => {
572
549
  const src = new Fr(1);
573
550
  const valuesArray = [[new Fr(42)], [new Fr(1337)], [new Fr(13)]];
574
551
 
575
- await database.dbStore(contract, src, valuesArray[0]);
552
+ await database.storeCapsule(contract, src, valuesArray[0]);
576
553
  // We skip src[1]
577
- await database.dbStore(contract, src.add(new Fr(2)), valuesArray[2]);
554
+ await database.storeCapsule(contract, src.add(new Fr(2)), valuesArray[2]);
578
555
 
579
556
  const dst = new Fr(5);
580
- await expect(database.dbCopy(contract, src, dst, 3)).rejects.toThrow('Attempted to copy empty slot');
557
+ await expect(database.copyCapsule(contract, src, dst, 3)).rejects.toThrow('Attempted to copy empty slot');
581
558
  });
582
559
  });
583
560
  });
@@ -330,7 +330,7 @@ export class KernelProver {
330
330
  const ivcProof = await this.proofCreator.createClientIvcProof(acirs, witnessStack);
331
331
  tailOutput.clientIvcProof = ivcProof;
332
332
  } else {
333
- tailOutput.clientIvcProof = ClientIvcProof.empty();
333
+ tailOutput.clientIvcProof = ClientIvcProof.random();
334
334
  }
335
335
 
336
336
  return tailOutput;
@@ -137,8 +137,8 @@ export class PXEService implements PXE {
137
137
  return this.db.getAuthWitness(messageHash);
138
138
  }
139
139
 
140
- public addCapsule(capsule: Fr[]) {
141
- return this.db.addCapsule(capsule);
140
+ public storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]) {
141
+ return this.db.storeCapsule(contract, storageSlot, capsule);
142
142
  }
143
143
 
144
144
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
@@ -101,14 +101,6 @@ export class SimulatorOracle implements DBOracle {
101
101
  return witness;
102
102
  }
103
103
 
104
- async popCapsule(): Promise<Fr[]> {
105
- const capsule = await this.db.popCapsule();
106
- if (!capsule) {
107
- throw new Error(`No capsules available`);
108
- }
109
- return capsule;
110
- }
111
-
112
104
  async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]) {
113
105
  const noteDaos = await this.db.getNotes({
114
106
  contractAddress,
@@ -833,20 +825,20 @@ export class SimulatorOracle implements DBOracle {
833
825
  );
834
826
  }
835
827
 
836
- dbStore(contractAddress: AztecAddress, slot: Fr, values: Fr[]): Promise<void> {
837
- return this.db.dbStore(contractAddress, slot, values);
828
+ storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
829
+ return this.db.storeCapsule(contractAddress, slot, capsule);
838
830
  }
839
831
 
840
- dbLoad(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
841
- return this.db.dbLoad(contractAddress, slot);
832
+ loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
833
+ return this.db.loadCapsule(contractAddress, slot);
842
834
  }
843
835
 
844
- dbDelete(contractAddress: AztecAddress, slot: Fr): Promise<void> {
845
- return this.db.dbDelete(contractAddress, slot);
836
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
837
+ return this.db.deleteCapsule(contractAddress, slot);
846
838
  }
847
839
 
848
- dbCopy(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
849
- return this.db.dbCopy(contractAddress, srcSlot, dstSlot, numEntries);
840
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
841
+ return this.db.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
850
842
  }
851
843
  }
852
844