@aztec/txe 0.0.1-commit.ff7989d6c → 0.0.1-commit.fff30aa

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 (42) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +8 -6
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +12 -12
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -22
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +73 -46
  12. package/dest/rpc_translator.d.ts +120 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +376 -153
  15. package/dest/state_machine/archiver.d.ts +3 -3
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +5 -7
  18. package/dest/state_machine/dummy_p2p_client.d.ts +2 -2
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +1 -1
  21. package/dest/state_machine/index.d.ts +4 -2
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +6 -2
  24. package/dest/state_machine/synchronizer.d.ts +5 -5
  25. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  26. package/dest/state_machine/synchronizer.js +3 -3
  27. package/dest/txe_session.d.ts +9 -3
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +36 -17
  30. package/dest/util/encoding.d.ts +40 -41
  31. package/dest/util/encoding.d.ts.map +1 -1
  32. package/package.json +15 -15
  33. package/src/index.ts +8 -5
  34. package/src/oracle/interfaces.ts +32 -31
  35. package/src/oracle/txe_oracle_public_context.ts +12 -12
  36. package/src/oracle/txe_oracle_top_level_context.ts +96 -49
  37. package/src/rpc_translator.ts +438 -175
  38. package/src/state_machine/archiver.ts +5 -5
  39. package/src/state_machine/dummy_p2p_client.ts +1 -1
  40. package/src/state_machine/index.ts +5 -1
  41. package/src/state_machine/synchronizer.ts +4 -4
  42. package/src/txe_session.ts +45 -17
@@ -6,7 +6,7 @@ import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { BlockHash } from '@aztec/stdlib/block';
8
8
  import { addressFromSingle, arrayOfArraysToBoundedVecOfArrays, arrayToBoundedVec, bufferToU8Array, fromArray, fromSingle, fromUintArray, fromUintBoundedVec, toArray, toForeignCallResult, toSingle } from './util/encoding.js';
9
- const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
9
+ const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
10
10
  const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
11
11
  export class UnavailableOracleError extends Error {
12
12
  constructor(oracleName){
@@ -61,59 +61,69 @@ export class RPCTranslator {
61
61
  return this.oracleHandler;
62
62
  }
63
63
  // TXE session state transition functions - these get handled by the state handler
64
- async txeSetTopLevelTXEContext() {
64
+ // eslint-disable-next-line camelcase
65
+ async aztec_txe_setTopLevelTXEContext() {
65
66
  await this.stateHandler.enterTopLevelState();
66
67
  return toForeignCallResult([]);
67
68
  }
68
- async txeSetPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue, foreignAnchorBlockNumberIsSome, foreignAnchorBlockNumberValue) {
69
+ // eslint-disable-next-line camelcase
70
+ async aztec_txe_setPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue, foreignAnchorBlockNumberIsSome, foreignAnchorBlockNumberValue) {
69
71
  const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
70
72
  const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool() ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber()) : undefined;
71
73
  const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
72
74
  return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
73
75
  }
74
- async txeSetPublicTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
76
+ // eslint-disable-next-line camelcase
77
+ async aztec_txe_setPublicTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
75
78
  const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
76
79
  await this.stateHandler.enterPublicState(contractAddress);
77
80
  return toForeignCallResult([]);
78
81
  }
79
- async txeSetUtilityTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
82
+ // eslint-disable-next-line camelcase
83
+ async aztec_txe_setUtilityTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
80
84
  const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
81
85
  await this.stateHandler.enterUtilityState(contractAddress);
82
86
  return toForeignCallResult([]);
83
87
  }
84
88
  // Other oracles - these get handled by the oracle handler
85
89
  // TXE-specific oracles
86
- txeGetDefaultAddress() {
87
- const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
90
+ // eslint-disable-next-line camelcase
91
+ aztec_txe_getDefaultAddress() {
92
+ const defaultAddress = this.handlerAsTxe().getDefaultAddress();
88
93
  return toForeignCallResult([
89
94
  toSingle(defaultAddress)
90
95
  ]);
91
96
  }
92
- async txeGetNextBlockNumber() {
93
- const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
97
+ // eslint-disable-next-line camelcase
98
+ async aztec_txe_getNextBlockNumber() {
99
+ const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
94
100
  return toForeignCallResult([
95
101
  toSingle(nextBlockNumber)
96
102
  ]);
97
103
  }
98
- async txeGetNextBlockTimestamp() {
99
- const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
104
+ // eslint-disable-next-line camelcase
105
+ async aztec_txe_getNextBlockTimestamp() {
106
+ const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
100
107
  return toForeignCallResult([
101
108
  toSingle(nextBlockTimestamp)
102
109
  ]);
103
110
  }
104
- async txeAdvanceBlocksBy(foreignBlocks) {
111
+ // eslint-disable-next-line camelcase
112
+ async aztec_txe_advanceBlocksBy(foreignBlocks) {
105
113
  const blocks = fromSingle(foreignBlocks).toNumber();
106
- await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
114
+ await this.handlerAsTxe().advanceBlocksBy(blocks);
107
115
  return toForeignCallResult([]);
108
116
  }
109
- txeAdvanceTimestampBy(foreignDuration) {
117
+ // eslint-disable-next-line camelcase
118
+ aztec_txe_advanceTimestampBy(foreignDuration) {
110
119
  const duration = fromSingle(foreignDuration).toBigInt();
111
- this.handlerAsTxe().txeAdvanceTimestampBy(duration);
120
+ this.handlerAsTxe().advanceTimestampBy(duration);
112
121
  return toForeignCallResult([]);
113
122
  }
114
- async txeDeploy(artifact, instance, foreignSecret) {
123
+ // eslint-disable-next-line camelcase
124
+ async aztec_txe_deploy(artifact, instance, foreignSecret) {
115
125
  const secret = fromSingle(foreignSecret);
116
- await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
126
+ await this.handlerAsTxe().deploy(artifact, instance, secret);
117
127
  return toForeignCallResult([
118
128
  toArray([
119
129
  instance.salt,
@@ -124,59 +134,74 @@ export class RPCTranslator {
124
134
  ])
125
135
  ]);
126
136
  }
127
- async txeCreateAccount(foreignSecret) {
137
+ // eslint-disable-next-line camelcase
138
+ async aztec_txe_createAccount(foreignSecret) {
128
139
  const secret = fromSingle(foreignSecret);
129
- const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
140
+ const completeAddress = await this.handlerAsTxe().createAccount(secret);
130
141
  return toForeignCallResult([
131
142
  toSingle(completeAddress.address),
132
143
  ...completeAddress.publicKeys.toFields().map(toSingle)
133
144
  ]);
134
145
  }
135
- async txeAddAccount(artifact, instance, foreignSecret) {
146
+ // eslint-disable-next-line camelcase
147
+ async aztec_txe_addAccount(artifact, instance, foreignSecret) {
136
148
  const secret = fromSingle(foreignSecret);
137
- const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
149
+ const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
138
150
  return toForeignCallResult([
139
151
  toSingle(completeAddress.address),
140
152
  ...completeAddress.publicKeys.toFields().map(toSingle)
141
153
  ]);
142
154
  }
143
- async txeAddAuthWitness(foreignAddress, foreignMessageHash) {
155
+ // eslint-disable-next-line camelcase
156
+ async aztec_txe_addAuthWitness(foreignAddress, foreignMessageHash) {
144
157
  const address = addressFromSingle(foreignAddress);
145
158
  const messageHash = fromSingle(foreignMessageHash);
146
- await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
159
+ await this.handlerAsTxe().addAuthWitness(address, messageHash);
147
160
  return toForeignCallResult([]);
148
161
  }
149
162
  // PXE oracles
150
- utilityAssertCompatibleOracleVersion(foreignVersion) {
151
- const version = fromSingle(foreignVersion).toNumber();
152
- this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
163
+ // eslint-disable-next-line camelcase
164
+ aztec_utl_assertCompatibleOracleVersionV2(foreignMajor, foreignMinor) {
165
+ const major = fromSingle(foreignMajor).toNumber();
166
+ const minor = fromSingle(foreignMinor).toNumber();
167
+ this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
153
168
  return toForeignCallResult([]);
154
169
  }
155
- utilityGetRandomField() {
156
- const randomField = this.handlerAsMisc().utilityGetRandomField();
170
+ // eslint-disable-next-line camelcase
171
+ aztec_utl_getRandomField() {
172
+ const randomField = this.handlerAsMisc().getRandomField();
157
173
  return toForeignCallResult([
158
174
  toSingle(randomField)
159
175
  ]);
160
176
  }
161
- async txeGetLastBlockTimestamp() {
162
- const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
177
+ // eslint-disable-next-line camelcase
178
+ async aztec_txe_getLastBlockTimestamp() {
179
+ const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
163
180
  return toForeignCallResult([
164
181
  toSingle(new Fr(timestamp))
165
182
  ]);
166
183
  }
167
- async txeGetLastTxEffects() {
168
- const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
184
+ // eslint-disable-next-line camelcase
185
+ async aztec_txe_getLastTxEffects() {
186
+ const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
169
187
  return toForeignCallResult([
170
188
  toSingle(txHash.hash),
171
189
  ...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
172
190
  ...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
173
191
  ]);
174
192
  }
175
- async txeGetPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
193
+ // eslint-disable-next-line camelcase
194
+ async aztec_txe_getPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
176
195
  const selector = EventSelector.fromField(fromSingle(foreignSelector));
177
196
  const contractAddress = addressFromSingle(foreignContractAddress);
178
197
  const scope = addressFromSingle(foreignScope);
179
- const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
198
+ // TODO(F-335): Avoid doing the following 2 calls here.
199
+ {
200
+ await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
201
+ // We cycle job to commit the stores after the contract sync.
202
+ await this.stateHandler.cycleJob();
203
+ }
204
+ const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
180
205
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
181
206
  throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
182
207
  }
@@ -194,48 +219,54 @@ export class RPCTranslator {
194
219
  toSingle(queryLength)
195
220
  ]);
196
221
  }
197
- privateStoreInExecutionCache(foreignValues, foreignHash) {
222
+ // eslint-disable-next-line camelcase
223
+ aztec_prv_setHashPreimage(foreignValues, foreignHash) {
198
224
  const values = fromArray(foreignValues);
199
225
  const hash = fromSingle(foreignHash);
200
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
226
+ this.handlerAsPrivate().setHashPreimage(values, hash);
201
227
  return toForeignCallResult([]);
202
228
  }
203
- async privateLoadFromExecutionCache(foreignHash) {
229
+ // eslint-disable-next-line camelcase
230
+ async aztec_prv_getHashPreimage(foreignHash) {
204
231
  const hash = fromSingle(foreignHash);
205
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
232
+ const returns = await this.handlerAsPrivate().getHashPreimage(hash);
206
233
  return toForeignCallResult([
207
234
  toArray(returns)
208
235
  ]);
209
236
  }
210
237
  // When the argument is a slice, noir automatically adds a length field to oracle call.
211
238
  // When the argument is an array, we add the field length manually to the signature.
212
- async utilityLog(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
239
+ // eslint-disable-next-line camelcase
240
+ async aztec_utl_log(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
213
241
  const level = fromSingle(foreignLevel).toNumber();
214
242
  const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
215
243
  const fields = fromArray(foreignFields);
216
- await this.handlerAsMisc().utilityLog(level, message, fields);
244
+ await this.handlerAsMisc().log(level, message, fields);
217
245
  return toForeignCallResult([]);
218
246
  }
219
- async utilityStorageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
247
+ // eslint-disable-next-line camelcase
248
+ async aztec_utl_getFromPublicStorage(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
220
249
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
221
250
  const contractAddress = addressFromSingle(foreignContractAddress);
222
251
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
223
252
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
224
- const values = await this.handlerAsUtility().utilityStorageRead(blockHash, contractAddress, startStorageSlot, numberOfElements);
253
+ const values = await this.handlerAsUtility().getFromPublicStorage(blockHash, contractAddress, startStorageSlot, numberOfElements);
225
254
  return toForeignCallResult([
226
255
  toArray(values)
227
256
  ]);
228
257
  }
229
- async utilityGetPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
258
+ // eslint-disable-next-line camelcase
259
+ async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
230
260
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
231
261
  const leafSlot = fromSingle(foreignLeafSlot);
232
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
262
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
233
263
  if (!witness) {
234
264
  throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
235
265
  }
236
266
  return toForeignCallResult(witness.toNoirRepresentation());
237
267
  }
238
- async utilityGetNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
268
+ // eslint-disable-next-line camelcase
269
+ async aztec_utl_getNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
239
270
  // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
240
271
  const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
241
272
  const storageSlot = fromSingle(foreignStorageSlot);
@@ -254,7 +285,7 @@ export class RPCTranslator {
254
285
  const status = fromSingle(foreignStatus).toNumber();
255
286
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
256
287
  const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
257
- const noteDatas = await this.handlerAsUtility().utilityGetNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
288
+ const noteDatas = await this.handlerAsUtility().getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
258
289
  const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
259
290
  contractAddress: noteData.contractAddress,
260
291
  owner: noteData.owner,
@@ -269,7 +300,8 @@ export class RPCTranslator {
269
300
  // At last we convert the array of arrays to a bounded vec of arrays
270
301
  return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
271
302
  }
272
- privateNotifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
303
+ // eslint-disable-next-line camelcase
304
+ aztec_prv_notifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
273
305
  const owner = addressFromSingle(foreignOwner);
274
306
  const storageSlot = fromSingle(foreignStorageSlot);
275
307
  const randomness = fromSingle(foreignRandomness);
@@ -277,39 +309,44 @@ export class RPCTranslator {
277
309
  const note = fromArray(foreignNote);
278
310
  const noteHash = fromSingle(foreignNoteHash);
279
311
  const counter = fromSingle(foreignCounter).toNumber();
280
- this.handlerAsPrivate().privateNotifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
312
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
281
313
  return toForeignCallResult([]);
282
314
  }
283
- async privateNotifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
315
+ // eslint-disable-next-line camelcase
316
+ async aztec_prv_notifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
284
317
  const innerNullifier = fromSingle(foreignInnerNullifier);
285
318
  const noteHash = fromSingle(foreignNoteHash);
286
319
  const counter = fromSingle(foreignCounter).toNumber();
287
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
320
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
288
321
  return toForeignCallResult([]);
289
322
  }
290
- async privateNotifyCreatedNullifier(foreignInnerNullifier) {
323
+ // eslint-disable-next-line camelcase
324
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier) {
291
325
  const innerNullifier = fromSingle(foreignInnerNullifier);
292
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
326
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
293
327
  return toForeignCallResult([]);
294
328
  }
295
- async privateIsNullifierPending(foreignInnerNullifier, foreignContractAddress) {
329
+ // eslint-disable-next-line camelcase
330
+ async aztec_prv_isNullifierPending(foreignInnerNullifier, foreignContractAddress) {
296
331
  const innerNullifier = fromSingle(foreignInnerNullifier);
297
332
  const contractAddress = addressFromSingle(foreignContractAddress);
298
- const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
333
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
299
334
  return toForeignCallResult([
300
335
  toSingle(new Fr(isPending))
301
336
  ]);
302
337
  }
303
- async utilityCheckNullifierExists(foreignInnerNullifier) {
338
+ // eslint-disable-next-line camelcase
339
+ async aztec_utl_doesNullifierExist(foreignInnerNullifier) {
304
340
  const innerNullifier = fromSingle(foreignInnerNullifier);
305
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
341
+ const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
306
342
  return toForeignCallResult([
307
343
  toSingle(new Fr(exists))
308
344
  ]);
309
345
  }
310
- async utilityGetContractInstance(foreignAddress) {
346
+ // eslint-disable-next-line camelcase
347
+ async aztec_utl_getContractInstance(foreignAddress) {
311
348
  const address = addressFromSingle(foreignAddress);
312
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
349
+ const instance = await this.handlerAsUtility().getContractInstance(address);
313
350
  return toForeignCallResult([
314
351
  instance.salt,
315
352
  instance.deployer.toField(),
@@ -318,9 +355,10 @@ export class RPCTranslator {
318
355
  ...instance.publicKeys.toFields()
319
356
  ].map(toSingle));
320
357
  }
321
- async utilityTryGetPublicKeysAndPartialAddress(foreignAddress) {
358
+ // eslint-disable-next-line camelcase
359
+ async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress) {
322
360
  const address = addressFromSingle(foreignAddress);
323
- const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
361
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
324
362
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
325
363
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
326
364
  if (result === undefined) {
@@ -340,26 +378,30 @@ export class RPCTranslator {
340
378
  ]);
341
379
  }
342
380
  }
343
- async utilityGetKeyValidationRequest(foreignPkMHash) {
381
+ // eslint-disable-next-line camelcase
382
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
344
383
  const pkMHash = fromSingle(foreignPkMHash);
345
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
384
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
346
385
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
347
386
  }
348
- privateCallPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
387
+ // eslint-disable-next-line camelcase
388
+ aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
349
389
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
350
390
  }
351
- async utilityGetNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
391
+ // eslint-disable-next-line camelcase
392
+ async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
352
393
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
353
394
  const nullifier = fromSingle(foreignNullifier);
354
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
395
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
355
396
  if (!witness) {
356
397
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
357
398
  }
358
399
  return toForeignCallResult(witness.toNoirRepresentation());
359
400
  }
360
- async utilityGetAuthWitness(foreignMessageHash) {
401
+ // eslint-disable-next-line camelcase
402
+ async aztec_utl_getAuthWitness(foreignMessageHash) {
361
403
  const messageHash = fromSingle(foreignMessageHash);
362
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
404
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
363
405
  if (!authWitness) {
364
406
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
365
407
  }
@@ -367,92 +409,152 @@ export class RPCTranslator {
367
409
  toArray(authWitness)
368
410
  ]);
369
411
  }
370
- privateNotifyEnqueuedPublicFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
371
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
372
- }
373
- privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
412
+ // eslint-disable-next-line camelcase
413
+ aztec_prv_assertValidPublicCalldata(_foreignCalldataHash) {
374
414
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
375
415
  }
376
- privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter) {
416
+ // eslint-disable-next-line camelcase
417
+ aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
377
418
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
378
419
  }
379
- async privateIsSideEffectCounterRevertible(foreignSideEffectCounter) {
420
+ // eslint-disable-next-line camelcase
421
+ async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter) {
380
422
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
381
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
423
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
382
424
  return toForeignCallResult([
383
425
  toSingle(new Fr(isRevertible))
384
426
  ]);
385
427
  }
386
- utilityGetUtilityContext() {
387
- const context = this.handlerAsUtility().utilityGetUtilityContext();
428
+ // eslint-disable-next-line camelcase
429
+ aztec_utl_getUtilityContext() {
430
+ const context = this.handlerAsUtility().getUtilityContext();
388
431
  return toForeignCallResult(context.toNoirRepresentation());
389
432
  }
390
- async utilityGetBlockHeader(foreignBlockNumber) {
433
+ // eslint-disable-next-line camelcase
434
+ async aztec_utl_getBlockHeader(foreignBlockNumber) {
391
435
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
392
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
436
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
393
437
  if (!header) {
394
438
  throw new Error(`Block header not found for block ${blockNumber}.`);
395
439
  }
396
440
  return toForeignCallResult(header.toFields().map(toSingle));
397
441
  }
398
- async utilityGetNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
442
+ // eslint-disable-next-line camelcase
443
+ async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
399
444
  const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
400
445
  const noteHash = fromSingle(foreignNoteHash);
401
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
446
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
402
447
  if (!witness) {
403
448
  throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
404
449
  }
405
450
  return toForeignCallResult(witness.toNoirRepresentation());
406
451
  }
407
- async utilityGetBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
452
+ // eslint-disable-next-line camelcase
453
+ async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
408
454
  const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
409
455
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
410
- const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
456
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
411
457
  if (!witness) {
412
458
  throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
413
459
  }
414
460
  return toForeignCallResult(witness.toNoirRepresentation());
415
461
  }
416
- async utilityGetLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
462
+ // eslint-disable-next-line camelcase
463
+ async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
417
464
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
418
465
  const nullifier = fromSingle(foreignNullifier);
419
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
466
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
420
467
  if (!witness) {
421
468
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
422
469
  }
423
470
  return toForeignCallResult(witness.toNoirRepresentation());
424
471
  }
425
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
472
+ // eslint-disable-next-line camelcase
473
+ async aztec_utl_getPendingTaggedLogs(foreignPendingTaggedLogArrayBaseSlot, foreignScope) {
426
474
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
427
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
475
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
476
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
428
477
  return toForeignCallResult([]);
429
478
  }
430
- async utilityValidateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot) {
479
+ // eslint-disable-next-line camelcase
480
+ async aztec_utl_getPendingTaggedLogs_v2(foreignScope) {
481
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
482
+ const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
483
+ return toForeignCallResult([
484
+ toSingle(slot)
485
+ ]);
486
+ }
487
+ // eslint-disable-next-line camelcase
488
+ async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
431
489
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
432
490
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
433
491
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
434
- await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot);
492
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
493
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
494
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
495
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
496
+ return toForeignCallResult([]);
497
+ }
498
+ // eslint-disable-next-line camelcase
499
+ async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
500
+ const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
501
+ const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
502
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
503
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
504
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
505
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
435
506
  return toForeignCallResult([]);
436
507
  }
437
- async utilityBulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
508
+ // eslint-disable-next-line camelcase
509
+ async aztec_utl_getLogsByTag(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot, foreignScope) {
438
510
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
439
511
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
440
512
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
441
- await this.handlerAsUtility().utilityBulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
513
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
514
+ await this.handlerAsUtility().getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope);
442
515
  return toForeignCallResult([]);
443
516
  }
444
- async utilityStoreCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
517
+ // eslint-disable-next-line camelcase
518
+ async aztec_utl_getMessageContextsByTxHash(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot, foreignScope) {
519
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
520
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
521
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
522
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
523
+ await this.handlerAsUtility().getMessageContextsByTxHash(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot, scope);
524
+ return toForeignCallResult([]);
525
+ }
526
+ // eslint-disable-next-line camelcase
527
+ async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot) {
528
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
529
+ const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
530
+ return toForeignCallResult([
531
+ toSingle(responseSlot)
532
+ ]);
533
+ }
534
+ // eslint-disable-next-line camelcase
535
+ async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot) {
536
+ const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
537
+ const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
538
+ return toForeignCallResult([
539
+ toSingle(responseSlot)
540
+ ]);
541
+ }
542
+ // eslint-disable-next-line camelcase
543
+ aztec_utl_setCapsule(foreignContractAddress, foreignSlot, foreignCapsule, foreignScope) {
445
544
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
446
545
  const slot = fromSingle(foreignSlot);
447
546
  const capsule = fromArray(foreignCapsule);
448
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
547
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
548
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
449
549
  return toForeignCallResult([]);
450
550
  }
451
- async utilityLoadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
551
+ // eslint-disable-next-line camelcase
552
+ async aztec_utl_getCapsule(foreignContractAddress, foreignSlot, foreignTSize, foreignScope) {
452
553
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
453
554
  const slot = fromSingle(foreignSlot);
454
555
  const tSize = fromSingle(foreignTSize).toNumber();
455
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
556
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
557
+ const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
456
558
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
457
559
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
458
560
  if (values === null) {
@@ -469,197 +571,316 @@ export class RPCTranslator {
469
571
  ]);
470
572
  }
471
573
  }
472
- async utilityDeleteCapsule(foreignContractAddress, foreignSlot) {
574
+ // eslint-disable-next-line camelcase
575
+ aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot, foreignScope) {
473
576
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
474
577
  const slot = fromSingle(foreignSlot);
475
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
578
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
579
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
476
580
  return toForeignCallResult([]);
477
581
  }
478
- async utilityCopyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
582
+ // eslint-disable-next-line camelcase
583
+ async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries, foreignScope) {
479
584
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
480
585
  const srcSlot = fromSingle(foreignSrcSlot);
481
586
  const dstSlot = fromSingle(foreignDstSlot);
482
587
  const numEntries = fromSingle(foreignNumEntries).toNumber();
483
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
588
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
589
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
590
+ return toForeignCallResult([]);
591
+ }
592
+ // eslint-disable-next-line camelcase
593
+ aztec_utl_pushEphemeral(foreignSlot, foreignElements) {
594
+ const slot = fromSingle(foreignSlot);
595
+ const elements = fromArray(foreignElements);
596
+ const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
597
+ return toForeignCallResult([
598
+ toSingle(new Fr(newLen))
599
+ ]);
600
+ }
601
+ // eslint-disable-next-line camelcase
602
+ aztec_utl_popEphemeral(foreignSlot) {
603
+ const slot = fromSingle(foreignSlot);
604
+ const element = this.handlerAsUtility().popEphemeral(slot);
605
+ return toForeignCallResult([
606
+ toArray(element)
607
+ ]);
608
+ }
609
+ // eslint-disable-next-line camelcase
610
+ aztec_utl_getEphemeral(foreignSlot, foreignIndex) {
611
+ const slot = fromSingle(foreignSlot);
612
+ const index = fromSingle(foreignIndex).toNumber();
613
+ const element = this.handlerAsUtility().getEphemeral(slot, index);
614
+ return toForeignCallResult([
615
+ toArray(element)
616
+ ]);
617
+ }
618
+ // eslint-disable-next-line camelcase
619
+ aztec_utl_setEphemeral(foreignSlot, foreignIndex, foreignElements) {
620
+ const slot = fromSingle(foreignSlot);
621
+ const index = fromSingle(foreignIndex).toNumber();
622
+ const elements = fromArray(foreignElements);
623
+ this.handlerAsUtility().setEphemeral(slot, index, elements);
624
+ return toForeignCallResult([]);
625
+ }
626
+ // eslint-disable-next-line camelcase
627
+ aztec_utl_getEphemeralLen(foreignSlot) {
628
+ const slot = fromSingle(foreignSlot);
629
+ const len = this.handlerAsUtility().getEphemeralLen(slot);
630
+ return toForeignCallResult([
631
+ toSingle(new Fr(len))
632
+ ]);
633
+ }
634
+ // eslint-disable-next-line camelcase
635
+ aztec_utl_removeEphemeral(foreignSlot, foreignIndex) {
636
+ const slot = fromSingle(foreignSlot);
637
+ const index = fromSingle(foreignIndex).toNumber();
638
+ this.handlerAsUtility().removeEphemeral(slot, index);
639
+ return toForeignCallResult([]);
640
+ }
641
+ // eslint-disable-next-line camelcase
642
+ aztec_utl_clearEphemeral(foreignSlot) {
643
+ const slot = fromSingle(foreignSlot);
644
+ this.handlerAsUtility().clearEphemeral(slot);
484
645
  return toForeignCallResult([]);
485
646
  }
486
647
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
487
648
  // 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
488
649
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
489
650
  // existence of a txe_oracle method?
490
- async utilityAes128Decrypt(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
651
+ // eslint-disable-next-line camelcase
652
+ async aztec_utl_decryptAes128(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
491
653
  const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
492
654
  const iv = fromUintArray(foreignIv, 8);
493
655
  const symKey = fromUintArray(foreignSymKey, 8);
494
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
495
- return toForeignCallResult(arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length));
656
+ // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
657
+ try {
658
+ const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
659
+ const [storage, length] = arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length);
660
+ return toForeignCallResult([
661
+ toSingle(new Fr(1)),
662
+ storage,
663
+ length
664
+ ]);
665
+ } catch {
666
+ const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
667
+ return toForeignCallResult([
668
+ toSingle(new Fr(0)),
669
+ zeroStorage,
670
+ toSingle(new Fr(0))
671
+ ]);
672
+ }
496
673
  }
497
- async utilityGetSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
674
+ // eslint-disable-next-line camelcase
675
+ async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2, foreignContractAddress) {
498
676
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
499
677
  const ephPK = Point.fromFields([
500
678
  fromSingle(foreignEphPKField0),
501
679
  fromSingle(foreignEphPKField1),
502
680
  fromSingle(foreignEphPKField2)
503
681
  ]);
504
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
505
- return toForeignCallResult(secret.toFields().map(toSingle));
682
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
683
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
684
+ return toForeignCallResult([
685
+ toSingle(secret)
686
+ ]);
687
+ }
688
+ // eslint-disable-next-line camelcase
689
+ aztec_utl_setContractSyncCacheInvalid(foreignContractAddress, foreignScopes, foreignScopeCount) {
690
+ const contractAddress = addressFromSingle(foreignContractAddress);
691
+ const count = fromSingle(foreignScopeCount).toNumber();
692
+ const scopes = fromArray(foreignScopes).slice(0, count).map((f)=>new AztecAddress(f));
693
+ this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
694
+ return Promise.resolve(toForeignCallResult([]));
506
695
  }
507
- emitOffchainEffect(_foreignData) {
696
+ // eslint-disable-next-line camelcase
697
+ aztec_utl_emitOffchainEffect(_foreignData) {
508
698
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
509
699
  }
510
700
  // AVM opcodes
511
- avmOpcodeEmitPublicLog(_foreignMessage) {
701
+ // eslint-disable-next-line camelcase
702
+ aztec_avm_emitPublicLog(_foreignMessage) {
512
703
  // TODO(#8811): Implement
513
704
  return toForeignCallResult([]);
514
705
  }
515
- async avmOpcodeStorageRead(foreignSlot, foreignContractAddress) {
706
+ // eslint-disable-next-line camelcase
707
+ async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
516
708
  const slot = fromSingle(foreignSlot);
517
709
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
518
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
710
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
519
711
  return toForeignCallResult([
520
712
  toSingle(new Fr(value))
521
713
  ]);
522
714
  }
523
- async avmOpcodeStorageWrite(foreignSlot, foreignValue) {
715
+ // eslint-disable-next-line camelcase
716
+ async aztec_avm_storageWrite(foreignSlot, foreignValue) {
524
717
  const slot = fromSingle(foreignSlot);
525
718
  const value = fromSingle(foreignValue);
526
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
719
+ await this.handlerAsAvm().storageWrite(slot, value);
527
720
  return toForeignCallResult([]);
528
721
  }
529
- async avmOpcodeGetContractInstanceDeployer(foreignAddress) {
722
+ // eslint-disable-next-line camelcase
723
+ async aztec_avm_getContractInstanceDeployer(foreignAddress) {
530
724
  const address = addressFromSingle(foreignAddress);
531
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
725
+ const instance = await this.handlerAsUtility().getContractInstance(address);
532
726
  return toForeignCallResult([
533
727
  toSingle(instance.deployer),
534
728
  // AVM requires an extra boolean indicating the instance was found
535
729
  toSingle(new Fr(1))
536
730
  ]);
537
731
  }
538
- async avmOpcodeGetContractInstanceClassId(foreignAddress) {
732
+ // eslint-disable-next-line camelcase
733
+ async aztec_avm_getContractInstanceClassId(foreignAddress) {
539
734
  const address = addressFromSingle(foreignAddress);
540
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
735
+ const instance = await this.handlerAsUtility().getContractInstance(address);
541
736
  return toForeignCallResult([
542
737
  toSingle(instance.currentContractClassId),
543
738
  // AVM requires an extra boolean indicating the instance was found
544
739
  toSingle(new Fr(1))
545
740
  ]);
546
741
  }
547
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress) {
742
+ // eslint-disable-next-line camelcase
743
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
548
744
  const address = addressFromSingle(foreignAddress);
549
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
745
+ const instance = await this.handlerAsUtility().getContractInstance(address);
550
746
  return toForeignCallResult([
551
747
  toSingle(instance.initializationHash),
552
748
  // AVM requires an extra boolean indicating the instance was found
553
749
  toSingle(new Fr(1))
554
750
  ]);
555
751
  }
556
- async avmOpcodeSender() {
557
- const sender = await this.handlerAsAvm().avmOpcodeSender();
752
+ // eslint-disable-next-line camelcase
753
+ async aztec_avm_sender() {
754
+ const sender = await this.handlerAsAvm().sender();
558
755
  return toForeignCallResult([
559
756
  toSingle(sender)
560
757
  ]);
561
758
  }
562
- async avmOpcodeEmitNullifier(foreignNullifier) {
759
+ // eslint-disable-next-line camelcase
760
+ async aztec_avm_emitNullifier(foreignNullifier) {
563
761
  const nullifier = fromSingle(foreignNullifier);
564
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
762
+ await this.handlerAsAvm().emitNullifier(nullifier);
565
763
  return toForeignCallResult([]);
566
764
  }
567
- async avmOpcodeEmitNoteHash(foreignNoteHash) {
765
+ // eslint-disable-next-line camelcase
766
+ async aztec_avm_emitNoteHash(foreignNoteHash) {
568
767
  const noteHash = fromSingle(foreignNoteHash);
569
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
768
+ await this.handlerAsAvm().emitNoteHash(noteHash);
570
769
  return toForeignCallResult([]);
571
770
  }
572
- async avmOpcodeNullifierExists(foreignSiloedNullifier) {
771
+ // eslint-disable-next-line camelcase
772
+ async aztec_avm_nullifierExists(foreignSiloedNullifier) {
573
773
  const siloedNullifier = fromSingle(foreignSiloedNullifier);
574
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
774
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
575
775
  return toForeignCallResult([
576
776
  toSingle(new Fr(exists))
577
777
  ]);
578
778
  }
579
- async avmOpcodeAddress() {
580
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
779
+ // eslint-disable-next-line camelcase
780
+ async aztec_avm_address() {
781
+ const contractAddress = await this.handlerAsAvm().address();
581
782
  return toForeignCallResult([
582
783
  toSingle(contractAddress.toField())
583
784
  ]);
584
785
  }
585
- async avmOpcodeBlockNumber() {
586
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
786
+ // eslint-disable-next-line camelcase
787
+ async aztec_avm_blockNumber() {
788
+ const blockNumber = await this.handlerAsAvm().blockNumber();
587
789
  return toForeignCallResult([
588
790
  toSingle(new Fr(blockNumber))
589
791
  ]);
590
792
  }
591
- async avmOpcodeTimestamp() {
592
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
793
+ // eslint-disable-next-line camelcase
794
+ async aztec_avm_timestamp() {
795
+ const timestamp = await this.handlerAsAvm().timestamp();
593
796
  return toForeignCallResult([
594
797
  toSingle(new Fr(timestamp))
595
798
  ]);
596
799
  }
597
- async avmOpcodeIsStaticCall() {
598
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
800
+ // eslint-disable-next-line camelcase
801
+ async aztec_avm_isStaticCall() {
802
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
599
803
  return toForeignCallResult([
600
804
  toSingle(new Fr(isStaticCall ? 1 : 0))
601
805
  ]);
602
806
  }
603
- async avmOpcodeChainId() {
604
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
807
+ // eslint-disable-next-line camelcase
808
+ async aztec_avm_chainId() {
809
+ const chainId = await this.handlerAsAvm().chainId();
605
810
  return toForeignCallResult([
606
811
  toSingle(chainId)
607
812
  ]);
608
813
  }
609
- async avmOpcodeVersion() {
610
- const version = await this.handlerAsAvm().avmOpcodeVersion();
814
+ // eslint-disable-next-line camelcase
815
+ async aztec_avm_version() {
816
+ const version = await this.handlerAsAvm().version();
611
817
  return toForeignCallResult([
612
818
  toSingle(version)
613
819
  ]);
614
820
  }
615
- avmOpcodeReturndataSize() {
821
+ // eslint-disable-next-line camelcase
822
+ aztec_avm_returndataSize() {
616
823
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
617
824
  }
618
- avmOpcodeReturndataCopy(_foreignRdOffset, _foreignCopySize) {
825
+ // eslint-disable-next-line camelcase
826
+ aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
619
827
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
620
828
  }
621
- avmOpcodeCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
829
+ // eslint-disable-next-line camelcase
830
+ aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
622
831
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
623
832
  }
624
- avmOpcodeStaticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
833
+ // eslint-disable-next-line camelcase
834
+ aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
625
835
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
626
836
  }
627
- avmOpcodeSuccessCopy() {
837
+ // eslint-disable-next-line camelcase
838
+ aztec_avm_successCopy() {
628
839
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
629
840
  }
630
- async txePrivateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
841
+ // eslint-disable-next-line camelcase
842
+ async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
631
843
  const from = addressFromSingle(foreignFrom);
632
844
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
633
845
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
634
846
  const args = fromArray(foreignArgs);
635
847
  const argsHash = fromSingle(foreignArgsHash);
636
848
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
637
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall);
849
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
850
+ // TODO(F-335): Avoid doing the following call here.
851
+ await this.stateHandler.cycleJob();
638
852
  return toForeignCallResult([
639
853
  toArray(returnValues)
640
854
  ]);
641
855
  }
642
- async txeExecuteUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
856
+ // eslint-disable-next-line camelcase
857
+ async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
643
858
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
644
859
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
645
860
  const args = fromArray(foreignArgs);
646
- const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(targetContractAddress, functionSelector, args);
861
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
862
+ // TODO(F-335): Avoid doing the following call here.
863
+ await this.stateHandler.cycleJob();
647
864
  return toForeignCallResult([
648
865
  toArray(returnValues)
649
866
  ]);
650
867
  }
651
- async txePublicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
868
+ // eslint-disable-next-line camelcase
869
+ async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
652
870
  const from = addressFromSingle(foreignFrom);
653
871
  const address = addressFromSingle(foreignAddress);
654
872
  const calldata = fromArray(foreignCalldata);
655
873
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
656
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
874
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
875
+ // TODO(F-335): Avoid doing the following call here.
876
+ await this.stateHandler.cycleJob();
657
877
  return toForeignCallResult([
658
878
  toArray(returnValues)
659
879
  ]);
660
880
  }
661
- async privateGetSenderForTags() {
662
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
881
+ // eslint-disable-next-line camelcase
882
+ async aztec_prv_getSenderForTags() {
883
+ const sender = await this.handlerAsPrivate().getSenderForTags();
663
884
  // Return a Noir Option struct with `some` and `value` fields
664
885
  if (sender === undefined) {
665
886
  // No sender found, return Option with some=0 and value=0
@@ -675,15 +896,17 @@ export class RPCTranslator {
675
896
  ]);
676
897
  }
677
898
  }
678
- async privateSetSenderForTags(foreignSenderForTags) {
899
+ // eslint-disable-next-line camelcase
900
+ async aztec_prv_setSenderForTags(foreignSenderForTags) {
679
901
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
680
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
902
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
681
903
  return toForeignCallResult([]);
682
904
  }
683
- async privateGetNextAppTagAsSender(foreignSender, foreignRecipient) {
905
+ // eslint-disable-next-line camelcase
906
+ async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
684
907
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
685
908
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
686
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
909
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
687
910
  return toForeignCallResult([
688
911
  toSingle(nextAppTag.value)
689
912
  ]);