@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea

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 +36 -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 +206 -98
  15. package/dest/rpc_translator.d.ts +91 -79
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +330 -170
  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 +63 -94
  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 +7 -7
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +40 -23
  30. package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +14 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -2
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/state_machine/synchronizer.js +5 -4
  36. package/dest/txe_session.d.ts +26 -15
  37. package/dest/txe_session.d.ts.map +1 -1
  38. package/dest/txe_session.js +161 -55
  39. package/dest/util/encoding.d.ts +618 -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 +12 -29
  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 +251 -138
  60. package/src/rpc_translator.ts +368 -174
  61. package/src/state_machine/archiver.ts +59 -114
  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 +60 -21
  65. package/src/state_machine/mock_epoch_cache.ts +15 -11
  66. package/src/state_machine/synchronizer.ts +6 -5
  67. package/src/txe_session.ts +222 -103
  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 -45
  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,7 +651,8 @@ export class RPCTranslator {
524
651
  return toForeignCallResult([toArray(authWitness)]);
525
652
  }
526
653
 
527
- public privateNotifyEnqueuedPublicFunctionCall(
654
+ // eslint-disable-next-line camelcase
655
+ public aztec_prv_notifyEnqueuedPublicFunctionCall(
528
656
  _foreignTargetContractAddress: ForeignCallSingle,
529
657
  _foreignCalldataHash: ForeignCallSingle,
530
658
  _foreignSideEffectCounter: ForeignCallSingle,
@@ -533,7 +661,8 @@ export class RPCTranslator {
533
661
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
534
662
  }
535
663
 
536
- public privateNotifySetPublicTeardownFunctionCall(
664
+ // eslint-disable-next-line camelcase
665
+ public aztec_prv_notifySetPublicTeardownFunctionCall(
537
666
  _foreignTargetContractAddress: ForeignCallSingle,
538
667
  _foreignCalldataHash: ForeignCallSingle,
539
668
  _foreignSideEffectCounter: ForeignCallSingle,
@@ -542,26 +671,30 @@ export class RPCTranslator {
542
671
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
543
672
  }
544
673
 
545
- public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
674
+ // eslint-disable-next-line camelcase
675
+ public aztec_prv_notifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
546
676
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
547
677
  }
548
678
 
549
- public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
679
+ // eslint-disable-next-line camelcase
680
+ public async aztec_prv_isSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
550
681
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
551
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
682
+ const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible(sideEffectCounter);
552
683
  return toForeignCallResult([toSingle(new Fr(isRevertible))]);
553
684
  }
554
685
 
555
- async utilityGetUtilityContext() {
556
- const context = await this.handlerAsUtility().utilityGetUtilityContext();
686
+ // eslint-disable-next-line camelcase
687
+ aztec_utl_getUtilityContext() {
688
+ const context = this.handlerAsUtility().getUtilityContext();
557
689
 
558
690
  return toForeignCallResult(context.toNoirRepresentation());
559
691
  }
560
692
 
561
- async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
562
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
693
+ // eslint-disable-next-line camelcase
694
+ async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
695
+ const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
563
696
 
564
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
697
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
565
698
 
566
699
  if (!header) {
567
700
  throw new Error(`Block header not found for block ${blockNumber}.`);
@@ -569,49 +702,67 @@ export class RPCTranslator {
569
702
  return toForeignCallResult(header.toFields().map(toSingle));
570
703
  }
571
704
 
572
- async utilityGetMembershipWitness(
573
- foreignBlockNumber: ForeignCallSingle,
574
- foreignTreeId: ForeignCallSingle,
575
- foreignLeafValue: ForeignCallSingle,
705
+ // eslint-disable-next-line camelcase
706
+ async aztec_utl_getNoteHashMembershipWitness(
707
+ foreignAnchorBlockHash: ForeignCallSingle,
708
+ foreignNoteHash: ForeignCallSingle,
576
709
  ) {
577
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
578
- const treeId = fromSingle(foreignTreeId).toNumber();
579
- const leafValue = fromSingle(foreignLeafValue);
710
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
711
+ const noteHash = fromSingle(foreignNoteHash);
580
712
 
581
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
713
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
714
+
715
+ if (!witness) {
716
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
717
+ }
718
+ return toForeignCallResult(witness.toNoirRepresentation());
719
+ }
720
+
721
+ // eslint-disable-next-line camelcase
722
+ async aztec_utl_getBlockHashMembershipWitness(
723
+ foreignAnchorBlockHash: ForeignCallSingle,
724
+ foreignBlockHash: ForeignCallSingle,
725
+ ) {
726
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
727
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
728
+
729
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
582
730
 
583
731
  if (!witness) {
584
732
  throw new Error(
585
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
733
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
586
734
  );
587
735
  }
588
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
736
+ return toForeignCallResult(witness.toNoirRepresentation());
589
737
  }
590
738
 
591
- async utilityGetLowNullifierMembershipWitness(
592
- foreignBlockNumber: ForeignCallSingle,
739
+ // eslint-disable-next-line camelcase
740
+ async aztec_utl_getLowNullifierMembershipWitness(
741
+ foreignBlockHash: ForeignCallSingle,
593
742
  foreignNullifier: ForeignCallSingle,
594
743
  ) {
595
- const blockNumber = fromSingle(foreignBlockNumber).toNumber();
744
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
596
745
  const nullifier = fromSingle(foreignNullifier);
597
746
 
598
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
747
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
599
748
 
600
749
  if (!witness) {
601
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
750
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
602
751
  }
603
752
  return toForeignCallResult(witness.toNoirRepresentation());
604
753
  }
605
754
 
606
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
755
+ // eslint-disable-next-line camelcase
756
+ async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
607
757
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
608
758
 
609
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
759
+ await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
610
760
 
611
761
  return toForeignCallResult([]);
612
762
  }
613
763
 
614
- public async utilityValidateEnqueuedNotesAndEvents(
764
+ // eslint-disable-next-line camelcase
765
+ public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
615
766
  foreignContractAddress: ForeignCallSingle,
616
767
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
617
768
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
@@ -620,7 +771,7 @@ export class RPCTranslator {
620
771
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
621
772
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
622
773
 
623
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
774
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
624
775
  contractAddress,
625
776
  noteValidationRequestsArrayBaseSlot,
626
777
  eventValidationRequestsArrayBaseSlot,
@@ -629,7 +780,8 @@ export class RPCTranslator {
629
780
  return toForeignCallResult([]);
630
781
  }
631
782
 
632
- public async utilityBulkRetrieveLogs(
783
+ // eslint-disable-next-line camelcase
784
+ public async aztec_utl_bulkRetrieveLogs(
633
785
  foreignContractAddress: ForeignCallSingle,
634
786
  foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
635
787
  foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
@@ -638,7 +790,7 @@ export class RPCTranslator {
638
790
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
639
791
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
640
792
 
641
- await this.handlerAsUtility().utilityBulkRetrieveLogs(
793
+ await this.handlerAsUtility().bulkRetrieveLogs(
642
794
  contractAddress,
643
795
  logRetrievalRequestsArrayBaseSlot,
644
796
  logRetrievalResponsesArrayBaseSlot,
@@ -647,7 +799,8 @@ export class RPCTranslator {
647
799
  return toForeignCallResult([]);
648
800
  }
649
801
 
650
- async utilityStoreCapsule(
802
+ // eslint-disable-next-line camelcase
803
+ async aztec_utl_storeCapsule(
651
804
  foreignContractAddress: ForeignCallSingle,
652
805
  foreignSlot: ForeignCallSingle,
653
806
  foreignCapsule: ForeignCallArray,
@@ -656,12 +809,13 @@ export class RPCTranslator {
656
809
  const slot = fromSingle(foreignSlot);
657
810
  const capsule = fromArray(foreignCapsule);
658
811
 
659
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
812
+ await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
660
813
 
661
814
  return toForeignCallResult([]);
662
815
  }
663
816
 
664
- async utilityLoadCapsule(
817
+ // eslint-disable-next-line camelcase
818
+ async aztec_utl_loadCapsule(
665
819
  foreignContractAddress: ForeignCallSingle,
666
820
  foreignSlot: ForeignCallSingle,
667
821
  foreignTSize: ForeignCallSingle,
@@ -670,7 +824,7 @@ export class RPCTranslator {
670
824
  const slot = fromSingle(foreignSlot);
671
825
  const tSize = fromSingle(foreignTSize).toNumber();
672
826
 
673
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
827
+ const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
674
828
 
675
829
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
676
830
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -683,16 +837,18 @@ export class RPCTranslator {
683
837
  }
684
838
  }
685
839
 
686
- async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
840
+ // eslint-disable-next-line camelcase
841
+ async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
687
842
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
688
843
  const slot = fromSingle(foreignSlot);
689
844
 
690
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
845
+ await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
691
846
 
692
847
  return toForeignCallResult([]);
693
848
  }
694
849
 
695
- async utilityCopyCapsule(
850
+ // eslint-disable-next-line camelcase
851
+ async aztec_utl_copyCapsule(
696
852
  foreignContractAddress: ForeignCallSingle,
697
853
  foreignSrcSlot: ForeignCallSingle,
698
854
  foreignDstSlot: ForeignCallSingle,
@@ -703,7 +859,7 @@ export class RPCTranslator {
703
859
  const dstSlot = fromSingle(foreignDstSlot);
704
860
  const numEntries = fromSingle(foreignNumEntries).toNumber();
705
861
 
706
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
862
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
707
863
 
708
864
  return toForeignCallResult([]);
709
865
  }
@@ -712,7 +868,8 @@ export class RPCTranslator {
712
868
  // 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
869
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
714
870
  // existence of a txe_oracle method?
715
- async utilityAes128Decrypt(
871
+ // eslint-disable-next-line camelcase
872
+ async aztec_utl_aes128Decrypt(
716
873
  foreignCiphertextBVecStorage: ForeignCallArray,
717
874
  foreignCiphertextLength: ForeignCallSingle,
718
875
  foreignIv: ForeignCallArray,
@@ -722,14 +879,15 @@ export class RPCTranslator {
722
879
  const iv = fromUintArray(foreignIv, 8);
723
880
  const symKey = fromUintArray(foreignSymKey, 8);
724
881
 
725
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
882
+ const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
726
883
 
727
884
  return toForeignCallResult(
728
885
  arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
729
886
  );
730
887
  }
731
888
 
732
- async utilityGetSharedSecret(
889
+ // eslint-disable-next-line camelcase
890
+ async aztec_utl_getSharedSecret(
733
891
  foreignAddress: ForeignCallSingle,
734
892
  foreignEphPKField0: ForeignCallSingle,
735
893
  foreignEphPKField1: ForeignCallSingle,
@@ -742,43 +900,49 @@ export class RPCTranslator {
742
900
  fromSingle(foreignEphPKField2),
743
901
  ]);
744
902
 
745
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
903
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
746
904
 
747
905
  return toForeignCallResult(secret.toFields().map(toSingle));
748
906
  }
749
907
 
750
- emitOffchainEffect(_foreignData: ForeignCallArray) {
908
+ // eslint-disable-next-line camelcase
909
+ aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
751
910
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
752
911
  }
753
912
 
754
913
  // AVM opcodes
755
914
 
756
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
915
+ // eslint-disable-next-line camelcase
916
+ aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
757
917
  // TODO(#8811): Implement
758
918
  return toForeignCallResult([]);
759
919
  }
760
920
 
761
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
921
+ // eslint-disable-next-line camelcase
922
+ async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
762
923
  const slot = fromSingle(foreignSlot);
924
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
763
925
 
764
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
926
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
765
927
 
766
928
  return toForeignCallResult([toSingle(new Fr(value))]);
767
929
  }
768
930
 
769
- async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
931
+ // eslint-disable-next-line camelcase
932
+ async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
770
933
  const slot = fromSingle(foreignSlot);
771
934
  const value = fromSingle(foreignValue);
772
935
 
773
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
936
+ await this.handlerAsAvm().storageWrite(slot, value);
774
937
 
775
938
  return toForeignCallResult([]);
776
939
  }
777
940
 
778
- async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
941
+ // eslint-disable-next-line camelcase
942
+ async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
779
943
  const address = addressFromSingle(foreignAddress);
780
944
 
781
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
945
+ const instance = await this.handlerAsUtility().getContractInstance(address);
782
946
 
783
947
  return toForeignCallResult([
784
948
  toSingle(instance.deployer),
@@ -787,10 +951,11 @@ export class RPCTranslator {
787
951
  ]);
788
952
  }
789
953
 
790
- async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
954
+ // eslint-disable-next-line camelcase
955
+ async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
791
956
  const address = addressFromSingle(foreignAddress);
792
957
 
793
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
958
+ const instance = await this.handlerAsUtility().getContractInstance(address);
794
959
 
795
960
  return toForeignCallResult([
796
961
  toSingle(instance.currentContractClassId),
@@ -799,10 +964,11 @@ export class RPCTranslator {
799
964
  ]);
800
965
  }
801
966
 
802
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
967
+ // eslint-disable-next-line camelcase
968
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
803
969
  const address = addressFromSingle(foreignAddress);
804
970
 
805
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
971
+ const instance = await this.handlerAsUtility().getContractInstance(address);
806
972
 
807
973
  return toForeignCallResult([
808
974
  toSingle(instance.initializationHash),
@@ -811,86 +977,98 @@ export class RPCTranslator {
811
977
  ]);
812
978
  }
813
979
 
814
- async avmOpcodeSender() {
815
- const sender = await this.handlerAsAvm().avmOpcodeSender();
980
+ // eslint-disable-next-line camelcase
981
+ async aztec_avm_sender() {
982
+ const sender = await this.handlerAsAvm().sender();
816
983
 
817
984
  return toForeignCallResult([toSingle(sender)]);
818
985
  }
819
986
 
820
- async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
987
+ // eslint-disable-next-line camelcase
988
+ async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
821
989
  const nullifier = fromSingle(foreignNullifier);
822
990
 
823
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
991
+ await this.handlerAsAvm().emitNullifier(nullifier);
824
992
 
825
993
  return toForeignCallResult([]);
826
994
  }
827
995
 
828
- async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
996
+ // eslint-disable-next-line camelcase
997
+ async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
829
998
  const noteHash = fromSingle(foreignNoteHash);
830
999
 
831
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
1000
+ await this.handlerAsAvm().emitNoteHash(noteHash);
832
1001
 
833
1002
  return toForeignCallResult([]);
834
1003
  }
835
1004
 
836
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
837
- const innerNullifier = fromSingle(foreignInnerNullifier);
838
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
1005
+ // eslint-disable-next-line camelcase
1006
+ async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1007
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
839
1008
 
840
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
1009
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
841
1010
 
842
1011
  return toForeignCallResult([toSingle(new Fr(exists))]);
843
1012
  }
844
1013
 
845
- async avmOpcodeAddress() {
846
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
1014
+ // eslint-disable-next-line camelcase
1015
+ async aztec_avm_address() {
1016
+ const contractAddress = await this.handlerAsAvm().address();
847
1017
 
848
1018
  return toForeignCallResult([toSingle(contractAddress.toField())]);
849
1019
  }
850
1020
 
851
- async avmOpcodeBlockNumber() {
852
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
1021
+ // eslint-disable-next-line camelcase
1022
+ async aztec_avm_blockNumber() {
1023
+ const blockNumber = await this.handlerAsAvm().blockNumber();
853
1024
 
854
1025
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
855
1026
  }
856
1027
 
857
- async avmOpcodeTimestamp() {
858
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
1028
+ // eslint-disable-next-line camelcase
1029
+ async aztec_avm_timestamp() {
1030
+ const timestamp = await this.handlerAsAvm().timestamp();
859
1031
 
860
1032
  return toForeignCallResult([toSingle(new Fr(timestamp))]);
861
1033
  }
862
1034
 
863
- async avmOpcodeIsStaticCall() {
864
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
1035
+ // eslint-disable-next-line camelcase
1036
+ async aztec_avm_isStaticCall() {
1037
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
865
1038
 
866
1039
  return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
867
1040
  }
868
1041
 
869
- async avmOpcodeChainId() {
870
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
1042
+ // eslint-disable-next-line camelcase
1043
+ async aztec_avm_chainId() {
1044
+ const chainId = await this.handlerAsAvm().chainId();
871
1045
 
872
1046
  return toForeignCallResult([toSingle(chainId)]);
873
1047
  }
874
1048
 
875
- async avmOpcodeVersion() {
876
- const version = await this.handlerAsAvm().avmOpcodeVersion();
1049
+ // eslint-disable-next-line camelcase
1050
+ async aztec_avm_version() {
1051
+ const version = await this.handlerAsAvm().version();
877
1052
 
878
1053
  return toForeignCallResult([toSingle(version)]);
879
1054
  }
880
1055
 
881
- avmOpcodeReturndataSize() {
1056
+ // eslint-disable-next-line camelcase
1057
+ aztec_avm_returndataSize() {
882
1058
  throw new Error(
883
1059
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
884
1060
  );
885
1061
  }
886
1062
 
887
- avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
1063
+ // eslint-disable-next-line camelcase
1064
+ aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
888
1065
  throw new Error(
889
1066
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
890
1067
  );
891
1068
  }
892
1069
 
893
- avmOpcodeCall(
1070
+ // eslint-disable-next-line camelcase
1071
+ aztec_avm_call(
894
1072
  _foreignL2Gas: ForeignCallSingle,
895
1073
  _foreignDaGas: ForeignCallSingle,
896
1074
  _foreignAddress: ForeignCallSingle,
@@ -902,7 +1080,8 @@ export class RPCTranslator {
902
1080
  );
903
1081
  }
904
1082
 
905
- avmOpcodeStaticCall(
1083
+ // eslint-disable-next-line camelcase
1084
+ aztec_avm_staticCall(
906
1085
  _foreignL2Gas: ForeignCallSingle,
907
1086
  _foreignDaGas: ForeignCallSingle,
908
1087
  _foreignAddress: ForeignCallSingle,
@@ -914,13 +1093,15 @@ export class RPCTranslator {
914
1093
  );
915
1094
  }
916
1095
 
917
- avmOpcodeSuccessCopy() {
1096
+ // eslint-disable-next-line camelcase
1097
+ aztec_avm_successCopy() {
918
1098
  throw new Error(
919
1099
  'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
920
1100
  );
921
1101
  }
922
1102
 
923
- async txePrivateCallNewFlow(
1103
+ // eslint-disable-next-line camelcase
1104
+ async aztec_txe_privateCallNewFlow(
924
1105
  foreignFrom: ForeignCallSingle,
925
1106
  foreignTargetContractAddress: ForeignCallSingle,
926
1107
  foreignFunctionSelector: ForeignCallSingle,
@@ -935,19 +1116,23 @@ export class RPCTranslator {
935
1116
  const argsHash = fromSingle(foreignArgsHash);
936
1117
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
937
1118
 
938
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
1119
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(
939
1120
  from,
940
1121
  targetContractAddress,
941
1122
  functionSelector,
942
1123
  args,
943
1124
  argsHash,
944
1125
  isStaticCall,
1126
+ this.stateHandler.getCurrentJob(),
945
1127
  );
946
1128
 
1129
+ // TODO(F-335): Avoid doing the following call here.
1130
+ await this.stateHandler.cycleJob();
947
1131
  return toForeignCallResult([toArray(returnValues)]);
948
1132
  }
949
1133
 
950
- async txeSimulateUtilityFunction(
1134
+ // eslint-disable-next-line camelcase
1135
+ async aztec_txe_executeUtilityFunction(
951
1136
  foreignTargetContractAddress: ForeignCallSingle,
952
1137
  foreignFunctionSelector: ForeignCallSingle,
953
1138
  foreignArgs: ForeignCallArray,
@@ -956,16 +1141,20 @@ export class RPCTranslator {
956
1141
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
957
1142
  const args = fromArray(foreignArgs);
958
1143
 
959
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1144
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(
960
1145
  targetContractAddress,
961
1146
  functionSelector,
962
1147
  args,
1148
+ this.stateHandler.getCurrentJob(),
963
1149
  );
964
1150
 
1151
+ // TODO(F-335): Avoid doing the following call here.
1152
+ await this.stateHandler.cycleJob();
965
1153
  return toForeignCallResult([toArray(returnValues)]);
966
1154
  }
967
1155
 
968
- async txePublicCallNewFlow(
1156
+ // eslint-disable-next-line camelcase
1157
+ async aztec_txe_publicCallNewFlow(
969
1158
  foreignFrom: ForeignCallSingle,
970
1159
  foreignAddress: ForeignCallSingle,
971
1160
  foreignCalldata: ForeignCallArray,
@@ -976,13 +1165,16 @@ export class RPCTranslator {
976
1165
  const calldata = fromArray(foreignCalldata);
977
1166
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
978
1167
 
979
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
1168
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
980
1169
 
1170
+ // TODO(F-335): Avoid doing the following call here.
1171
+ await this.stateHandler.cycleJob();
981
1172
  return toForeignCallResult([toArray(returnValues)]);
982
1173
  }
983
1174
 
984
- async privateGetSenderForTags() {
985
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
1175
+ // eslint-disable-next-line camelcase
1176
+ async aztec_prv_getSenderForTags() {
1177
+ const sender = await this.handlerAsPrivate().getSenderForTags();
986
1178
 
987
1179
  // Return a Noir Option struct with `some` and `value` fields
988
1180
  if (sender === undefined) {
@@ -994,19 +1186,21 @@ export class RPCTranslator {
994
1186
  }
995
1187
  }
996
1188
 
997
- async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
1189
+ // eslint-disable-next-line camelcase
1190
+ async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
998
1191
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
999
1192
 
1000
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
1193
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
1001
1194
 
1002
1195
  return toForeignCallResult([]);
1003
1196
  }
1004
1197
 
1005
- async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1198
+ // eslint-disable-next-line camelcase
1199
+ async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1006
1200
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
1007
1201
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1008
1202
 
1009
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
1203
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1010
1204
 
1011
1205
  return toForeignCallResult([toSingle(nextAppTag.value)]);
1012
1206
  }