@aztec/txe 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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 (78) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +91 -56
  7. package/dest/oracle/interfaces.d.ts +33 -29
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +20 -22
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +37 -27
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +211 -98
  15. package/dest/rpc_translator.d.ts +96 -79
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +362 -173
  18. package/dest/state_machine/archiver.d.ts +21 -52
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +66 -99
  21. package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +42 -25
  24. package/dest/state_machine/global_variable_builder.d.ts +6 -5
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +13 -1
  27. package/dest/state_machine/index.d.ts +9 -7
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +44 -23
  30. package/dest/state_machine/mock_epoch_cache.d.ts +25 -8
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +46 -9
  33. package/dest/state_machine/synchronizer.d.ts +6 -5
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +8 -7
  36. package/dest/txe_session.d.ts +27 -15
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +170 -55
  39. package/dest/util/encoding.d.ts +686 -19
  40. package/dest/util/encoding.d.ts.map +1 -1
  41. package/dest/util/encoding.js +1 -1
  42. package/dest/util/txe_account_store.d.ts +10 -0
  43. package/dest/util/txe_account_store.d.ts.map +1 -0
  44. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  45. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  46. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  47. package/dest/util/txe_public_contract_data_source.js +13 -32
  48. package/dest/utils/block_creation.d.ts +21 -6
  49. package/dest/utils/block_creation.d.ts.map +1 -1
  50. package/dest/utils/block_creation.js +38 -4
  51. package/dest/utils/tx_effect_creation.d.ts +3 -3
  52. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  53. package/dest/utils/tx_effect_creation.js +4 -7
  54. package/package.json +18 -18
  55. package/src/constants.ts +3 -0
  56. package/src/index.ts +103 -63
  57. package/src/oracle/interfaces.ts +36 -32
  58. package/src/oracle/txe_oracle_public_context.ts +21 -28
  59. package/src/oracle/txe_oracle_top_level_context.ts +256 -138
  60. package/src/rpc_translator.ts +419 -191
  61. package/src/state_machine/archiver.ts +62 -117
  62. package/src/state_machine/dummy_p2p_client.ts +58 -33
  63. package/src/state_machine/global_variable_builder.ts +21 -4
  64. package/src/state_machine/index.ts +65 -21
  65. package/src/state_machine/mock_epoch_cache.ts +57 -14
  66. package/src/state_machine/synchronizer.ts +9 -8
  67. package/src/txe_session.ts +236 -104
  68. package/src/util/encoding.ts +1 -1
  69. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  70. package/src/util/txe_public_contract_data_source.ts +20 -47
  71. package/src/utils/block_creation.ts +49 -15
  72. package/src/utils/tx_effect_creation.ts +5 -12
  73. package/dest/util/txe_account_data_provider.d.ts +0 -10
  74. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  75. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  76. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  77. package/dest/util/txe_contract_data_provider.js +0 -22
  78. package/src/util/txe_contract_data_provider.ts +0 -36
@@ -1,15 +1,16 @@
1
1
  import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
2
2
  import { Fr, Point } from '@aztec/aztec.js/fields';
3
3
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
4
+ import { BlockNumber } from '@aztec/foundation/branded-types';
4
5
  import {
5
6
  type IMiscOracle,
6
7
  type IPrivateExecutionOracle,
7
8
  type IUtilityExecutionOracle,
8
- packAsRetrievedNote,
9
+ packAsHintedNote,
9
10
  } from '@aztec/pxe/simulator';
10
- import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
11
+ import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
11
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
12
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import { BlockHash } from '@aztec/stdlib/block';
13
14
 
14
15
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
15
16
  import type { TXESessionStateHandler } from './txe_session.js';
@@ -29,6 +30,9 @@ import {
29
30
  toSingle,
30
31
  } from './util/encoding.js';
31
32
 
33
+ const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
34
+ const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
35
+
32
36
  export class UnavailableOracleError extends Error {
33
37
  constructor(oracleName: string) {
34
38
  super(`${oracleName} oracles not available with the current handler`);
@@ -100,13 +104,15 @@ export class RPCTranslator {
100
104
 
101
105
  // TXE session state transition functions - these get handled by the state handler
102
106
 
103
- async txeSetTopLevelTXEContext() {
107
+ // eslint-disable-next-line camelcase
108
+ async aztec_txe_setTopLevelTXEContext() {
104
109
  await this.stateHandler.enterTopLevelState();
105
110
 
106
111
  return toForeignCallResult([]);
107
112
  }
108
113
 
109
- async txeSetPrivateTXEContext(
114
+ // eslint-disable-next-line camelcase
115
+ async aztec_txe_setPrivateTXEContext(
110
116
  foreignContractAddressIsSome: ForeignCallSingle,
111
117
  foreignContractAddressValue: ForeignCallSingle,
112
118
  foreignAnchorBlockNumberIsSome: ForeignCallSingle,
@@ -117,7 +123,7 @@ export class RPCTranslator {
117
123
  : undefined;
118
124
 
119
125
  const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
120
- ? fromSingle(foreignAnchorBlockNumberValue).toNumber()
126
+ ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
121
127
  : undefined;
122
128
 
123
129
  const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
@@ -125,7 +131,8 @@ export class RPCTranslator {
125
131
  return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
126
132
  }
127
133
 
128
- async txeSetPublicTXEContext(
134
+ // eslint-disable-next-line camelcase
135
+ async aztec_txe_setPublicTXEContext(
129
136
  foreignContractAddressIsSome: ForeignCallSingle,
130
137
  foreignContractAddressValue: ForeignCallSingle,
131
138
  ) {
@@ -138,7 +145,8 @@ export class RPCTranslator {
138
145
  return toForeignCallResult([]);
139
146
  }
140
147
 
141
- async txeSetUtilityTXEContext(
148
+ // eslint-disable-next-line camelcase
149
+ async aztec_txe_setUtilityTXEContext(
142
150
  foreignContractAddressIsSome: ForeignCallSingle,
143
151
  foreignContractAddressValue: ForeignCallSingle,
144
152
  ) {
@@ -155,38 +163,54 @@ export class RPCTranslator {
155
163
 
156
164
  // TXE-specific oracles
157
165
 
158
- async txeGetNextBlockNumber() {
159
- const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
166
+ // eslint-disable-next-line camelcase
167
+ aztec_txe_getDefaultAddress() {
168
+ const defaultAddress = this.handlerAsTxe().getDefaultAddress();
169
+
170
+ return toForeignCallResult([toSingle(defaultAddress)]);
171
+ }
172
+
173
+ // eslint-disable-next-line camelcase
174
+ async aztec_txe_getNextBlockNumber() {
175
+ const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
160
176
 
161
177
  return toForeignCallResult([toSingle(nextBlockNumber)]);
162
178
  }
163
179
 
164
- async txeGetNextBlockTimestamp() {
165
- const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
180
+ // eslint-disable-next-line camelcase
181
+ async aztec_txe_getNextBlockTimestamp() {
182
+ const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
166
183
 
167
184
  return toForeignCallResult([toSingle(nextBlockTimestamp)]);
168
185
  }
169
186
 
170
- async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
187
+ // eslint-disable-next-line camelcase
188
+ async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
171
189
  const blocks = fromSingle(foreignBlocks).toNumber();
172
190
 
173
- await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
191
+ await this.handlerAsTxe().advanceBlocksBy(blocks);
174
192
 
175
193
  return toForeignCallResult([]);
176
194
  }
177
195
 
178
- txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
196
+ // eslint-disable-next-line camelcase
197
+ aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
179
198
  const duration = fromSingle(foreignDuration).toBigInt();
180
199
 
181
- this.handlerAsTxe().txeAdvanceTimestampBy(duration);
200
+ this.handlerAsTxe().advanceTimestampBy(duration);
182
201
 
183
202
  return toForeignCallResult([]);
184
203
  }
185
204
 
186
- async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: ForeignCallSingle) {
205
+ // eslint-disable-next-line camelcase
206
+ async aztec_txe_deploy(
207
+ artifact: ContractArtifact,
208
+ instance: ContractInstanceWithAddress,
209
+ foreignSecret: ForeignCallSingle,
210
+ ) {
187
211
  const secret = fromSingle(foreignSecret);
188
212
 
189
- await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
213
+ await this.handlerAsTxe().deploy(artifact, instance, secret);
190
214
 
191
215
  return toForeignCallResult([
192
216
  toArray([
@@ -199,10 +223,11 @@ export class RPCTranslator {
199
223
  ]);
200
224
  }
201
225
 
202
- async txeCreateAccount(foreignSecret: ForeignCallSingle) {
226
+ // eslint-disable-next-line camelcase
227
+ async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
203
228
  const secret = fromSingle(foreignSecret);
204
229
 
205
- const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
230
+ const completeAddress = await this.handlerAsTxe().createAccount(secret);
206
231
 
207
232
  return toForeignCallResult([
208
233
  toSingle(completeAddress.address),
@@ -210,14 +235,15 @@ export class RPCTranslator {
210
235
  ]);
211
236
  }
212
237
 
213
- async txeAddAccount(
238
+ // eslint-disable-next-line camelcase
239
+ async aztec_txe_addAccount(
214
240
  artifact: ContractArtifact,
215
241
  instance: ContractInstanceWithAddress,
216
242
  foreignSecret: ForeignCallSingle,
217
243
  ) {
218
244
  const secret = fromSingle(foreignSecret);
219
245
 
220
- const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
246
+ const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
221
247
 
222
248
  return toForeignCallResult([
223
249
  toSingle(completeAddress.address),
@@ -225,39 +251,44 @@ export class RPCTranslator {
225
251
  ]);
226
252
  }
227
253
 
228
- async txeAddAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
254
+ // eslint-disable-next-line camelcase
255
+ async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
229
256
  const address = addressFromSingle(foreignAddress);
230
257
  const messageHash = fromSingle(foreignMessageHash);
231
258
 
232
- await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
259
+ await this.handlerAsTxe().addAuthWitness(address, messageHash);
233
260
 
234
261
  return toForeignCallResult([]);
235
262
  }
236
263
 
237
264
  // PXE oracles
238
265
 
239
- utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
266
+ // eslint-disable-next-line camelcase
267
+ aztec_utl_assertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
240
268
  const version = fromSingle(foreignVersion).toNumber();
241
269
 
242
- this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
270
+ this.handlerAsMisc().assertCompatibleOracleVersion(version);
243
271
 
244
272
  return toForeignCallResult([]);
245
273
  }
246
274
 
247
- utilityGetRandomField() {
248
- const randomField = this.handlerAsMisc().utilityGetRandomField();
275
+ // eslint-disable-next-line camelcase
276
+ aztec_utl_getRandomField() {
277
+ const randomField = this.handlerAsMisc().getRandomField();
249
278
 
250
279
  return toForeignCallResult([toSingle(randomField)]);
251
280
  }
252
281
 
253
- async txeGetLastBlockTimestamp() {
254
- const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
282
+ // eslint-disable-next-line camelcase
283
+ async aztec_txe_getLastBlockTimestamp() {
284
+ const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
255
285
 
256
286
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
257
287
  }
258
288
 
259
- async txeGetLastTxEffects() {
260
- const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
289
+ // eslint-disable-next-line camelcase
290
+ async aztec_txe_getLastTxEffects() {
291
+ const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
261
292
 
262
293
  return toForeignCallResult([
263
294
  toSingle(txHash.hash),
@@ -266,26 +297,70 @@ export class RPCTranslator {
266
297
  ]);
267
298
  }
268
299
 
269
- privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
300
+ // eslint-disable-next-line camelcase
301
+ async aztec_txe_getPrivateEvents(
302
+ foreignSelector: ForeignCallSingle,
303
+ foreignContractAddress: ForeignCallSingle,
304
+ foreignScope: ForeignCallSingle,
305
+ ) {
306
+ const selector = EventSelector.fromField(fromSingle(foreignSelector));
307
+ const contractAddress = addressFromSingle(foreignContractAddress);
308
+ const scope = addressFromSingle(foreignScope);
309
+
310
+ // TODO(F-335): Avoid doing the following 2 calls here.
311
+ {
312
+ await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
313
+ // We cycle job to commit the stores after the contract sync.
314
+ await this.stateHandler.cycleJob();
315
+ }
316
+
317
+ const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
318
+
319
+ if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
320
+ throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
321
+ }
322
+
323
+ if (events.some(e => e.length > MAX_EVENT_LEN)) {
324
+ throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
325
+ }
326
+
327
+ // This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
328
+ // multidimensional array in get_private_events_oracle and create the BoundedVecs here.
329
+ const rawArrayStorage = events
330
+ .map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
331
+ .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
332
+ .flat();
333
+ const eventLengths = events
334
+ .map(e => new Fr(e.length))
335
+ .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
336
+ const queryLength = new Fr(events.length);
337
+
338
+ return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
339
+ }
340
+
341
+ // eslint-disable-next-line camelcase
342
+ aztec_prv_storeInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
270
343
  const values = fromArray(foreignValues);
271
344
  const hash = fromSingle(foreignHash);
272
345
 
273
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
346
+ this.handlerAsPrivate().storeInExecutionCache(values, hash);
274
347
 
275
348
  return toForeignCallResult([]);
276
349
  }
277
350
 
278
- async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
351
+ // eslint-disable-next-line camelcase
352
+ async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
279
353
  const hash = fromSingle(foreignHash);
280
354
 
281
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
355
+ const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
282
356
 
283
357
  return toForeignCallResult([toArray(returns)]);
284
358
  }
285
359
 
286
360
  // When the argument is a slice, noir automatically adds a length field to oracle call.
287
361
  // When the argument is an array, we add the field length manually to the signature.
288
- utilityDebugLog(
362
+ // eslint-disable-next-line camelcase
363
+ async aztec_utl_log(
289
364
  foreignLevel: ForeignCallSingle,
290
365
  foreignMessage: ForeignCallArray,
291
366
  _foreignLength: ForeignCallSingle,
@@ -297,45 +372,50 @@ export class RPCTranslator {
297
372
  .join('');
298
373
  const fields = fromArray(foreignFields);
299
374
 
300
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
375
+ await this.handlerAsMisc().log(level, message, fields);
301
376
 
302
377
  return toForeignCallResult([]);
303
378
  }
304
379
 
305
- async utilityStorageRead(
380
+ // eslint-disable-next-line camelcase
381
+ async aztec_utl_storageRead(
382
+ foreignBlockHash: ForeignCallSingle,
306
383
  foreignContractAddress: ForeignCallSingle,
307
384
  foreignStartStorageSlot: ForeignCallSingle,
308
- foreignBlockNumber: ForeignCallSingle,
309
385
  foreignNumberOfElements: ForeignCallSingle,
310
386
  ) {
387
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
311
388
  const contractAddress = addressFromSingle(foreignContractAddress);
312
389
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
313
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
314
390
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
315
391
 
316
- const values = await this.handlerAsUtility().utilityStorageRead(
392
+ const values = await this.handlerAsUtility().storageRead(
393
+ blockHash,
317
394
  contractAddress,
318
395
  startStorageSlot,
319
- blockNumber,
320
396
  numberOfElements,
321
397
  );
322
398
 
323
399
  return toForeignCallResult([toArray(values)]);
324
400
  }
325
401
 
326
- async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
327
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
402
+ // eslint-disable-next-line camelcase
403
+ async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
404
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
328
405
  const leafSlot = fromSingle(foreignLeafSlot);
329
406
 
330
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
407
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
331
408
 
332
409
  if (!witness) {
333
- throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
410
+ throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
334
411
  }
335
412
  return toForeignCallResult(witness.toNoirRepresentation());
336
413
  }
337
414
 
338
- async utilityGetNotes(
415
+ // eslint-disable-next-line camelcase
416
+ async aztec_utl_getNotes(
417
+ foreignOwnerIsSome: ForeignCallSingle,
418
+ foreignOwnerValue: ForeignCallSingle,
339
419
  foreignStorageSlot: ForeignCallSingle,
340
420
  foreignNumSelects: ForeignCallSingle,
341
421
  foreignSelectByIndexes: ForeignCallArray,
@@ -351,8 +431,12 @@ export class RPCTranslator {
351
431
  foreignOffset: ForeignCallSingle,
352
432
  foreignStatus: ForeignCallSingle,
353
433
  foreignMaxNotes: ForeignCallSingle,
354
- foreignPackedRetrievedNoteLength: ForeignCallSingle,
434
+ foreignPackedHintedNoteLength: ForeignCallSingle,
355
435
  ) {
436
+ // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
437
+ const owner = fromSingle(foreignOwnerIsSome).toBool()
438
+ ? AztecAddress.fromField(fromSingle(foreignOwnerValue))
439
+ : undefined;
356
440
  const storageSlot = fromSingle(foreignStorageSlot);
357
441
  const numSelects = fromSingle(foreignNumSelects).toNumber();
358
442
  const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
@@ -368,9 +452,10 @@ export class RPCTranslator {
368
452
  const offset = fromSingle(foreignOffset).toNumber();
369
453
  const status = fromSingle(foreignStatus).toNumber();
370
454
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
371
- const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
455
+ const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
372
456
 
373
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(
457
+ const noteDatas = await this.handlerAsUtility().getNotes(
458
+ owner,
374
459
  storageSlot,
375
460
  numSelects,
376
461
  selectByIndexes,
@@ -387,7 +472,17 @@ export class RPCTranslator {
387
472
  status,
388
473
  );
389
474
 
390
- const returnDataAsArrayOfArrays = noteDatas.map(packAsRetrievedNote);
475
+ const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
476
+ packAsHintedNote({
477
+ contractAddress: noteData.contractAddress,
478
+ owner: noteData.owner,
479
+ randomness: noteData.randomness,
480
+ storageSlot: noteData.storageSlot,
481
+ noteNonce: noteData.noteNonce,
482
+ isPending: noteData.isPending,
483
+ note: noteData.note,
484
+ }),
485
+ );
391
486
 
392
487
  // Now we convert each sub-array to an array of ForeignCallSingles
393
488
  const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
@@ -396,15 +491,13 @@ export class RPCTranslator {
396
491
 
397
492
  // At last we convert the array of arrays to a bounded vec of arrays
398
493
  return toForeignCallResult(
399
- arrayOfArraysToBoundedVecOfArrays(
400
- returnDataAsArrayOfForeignCallSingleArrays,
401
- maxNotes,
402
- packedRetrievedNoteLength,
403
- ),
494
+ arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
404
495
  );
405
496
  }
406
497
 
407
- privateNotifyCreatedNote(
498
+ // eslint-disable-next-line camelcase
499
+ aztec_prv_notifyCreatedNote(
500
+ foreignOwner: ForeignCallSingle,
408
501
  foreignStorageSlot: ForeignCallSingle,
409
502
  foreignRandomness: ForeignCallSingle,
410
503
  foreignNoteTypeId: ForeignCallSingle,
@@ -412,6 +505,7 @@ export class RPCTranslator {
412
505
  foreignNoteHash: ForeignCallSingle,
413
506
  foreignCounter: ForeignCallSingle,
414
507
  ) {
508
+ const owner = addressFromSingle(foreignOwner);
415
509
  const storageSlot = fromSingle(foreignStorageSlot);
416
510
  const randomness = fromSingle(foreignRandomness);
417
511
  const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
@@ -419,12 +513,13 @@ export class RPCTranslator {
419
513
  const noteHash = fromSingle(foreignNoteHash);
420
514
  const counter = fromSingle(foreignCounter).toNumber();
421
515
 
422
- this.handlerAsPrivate().privateNotifyCreatedNote(storageSlot, randomness, noteTypeId, note, noteHash, counter);
516
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
423
517
 
424
518
  return toForeignCallResult([]);
425
519
  }
426
520
 
427
- async privateNotifyNullifiedNote(
521
+ // eslint-disable-next-line camelcase
522
+ async aztec_prv_notifyNullifiedNote(
428
523
  foreignInnerNullifier: ForeignCallSingle,
429
524
  foreignNoteHash: ForeignCallSingle,
430
525
  foreignCounter: ForeignCallSingle,
@@ -433,31 +528,47 @@ export class RPCTranslator {
433
528
  const noteHash = fromSingle(foreignNoteHash);
434
529
  const counter = fromSingle(foreignCounter).toNumber();
435
530
 
436
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
531
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
437
532
 
438
533
  return toForeignCallResult([]);
439
534
  }
440
535
 
441
- async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
536
+ // eslint-disable-next-line camelcase
537
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
442
538
  const innerNullifier = fromSingle(foreignInnerNullifier);
443
539
 
444
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
540
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
445
541
 
446
542
  return toForeignCallResult([]);
447
543
  }
448
544
 
449
- async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
545
+ // eslint-disable-next-line camelcase
546
+ async aztec_prv_isNullifierPending(
547
+ foreignInnerNullifier: ForeignCallSingle,
548
+ foreignContractAddress: ForeignCallSingle,
549
+ ) {
550
+ const innerNullifier = fromSingle(foreignInnerNullifier);
551
+ const contractAddress = addressFromSingle(foreignContractAddress);
552
+
553
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
554
+
555
+ return toForeignCallResult([toSingle(new Fr(isPending))]);
556
+ }
557
+
558
+ // eslint-disable-next-line camelcase
559
+ async aztec_utl_checkNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
450
560
  const innerNullifier = fromSingle(foreignInnerNullifier);
451
561
 
452
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
562
+ const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
453
563
 
454
564
  return toForeignCallResult([toSingle(new Fr(exists))]);
455
565
  }
456
566
 
457
- async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
567
+ // eslint-disable-next-line camelcase
568
+ async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
458
569
  const address = addressFromSingle(foreignAddress);
459
570
 
460
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
571
+ const instance = await this.handlerAsUtility().getContractInstance(address);
461
572
 
462
573
  return toForeignCallResult(
463
574
  [
@@ -470,23 +581,37 @@ export class RPCTranslator {
470
581
  );
471
582
  }
472
583
 
473
- async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
584
+ // eslint-disable-next-line camelcase
585
+ async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
474
586
  const address = addressFromSingle(foreignAddress);
475
587
 
476
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
588
+ const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
477
589
 
478
- return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
590
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
591
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
592
+ if (result === undefined) {
593
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
594
+ return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
595
+ } else {
596
+ // Data was found so we set `some` to 1 and return it along with `value`.
597
+ return toForeignCallResult([
598
+ toSingle(new Fr(1)),
599
+ toArray([...result.publicKeys.toFields(), result.partialAddress]),
600
+ ]);
601
+ }
479
602
  }
480
603
 
481
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
604
+ // eslint-disable-next-line camelcase
605
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
482
606
  const pkMHash = fromSingle(foreignPkMHash);
483
607
 
484
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
608
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
485
609
 
486
610
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
487
611
  }
488
612
 
489
- privateCallPrivateFunction(
613
+ // eslint-disable-next-line camelcase
614
+ aztec_prv_callPrivateFunction(
490
615
  _foreignTargetContractAddress: ForeignCallSingle,
491
616
  _foreignFunctionSelector: ForeignCallSingle,
492
617
  _foreignArgsHash: ForeignCallSingle,
@@ -498,25 +623,27 @@ export class RPCTranslator {
498
623
  );
499
624
  }
500
625
 
501
- async utilityGetNullifierMembershipWitness(
502
- foreignBlockNumber: ForeignCallSingle,
626
+ // eslint-disable-next-line camelcase
627
+ async aztec_utl_getNullifierMembershipWitness(
628
+ foreignBlockHash: ForeignCallSingle,
503
629
  foreignNullifier: ForeignCallSingle,
504
630
  ) {
505
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
631
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
506
632
  const nullifier = fromSingle(foreignNullifier);
507
633
 
508
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
634
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
509
635
 
510
636
  if (!witness) {
511
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
637
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
512
638
  }
513
639
  return toForeignCallResult(witness.toNoirRepresentation());
514
640
  }
515
641
 
516
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
642
+ // eslint-disable-next-line camelcase
643
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
517
644
  const messageHash = fromSingle(foreignMessageHash);
518
645
 
519
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
646
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
520
647
 
521
648
  if (!authWitness) {
522
649
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -524,44 +651,35 @@ export class RPCTranslator {
524
651
  return toForeignCallResult([toArray(authWitness)]);
525
652
  }
526
653
 
527
- public privateNotifyEnqueuedPublicFunctionCall(
528
- _foreignTargetContractAddress: ForeignCallSingle,
529
- _foreignCalldataHash: ForeignCallSingle,
530
- _foreignSideEffectCounter: ForeignCallSingle,
531
- _foreignIsStaticCall: ForeignCallSingle,
532
- ) {
654
+ // eslint-disable-next-line camelcase
655
+ public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
533
656
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
534
657
  }
535
658
 
536
- public privateNotifySetPublicTeardownFunctionCall(
537
- _foreignTargetContractAddress: ForeignCallSingle,
538
- _foreignCalldataHash: ForeignCallSingle,
539
- _foreignSideEffectCounter: ForeignCallSingle,
540
- _foreignIsStaticCall: ForeignCallSingle,
541
- ) {
659
+ // eslint-disable-next-line camelcase
660
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
542
661
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
543
662
  }
544
663
 
545
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
546
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
547
- }
548
-
549
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
664
+ // eslint-disable-next-line camelcase
665
+ public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
550
666
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
551
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
667
+ const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
552
668
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
553
669
  }
554
670
 
555
- async utilityGetUtilityContext() {
556
- const context = await this.handlerAsUtility().utilityGetUtilityContext();
671
+ // eslint-disable-next-line camelcase
672
+ aztec_utl_getUtilityContext() {
673
+ const context = this.handlerAsUtility().getUtilityContext();
557
674
 
558
675
  return toForeignCallResult(context.toNoirRepresentation());
559
676
  }
560
677
 
561
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
562
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
678
+ // eslint-disable-next-line camelcase
679
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
680
+ const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
563
681
 
564
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
682
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
565
683
 
566
684
  if (!header) {
567
685
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -569,67 +687,92 @@ export class RPCTranslator {
569
687
  return toForeignCallResult(header.toFields().map(toSingle));
570
688
  }
571
689
 
572
- async utilityGetMembershipWitness(
573
- foreignBlockNumber: ForeignCallSingle,
574
- foreignTreeId: ForeignCallSingle,
575
- foreignLeafValue: ForeignCallSingle,
690
+ // eslint-disable-next-line camelcase
691
+ async aztec_utl_getNoteHashMembershipWitness(
692
+ foreignAnchorBlockHash: ForeignCallSingle,
693
+ foreignNoteHash: ForeignCallSingle,
576
694
  ) {
577
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
578
- const treeId = fromSingle(foreignTreeId).toNumber();
579
- const leafValue = fromSingle(foreignLeafValue);
695
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
696
+ const noteHash = fromSingle(foreignNoteHash);
580
697
 
581
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
698
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
699
+
700
+ if (!witness) {
701
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
702
+ }
703
+ return toForeignCallResult(witness.toNoirRepresentation());
704
+ }
705
+
706
+ // eslint-disable-next-line camelcase
707
+ async aztec_utl_getBlockHashMembershipWitness(
708
+ foreignAnchorBlockHash: ForeignCallSingle,
709
+ foreignBlockHash: ForeignCallSingle,
710
+ ) {
711
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
712
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
713
+
714
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
582
715
 
583
716
  if (!witness) {
584
717
  throw new Error(
585
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
718
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
586
719
  );
587
720
  }
588
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
721
+ return toForeignCallResult(witness.toNoirRepresentation());
589
722
  }
590
723
 
591
- async utilityGetLowNullifierMembershipWitness(
592
- foreignBlockNumber: ForeignCallSingle,
724
+ // eslint-disable-next-line camelcase
725
+ async aztec_utl_getLowNullifierMembershipWitness(
726
+ foreignBlockHash: ForeignCallSingle,
593
727
  foreignNullifier: ForeignCallSingle,
594
728
  ) {
595
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
729
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
596
730
  const nullifier = fromSingle(foreignNullifier);
597
731
 
598
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
732
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
599
733
 
600
734
  if (!witness) {
601
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
735
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
602
736
  }
603
737
  return toForeignCallResult(witness.toNoirRepresentation());
604
738
  }
605
739
 
606
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
740
+ // eslint-disable-next-line camelcase
741
+ async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
607
742
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
608
743
 
609
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
744
+ await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
610
745
 
611
746
  return toForeignCallResult([]);
612
747
  }
613
748
 
614
- public async utilityValidateEnqueuedNotesAndEvents(
749
+ // eslint-disable-next-line camelcase
750
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
615
751
  foreignContractAddress: ForeignCallSingle,
616
752
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
617
753
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
754
+ foreignMaxNotePackedLen: ForeignCallSingle,
755
+ foreignMaxEventSerializedLen: ForeignCallSingle,
618
756
  ) {
619
757
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
620
758
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
621
759
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
760
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
761
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
622
762
 
623
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
763
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
624
764
  contractAddress,
625
765
  noteValidationRequestsArrayBaseSlot,
626
766
  eventValidationRequestsArrayBaseSlot,
767
+ maxNotePackedLen,
768
+ maxEventSerializedLen,
627
769
  );
628
770
 
629
771
  return toForeignCallResult([]);
630
772
  }
631
773
 
632
- public async utilityBulkRetrieveLogs(
774
+ // eslint-disable-next-line camelcase
775
+ public async aztec_utl_bulkRetrieveLogs(
633
776
  foreignContractAddress: ForeignCallSingle,
634
777
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
635
778
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
@@ -638,7 +781,7 @@ export class RPCTranslator {
638
781
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
639
782
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
640
783
 
641
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
784
+ await this.handlerAsUtility().bulkRetrieveLogs(
642
785
  contractAddress,
643
786
  logRetrievalRequestsArrayBaseSlot,
644
787
  logRetrievalResponsesArrayBaseSlot,
@@ -647,7 +790,27 @@ export class RPCTranslator {
647
790
  return toForeignCallResult([]);
648
791
  }
649
792
 
650
- async utilityStoreCapsule(
793
+ // eslint-disable-next-line camelcase
794
+ public async aztec_utl_utilityResolveMessageContexts(
795
+ foreignContractAddress: ForeignCallSingle,
796
+ foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
797
+ foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
798
+ ) {
799
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
800
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
801
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
802
+
803
+ await this.handlerAsUtility().utilityResolveMessageContexts(
804
+ contractAddress,
805
+ messageContextRequestsArrayBaseSlot,
806
+ messageContextResponsesArrayBaseSlot,
807
+ );
808
+
809
+ return toForeignCallResult([]);
810
+ }
811
+
812
+ // eslint-disable-next-line camelcase
813
+ async aztec_utl_storeCapsule(
651
814
  foreignContractAddress: ForeignCallSingle,
652
815
  foreignSlot: ForeignCallSingle,
653
816
  foreignCapsule: ForeignCallArray,
@@ -656,12 +819,13 @@ export class RPCTranslator {
656
819
  const slot = fromSingle(foreignSlot);
657
820
  const capsule = fromArray(foreignCapsule);
658
821
 
659
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
822
+ await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
660
823
 
661
824
  return toForeignCallResult([]);
662
825
  }
663
826
 
664
- async utilityLoadCapsule(
827
+ // eslint-disable-next-line camelcase
828
+ async aztec_utl_loadCapsule(
665
829
  foreignContractAddress: ForeignCallSingle,
666
830
  foreignSlot: ForeignCallSingle,
667
831
  foreignTSize: ForeignCallSingle,
@@ -670,7 +834,7 @@ export class RPCTranslator {
670
834
  const slot = fromSingle(foreignSlot);
671
835
  const tSize = fromSingle(foreignTSize).toNumber();
672
836
 
673
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
837
+ const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
674
838
 
675
839
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
676
840
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -683,16 +847,18 @@ export class RPCTranslator {
683
847
  }
684
848
  }
685
849
 
686
- async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
850
+ // eslint-disable-next-line camelcase
851
+ async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
687
852
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
688
853
  const slot = fromSingle(foreignSlot);
689
854
 
690
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
855
+ await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
691
856
 
692
857
  return toForeignCallResult([]);
693
858
  }
694
859
 
695
- async utilityCopyCapsule(
860
+ // eslint-disable-next-line camelcase
861
+ async aztec_utl_copyCapsule(
696
862
  foreignContractAddress: ForeignCallSingle,
697
863
  foreignSrcSlot: ForeignCallSingle,
698
864
  foreignDstSlot: ForeignCallSingle,
@@ -703,7 +869,7 @@ export class RPCTranslator {
703
869
  const dstSlot = fromSingle(foreignDstSlot);
704
870
  const numEntries = fromSingle(foreignNumEntries).toNumber();
705
871
 
706
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
872
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
707
873
 
708
874
  return toForeignCallResult([]);
709
875
  }
@@ -712,7 +878,8 @@ export class RPCTranslator {
712
878
  // The compiler didn't throw an error, so it took me a while to learn of the existence of this file, and that I need
713
879
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
714
880
  // existence of a txe_oracle method?
715
- async utilityAes128Decrypt(
881
+ // eslint-disable-next-line camelcase
882
+ async aztec_utl_tryAes128Decrypt(
716
883
  foreignCiphertextBVecStorage: ForeignCallArray,
717
884
  foreignCiphertextLength: ForeignCallSingle,
718
885
  foreignIv: ForeignCallArray,
@@ -722,14 +889,22 @@ export class RPCTranslator {
722
889
  const iv = fromUintArray(foreignIv, 8);
723
890
  const symKey = fromUintArray(foreignSymKey, 8);
724
891
 
725
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
726
-
727
- return toForeignCallResult(
728
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
729
- );
892
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
893
+ try {
894
+ const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
895
+ const [storage, length] = arrayToBoundedVec(
896
+ bufferToU8Array(plaintextBuffer),
897
+ foreignCiphertextBVecStorage.length,
898
+ );
899
+ return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
900
+ } catch {
901
+ const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
902
+ return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
903
+ }
730
904
  }
731
905
 
732
- async utilityGetSharedSecret(
906
+ // eslint-disable-next-line camelcase
907
+ async aztec_utl_getSharedSecret(
733
908
  foreignAddress: ForeignCallSingle,
734
909
  foreignEphPKField0: ForeignCallSingle,
735
910
  foreignEphPKField1: ForeignCallSingle,
@@ -742,43 +917,66 @@ export class RPCTranslator {
742
917
  fromSingle(foreignEphPKField2),
743
918
  ]);
744
919
 
745
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
920
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
746
921
 
747
922
  return toForeignCallResult(secret.toFields().map(toSingle));
748
923
  }
749
924
 
750
- emitOffchainEffect(_foreignData: ForeignCallArray) {
925
+ // eslint-disable-next-line camelcase
926
+ aztec_utl_invalidateContractSyncCache(
927
+ foreignContractAddress: ForeignCallSingle,
928
+ foreignScopes: ForeignCallArray,
929
+ foreignScopeCount: ForeignCallSingle,
930
+ ) {
931
+ const contractAddress = addressFromSingle(foreignContractAddress);
932
+ const count = fromSingle(foreignScopeCount).toNumber();
933
+ const scopes = fromArray(foreignScopes)
934
+ .slice(0, count)
935
+ .map(f => new AztecAddress(f));
936
+
937
+ this.handlerAsUtility().invalidateContractSyncCache(contractAddress, scopes);
938
+
939
+ return Promise.resolve(toForeignCallResult([]));
940
+ }
941
+
942
+ // eslint-disable-next-line camelcase
943
+ aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
751
944
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
752
945
  }
753
946
 
754
947
  // AVM opcodes
755
948
 
756
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
949
+ // eslint-disable-next-line camelcase
950
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
757
951
  // TODO(#8811): Implement
758
952
  return toForeignCallResult([]);
759
953
  }
760
954
 
761
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
955
+ // eslint-disable-next-line camelcase
956
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
762
957
  const slot = fromSingle(foreignSlot);
958
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
763
959
 
764
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
960
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
765
961
 
766
962
  return toForeignCallResult([toSingle(new Fr(value))]);
767
963
  }
768
964
 
769
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
965
+ // eslint-disable-next-line camelcase
966
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
770
967
  const slot = fromSingle(foreignSlot);
771
968
  const value = fromSingle(foreignValue);
772
969
 
773
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
970
+ await this.handlerAsAvm().storageWrite(slot, value);
774
971
 
775
972
  return toForeignCallResult([]);
776
973
  }
777
974
 
778
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
975
+ // eslint-disable-next-line camelcase
976
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
779
977
  const address = addressFromSingle(foreignAddress);
780
978
 
781
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
979
+ const instance = await this.handlerAsUtility().getContractInstance(address);
782
980
 
783
981
  return toForeignCallResult([
784
982
  toSingle(instance.deployer),
@@ -787,10 +985,11 @@ export class RPCTranslator {
787
985
  ]);
788
986
  }
789
987
 
790
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
988
+ // eslint-disable-next-line camelcase
989
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
791
990
  const address = addressFromSingle(foreignAddress);
792
991
 
793
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
992
+ const instance = await this.handlerAsUtility().getContractInstance(address);
794
993
 
795
994
  return toForeignCallResult([
796
995
  toSingle(instance.currentContractClassId),
@@ -799,10 +998,11 @@ export class RPCTranslator {
799
998
  ]);
800
999
  }
801
1000
 
802
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1001
+ // eslint-disable-next-line camelcase
1002
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
803
1003
  const address = addressFromSingle(foreignAddress);
804
1004
 
805
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1005
+ const instance = await this.handlerAsUtility().getContractInstance(address);
806
1006
 
807
1007
  return toForeignCallResult([
808
1008
  toSingle(instance.initializationHash),
@@ -811,86 +1011,98 @@ export class RPCTranslator {
811
1011
  ]);
812
1012
  }
813
1013
 
814
- async avmOpcodeSender() {
815
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1014
+ // eslint-disable-next-line camelcase
1015
+ async aztec_avm_sender() {
1016
+ const sender = await this.handlerAsAvm().sender();
816
1017
 
817
1018
  return toForeignCallResult([toSingle(sender)]);
818
1019
  }
819
1020
 
820
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1021
+ // eslint-disable-next-line camelcase
1022
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
821
1023
  const nullifier = fromSingle(foreignNullifier);
822
1024
 
823
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1025
+ await this.handlerAsAvm().emitNullifier(nullifier);
824
1026
 
825
1027
  return toForeignCallResult([]);
826
1028
  }
827
1029
 
828
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1030
+ // eslint-disable-next-line camelcase
1031
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
829
1032
  const noteHash = fromSingle(foreignNoteHash);
830
1033
 
831
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1034
+ await this.handlerAsAvm().emitNoteHash(noteHash);
832
1035
 
833
1036
  return toForeignCallResult([]);
834
1037
  }
835
1038
 
836
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
837
- const innerNullifier = fromSingle(foreignInnerNullifier);
838
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
1039
+ // eslint-disable-next-line camelcase
1040
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1041
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
839
1042
 
840
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
1043
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
841
1044
 
842
1045
  return toForeignCallResult([toSingle(new Fr(exists))]);
843
1046
  }
844
1047
 
845
- async avmOpcodeAddress() {
846
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1048
+ // eslint-disable-next-line camelcase
1049
+ async aztec_avm_address() {
1050
+ const contractAddress = await this.handlerAsAvm().address();
847
1051
 
848
1052
  return toForeignCallResult([toSingle(contractAddress.toField())]);
849
1053
  }
850
1054
 
851
- async avmOpcodeBlockNumber() {
852
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1055
+ // eslint-disable-next-line camelcase
1056
+ async aztec_avm_blockNumber() {
1057
+ const blockNumber = await this.handlerAsAvm().blockNumber();
853
1058
 
854
1059
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
855
1060
  }
856
1061
 
857
- async avmOpcodeTimestamp() {
858
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1062
+ // eslint-disable-next-line camelcase
1063
+ async aztec_avm_timestamp() {
1064
+ const timestamp = await this.handlerAsAvm().timestamp();
859
1065
 
860
1066
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
861
1067
  }
862
1068
 
863
- async avmOpcodeIsStaticCall() {
864
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1069
+ // eslint-disable-next-line camelcase
1070
+ async aztec_avm_isStaticCall() {
1071
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
865
1072
 
866
1073
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
867
1074
  }
868
1075
 
869
- async avmOpcodeChainId() {
870
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1076
+ // eslint-disable-next-line camelcase
1077
+ async aztec_avm_chainId() {
1078
+ const chainId = await this.handlerAsAvm().chainId();
871
1079
 
872
1080
  return toForeignCallResult([toSingle(chainId)]);
873
1081
  }
874
1082
 
875
- async avmOpcodeVersion() {
876
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1083
+ // eslint-disable-next-line camelcase
1084
+ async aztec_avm_version() {
1085
+ const version = await this.handlerAsAvm().version();
877
1086
 
878
1087
  return toForeignCallResult([toSingle(version)]);
879
1088
  }
880
1089
 
881
- avmOpcodeReturndataSize() {
1090
+ // eslint-disable-next-line camelcase
1091
+ aztec_avm_returndataSize() {
882
1092
  throw new Error(
883
1093
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
884
1094
  );
885
1095
  }
886
1096
 
887
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1097
+ // eslint-disable-next-line camelcase
1098
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
888
1099
  throw new Error(
889
1100
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
890
1101
  );
891
1102
  }
892
1103
 
893
- avmOpcodeCall(
1104
+ // eslint-disable-next-line camelcase
1105
+ aztec_avm_call(
894
1106
  _foreignL2Gas: ForeignCallSingle,
895
1107
  _foreignDaGas: ForeignCallSingle,
896
1108
  _foreignAddress: ForeignCallSingle,
@@ -902,7 +1114,8 @@ export class RPCTranslator {
902
1114
  );
903
1115
  }
904
1116
 
905
- avmOpcodeStaticCall(
1117
+ // eslint-disable-next-line camelcase
1118
+ aztec_avm_staticCall(
906
1119
  _foreignL2Gas: ForeignCallSingle,
907
1120
  _foreignDaGas: ForeignCallSingle,
908
1121
  _foreignAddress: ForeignCallSingle,
@@ -914,13 +1127,15 @@ export class RPCTranslator {
914
1127
  );
915
1128
  }
916
1129
 
917
- avmOpcodeSuccessCopy() {
1130
+ // eslint-disable-next-line camelcase
1131
+ aztec_avm_successCopy() {
918
1132
  throw new Error(
919
1133
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
920
1134
  );
921
1135
  }
922
1136
 
923
- async txePrivateCallNewFlow(
1137
+ // eslint-disable-next-line camelcase
1138
+ async aztec_txe_privateCallNewFlow(
924
1139
  foreignFrom: ForeignCallSingle,
925
1140
  foreignTargetContractAddress: ForeignCallSingle,
926
1141
  foreignFunctionSelector: ForeignCallSingle,
@@ -935,19 +1150,23 @@ export class RPCTranslator {
935
1150
  const argsHash = fromSingle(foreignArgsHash);
936
1151
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
937
1152
 
938
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1153
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(
939
1154
  from,
940
1155
  targetContractAddress,
941
1156
  functionSelector,
942
1157
  args,
943
1158
  argsHash,
944
1159
  isStaticCall,
1160
+ this.stateHandler.getCurrentJob(),
945
1161
  );
946
1162
 
1163
+ // TODO(F-335): Avoid doing the following call here.
1164
+ await this.stateHandler.cycleJob();
947
1165
  return toForeignCallResult([toArray(returnValues)]);
948
1166
  }
949
1167
 
950
- async txeSimulateUtilityFunction(
1168
+ // eslint-disable-next-line camelcase
1169
+ async aztec_txe_executeUtilityFunction(
951
1170
  foreignTargetContractAddress: ForeignCallSingle,
952
1171
  foreignFunctionSelector: ForeignCallSingle,
953
1172
  foreignArgs: ForeignCallArray,
@@ -956,16 +1175,20 @@ export class RPCTranslator {
956
1175
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
957
1176
  const args = fromArray(foreignArgs);
958
1177
 
959
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1178
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(
960
1179
  targetContractAddress,
961
1180
  functionSelector,
962
1181
  args,
1182
+ this.stateHandler.getCurrentJob(),
963
1183
  );
964
1184
 
1185
+ // TODO(F-335): Avoid doing the following call here.
1186
+ await this.stateHandler.cycleJob();
965
1187
  return toForeignCallResult([toArray(returnValues)]);
966
1188
  }
967
1189
 
968
- async txePublicCallNewFlow(
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_txe_publicCallNewFlow(
969
1192
  foreignFrom: ForeignCallSingle,
970
1193
  foreignAddress: ForeignCallSingle,
971
1194
  foreignCalldata: ForeignCallArray,
@@ -976,13 +1199,16 @@ export class RPCTranslator {
976
1199
  const calldata = fromArray(foreignCalldata);
977
1200
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
978
1201
 
979
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
1202
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
980
1203
 
1204
+ // TODO(F-335): Avoid doing the following call here.
1205
+ await this.stateHandler.cycleJob();
981
1206
  return toForeignCallResult([toArray(returnValues)]);
982
1207
  }
983
1208
 
984
- async privateGetSenderForTags() {
985
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1209
+ // eslint-disable-next-line camelcase
1210
+ async aztec_prv_getSenderForTags() {
1211
+ const sender = await this.handlerAsPrivate().getSenderForTags();
986
1212
 
987
1213
  // Return a Noir Option struct with `some` and `value` fields
988
1214
  if (sender === undefined) {
@@ -994,19 +1220,21 @@ export class RPCTranslator {
994
1220
  }
995
1221
  }
996
1222
 
997
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1223
+ // eslint-disable-next-line camelcase
1224
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
998
1225
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
999
1226
 
1000
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1227
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1001
1228
 
1002
1229
  return toForeignCallResult([]);
1003
1230
  }
1004
1231
 
1005
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1232
+ // eslint-disable-next-line camelcase
1233
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1006
1234
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1007
1235
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1008
1236
 
1009
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1237
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1010
1238
 
1011
1239
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1012
1240
  }