@aztec/pxe 0.14.2 → 0.15.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 (40) hide show
  1. package/dest/contract_data_oracle/index.d.ts.map +1 -1
  2. package/dest/contract_data_oracle/index.js +3 -4
  3. package/dest/contract_tree/index.d.ts +3 -4
  4. package/dest/contract_tree/index.d.ts.map +1 -1
  5. package/dest/contract_tree/index.js +16 -18
  6. package/dest/database/database.d.ts +12 -0
  7. package/dest/database/database.d.ts.map +1 -1
  8. package/dest/database/memory_db.d.ts +3 -0
  9. package/dest/database/memory_db.d.ts.map +1 -1
  10. package/dest/database/memory_db.js +15 -3
  11. package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
  12. package/dest/kernel_prover/kernel_prover.js +8 -4
  13. package/dest/kernel_prover/proof_creator.d.ts.map +1 -1
  14. package/dest/kernel_prover/proof_creator.js +4 -5
  15. package/dest/note_processor/note_processor.d.ts.map +1 -1
  16. package/dest/note_processor/note_processor.js +9 -8
  17. package/dest/pxe_service/create_pxe_service.js +2 -2
  18. package/dest/pxe_service/pxe_service.d.ts +1 -0
  19. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  20. package/dest/pxe_service/pxe_service.js +13 -10
  21. package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
  22. package/dest/pxe_service/test/pxe_test_suite.js +12 -12
  23. package/dest/simulator_oracle/index.d.ts +1 -0
  24. package/dest/simulator_oracle/index.d.ts.map +1 -1
  25. package/dest/simulator_oracle/index.js +13 -4
  26. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  27. package/dest/synchronizer/synchronizer.js +9 -7
  28. package/package.json +10 -11
  29. package/src/contract_data_oracle/index.ts +2 -3
  30. package/src/contract_tree/index.ts +13 -16
  31. package/src/database/database.ts +14 -0
  32. package/src/database/memory_db.ts +19 -3
  33. package/src/kernel_prover/kernel_prover.ts +7 -5
  34. package/src/kernel_prover/proof_creator.ts +2 -4
  35. package/src/note_processor/note_processor.ts +10 -7
  36. package/src/pxe_service/create_pxe_service.ts +1 -1
  37. package/src/pxe_service/pxe_service.ts +14 -10
  38. package/src/pxe_service/test/pxe_test_suite.ts +11 -17
  39. package/src/simulator_oracle/index.ts +13 -2
  40. package/src/synchronizer/synchronizer.ts +11 -6
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  CONTRACT_TREE_HEIGHT,
3
- CircuitsWasm,
4
3
  EthAddress,
5
4
  FUNCTION_TREE_HEIGHT,
6
5
  Fr,
@@ -8,7 +7,6 @@ import {
8
7
  MembershipWitness,
9
8
  NewContractConstructor,
10
9
  NewContractData,
11
- computeFunctionTree,
12
10
  computeFunctionTreeData,
13
11
  generateFunctionLeaves,
14
12
  hashVKStr,
@@ -18,6 +16,7 @@ import {
18
16
  import {
19
17
  computeCompleteAddress,
20
18
  computeContractLeaf,
19
+ computeFunctionTree,
21
20
  computeFunctionTreeRoot,
22
21
  computeVarArgsHash,
23
22
  hashConstructor,
@@ -44,7 +43,6 @@ export class ContractTree {
44
43
  */
45
44
  public readonly contract: ContractDao,
46
45
  private stateInfoProvider: StateInfoProvider,
47
- private wasm: CircuitsWasm,
48
46
  /**
49
47
  * Data associated with the contract constructor for a new contract.
50
48
  */
@@ -66,7 +64,7 @@ export class ContractTree {
66
64
  * @param node - An instance of the AztecNode class representing the current node.
67
65
  * @returns A new ContractTree instance containing the contract data and computed values.
68
66
  */
69
- public static async new(
67
+ public static new(
70
68
  artifact: ContractArtifact,
71
69
  args: Fr[],
72
70
  portalContract: EthAddress,
@@ -74,7 +72,6 @@ export class ContractTree {
74
72
  from: PublicKey,
75
73
  node: AztecNode,
76
74
  ) {
77
- const wasm = await CircuitsWasm.get();
78
75
  const constructorArtifact = artifact.functions.find(isConstructor);
79
76
  if (!constructorArtifact) {
80
77
  throw new Error('Constructor not found.');
@@ -87,14 +84,14 @@ export class ContractTree {
87
84
  ...f,
88
85
  selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters),
89
86
  }));
90
- const leaves = generateFunctionLeaves(functions, wasm);
91
- const root = computeFunctionTreeRoot(wasm, leaves);
87
+ const leaves = generateFunctionLeaves(functions);
88
+ const root = computeFunctionTreeRoot(leaves);
92
89
  const functionData = FunctionData.fromAbi(constructorArtifact);
93
- const vkHash = hashVKStr(constructorArtifact.verificationKey, wasm);
94
- const argsHash = await computeVarArgsHash(wasm, args);
95
- const constructorHash = hashConstructor(wasm, functionData, argsHash, vkHash);
90
+ const vkHash = hashVKStr(constructorArtifact.verificationKey);
91
+ const argsHash = computeVarArgsHash(args);
92
+ const constructorHash = hashConstructor(functionData, argsHash, vkHash);
96
93
 
97
- const completeAddress = computeCompleteAddress(wasm, from, contractAddressSalt, root, constructorHash);
94
+ const completeAddress = computeCompleteAddress(from, contractAddressSalt, root, constructorHash);
98
95
 
99
96
  const contractDao: ContractDao = {
100
97
  ...artifact,
@@ -106,7 +103,7 @@ export class ContractTree {
106
103
  functionData,
107
104
  vkHash,
108
105
  };
109
- return new ContractTree(contractDao, node, wasm, NewContractConstructor);
106
+ return new ContractTree(contractDao, node, NewContractConstructor);
110
107
  }
111
108
 
112
109
  /**
@@ -172,7 +169,7 @@ export class ContractTree {
172
169
  public getFunctionTreeRoot() {
173
170
  if (!this.functionTreeRoot) {
174
171
  const leaves = this.getFunctionLeaves();
175
- this.functionTreeRoot = computeFunctionTreeRoot(this.wasm, leaves);
172
+ this.functionTreeRoot = computeFunctionTreeRoot(leaves);
176
173
  }
177
174
  return Promise.resolve(this.functionTreeRoot);
178
175
  }
@@ -197,7 +194,7 @@ export class ContractTree {
197
194
 
198
195
  if (!this.functionTree) {
199
196
  const leaves = this.getFunctionLeaves();
200
- this.functionTree = computeFunctionTree(this.wasm, leaves);
197
+ this.functionTree = computeFunctionTree(leaves);
201
198
  }
202
199
  const functionTreeData = computeFunctionTreeData(this.functionTree, functionIndex);
203
200
  return Promise.resolve(
@@ -218,7 +215,7 @@ export class ContractTree {
218
215
  */
219
216
  private getFunctionLeaves() {
220
217
  if (!this.functionLeaves) {
221
- this.functionLeaves = generateFunctionLeaves(this.contract.functions, this.wasm);
218
+ this.functionLeaves = generateFunctionLeaves(this.contract.functions);
222
219
  }
223
220
  return this.functionLeaves;
224
221
  }
@@ -228,7 +225,7 @@ export class ContractTree {
228
225
  const { completeAddress, portalContract } = this.contract;
229
226
  const root = await this.getFunctionTreeRoot();
230
227
  const newContractData = new NewContractData(completeAddress.address, portalContract, root);
231
- const commitment = computeContractLeaf(this.wasm, newContractData);
228
+ const commitment = computeContractLeaf(newContractData);
232
229
  this.contractIndex = await this.stateInfoProvider.findLeafIndex(MerkleTreeId.CONTRACT_TREE, commitment);
233
230
  if (this.contractIndex === undefined) {
234
231
  throw new Error(
@@ -24,6 +24,20 @@ export interface Database extends ContractDatabase {
24
24
  */
25
25
  getAuthWitness(messageHash: Fr): Promise<Fr[]>;
26
26
 
27
+ /**
28
+ * Adding a capsule to the capsule dispenser.
29
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
30
+ * @param capsule - An array of field elements representing the capsule.
31
+ */
32
+ addCapsule(capsule: Fr[]): Promise<void>;
33
+
34
+ /**
35
+ * Get the next capsule from the capsule dispenser.
36
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
37
+ * @returns A promise that resolves to an array of field elements representing the capsule.
38
+ */
39
+ popCapsule(): Promise<Fr[] | undefined>;
40
+
27
41
  /**
28
42
  * Gets notes based on the provided filter.
29
43
  * @param filter - The filter to apply to the notes.
@@ -20,6 +20,9 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
20
20
  private globalVariablesHash: Fr | undefined;
21
21
  private addresses: CompleteAddress[] = [];
22
22
  private authWitnesses: Record<string, Fr[]> = {};
23
+ // A capsule is a "blob" of data that is passed to the contract through an oracle.
24
+ // We are using a stack to keep track of the capsules that are passed to the contract.
25
+ private capsuleStack: Fr[][] = [];
23
26
 
24
27
  constructor(logSuffix?: string) {
25
28
  super(createDebugLogger(logSuffix ? 'aztec:memory_db_' + logSuffix : 'aztec:memory_db'));
@@ -44,11 +47,20 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
44
47
  return Promise.resolve(this.authWitnesses[messageHash.toString()]);
45
48
  }
46
49
 
47
- public addNote(note: NoteDao) {
50
+ public addNote(note: NoteDao): Promise<void> {
48
51
  this.notesTable.push(note);
49
52
  return Promise.resolve();
50
53
  }
51
54
 
55
+ public addCapsule(capsule: Fr[]): Promise<void> {
56
+ this.capsuleStack.push(capsule);
57
+ return Promise.resolve();
58
+ }
59
+
60
+ public popCapsule(): Promise<Fr[] | undefined> {
61
+ return Promise.resolve(this.capsuleStack.pop());
62
+ }
63
+
52
64
  public addNotes(notes: NoteDao[]) {
53
65
  this.notesTable.push(...notes);
54
66
  return Promise.resolve();
@@ -95,7 +107,9 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
95
107
 
96
108
  public getTreeRoots(): Record<MerkleTreeId, Fr> {
97
109
  const roots = this.treeRoots;
98
- if (!roots) throw new Error(`Tree roots not set in memory database`);
110
+ if (!roots) {
111
+ throw new Error(`Tree roots not set in memory database`);
112
+ }
99
113
  return roots;
100
114
  }
101
115
 
@@ -106,7 +120,9 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
106
120
 
107
121
  public getHistoricBlockData(): HistoricBlockData {
108
122
  const roots = this.getTreeRoots();
109
- if (!this.globalVariablesHash) throw new Error(`Global variables hash not set in memory database`);
123
+ if (!this.globalVariablesHash) {
124
+ throw new Error(`Global variables hash not set in memory database`);
125
+ }
110
126
  return new HistoricBlockData(
111
127
  roots[MerkleTreeId.NOTE_HASH_TREE],
112
128
  roots[MerkleTreeId.NULLIFIER_TREE],
@@ -110,11 +110,13 @@ export class KernelProver {
110
110
  // and fill the non-transient ones in with sibling paths via oracle.
111
111
  const readRequestMembershipWitnesses = currentExecution.readRequestPartialWitnesses;
112
112
  for (let rr = 0; rr < readRequestMembershipWitnesses.length; rr++) {
113
- if (currentExecution.callStackItem.publicInputs.readRequests[rr] == Fr.zero()) {
114
- throw new Error(
115
- 'Number of read requests output from Noir circuit does not match number of read request commitment indices output from simulator.',
116
- );
117
- }
113
+ // Pretty sure this check was forever broken. I made some changes to Fr and this started triggering.
114
+ // The conditional makes no sense to me anyway.
115
+ // if (currentExecution.callStackItem.publicInputs.readRequests[rr] == Fr.ZERO) {
116
+ // throw new Error(
117
+ // 'Number of read requests output from Noir circuit does not match number of read request commitment indices output from simulator.',
118
+ // );
119
+ // }
118
120
  const rrWitness = readRequestMembershipWitnesses[rr];
119
121
  if (!rrWitness.isTransient) {
120
122
  // Non-transient reads must contain full membership witness with sibling path from commitment to root.
@@ -1,5 +1,4 @@
1
1
  import {
2
- CircuitsWasm,
3
2
  KernelCircuitPublicInputs,
4
3
  KernelCircuitPublicInputsFinal,
5
4
  PrivateCircuitPublicInputs,
@@ -98,11 +97,10 @@ export interface ProofCreator {
98
97
  export class KernelProofCreator implements ProofCreator {
99
98
  constructor(private log = createDebugLogger('aztec:kernel_proof_creator')) {}
100
99
 
101
- public async getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) {
102
- const wasm = await CircuitsWasm.get();
100
+ public getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) {
103
101
  const contractAddress = publicInputs.callContext.storageContractAddress;
104
102
 
105
- return publicInputs.newCommitments.map(commitment => siloCommitment(wasm, contractAddress, commitment));
103
+ return Promise.resolve(publicInputs.newCommitments.map(commitment => siloCommitment(contractAddress, commitment)));
106
104
  }
107
105
 
108
106
  public async createProofInit(privateInputs: PrivateKernelInputsInit): Promise<ProofOutput> {
@@ -1,4 +1,4 @@
1
- import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js';
1
+ import { MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js';
2
2
  import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis';
3
3
  import { Grumpkin } from '@aztec/circuits.js/barretenberg';
4
4
  import { Fr } from '@aztec/foundation/fields';
@@ -94,7 +94,7 @@ export class NoteProcessor {
94
94
  }
95
95
 
96
96
  const blocksAndNotes: ProcessedData[] = [];
97
- const curve = await Grumpkin.new();
97
+ const curve = new Grumpkin();
98
98
 
99
99
  // Iterate over both blocks and encrypted logs.
100
100
  for (let blockIndex = 0; blockIndex < encryptedL2BlockLogs.length; ++blockIndex) {
@@ -196,7 +196,6 @@ export class NoteProcessor {
196
196
  { contractAddress, storageSlot, note }: L1NotePayload,
197
197
  excludedIndices: Set<number>,
198
198
  ) {
199
- const wasm = await CircuitsWasm.get();
200
199
  let commitmentIndex = 0;
201
200
  let nonce: Fr | undefined;
202
201
  let innerNoteHash: Fr | undefined;
@@ -204,12 +203,16 @@ export class NoteProcessor {
204
203
  let uniqueSiloedNoteHash: Fr | undefined;
205
204
  let innerNullifier: Fr | undefined;
206
205
  for (; commitmentIndex < commitments.length; ++commitmentIndex) {
207
- if (excludedIndices.has(commitmentIndex)) continue;
206
+ if (excludedIndices.has(commitmentIndex)) {
207
+ continue;
208
+ }
208
209
 
209
210
  const commitment = commitments[commitmentIndex];
210
- if (commitment.equals(Fr.ZERO)) break;
211
+ if (commitment.equals(Fr.ZERO)) {
212
+ break;
213
+ }
211
214
 
212
- const expectedNonce = computeCommitmentNonce(wasm, firstNullifier, commitmentIndex);
215
+ const expectedNonce = computeCommitmentNonce(firstNullifier, commitmentIndex);
213
216
  ({ innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } =
214
217
  await this.simulator.computeNoteHashAndNullifier(contractAddress, expectedNonce, storageSlot, note));
215
218
  if (commitment.equals(uniqueSiloedNoteHash)) {
@@ -244,7 +247,7 @@ https://github.com/AztecProtocol/aztec-packages/issues/1641`;
244
247
  commitmentIndex,
245
248
  nonce,
246
249
  innerNoteHash: innerNoteHash!,
247
- siloedNullifier: siloNullifier(wasm, contractAddress, innerNullifier!),
250
+ siloedNullifier: siloNullifier(contractAddress, innerNullifier!),
248
251
  };
249
252
  }
250
253
 
@@ -43,7 +43,7 @@ export async function createPXEService(
43
43
  : undefined
44
44
  : useLogSuffix;
45
45
 
46
- keyStore = keyStore || new TestKeyStore(await Grumpkin.new());
46
+ keyStore = keyStore || new TestKeyStore(new Grumpkin());
47
47
  db = db || new MemoryDB(logSuffix);
48
48
 
49
49
  const server = new PXEService(keyStore, aztecNode, db, config, logSuffix);
@@ -8,7 +8,6 @@ import {
8
8
  } from '@aztec/acir-simulator';
9
9
  import {
10
10
  AztecAddress,
11
- CircuitsWasm,
12
11
  CompleteAddress,
13
12
  FunctionData,
14
13
  GrumpkinPrivateKey,
@@ -120,8 +119,12 @@ export class PXEService implements PXE {
120
119
  return this.db.addAuthWitness(witness.requestHash, witness.witness);
121
120
  }
122
121
 
122
+ public addCapsule(capsule: Fr[]) {
123
+ return this.db.addCapsule(capsule);
124
+ }
125
+
123
126
  public async registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise<CompleteAddress> {
124
- const completeAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(privKey, partialAddress);
127
+ const completeAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(privKey, partialAddress);
125
128
  const wasAdded = await this.db.addCompleteAddress(completeAddress);
126
129
  if (wasAdded) {
127
130
  const pubKey = this.keyStore.addAccount(privKey);
@@ -238,8 +241,7 @@ export class PXEService implements PXE {
238
241
  throw new Error('Note does not exist.');
239
242
  }
240
243
 
241
- const wasm = await CircuitsWasm.get();
242
- const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!);
244
+ const siloedNullifier = siloNullifier(note.contractAddress, innerNullifier!);
243
245
  const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier);
244
246
  if (nullifierIndex !== undefined) {
245
247
  throw new Error('The note has been destroyed.');
@@ -273,16 +275,16 @@ export class PXEService implements PXE {
273
275
  throw new Error(`Unknown tx: ${note.txHash}`);
274
276
  }
275
277
 
276
- const wasm = await CircuitsWasm.get();
277
-
278
278
  const nonces: Fr[] = [];
279
279
  const firstNullifier = tx.newNullifiers[0];
280
280
  const commitments = tx.newCommitments;
281
281
  for (let i = 0; i < commitments.length; ++i) {
282
282
  const commitment = commitments[i];
283
- if (commitment.equals(Fr.ZERO)) break;
283
+ if (commitment.equals(Fr.ZERO)) {
284
+ break;
285
+ }
284
286
 
285
- const nonce = computeCommitmentNonce(wasm, firstNullifier, i);
287
+ const nonce = computeCommitmentNonce(firstNullifier, i);
286
288
  const { siloedNoteHash, uniqueSiloedNoteHash } = await this.simulator.computeNoteHashAndNullifier(
287
289
  note.contractAddress,
288
290
  nonce,
@@ -325,7 +327,9 @@ export class PXEService implements PXE {
325
327
  const newContract = deployedContractAddress ? await this.db.getContract(deployedContractAddress) : undefined;
326
328
 
327
329
  const tx = await this.#simulateAndProve(txRequest, newContract);
328
- if (simulatePublic) await this.#simulatePublicCalls(tx);
330
+ if (simulatePublic) {
331
+ await this.#simulatePublicCalls(tx);
332
+ }
329
333
  this.log.info(`Executed local simulation for ${await tx.getTxHash()}`);
330
334
 
331
335
  return tx;
@@ -626,7 +630,7 @@ export class PXEService implements PXE {
626
630
  publicInputs: KernelCircuitPublicInputsFinal,
627
631
  enqueuedPublicCalls: PublicCallRequest[],
628
632
  ) {
629
- const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().then(item => item.hash());
633
+ const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().hash();
630
634
  const enqueuedPublicCallsHashes = await Promise.all(enqueuedPublicCalls.map(callToHash));
631
635
  const { publicCallStack } = publicInputs.end;
632
636
 
@@ -12,13 +12,10 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
12
12
  }, 120_000);
13
13
 
14
14
  it('registers an account and returns it as an account only and not as a recipient', async () => {
15
- const keyPair = ConstantKeyPair.random(await Grumpkin.new());
16
- const completeAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(
17
- await keyPair.getPrivateKey(),
18
- Fr.random(),
19
- );
15
+ const keyPair = ConstantKeyPair.random(new Grumpkin());
16
+ const completeAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(keyPair.getPrivateKey(), Fr.random());
20
17
 
21
- await pxe.registerAccount(await keyPair.getPrivateKey(), completeAddress.partialAddress);
18
+ await pxe.registerAccount(keyPair.getPrivateKey(), completeAddress.partialAddress);
22
19
 
23
20
  // Check that the account is correctly registered using the getAccounts and getRecipients methods
24
21
  const accounts = await pxe.getRegisteredAccounts();
@@ -34,7 +31,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
34
31
  });
35
32
 
36
33
  it('registers a recipient and returns it as a recipient only and not as an account', async () => {
37
- const completeAddress = await CompleteAddress.random();
34
+ const completeAddress = CompleteAddress.random();
38
35
 
39
36
  await pxe.registerRecipient(completeAddress);
40
37
 
@@ -52,18 +49,15 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
52
49
  });
53
50
 
54
51
  it('does not throw when registering the same account twice (just ignores the second attempt)', async () => {
55
- const keyPair = ConstantKeyPair.random(await Grumpkin.new());
56
- const completeAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(
57
- await keyPair.getPrivateKey(),
58
- Fr.random(),
59
- );
52
+ const keyPair = ConstantKeyPair.random(new Grumpkin());
53
+ const completeAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(keyPair.getPrivateKey(), Fr.random());
60
54
 
61
- await pxe.registerAccount(await keyPair.getPrivateKey(), completeAddress.partialAddress);
62
- await pxe.registerAccount(await keyPair.getPrivateKey(), completeAddress.partialAddress);
55
+ await pxe.registerAccount(keyPair.getPrivateKey(), completeAddress.partialAddress);
56
+ await pxe.registerAccount(keyPair.getPrivateKey(), completeAddress.partialAddress);
63
57
  });
64
58
 
65
59
  it('cannot register a recipient with the same aztec address but different pub key or partial address', async () => {
66
- const recipient1 = await CompleteAddress.random();
60
+ const recipient1 = CompleteAddress.random();
67
61
  const recipient2 = new CompleteAddress(recipient1.address, Point.random(), Fr.random());
68
62
 
69
63
  await pxe.registerRecipient(recipient1);
@@ -73,14 +67,14 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
73
67
  });
74
68
 
75
69
  it('does not throw when registering the same recipient twice (just ignores the second attempt)', async () => {
76
- const completeAddress = await CompleteAddress.random();
70
+ const completeAddress = CompleteAddress.random();
77
71
 
78
72
  await pxe.registerRecipient(completeAddress);
79
73
  await pxe.registerRecipient(completeAddress);
80
74
  });
81
75
 
82
76
  it('successfully adds a contract', async () => {
83
- const contracts: DeployedContract[] = [await randomDeployedContract(), await randomDeployedContract()];
77
+ const contracts: DeployedContract[] = [randomDeployedContract(), randomDeployedContract()];
84
78
  await pxe.addContracts(contracts);
85
79
 
86
80
  const expectedContractAddresses = contracts.map(contract => contract.completeAddress.address);
@@ -31,19 +31,30 @@ export class SimulatorOracle implements DBOracle {
31
31
 
32
32
  async getCompleteAddress(address: AztecAddress): Promise<CompleteAddress> {
33
33
  const completeAddress = await this.db.getCompleteAddress(address);
34
- if (!completeAddress)
34
+ if (!completeAddress) {
35
35
  throw new Error(
36
36
  `No public key registered for address ${address.toString()}. Register it by calling pxe.registerRecipient(...) or pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/dev_docs/contracts/common_errors#no-public-key-registered-error`,
37
37
  );
38
+ }
38
39
  return completeAddress;
39
40
  }
40
41
 
41
42
  async getAuthWitness(messageHash: Fr): Promise<Fr[]> {
42
43
  const witness = await this.db.getAuthWitness(messageHash);
43
- if (!witness) throw new Error(`Unknown auth witness for message hash ${messageHash.toString(true)}`);
44
+ if (!witness) {
45
+ throw new Error(`Unknown auth witness for message hash ${messageHash.toString()}`);
46
+ }
44
47
  return witness;
45
48
  }
46
49
 
50
+ async popCapsule(): Promise<Fr[]> {
51
+ const capsule = await this.db.popCapsule();
52
+ if (!capsule) {
53
+ throw new Error(`No capsules available`);
54
+ }
55
+ return capsule;
56
+ }
57
+
47
58
  async getNotes(contractAddress: AztecAddress, storageSlot: Fr) {
48
59
  const noteDaos = await this.db.getNotes({ contractAddress, storageSlot });
49
60
  return noteDaos.map(({ contractAddress, storageSlot, nonce, note, innerNoteHash, siloedNullifier, index }) => ({
@@ -1,4 +1,4 @@
1
- import { AztecAddress, CircuitsWasm, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js';
1
+ import { AztecAddress, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js';
2
2
  import { computeGlobalsHash } from '@aztec/circuits.js/abis';
3
3
  import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
4
4
  import { InterruptibleSleep } from '@aztec/foundation/sleep';
@@ -39,7 +39,9 @@ export class Synchronizer {
39
39
  * @param retryInterval - The time interval (in ms) to wait before retrying if no data is available.
40
40
  */
41
41
  public async start(from = INITIAL_L2_BLOCK_NUM, limit = 1, retryInterval = 1000) {
42
- if (this.running) return;
42
+ if (this.running) {
43
+ return;
44
+ }
43
45
  this.running = true;
44
46
 
45
47
  if (from < this.synchedToBlock + 1) {
@@ -197,10 +199,11 @@ export class Synchronizer {
197
199
 
198
200
  private async setBlockDataFromBlock(latestBlock: L2BlockContext) {
199
201
  const { block } = latestBlock;
200
- if (block.number < this.initialSyncBlockNumber) return;
202
+ if (block.number < this.initialSyncBlockNumber) {
203
+ return;
204
+ }
201
205
 
202
- const wasm = await CircuitsWasm.get();
203
- const globalsHash = computeGlobalsHash(wasm, latestBlock.block.globalVariables);
206
+ const globalsHash = computeGlobalsHash(latestBlock.block.globalVariables);
204
207
  const blockData = new HistoricBlockData(
205
208
  block.endNoteHashTreeSnapshot.root,
206
209
  block.endNullifierTreeSnapshot.root,
@@ -242,7 +245,9 @@ export class Synchronizer {
242
245
  public addAccount(publicKey: PublicKey, keyStore: KeyStore, startingBlock: number) {
243
246
  const predicate = (x: NoteProcessor) => x.publicKey.equals(publicKey);
244
247
  const processor = this.noteProcessors.find(predicate) ?? this.noteProcessorsToCatchUp.find(predicate);
245
- if (processor) return;
248
+ if (processor) {
249
+ return;
250
+ }
246
251
 
247
252
  this.noteProcessorsToCatchUp.push(new NoteProcessor(publicKey, keyStore, this.db, this.node, startingBlock));
248
253
  }