@aztec/txe 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448

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 (62) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  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 +14 -15
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +149 -63
  12. package/dest/rpc_translator.d.ts +121 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +406 -172
  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 +9 -8
  18. package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +33 -18
  21. package/dest/state_machine/global_variable_builder.d.ts +3 -2
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +1 -1
  24. package/dest/state_machine/index.d.ts +7 -5
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +19 -10
  27. package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +39 -2
  30. package/dest/state_machine/synchronizer.d.ts +5 -5
  31. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  32. package/dest/state_machine/synchronizer.js +3 -3
  33. package/dest/txe_session.d.ts +10 -6
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +94 -26
  36. package/dest/util/encoding.d.ts +69 -1
  37. package/dest/util/encoding.d.ts.map +1 -1
  38. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  39. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  40. package/dest/util/txe_public_contract_data_source.js +6 -25
  41. package/dest/utils/block_creation.d.ts +1 -1
  42. package/dest/utils/block_creation.d.ts.map +1 -1
  43. package/dest/utils/block_creation.js +3 -1
  44. package/package.json +15 -15
  45. package/src/index.ts +89 -52
  46. package/src/oracle/interfaces.ts +32 -31
  47. package/src/oracle/txe_oracle_public_context.ts +14 -16
  48. package/src/oracle/txe_oracle_top_level_context.ts +188 -115
  49. package/src/rpc_translator.ts +470 -189
  50. package/src/state_machine/archiver.ts +8 -5
  51. package/src/state_machine/dummy_p2p_client.ts +46 -24
  52. package/src/state_machine/global_variable_builder.ts +2 -0
  53. package/src/state_machine/index.ts +30 -9
  54. package/src/state_machine/mock_epoch_cache.ts +51 -3
  55. package/src/state_machine/synchronizer.ts +4 -4
  56. package/src/txe_session.ts +106 -85
  57. package/src/util/txe_public_contract_data_source.ts +10 -38
  58. package/src/utils/block_creation.ts +3 -1
  59. package/dest/util/txe_contract_store.d.ts +0 -12
  60. package/dest/util/txe_contract_store.d.ts.map +0 -1
  61. package/dest/util/txe_contract_store.js +0 -22
  62. package/src/util/txe_contract_store.ts +0 -36
@@ -4,9 +4,9 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
4
4
  import { packAsHintedNote } from '@aztec/pxe/simulator';
5
5
  import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { L2BlockHash } from '@aztec/stdlib/block';
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
- utilityDebugLog(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
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
244
+ await this.handlerAsMisc().log(level, message, fields);
217
245
  return toForeignCallResult([]);
218
246
  }
219
- async utilityStorageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
220
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
247
+ // eslint-disable-next-line camelcase
248
+ async aztec_utl_getFromPublicStorage(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
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) {
230
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
258
+ // eslint-disable-next-line camelcase
259
+ async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
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,36 +355,53 @@ export class RPCTranslator {
318
355
  ...instance.publicKeys.toFields()
319
356
  ].map(toSingle));
320
357
  }
321
- async utilityGetPublicKeysAndPartialAddress(foreignAddress) {
358
+ // eslint-disable-next-line camelcase
359
+ async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress) {
322
360
  const address = addressFromSingle(foreignAddress);
323
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
324
- return toForeignCallResult([
325
- toArray([
326
- ...publicKeys.toFields(),
327
- partialAddress
328
- ])
329
- ]);
361
+ const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
362
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
363
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
364
+ if (result === undefined) {
365
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
366
+ return toForeignCallResult([
367
+ toSingle(new Fr(0)),
368
+ toArray(Array(13).fill(new Fr(0)))
369
+ ]);
370
+ } else {
371
+ // Data was found so we set `some` to 1 and return it along with `value`.
372
+ return toForeignCallResult([
373
+ toSingle(new Fr(1)),
374
+ toArray([
375
+ ...result.publicKeys.toFields(),
376
+ result.partialAddress
377
+ ])
378
+ ]);
379
+ }
330
380
  }
331
- async utilityGetKeyValidationRequest(foreignPkMHash) {
381
+ // eslint-disable-next-line camelcase
382
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
332
383
  const pkMHash = fromSingle(foreignPkMHash);
333
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
384
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
334
385
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
335
386
  }
336
- privateCallPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
387
+ // eslint-disable-next-line camelcase
388
+ aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
337
389
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
338
390
  }
339
- async utilityGetNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
340
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
391
+ // eslint-disable-next-line camelcase
392
+ async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
393
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
341
394
  const nullifier = fromSingle(foreignNullifier);
342
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
395
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
343
396
  if (!witness) {
344
397
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
345
398
  }
346
399
  return toForeignCallResult(witness.toNoirRepresentation());
347
400
  }
348
- async utilityGetAuthWitness(foreignMessageHash) {
401
+ // eslint-disable-next-line camelcase
402
+ async aztec_utl_getAuthWitness(foreignMessageHash) {
349
403
  const messageHash = fromSingle(foreignMessageHash);
350
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
404
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
351
405
  if (!authWitness) {
352
406
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
353
407
  }
@@ -355,92 +409,152 @@ export class RPCTranslator {
355
409
  toArray(authWitness)
356
410
  ]);
357
411
  }
358
- privateNotifyEnqueuedPublicFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
359
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
360
- }
361
- privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
412
+ // eslint-disable-next-line camelcase
413
+ aztec_prv_assertValidPublicCalldata(_foreignCalldataHash) {
362
414
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
363
415
  }
364
- privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter) {
416
+ // eslint-disable-next-line camelcase
417
+ aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
365
418
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
366
419
  }
367
- async privateIsSideEffectCounterRevertible(foreignSideEffectCounter) {
420
+ // eslint-disable-next-line camelcase
421
+ async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter) {
368
422
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
369
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
423
+ const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
370
424
  return toForeignCallResult([
371
425
  toSingle(new Fr(isRevertible))
372
426
  ]);
373
427
  }
374
- utilityGetUtilityContext() {
375
- const context = this.handlerAsUtility().utilityGetUtilityContext();
428
+ // eslint-disable-next-line camelcase
429
+ aztec_utl_getUtilityContext() {
430
+ const context = this.handlerAsUtility().getUtilityContext();
376
431
  return toForeignCallResult(context.toNoirRepresentation());
377
432
  }
378
- async utilityGetBlockHeader(foreignBlockNumber) {
433
+ // eslint-disable-next-line camelcase
434
+ async aztec_utl_getBlockHeader(foreignBlockNumber) {
379
435
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
380
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
436
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
381
437
  if (!header) {
382
438
  throw new Error(`Block header not found for block ${blockNumber}.`);
383
439
  }
384
440
  return toForeignCallResult(header.toFields().map(toSingle));
385
441
  }
386
- async utilityGetNoteHashMembershipWitness(foreignBlockHash, foreignLeafValue) {
387
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
388
- const leafValue = fromSingle(foreignLeafValue);
389
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, leafValue);
442
+ // eslint-disable-next-line camelcase
443
+ async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
444
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
445
+ const noteHash = fromSingle(foreignNoteHash);
446
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
390
447
  if (!witness) {
391
- throw new Error(`Note hash ${leafValue} not found in the note hash tree at block ${blockHash.toString()}.`);
448
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
392
449
  }
393
450
  return toForeignCallResult(witness.toNoirRepresentation());
394
451
  }
395
- async utilityGetArchiveMembershipWitness(foreignBlockHash, foreignLeafValue) {
396
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
397
- const leafValue = fromSingle(foreignLeafValue);
398
- const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(blockHash, leafValue);
452
+ // eslint-disable-next-line camelcase
453
+ async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
454
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
455
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
456
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
399
457
  if (!witness) {
400
- throw new Error(`Block hash ${leafValue} not found in the archive tree at block ${blockHash.toString()}.`);
458
+ throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
401
459
  }
402
460
  return toForeignCallResult(witness.toNoirRepresentation());
403
461
  }
404
- async utilityGetLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
405
- const blockHash = L2BlockHash.fromString(foreignBlockHash);
462
+ // eslint-disable-next-line camelcase
463
+ async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
464
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
406
465
  const nullifier = fromSingle(foreignNullifier);
407
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
466
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
408
467
  if (!witness) {
409
468
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
410
469
  }
411
470
  return toForeignCallResult(witness.toNoirRepresentation());
412
471
  }
413
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
472
+ // eslint-disable-next-line camelcase
473
+ async aztec_utl_getPendingTaggedLogs(foreignPendingTaggedLogArrayBaseSlot, foreignScope) {
414
474
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
415
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
475
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
476
+ await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
416
477
  return toForeignCallResult([]);
417
478
  }
418
- 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) {
419
489
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
420
490
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
421
491
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
422
- 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);
423
496
  return toForeignCallResult([]);
424
497
  }
425
- async utilityBulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
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);
506
+ return toForeignCallResult([]);
507
+ }
508
+ // eslint-disable-next-line camelcase
509
+ async aztec_utl_getLogsByTag(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot, foreignScope) {
426
510
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
427
511
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
428
512
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
429
- await this.handlerAsUtility().utilityBulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
513
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
514
+ await this.handlerAsUtility().getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope);
515
+ return toForeignCallResult([]);
516
+ }
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);
430
524
  return toForeignCallResult([]);
431
525
  }
432
- async utilityStoreCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
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) {
433
544
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
434
545
  const slot = fromSingle(foreignSlot);
435
546
  const capsule = fromArray(foreignCapsule);
436
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
547
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
548
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
437
549
  return toForeignCallResult([]);
438
550
  }
439
- async utilityLoadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
551
+ // eslint-disable-next-line camelcase
552
+ async aztec_utl_getCapsule(foreignContractAddress, foreignSlot, foreignTSize, foreignScope) {
440
553
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
441
554
  const slot = fromSingle(foreignSlot);
442
555
  const tSize = fromSingle(foreignTSize).toNumber();
443
- 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);
444
558
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
445
559
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
446
560
  if (values === null) {
@@ -457,198 +571,316 @@ export class RPCTranslator {
457
571
  ]);
458
572
  }
459
573
  }
460
- async utilityDeleteCapsule(foreignContractAddress, foreignSlot) {
574
+ // eslint-disable-next-line camelcase
575
+ aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot, foreignScope) {
461
576
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
462
577
  const slot = fromSingle(foreignSlot);
463
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
578
+ const scope = AztecAddress.fromField(fromSingle(foreignScope));
579
+ this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
464
580
  return toForeignCallResult([]);
465
581
  }
466
- async utilityCopyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
582
+ // eslint-disable-next-line camelcase
583
+ async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries, foreignScope) {
467
584
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
468
585
  const srcSlot = fromSingle(foreignSrcSlot);
469
586
  const dstSlot = fromSingle(foreignDstSlot);
470
587
  const numEntries = fromSingle(foreignNumEntries).toNumber();
471
- 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);
472
645
  return toForeignCallResult([]);
473
646
  }
474
647
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
475
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
476
649
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
477
650
  // existence of a txe_oracle method?
478
- async utilityAes128Decrypt(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
651
+ // eslint-disable-next-line camelcase
652
+ async aztec_utl_decryptAes128(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
479
653
  const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
480
654
  const iv = fromUintArray(foreignIv, 8);
481
655
  const symKey = fromUintArray(foreignSymKey, 8);
482
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
483
- 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
+ }
484
673
  }
485
- async utilityGetSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
674
+ // eslint-disable-next-line camelcase
675
+ async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2, foreignContractAddress) {
486
676
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
487
677
  const ephPK = Point.fromFields([
488
678
  fromSingle(foreignEphPKField0),
489
679
  fromSingle(foreignEphPKField1),
490
680
  fromSingle(foreignEphPKField2)
491
681
  ]);
492
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
493
- 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([]));
494
695
  }
495
- emitOffchainEffect(_foreignData) {
696
+ // eslint-disable-next-line camelcase
697
+ aztec_utl_emitOffchainEffect(_foreignData) {
496
698
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
497
699
  }
498
700
  // AVM opcodes
499
- avmOpcodeEmitUnencryptedLog(_foreignMessage) {
701
+ // eslint-disable-next-line camelcase
702
+ aztec_avm_emitPublicLog(_foreignMessage) {
500
703
  // TODO(#8811): Implement
501
704
  return toForeignCallResult([]);
502
705
  }
503
- async avmOpcodeStorageRead(foreignSlot, foreignContractAddress) {
706
+ // eslint-disable-next-line camelcase
707
+ async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
504
708
  const slot = fromSingle(foreignSlot);
505
709
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
506
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
710
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
507
711
  return toForeignCallResult([
508
712
  toSingle(new Fr(value))
509
713
  ]);
510
714
  }
511
- async avmOpcodeStorageWrite(foreignSlot, foreignValue) {
715
+ // eslint-disable-next-line camelcase
716
+ async aztec_avm_storageWrite(foreignSlot, foreignValue) {
512
717
  const slot = fromSingle(foreignSlot);
513
718
  const value = fromSingle(foreignValue);
514
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
719
+ await this.handlerAsAvm().storageWrite(slot, value);
515
720
  return toForeignCallResult([]);
516
721
  }
517
- async avmOpcodeGetContractInstanceDeployer(foreignAddress) {
722
+ // eslint-disable-next-line camelcase
723
+ async aztec_avm_getContractInstanceDeployer(foreignAddress) {
518
724
  const address = addressFromSingle(foreignAddress);
519
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
725
+ const instance = await this.handlerAsUtility().getContractInstance(address);
520
726
  return toForeignCallResult([
521
727
  toSingle(instance.deployer),
522
728
  // AVM requires an extra boolean indicating the instance was found
523
729
  toSingle(new Fr(1))
524
730
  ]);
525
731
  }
526
- async avmOpcodeGetContractInstanceClassId(foreignAddress) {
732
+ // eslint-disable-next-line camelcase
733
+ async aztec_avm_getContractInstanceClassId(foreignAddress) {
527
734
  const address = addressFromSingle(foreignAddress);
528
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
735
+ const instance = await this.handlerAsUtility().getContractInstance(address);
529
736
  return toForeignCallResult([
530
737
  toSingle(instance.currentContractClassId),
531
738
  // AVM requires an extra boolean indicating the instance was found
532
739
  toSingle(new Fr(1))
533
740
  ]);
534
741
  }
535
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress) {
742
+ // eslint-disable-next-line camelcase
743
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
536
744
  const address = addressFromSingle(foreignAddress);
537
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
745
+ const instance = await this.handlerAsUtility().getContractInstance(address);
538
746
  return toForeignCallResult([
539
747
  toSingle(instance.initializationHash),
540
748
  // AVM requires an extra boolean indicating the instance was found
541
749
  toSingle(new Fr(1))
542
750
  ]);
543
751
  }
544
- async avmOpcodeSender() {
545
- const sender = await this.handlerAsAvm().avmOpcodeSender();
752
+ // eslint-disable-next-line camelcase
753
+ async aztec_avm_sender() {
754
+ const sender = await this.handlerAsAvm().sender();
546
755
  return toForeignCallResult([
547
756
  toSingle(sender)
548
757
  ]);
549
758
  }
550
- async avmOpcodeEmitNullifier(foreignNullifier) {
759
+ // eslint-disable-next-line camelcase
760
+ async aztec_avm_emitNullifier(foreignNullifier) {
551
761
  const nullifier = fromSingle(foreignNullifier);
552
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
762
+ await this.handlerAsAvm().emitNullifier(nullifier);
553
763
  return toForeignCallResult([]);
554
764
  }
555
- async avmOpcodeEmitNoteHash(foreignNoteHash) {
765
+ // eslint-disable-next-line camelcase
766
+ async aztec_avm_emitNoteHash(foreignNoteHash) {
556
767
  const noteHash = fromSingle(foreignNoteHash);
557
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
768
+ await this.handlerAsAvm().emitNoteHash(noteHash);
558
769
  return toForeignCallResult([]);
559
770
  }
560
- async avmOpcodeNullifierExists(foreignInnerNullifier, foreignTargetAddress) {
561
- const innerNullifier = fromSingle(foreignInnerNullifier);
562
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
563
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
771
+ // eslint-disable-next-line camelcase
772
+ async aztec_avm_nullifierExists(foreignSiloedNullifier) {
773
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
774
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
564
775
  return toForeignCallResult([
565
776
  toSingle(new Fr(exists))
566
777
  ]);
567
778
  }
568
- async avmOpcodeAddress() {
569
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
779
+ // eslint-disable-next-line camelcase
780
+ async aztec_avm_address() {
781
+ const contractAddress = await this.handlerAsAvm().address();
570
782
  return toForeignCallResult([
571
783
  toSingle(contractAddress.toField())
572
784
  ]);
573
785
  }
574
- async avmOpcodeBlockNumber() {
575
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
786
+ // eslint-disable-next-line camelcase
787
+ async aztec_avm_blockNumber() {
788
+ const blockNumber = await this.handlerAsAvm().blockNumber();
576
789
  return toForeignCallResult([
577
790
  toSingle(new Fr(blockNumber))
578
791
  ]);
579
792
  }
580
- async avmOpcodeTimestamp() {
581
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
793
+ // eslint-disable-next-line camelcase
794
+ async aztec_avm_timestamp() {
795
+ const timestamp = await this.handlerAsAvm().timestamp();
582
796
  return toForeignCallResult([
583
797
  toSingle(new Fr(timestamp))
584
798
  ]);
585
799
  }
586
- async avmOpcodeIsStaticCall() {
587
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
800
+ // eslint-disable-next-line camelcase
801
+ async aztec_avm_isStaticCall() {
802
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
588
803
  return toForeignCallResult([
589
804
  toSingle(new Fr(isStaticCall ? 1 : 0))
590
805
  ]);
591
806
  }
592
- async avmOpcodeChainId() {
593
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
807
+ // eslint-disable-next-line camelcase
808
+ async aztec_avm_chainId() {
809
+ const chainId = await this.handlerAsAvm().chainId();
594
810
  return toForeignCallResult([
595
811
  toSingle(chainId)
596
812
  ]);
597
813
  }
598
- async avmOpcodeVersion() {
599
- const version = await this.handlerAsAvm().avmOpcodeVersion();
814
+ // eslint-disable-next-line camelcase
815
+ async aztec_avm_version() {
816
+ const version = await this.handlerAsAvm().version();
600
817
  return toForeignCallResult([
601
818
  toSingle(version)
602
819
  ]);
603
820
  }
604
- avmOpcodeReturndataSize() {
821
+ // eslint-disable-next-line camelcase
822
+ aztec_avm_returndataSize() {
605
823
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
606
824
  }
607
- avmOpcodeReturndataCopy(_foreignRdOffset, _foreignCopySize) {
825
+ // eslint-disable-next-line camelcase
826
+ aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
608
827
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
609
828
  }
610
- avmOpcodeCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
829
+ // eslint-disable-next-line camelcase
830
+ aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
611
831
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
612
832
  }
613
- avmOpcodeStaticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
833
+ // eslint-disable-next-line camelcase
834
+ aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
614
835
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
615
836
  }
616
- avmOpcodeSuccessCopy() {
837
+ // eslint-disable-next-line camelcase
838
+ aztec_avm_successCopy() {
617
839
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
618
840
  }
619
- 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) {
620
843
  const from = addressFromSingle(foreignFrom);
621
844
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
622
845
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
623
846
  const args = fromArray(foreignArgs);
624
847
  const argsHash = fromSingle(foreignArgsHash);
625
848
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
626
- 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();
627
852
  return toForeignCallResult([
628
853
  toArray(returnValues)
629
854
  ]);
630
855
  }
631
- async txeSimulateUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
856
+ // eslint-disable-next-line camelcase
857
+ async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
632
858
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
633
859
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
634
860
  const args = fromArray(foreignArgs);
635
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(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();
636
864
  return toForeignCallResult([
637
865
  toArray(returnValues)
638
866
  ]);
639
867
  }
640
- async txePublicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
868
+ // eslint-disable-next-line camelcase
869
+ async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
641
870
  const from = addressFromSingle(foreignFrom);
642
871
  const address = addressFromSingle(foreignAddress);
643
872
  const calldata = fromArray(foreignCalldata);
644
873
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
645
- 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();
646
877
  return toForeignCallResult([
647
878
  toArray(returnValues)
648
879
  ]);
649
880
  }
650
- async privateGetSenderForTags() {
651
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
881
+ // eslint-disable-next-line camelcase
882
+ async aztec_prv_getSenderForTags() {
883
+ const sender = await this.handlerAsPrivate().getSenderForTags();
652
884
  // Return a Noir Option struct with `some` and `value` fields
653
885
  if (sender === undefined) {
654
886
  // No sender found, return Option with some=0 and value=0
@@ -664,15 +896,17 @@ export class RPCTranslator {
664
896
  ]);
665
897
  }
666
898
  }
667
- async privateSetSenderForTags(foreignSenderForTags) {
899
+ // eslint-disable-next-line camelcase
900
+ async aztec_prv_setSenderForTags(foreignSenderForTags) {
668
901
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
669
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
902
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
670
903
  return toForeignCallResult([]);
671
904
  }
672
- async privateGetNextAppTagAsSender(foreignSender, foreignRecipient) {
905
+ // eslint-disable-next-line camelcase
906
+ async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
673
907
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
674
908
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
675
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
909
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
676
910
  return toForeignCallResult([
677
911
  toSingle(nextAppTag.value)
678
912
  ]);