@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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 (81) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/constants.d.ts +3 -0
  3. package/dest/constants.d.ts.map +1 -0
  4. package/dest/constants.js +2 -0
  5. package/dest/index.d.ts +1 -1
  6. package/dest/index.d.ts.map +1 -1
  7. package/dest/index.js +91 -56
  8. package/dest/oracle/interfaces.d.ts +33 -29
  9. package/dest/oracle/interfaces.d.ts.map +1 -1
  10. package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
  11. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  12. package/dest/oracle/txe_oracle_public_context.js +20 -22
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts +37 -27
  14. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  15. package/dest/oracle/txe_oracle_top_level_context.js +228 -106
  16. package/dest/rpc_translator.d.ts +98 -78
  17. package/dest/rpc_translator.d.ts.map +1 -1
  18. package/dest/rpc_translator.js +367 -171
  19. package/dest/state_machine/archiver.d.ts +21 -51
  20. package/dest/state_machine/archiver.d.ts.map +1 -1
  21. package/dest/state_machine/archiver.js +66 -99
  22. package/dest/state_machine/dummy_p2p_client.d.ts +21 -14
  23. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  24. package/dest/state_machine/dummy_p2p_client.js +42 -22
  25. package/dest/state_machine/global_variable_builder.d.ts +6 -4
  26. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  27. package/dest/state_machine/global_variable_builder.js +13 -1
  28. package/dest/state_machine/index.d.ts +9 -7
  29. package/dest/state_machine/index.d.ts.map +1 -1
  30. package/dest/state_machine/index.js +44 -23
  31. package/dest/state_machine/mock_epoch_cache.d.ts +30 -12
  32. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  33. package/dest/state_machine/mock_epoch_cache.js +53 -15
  34. package/dest/state_machine/synchronizer.d.ts +6 -5
  35. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  36. package/dest/state_machine/synchronizer.js +8 -7
  37. package/dest/txe_session.d.ts +27 -15
  38. package/dest/txe_session.d.ts.map +1 -1
  39. package/dest/txe_session.js +173 -56
  40. package/dest/util/encoding.d.ts +615 -16
  41. package/dest/util/encoding.d.ts.map +1 -1
  42. package/dest/util/encoding.js +1 -1
  43. package/dest/util/expected_failure_error.d.ts +1 -1
  44. package/dest/util/expected_failure_error.d.ts.map +1 -1
  45. package/dest/util/txe_account_store.d.ts +10 -0
  46. package/dest/util/txe_account_store.d.ts.map +1 -0
  47. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  48. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  49. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  50. package/dest/util/txe_public_contract_data_source.js +12 -29
  51. package/dest/utils/block_creation.d.ts +21 -6
  52. package/dest/utils/block_creation.d.ts.map +1 -1
  53. package/dest/utils/block_creation.js +38 -4
  54. package/dest/utils/tx_effect_creation.d.ts +3 -3
  55. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  56. package/dest/utils/tx_effect_creation.js +4 -7
  57. package/package.json +18 -17
  58. package/src/constants.ts +3 -0
  59. package/src/index.ts +103 -63
  60. package/src/oracle/interfaces.ts +36 -32
  61. package/src/oracle/txe_oracle_public_context.ts +21 -28
  62. package/src/oracle/txe_oracle_top_level_context.ts +272 -145
  63. package/src/rpc_translator.ts +422 -194
  64. package/src/state_machine/archiver.ts +63 -117
  65. package/src/state_machine/dummy_p2p_client.ts +59 -29
  66. package/src/state_machine/global_variable_builder.ts +22 -4
  67. package/src/state_machine/index.ts +64 -21
  68. package/src/state_machine/mock_epoch_cache.ts +67 -23
  69. package/src/state_machine/synchronizer.ts +9 -8
  70. package/src/txe_session.ts +239 -105
  71. package/src/util/encoding.ts +1 -1
  72. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  73. package/src/util/txe_public_contract_data_source.ts +20 -45
  74. package/src/utils/block_creation.ts +49 -14
  75. package/src/utils/tx_effect_creation.ts +5 -12
  76. package/dest/util/txe_account_data_provider.d.ts +0 -10
  77. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  78. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  79. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  80. package/dest/util/txe_contract_data_provider.js +0 -22
  81. 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,31 +297,70 @@ export class RPCTranslator {
266
297
  ]);
267
298
  }
268
299
 
269
- // Since the argument is a slice, noir automatically adds a length field to oracle call.
270
- privateStoreInExecutionCache(
271
- _foreignLength: ForeignCallSingle,
272
- foreignValues: ForeignCallArray,
273
- foreignHash: ForeignCallSingle,
300
+ // eslint-disable-next-line camelcase
301
+ async aztec_txe_getPrivateEvents(
302
+ foreignSelector: ForeignCallSingle,
303
+ foreignContractAddress: ForeignCallSingle,
304
+ foreignScope: ForeignCallSingle,
274
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) {
275
343
  const values = fromArray(foreignValues);
276
344
  const hash = fromSingle(foreignHash);
277
345
 
278
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
346
+ this.handlerAsPrivate().storeInExecutionCache(values, hash);
279
347
 
280
348
  return toForeignCallResult([]);
281
349
  }
282
350
 
283
- async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
351
+ // eslint-disable-next-line camelcase
352
+ async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
284
353
  const hash = fromSingle(foreignHash);
285
354
 
286
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
355
+ const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
287
356
 
288
357
  return toForeignCallResult([toArray(returns)]);
289
358
  }
290
359
 
291
360
  // When the argument is a slice, noir automatically adds a length field to oracle call.
292
361
  // When the argument is an array, we add the field length manually to the signature.
293
- utilityDebugLog(
362
+ // eslint-disable-next-line camelcase
363
+ async aztec_utl_log(
294
364
  foreignLevel: ForeignCallSingle,
295
365
  foreignMessage: ForeignCallArray,
296
366
  _foreignLength: ForeignCallSingle,
@@ -302,45 +372,50 @@ export class RPCTranslator {
302
372
  .join('');
303
373
  const fields = fromArray(foreignFields);
304
374
 
305
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
375
+ await this.handlerAsMisc().log(level, message, fields);
306
376
 
307
377
  return toForeignCallResult([]);
308
378
  }
309
379
 
310
- async utilityStorageRead(
380
+ // eslint-disable-next-line camelcase
381
+ async aztec_utl_storageRead(
382
+ foreignBlockHash: ForeignCallSingle,
311
383
  foreignContractAddress: ForeignCallSingle,
312
384
  foreignStartStorageSlot: ForeignCallSingle,
313
- foreignBlockNumber: ForeignCallSingle,
314
385
  foreignNumberOfElements: ForeignCallSingle,
315
386
  ) {
387
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
316
388
  const contractAddress = addressFromSingle(foreignContractAddress);
317
389
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
318
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
319
390
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
320
391
 
321
- const values = await this.handlerAsUtility().utilityStorageRead(
392
+ const values = await this.handlerAsUtility().storageRead(
393
+ blockHash,
322
394
  contractAddress,
323
395
  startStorageSlot,
324
- blockNumber,
325
396
  numberOfElements,
326
397
  );
327
398
 
328
399
  return toForeignCallResult([toArray(values)]);
329
400
  }
330
401
 
331
- async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
332
- 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));
333
405
  const leafSlot = fromSingle(foreignLeafSlot);
334
406
 
335
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
407
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
336
408
 
337
409
  if (!witness) {
338
- 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()}.`);
339
411
  }
340
412
  return toForeignCallResult(witness.toNoirRepresentation());
341
413
  }
342
414
 
343
- async utilityGetNotes(
415
+ // eslint-disable-next-line camelcase
416
+ async aztec_utl_getNotes(
417
+ foreignOwnerIsSome: ForeignCallSingle,
418
+ foreignOwnerValue: ForeignCallSingle,
344
419
  foreignStorageSlot: ForeignCallSingle,
345
420
  foreignNumSelects: ForeignCallSingle,
346
421
  foreignSelectByIndexes: ForeignCallArray,
@@ -356,8 +431,12 @@ export class RPCTranslator {
356
431
  foreignOffset: ForeignCallSingle,
357
432
  foreignStatus: ForeignCallSingle,
358
433
  foreignMaxNotes: ForeignCallSingle,
359
- foreignPackedRetrievedNoteLength: ForeignCallSingle,
434
+ foreignPackedHintedNoteLength: ForeignCallSingle,
360
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;
361
440
  const storageSlot = fromSingle(foreignStorageSlot);
362
441
  const numSelects = fromSingle(foreignNumSelects).toNumber();
363
442
  const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
@@ -373,9 +452,10 @@ export class RPCTranslator {
373
452
  const offset = fromSingle(foreignOffset).toNumber();
374
453
  const status = fromSingle(foreignStatus).toNumber();
375
454
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
376
- const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
455
+ const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
377
456
 
378
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(
457
+ const noteDatas = await this.handlerAsUtility().getNotes(
458
+ owner,
379
459
  storageSlot,
380
460
  numSelects,
381
461
  selectByIndexes,
@@ -392,7 +472,17 @@ export class RPCTranslator {
392
472
  status,
393
473
  );
394
474
 
395
- 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
+ );
396
486
 
397
487
  // Now we convert each sub-array to an array of ForeignCallSingles
398
488
  const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
@@ -401,33 +491,35 @@ export class RPCTranslator {
401
491
 
402
492
  // At last we convert the array of arrays to a bounded vec of arrays
403
493
  return toForeignCallResult(
404
- arrayOfArraysToBoundedVecOfArrays(
405
- returnDataAsArrayOfForeignCallSingleArrays,
406
- maxNotes,
407
- packedRetrievedNoteLength,
408
- ),
494
+ arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
409
495
  );
410
496
  }
411
497
 
412
- privateNotifyCreatedNote(
498
+ // eslint-disable-next-line camelcase
499
+ aztec_prv_notifyCreatedNote(
500
+ foreignOwner: ForeignCallSingle,
413
501
  foreignStorageSlot: ForeignCallSingle,
502
+ foreignRandomness: ForeignCallSingle,
414
503
  foreignNoteTypeId: ForeignCallSingle,
415
504
  foreignNote: ForeignCallArray,
416
505
  foreignNoteHash: ForeignCallSingle,
417
506
  foreignCounter: ForeignCallSingle,
418
507
  ) {
508
+ const owner = addressFromSingle(foreignOwner);
419
509
  const storageSlot = fromSingle(foreignStorageSlot);
510
+ const randomness = fromSingle(foreignRandomness);
420
511
  const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
421
512
  const note = fromArray(foreignNote);
422
513
  const noteHash = fromSingle(foreignNoteHash);
423
514
  const counter = fromSingle(foreignCounter).toNumber();
424
515
 
425
- this.handlerAsPrivate().privateNotifyCreatedNote(storageSlot, noteTypeId, note, noteHash, counter);
516
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
426
517
 
427
518
  return toForeignCallResult([]);
428
519
  }
429
520
 
430
- async privateNotifyNullifiedNote(
521
+ // eslint-disable-next-line camelcase
522
+ async aztec_prv_notifyNullifiedNote(
431
523
  foreignInnerNullifier: ForeignCallSingle,
432
524
  foreignNoteHash: ForeignCallSingle,
433
525
  foreignCounter: ForeignCallSingle,
@@ -436,31 +528,47 @@ export class RPCTranslator {
436
528
  const noteHash = fromSingle(foreignNoteHash);
437
529
  const counter = fromSingle(foreignCounter).toNumber();
438
530
 
439
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
531
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
440
532
 
441
533
  return toForeignCallResult([]);
442
534
  }
443
535
 
444
- async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
536
+ // eslint-disable-next-line camelcase
537
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
445
538
  const innerNullifier = fromSingle(foreignInnerNullifier);
446
539
 
447
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
540
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
448
541
 
449
542
  return toForeignCallResult([]);
450
543
  }
451
544
 
452
- async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
545
+ // eslint-disable-next-line camelcase
546
+ async aztec_prv_isNullifierPending(
547
+ foreignInnerNullifier: ForeignCallSingle,
548
+ foreignContractAddress: ForeignCallSingle,
549
+ ) {
453
550
  const innerNullifier = fromSingle(foreignInnerNullifier);
551
+ const contractAddress = addressFromSingle(foreignContractAddress);
552
+
553
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
454
554
 
455
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
555
+ return toForeignCallResult([toSingle(new Fr(isPending))]);
556
+ }
557
+
558
+ // eslint-disable-next-line camelcase
559
+ async aztec_utl_checkNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
560
+ const innerNullifier = fromSingle(foreignInnerNullifier);
561
+
562
+ const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
456
563
 
457
564
  return toForeignCallResult([toSingle(new Fr(exists))]);
458
565
  }
459
566
 
460
- async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
567
+ // eslint-disable-next-line camelcase
568
+ async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
461
569
  const address = addressFromSingle(foreignAddress);
462
570
 
463
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
571
+ const instance = await this.handlerAsUtility().getContractInstance(address);
464
572
 
465
573
  return toForeignCallResult(
466
574
  [
@@ -473,23 +581,37 @@ export class RPCTranslator {
473
581
  );
474
582
  }
475
583
 
476
- async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
584
+ // eslint-disable-next-line camelcase
585
+ async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
477
586
  const address = addressFromSingle(foreignAddress);
478
587
 
479
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
588
+ const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
480
589
 
481
- 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
+ }
482
602
  }
483
603
 
484
- async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
604
+ // eslint-disable-next-line camelcase
605
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
485
606
  const pkMHash = fromSingle(foreignPkMHash);
486
607
 
487
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
608
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
488
609
 
489
610
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
490
611
  }
491
612
 
492
- privateCallPrivateFunction(
613
+ // eslint-disable-next-line camelcase
614
+ aztec_prv_callPrivateFunction(
493
615
  _foreignTargetContractAddress: ForeignCallSingle,
494
616
  _foreignFunctionSelector: ForeignCallSingle,
495
617
  _foreignArgsHash: ForeignCallSingle,
@@ -501,25 +623,27 @@ export class RPCTranslator {
501
623
  );
502
624
  }
503
625
 
504
- async utilityGetNullifierMembershipWitness(
505
- foreignBlockNumber: ForeignCallSingle,
626
+ // eslint-disable-next-line camelcase
627
+ async aztec_utl_getNullifierMembershipWitness(
628
+ foreignBlockHash: ForeignCallSingle,
506
629
  foreignNullifier: ForeignCallSingle,
507
630
  ) {
508
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
631
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
509
632
  const nullifier = fromSingle(foreignNullifier);
510
633
 
511
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
634
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
512
635
 
513
636
  if (!witness) {
514
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
637
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
515
638
  }
516
639
  return toForeignCallResult(witness.toNoirRepresentation());
517
640
  }
518
641
 
519
- async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
642
+ // eslint-disable-next-line camelcase
643
+ async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
520
644
  const messageHash = fromSingle(foreignMessageHash);
521
645
 
522
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
646
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
523
647
 
524
648
  if (!authWitness) {
525
649
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
@@ -527,38 +651,35 @@ export class RPCTranslator {
527
651
  return toForeignCallResult([toArray(authWitness)]);
528
652
  }
529
653
 
530
- public privateNotifyEnqueuedPublicFunctionCall(
531
- _foreignTargetContractAddress: ForeignCallSingle,
532
- _foreignCalldataHash: ForeignCallSingle,
533
- _foreignSideEffectCounter: ForeignCallSingle,
534
- _foreignIsStaticCall: ForeignCallSingle,
535
- ) {
654
+ // eslint-disable-next-line camelcase
655
+ public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
536
656
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
537
657
  }
538
658
 
539
- public privateNotifySetPublicTeardownFunctionCall(
540
- _foreignTargetContractAddress: ForeignCallSingle,
541
- _foreignCalldataHash: ForeignCallSingle,
542
- _foreignSideEffectCounter: ForeignCallSingle,
543
- _foreignIsStaticCall: ForeignCallSingle,
544
- ) {
659
+ // eslint-disable-next-line camelcase
660
+ public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
545
661
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
546
662
  }
547
663
 
548
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
549
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
664
+ // eslint-disable-next-line camelcase
665
+ public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
666
+ const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
667
+ const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
668
+ return toForeignCallResult([toSingle(new Fr(isRevertible))]);
550
669
  }
551
670
 
552
- async utilityGetUtilityContext() {
553
- const context = await this.handlerAsUtility().utilityGetUtilityContext();
671
+ // eslint-disable-next-line camelcase
672
+ aztec_utl_getUtilityContext() {
673
+ const context = this.handlerAsUtility().getUtilityContext();
554
674
 
555
675
  return toForeignCallResult(context.toNoirRepresentation());
556
676
  }
557
677
 
558
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
559
- 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());
560
681
 
561
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
682
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
562
683
 
563
684
  if (!header) {
564
685
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -566,67 +687,92 @@ export class RPCTranslator {
566
687
  return toForeignCallResult(header.toFields().map(toSingle));
567
688
  }
568
689
 
569
- async utilityGetMembershipWitness(
570
- foreignBlockNumber: ForeignCallSingle,
571
- foreignTreeId: ForeignCallSingle,
572
- foreignLeafValue: ForeignCallSingle,
690
+ // eslint-disable-next-line camelcase
691
+ async aztec_utl_getNoteHashMembershipWitness(
692
+ foreignAnchorBlockHash: ForeignCallSingle,
693
+ foreignNoteHash: ForeignCallSingle,
573
694
  ) {
574
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
575
- const treeId = fromSingle(foreignTreeId).toNumber();
576
- const leafValue = fromSingle(foreignLeafValue);
695
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
696
+ const noteHash = fromSingle(foreignNoteHash);
577
697
 
578
- 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);
579
715
 
580
716
  if (!witness) {
581
717
  throw new Error(
582
- `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()}.`,
583
719
  );
584
720
  }
585
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
721
+ return toForeignCallResult(witness.toNoirRepresentation());
586
722
  }
587
723
 
588
- async utilityGetLowNullifierMembershipWitness(
589
- foreignBlockNumber: ForeignCallSingle,
724
+ // eslint-disable-next-line camelcase
725
+ async aztec_utl_getLowNullifierMembershipWitness(
726
+ foreignBlockHash: ForeignCallSingle,
590
727
  foreignNullifier: ForeignCallSingle,
591
728
  ) {
592
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
729
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
593
730
  const nullifier = fromSingle(foreignNullifier);
594
731
 
595
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
732
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
596
733
 
597
734
  if (!witness) {
598
- 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}.`);
599
736
  }
600
737
  return toForeignCallResult(witness.toNoirRepresentation());
601
738
  }
602
739
 
603
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
740
+ // eslint-disable-next-line camelcase
741
+ async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
604
742
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
605
743
 
606
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
744
+ await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
607
745
 
608
746
  return toForeignCallResult([]);
609
747
  }
610
748
 
611
- public async utilityValidateEnqueuedNotesAndEvents(
749
+ // eslint-disable-next-line camelcase
750
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
612
751
  foreignContractAddress: ForeignCallSingle,
613
752
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
614
753
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
754
+ foreignMaxNotePackedLen: ForeignCallSingle,
755
+ foreignMaxEventSerializedLen: ForeignCallSingle,
615
756
  ) {
616
757
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
617
758
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
618
759
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
760
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
761
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
619
762
 
620
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
763
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
621
764
  contractAddress,
622
765
  noteValidationRequestsArrayBaseSlot,
623
766
  eventValidationRequestsArrayBaseSlot,
767
+ maxNotePackedLen,
768
+ maxEventSerializedLen,
624
769
  );
625
770
 
626
771
  return toForeignCallResult([]);
627
772
  }
628
773
 
629
- public async utilityBulkRetrieveLogs(
774
+ // eslint-disable-next-line camelcase
775
+ public async aztec_utl_bulkRetrieveLogs(
630
776
  foreignContractAddress: ForeignCallSingle,
631
777
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
632
778
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
@@ -635,7 +781,7 @@ export class RPCTranslator {
635
781
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
636
782
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
637
783
 
638
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
784
+ await this.handlerAsUtility().bulkRetrieveLogs(
639
785
  contractAddress,
640
786
  logRetrievalRequestsArrayBaseSlot,
641
787
  logRetrievalResponsesArrayBaseSlot,
@@ -644,7 +790,27 @@ export class RPCTranslator {
644
790
  return toForeignCallResult([]);
645
791
  }
646
792
 
647
- 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(
648
814
  foreignContractAddress: ForeignCallSingle,
649
815
  foreignSlot: ForeignCallSingle,
650
816
  foreignCapsule: ForeignCallArray,
@@ -653,12 +819,13 @@ export class RPCTranslator {
653
819
  const slot = fromSingle(foreignSlot);
654
820
  const capsule = fromArray(foreignCapsule);
655
821
 
656
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
822
+ await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
657
823
 
658
824
  return toForeignCallResult([]);
659
825
  }
660
826
 
661
- async utilityLoadCapsule(
827
+ // eslint-disable-next-line camelcase
828
+ async aztec_utl_loadCapsule(
662
829
  foreignContractAddress: ForeignCallSingle,
663
830
  foreignSlot: ForeignCallSingle,
664
831
  foreignTSize: ForeignCallSingle,
@@ -667,7 +834,7 @@ export class RPCTranslator {
667
834
  const slot = fromSingle(foreignSlot);
668
835
  const tSize = fromSingle(foreignTSize).toNumber();
669
836
 
670
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
837
+ const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
671
838
 
672
839
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
673
840
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -680,16 +847,18 @@ export class RPCTranslator {
680
847
  }
681
848
  }
682
849
 
683
- async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
850
+ // eslint-disable-next-line camelcase
851
+ async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
684
852
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
685
853
  const slot = fromSingle(foreignSlot);
686
854
 
687
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
855
+ await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
688
856
 
689
857
  return toForeignCallResult([]);
690
858
  }
691
859
 
692
- async utilityCopyCapsule(
860
+ // eslint-disable-next-line camelcase
861
+ async aztec_utl_copyCapsule(
693
862
  foreignContractAddress: ForeignCallSingle,
694
863
  foreignSrcSlot: ForeignCallSingle,
695
864
  foreignDstSlot: ForeignCallSingle,
@@ -700,7 +869,7 @@ export class RPCTranslator {
700
869
  const dstSlot = fromSingle(foreignDstSlot);
701
870
  const numEntries = fromSingle(foreignNumEntries).toNumber();
702
871
 
703
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
872
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
704
873
 
705
874
  return toForeignCallResult([]);
706
875
  }
@@ -709,7 +878,8 @@ export class RPCTranslator {
709
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
710
879
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
711
880
  // existence of a txe_oracle method?
712
- async utilityAes128Decrypt(
881
+ // eslint-disable-next-line camelcase
882
+ async aztec_utl_tryAes128Decrypt(
713
883
  foreignCiphertextBVecStorage: ForeignCallArray,
714
884
  foreignCiphertextLength: ForeignCallSingle,
715
885
  foreignIv: ForeignCallArray,
@@ -719,14 +889,22 @@ export class RPCTranslator {
719
889
  const iv = fromUintArray(foreignIv, 8);
720
890
  const symKey = fromUintArray(foreignSymKey, 8);
721
891
 
722
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
723
-
724
- return toForeignCallResult(
725
- arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
726
- );
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
+ }
727
904
  }
728
905
 
729
- async utilityGetSharedSecret(
906
+ // eslint-disable-next-line camelcase
907
+ async aztec_utl_getSharedSecret(
730
908
  foreignAddress: ForeignCallSingle,
731
909
  foreignEphPKField0: ForeignCallSingle,
732
910
  foreignEphPKField1: ForeignCallSingle,
@@ -739,43 +917,66 @@ export class RPCTranslator {
739
917
  fromSingle(foreignEphPKField2),
740
918
  ]);
741
919
 
742
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
920
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
743
921
 
744
922
  return toForeignCallResult(secret.toFields().map(toSingle));
745
923
  }
746
924
 
747
- 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) {
748
944
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
749
945
  }
750
946
 
751
947
  // AVM opcodes
752
948
 
753
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
949
+ // eslint-disable-next-line camelcase
950
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
754
951
  // TODO(#8811): Implement
755
952
  return toForeignCallResult([]);
756
953
  }
757
954
 
758
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
955
+ // eslint-disable-next-line camelcase
956
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
759
957
  const slot = fromSingle(foreignSlot);
958
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
760
959
 
761
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
960
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
762
961
 
763
962
  return toForeignCallResult([toSingle(new Fr(value))]);
764
963
  }
765
964
 
766
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
965
+ // eslint-disable-next-line camelcase
966
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
767
967
  const slot = fromSingle(foreignSlot);
768
968
  const value = fromSingle(foreignValue);
769
969
 
770
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
970
+ await this.handlerAsAvm().storageWrite(slot, value);
771
971
 
772
972
  return toForeignCallResult([]);
773
973
  }
774
974
 
775
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
975
+ // eslint-disable-next-line camelcase
976
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
776
977
  const address = addressFromSingle(foreignAddress);
777
978
 
778
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
979
+ const instance = await this.handlerAsUtility().getContractInstance(address);
779
980
 
780
981
  return toForeignCallResult([
781
982
  toSingle(instance.deployer),
@@ -784,10 +985,11 @@ export class RPCTranslator {
784
985
  ]);
785
986
  }
786
987
 
787
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
988
+ // eslint-disable-next-line camelcase
989
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
788
990
  const address = addressFromSingle(foreignAddress);
789
991
 
790
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
992
+ const instance = await this.handlerAsUtility().getContractInstance(address);
791
993
 
792
994
  return toForeignCallResult([
793
995
  toSingle(instance.currentContractClassId),
@@ -796,10 +998,11 @@ export class RPCTranslator {
796
998
  ]);
797
999
  }
798
1000
 
799
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1001
+ // eslint-disable-next-line camelcase
1002
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
800
1003
  const address = addressFromSingle(foreignAddress);
801
1004
 
802
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
1005
+ const instance = await this.handlerAsUtility().getContractInstance(address);
803
1006
 
804
1007
  return toForeignCallResult([
805
1008
  toSingle(instance.initializationHash),
@@ -808,86 +1011,98 @@ export class RPCTranslator {
808
1011
  ]);
809
1012
  }
810
1013
 
811
- async avmOpcodeSender() {
812
- const sender = await this.handlerAsAvm().avmOpcodeSender();
1014
+ // eslint-disable-next-line camelcase
1015
+ async aztec_avm_sender() {
1016
+ const sender = await this.handlerAsAvm().sender();
813
1017
 
814
1018
  return toForeignCallResult([toSingle(sender)]);
815
1019
  }
816
1020
 
817
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
1021
+ // eslint-disable-next-line camelcase
1022
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
818
1023
  const nullifier = fromSingle(foreignNullifier);
819
1024
 
820
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
1025
+ await this.handlerAsAvm().emitNullifier(nullifier);
821
1026
 
822
1027
  return toForeignCallResult([]);
823
1028
  }
824
1029
 
825
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
1030
+ // eslint-disable-next-line camelcase
1031
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
826
1032
  const noteHash = fromSingle(foreignNoteHash);
827
1033
 
828
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1034
+ await this.handlerAsAvm().emitNoteHash(noteHash);
829
1035
 
830
1036
  return toForeignCallResult([]);
831
1037
  }
832
1038
 
833
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
834
- const innerNullifier = fromSingle(foreignInnerNullifier);
835
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
1039
+ // eslint-disable-next-line camelcase
1040
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1041
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
836
1042
 
837
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
1043
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
838
1044
 
839
1045
  return toForeignCallResult([toSingle(new Fr(exists))]);
840
1046
  }
841
1047
 
842
- async avmOpcodeAddress() {
843
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1048
+ // eslint-disable-next-line camelcase
1049
+ async aztec_avm_address() {
1050
+ const contractAddress = await this.handlerAsAvm().address();
844
1051
 
845
1052
  return toForeignCallResult([toSingle(contractAddress.toField())]);
846
1053
  }
847
1054
 
848
- async avmOpcodeBlockNumber() {
849
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1055
+ // eslint-disable-next-line camelcase
1056
+ async aztec_avm_blockNumber() {
1057
+ const blockNumber = await this.handlerAsAvm().blockNumber();
850
1058
 
851
1059
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
852
1060
  }
853
1061
 
854
- async avmOpcodeTimestamp() {
855
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1062
+ // eslint-disable-next-line camelcase
1063
+ async aztec_avm_timestamp() {
1064
+ const timestamp = await this.handlerAsAvm().timestamp();
856
1065
 
857
1066
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
858
1067
  }
859
1068
 
860
- async avmOpcodeIsStaticCall() {
861
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1069
+ // eslint-disable-next-line camelcase
1070
+ async aztec_avm_isStaticCall() {
1071
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
862
1072
 
863
1073
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
864
1074
  }
865
1075
 
866
- async avmOpcodeChainId() {
867
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1076
+ // eslint-disable-next-line camelcase
1077
+ async aztec_avm_chainId() {
1078
+ const chainId = await this.handlerAsAvm().chainId();
868
1079
 
869
1080
  return toForeignCallResult([toSingle(chainId)]);
870
1081
  }
871
1082
 
872
- async avmOpcodeVersion() {
873
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1083
+ // eslint-disable-next-line camelcase
1084
+ async aztec_avm_version() {
1085
+ const version = await this.handlerAsAvm().version();
874
1086
 
875
1087
  return toForeignCallResult([toSingle(version)]);
876
1088
  }
877
1089
 
878
- avmOpcodeReturndataSize() {
1090
+ // eslint-disable-next-line camelcase
1091
+ aztec_avm_returndataSize() {
879
1092
  throw new Error(
880
1093
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
881
1094
  );
882
1095
  }
883
1096
 
884
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1097
+ // eslint-disable-next-line camelcase
1098
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
885
1099
  throw new Error(
886
1100
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
887
1101
  );
888
1102
  }
889
1103
 
890
- avmOpcodeCall(
1104
+ // eslint-disable-next-line camelcase
1105
+ aztec_avm_call(
891
1106
  _foreignL2Gas: ForeignCallSingle,
892
1107
  _foreignDaGas: ForeignCallSingle,
893
1108
  _foreignAddress: ForeignCallSingle,
@@ -899,7 +1114,8 @@ export class RPCTranslator {
899
1114
  );
900
1115
  }
901
1116
 
902
- avmOpcodeStaticCall(
1117
+ // eslint-disable-next-line camelcase
1118
+ aztec_avm_staticCall(
903
1119
  _foreignL2Gas: ForeignCallSingle,
904
1120
  _foreignDaGas: ForeignCallSingle,
905
1121
  _foreignAddress: ForeignCallSingle,
@@ -911,17 +1127,18 @@ export class RPCTranslator {
911
1127
  );
912
1128
  }
913
1129
 
914
- avmOpcodeSuccessCopy() {
1130
+ // eslint-disable-next-line camelcase
1131
+ aztec_avm_successCopy() {
915
1132
  throw new Error(
916
1133
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
917
1134
  );
918
1135
  }
919
1136
 
920
- async txePrivateCallNewFlow(
1137
+ // eslint-disable-next-line camelcase
1138
+ async aztec_txe_privateCallNewFlow(
921
1139
  foreignFrom: ForeignCallSingle,
922
1140
  foreignTargetContractAddress: ForeignCallSingle,
923
1141
  foreignFunctionSelector: ForeignCallSingle,
924
- _foreignArgsLength: ForeignCallSingle,
925
1142
  foreignArgs: ForeignCallArray,
926
1143
  foreignArgsHash: ForeignCallSingle,
927
1144
  foreignIsStaticCall: ForeignCallSingle,
@@ -933,41 +1150,47 @@ export class RPCTranslator {
933
1150
  const argsHash = fromSingle(foreignArgsHash);
934
1151
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
935
1152
 
936
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1153
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(
937
1154
  from,
938
1155
  targetContractAddress,
939
1156
  functionSelector,
940
1157
  args,
941
1158
  argsHash,
942
1159
  isStaticCall,
1160
+ this.stateHandler.getCurrentJob(),
943
1161
  );
944
1162
 
1163
+ // TODO(F-335): Avoid doing the following call here.
1164
+ await this.stateHandler.cycleJob();
945
1165
  return toForeignCallResult([toArray(returnValues)]);
946
1166
  }
947
1167
 
948
- async txeSimulateUtilityFunction(
1168
+ // eslint-disable-next-line camelcase
1169
+ async aztec_txe_executeUtilityFunction(
949
1170
  foreignTargetContractAddress: ForeignCallSingle,
950
1171
  foreignFunctionSelector: ForeignCallSingle,
951
- _foreignArgsLength: ForeignCallSingle,
952
1172
  foreignArgs: ForeignCallArray,
953
1173
  ) {
954
1174
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
955
1175
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
956
1176
  const args = fromArray(foreignArgs);
957
1177
 
958
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1178
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(
959
1179
  targetContractAddress,
960
1180
  functionSelector,
961
1181
  args,
1182
+ this.stateHandler.getCurrentJob(),
962
1183
  );
963
1184
 
1185
+ // TODO(F-335): Avoid doing the following call here.
1186
+ await this.stateHandler.cycleJob();
964
1187
  return toForeignCallResult([toArray(returnValues)]);
965
1188
  }
966
1189
 
967
- async txePublicCallNewFlow(
1190
+ // eslint-disable-next-line camelcase
1191
+ async aztec_txe_publicCallNewFlow(
968
1192
  foreignFrom: ForeignCallSingle,
969
1193
  foreignAddress: ForeignCallSingle,
970
- _foreignLength: ForeignCallSingle,
971
1194
  foreignCalldata: ForeignCallArray,
972
1195
  foreignIsStaticCall: ForeignCallSingle,
973
1196
  ) {
@@ -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
  }