@aztec/txe 0.0.1-commit.b468ad8 → 0.0.1-commit.b64cb54f6

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 (52) 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 +12 -12
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -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 +121 -50
  12. package/dest/rpc_translator.d.ts +85 -83
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +267 -156
  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 +7 -7
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +7 -5
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +19 -10
  24. package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +4 -0
  27. package/dest/txe_session.d.ts +9 -6
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +85 -23
  30. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  31. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  32. package/dest/util/txe_public_contract_data_source.js +5 -22
  33. package/dest/utils/block_creation.d.ts +1 -1
  34. package/dest/utils/block_creation.d.ts.map +1 -1
  35. package/dest/utils/block_creation.js +3 -1
  36. package/package.json +15 -15
  37. package/src/index.ts +89 -52
  38. package/src/oracle/interfaces.ts +32 -31
  39. package/src/oracle/txe_oracle_public_context.ts +12 -12
  40. package/src/oracle/txe_oracle_top_level_context.ts +134 -96
  41. package/src/rpc_translator.ts +289 -170
  42. package/src/state_machine/archiver.ts +7 -5
  43. package/src/state_machine/dummy_p2p_client.ts +40 -22
  44. package/src/state_machine/index.ts +29 -9
  45. package/src/state_machine/mock_epoch_cache.ts +5 -0
  46. package/src/txe_session.ts +88 -71
  47. package/src/util/txe_public_contract_data_source.ts +10 -36
  48. package/src/utils/block_creation.ts +3 -1
  49. package/dest/util/txe_contract_store.d.ts +0 -12
  50. package/dest/util/txe_contract_store.d.ts.map +0 -1
  51. package/dest/util/txe_contract_store.js +0 -22
  52. package/src/util/txe_contract_store.ts +0 -36
@@ -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,73 @@ 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) {
163
+ // eslint-disable-next-line camelcase
164
+ aztec_utl_assertCompatibleOracleVersion(foreignVersion) {
151
165
  const version = fromSingle(foreignVersion).toNumber();
152
- this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
166
+ this.handlerAsMisc().assertCompatibleOracleVersion(version);
153
167
  return toForeignCallResult([]);
154
168
  }
155
- utilityGetRandomField() {
156
- const randomField = this.handlerAsMisc().utilityGetRandomField();
169
+ // eslint-disable-next-line camelcase
170
+ aztec_utl_getRandomField() {
171
+ const randomField = this.handlerAsMisc().getRandomField();
157
172
  return toForeignCallResult([
158
173
  toSingle(randomField)
159
174
  ]);
160
175
  }
161
- async txeGetLastBlockTimestamp() {
162
- const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
176
+ // eslint-disable-next-line camelcase
177
+ async aztec_txe_getLastBlockTimestamp() {
178
+ const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
163
179
  return toForeignCallResult([
164
180
  toSingle(new Fr(timestamp))
165
181
  ]);
166
182
  }
167
- async txeGetLastTxEffects() {
168
- const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
183
+ // eslint-disable-next-line camelcase
184
+ async aztec_txe_getLastTxEffects() {
185
+ const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
169
186
  return toForeignCallResult([
170
187
  toSingle(txHash.hash),
171
188
  ...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
172
189
  ...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
173
190
  ]);
174
191
  }
175
- async txeGetPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
192
+ // eslint-disable-next-line camelcase
193
+ async aztec_txe_getPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
176
194
  const selector = EventSelector.fromField(fromSingle(foreignSelector));
177
195
  const contractAddress = addressFromSingle(foreignContractAddress);
178
196
  const scope = addressFromSingle(foreignScope);
179
- const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
197
+ // TODO(F-335): Avoid doing the following 2 calls here.
198
+ {
199
+ await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
200
+ // We cycle job to commit the stores after the contract sync.
201
+ await this.stateHandler.cycleJob();
202
+ }
203
+ const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
180
204
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
181
205
  throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
182
206
  }
@@ -194,48 +218,54 @@ export class RPCTranslator {
194
218
  toSingle(queryLength)
195
219
  ]);
196
220
  }
197
- privateStoreInExecutionCache(foreignValues, foreignHash) {
221
+ // eslint-disable-next-line camelcase
222
+ aztec_prv_storeInExecutionCache(foreignValues, foreignHash) {
198
223
  const values = fromArray(foreignValues);
199
224
  const hash = fromSingle(foreignHash);
200
- this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
225
+ this.handlerAsPrivate().storeInExecutionCache(values, hash);
201
226
  return toForeignCallResult([]);
202
227
  }
203
- async privateLoadFromExecutionCache(foreignHash) {
228
+ // eslint-disable-next-line camelcase
229
+ async aztec_prv_loadFromExecutionCache(foreignHash) {
204
230
  const hash = fromSingle(foreignHash);
205
- const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
231
+ const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
206
232
  return toForeignCallResult([
207
233
  toArray(returns)
208
234
  ]);
209
235
  }
210
236
  // When the argument is a slice, noir automatically adds a length field to oracle call.
211
237
  // When the argument is an array, we add the field length manually to the signature.
212
- utilityDebugLog(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
238
+ // eslint-disable-next-line camelcase
239
+ async aztec_utl_log(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
213
240
  const level = fromSingle(foreignLevel).toNumber();
214
241
  const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
215
242
  const fields = fromArray(foreignFields);
216
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
243
+ await this.handlerAsMisc().log(level, message, fields);
217
244
  return toForeignCallResult([]);
218
245
  }
219
- async utilityStorageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
246
+ // eslint-disable-next-line camelcase
247
+ async aztec_utl_storageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
220
248
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
221
249
  const contractAddress = addressFromSingle(foreignContractAddress);
222
250
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
223
251
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
224
- const values = await this.handlerAsUtility().utilityStorageRead(blockHash, contractAddress, startStorageSlot, numberOfElements);
252
+ const values = await this.handlerAsUtility().storageRead(blockHash, contractAddress, startStorageSlot, numberOfElements);
225
253
  return toForeignCallResult([
226
254
  toArray(values)
227
255
  ]);
228
256
  }
229
- async utilityGetPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
257
+ // eslint-disable-next-line camelcase
258
+ async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
230
259
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
231
260
  const leafSlot = fromSingle(foreignLeafSlot);
232
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
261
+ const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
233
262
  if (!witness) {
234
263
  throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
235
264
  }
236
265
  return toForeignCallResult(witness.toNoirRepresentation());
237
266
  }
238
- async utilityGetNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
267
+ // eslint-disable-next-line camelcase
268
+ async aztec_utl_getNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
239
269
  // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
240
270
  const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
241
271
  const storageSlot = fromSingle(foreignStorageSlot);
@@ -254,7 +284,7 @@ export class RPCTranslator {
254
284
  const status = fromSingle(foreignStatus).toNumber();
255
285
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
256
286
  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);
287
+ const noteDatas = await this.handlerAsUtility().getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
258
288
  const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
259
289
  contractAddress: noteData.contractAddress,
260
290
  owner: noteData.owner,
@@ -269,7 +299,8 @@ export class RPCTranslator {
269
299
  // At last we convert the array of arrays to a bounded vec of arrays
270
300
  return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
271
301
  }
272
- privateNotifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
302
+ // eslint-disable-next-line camelcase
303
+ aztec_prv_notifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
273
304
  const owner = addressFromSingle(foreignOwner);
274
305
  const storageSlot = fromSingle(foreignStorageSlot);
275
306
  const randomness = fromSingle(foreignRandomness);
@@ -277,39 +308,44 @@ export class RPCTranslator {
277
308
  const note = fromArray(foreignNote);
278
309
  const noteHash = fromSingle(foreignNoteHash);
279
310
  const counter = fromSingle(foreignCounter).toNumber();
280
- this.handlerAsPrivate().privateNotifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
311
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
281
312
  return toForeignCallResult([]);
282
313
  }
283
- async privateNotifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
314
+ // eslint-disable-next-line camelcase
315
+ async aztec_prv_notifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
284
316
  const innerNullifier = fromSingle(foreignInnerNullifier);
285
317
  const noteHash = fromSingle(foreignNoteHash);
286
318
  const counter = fromSingle(foreignCounter).toNumber();
287
- await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
319
+ await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
288
320
  return toForeignCallResult([]);
289
321
  }
290
- async privateNotifyCreatedNullifier(foreignInnerNullifier) {
322
+ // eslint-disable-next-line camelcase
323
+ async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier) {
291
324
  const innerNullifier = fromSingle(foreignInnerNullifier);
292
- await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
325
+ await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
293
326
  return toForeignCallResult([]);
294
327
  }
295
- async privateIsNullifierPending(foreignInnerNullifier, foreignContractAddress) {
328
+ // eslint-disable-next-line camelcase
329
+ async aztec_prv_isNullifierPending(foreignInnerNullifier, foreignContractAddress) {
296
330
  const innerNullifier = fromSingle(foreignInnerNullifier);
297
331
  const contractAddress = addressFromSingle(foreignContractAddress);
298
- const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
332
+ const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
299
333
  return toForeignCallResult([
300
334
  toSingle(new Fr(isPending))
301
335
  ]);
302
336
  }
303
- async utilityCheckNullifierExists(foreignInnerNullifier) {
337
+ // eslint-disable-next-line camelcase
338
+ async aztec_utl_checkNullifierExists(foreignInnerNullifier) {
304
339
  const innerNullifier = fromSingle(foreignInnerNullifier);
305
- const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
340
+ const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
306
341
  return toForeignCallResult([
307
342
  toSingle(new Fr(exists))
308
343
  ]);
309
344
  }
310
- async utilityGetContractInstance(foreignAddress) {
345
+ // eslint-disable-next-line camelcase
346
+ async aztec_utl_getContractInstance(foreignAddress) {
311
347
  const address = addressFromSingle(foreignAddress);
312
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
348
+ const instance = await this.handlerAsUtility().getContractInstance(address);
313
349
  return toForeignCallResult([
314
350
  instance.salt,
315
351
  instance.deployer.toField(),
@@ -318,36 +354,53 @@ export class RPCTranslator {
318
354
  ...instance.publicKeys.toFields()
319
355
  ].map(toSingle));
320
356
  }
321
- async utilityGetPublicKeysAndPartialAddress(foreignAddress) {
357
+ // eslint-disable-next-line camelcase
358
+ async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress) {
322
359
  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
- ]);
360
+ const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
361
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
362
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
363
+ if (result === undefined) {
364
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
365
+ return toForeignCallResult([
366
+ toSingle(new Fr(0)),
367
+ toArray(Array(13).fill(new Fr(0)))
368
+ ]);
369
+ } else {
370
+ // Data was found so we set `some` to 1 and return it along with `value`.
371
+ return toForeignCallResult([
372
+ toSingle(new Fr(1)),
373
+ toArray([
374
+ ...result.publicKeys.toFields(),
375
+ result.partialAddress
376
+ ])
377
+ ]);
378
+ }
330
379
  }
331
- async utilityGetKeyValidationRequest(foreignPkMHash) {
380
+ // eslint-disable-next-line camelcase
381
+ async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
332
382
  const pkMHash = fromSingle(foreignPkMHash);
333
- const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
383
+ const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
334
384
  return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
335
385
  }
336
- privateCallPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
386
+ // eslint-disable-next-line camelcase
387
+ aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
337
388
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
338
389
  }
339
- async utilityGetNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
390
+ // eslint-disable-next-line camelcase
391
+ async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
340
392
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
341
393
  const nullifier = fromSingle(foreignNullifier);
342
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
394
+ const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
343
395
  if (!witness) {
344
396
  throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
345
397
  }
346
398
  return toForeignCallResult(witness.toNoirRepresentation());
347
399
  }
348
- async utilityGetAuthWitness(foreignMessageHash) {
400
+ // eslint-disable-next-line camelcase
401
+ async aztec_utl_getAuthWitness(foreignMessageHash) {
349
402
  const messageHash = fromSingle(foreignMessageHash);
350
- const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
403
+ const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
351
404
  if (!authWitness) {
352
405
  throw new Error(`Auth witness not found for message hash ${messageHash}.`);
353
406
  }
@@ -355,92 +408,112 @@ export class RPCTranslator {
355
408
  toArray(authWitness)
356
409
  ]);
357
410
  }
358
- privateNotifyEnqueuedPublicFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
411
+ // eslint-disable-next-line camelcase
412
+ aztec_prv_validatePublicCalldata(_foreignCalldataHash) {
359
413
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
360
414
  }
361
- privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
415
+ // eslint-disable-next-line camelcase
416
+ aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
362
417
  throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
363
418
  }
364
- privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter) {
365
- throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
366
- }
367
- async privateIsSideEffectCounterRevertible(foreignSideEffectCounter) {
419
+ // eslint-disable-next-line camelcase
420
+ async aztec_prv_inRevertiblePhase(foreignSideEffectCounter) {
368
421
  const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
369
- const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
422
+ const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
370
423
  return toForeignCallResult([
371
424
  toSingle(new Fr(isRevertible))
372
425
  ]);
373
426
  }
374
- utilityGetUtilityContext() {
375
- const context = this.handlerAsUtility().utilityGetUtilityContext();
427
+ // eslint-disable-next-line camelcase
428
+ aztec_utl_getUtilityContext() {
429
+ const context = this.handlerAsUtility().getUtilityContext();
376
430
  return toForeignCallResult(context.toNoirRepresentation());
377
431
  }
378
- async utilityGetBlockHeader(foreignBlockNumber) {
432
+ // eslint-disable-next-line camelcase
433
+ async aztec_utl_getBlockHeader(foreignBlockNumber) {
379
434
  const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
380
- const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
435
+ const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
381
436
  if (!header) {
382
437
  throw new Error(`Block header not found for block ${blockNumber}.`);
383
438
  }
384
439
  return toForeignCallResult(header.toFields().map(toSingle));
385
440
  }
386
- async utilityGetNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
441
+ // eslint-disable-next-line camelcase
442
+ async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
387
443
  const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
388
444
  const noteHash = fromSingle(foreignNoteHash);
389
- const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
445
+ const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
390
446
  if (!witness) {
391
447
  throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
392
448
  }
393
449
  return toForeignCallResult(witness.toNoirRepresentation());
394
450
  }
395
- async utilityGetBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
451
+ // eslint-disable-next-line camelcase
452
+ async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
396
453
  const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
397
454
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
398
- const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
455
+ const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
399
456
  if (!witness) {
400
457
  throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
401
458
  }
402
459
  return toForeignCallResult(witness.toNoirRepresentation());
403
460
  }
404
- async utilityGetLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
461
+ // eslint-disable-next-line camelcase
462
+ async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
405
463
  const blockHash = new BlockHash(fromSingle(foreignBlockHash));
406
464
  const nullifier = fromSingle(foreignNullifier);
407
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
465
+ const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
408
466
  if (!witness) {
409
467
  throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
410
468
  }
411
469
  return toForeignCallResult(witness.toNoirRepresentation());
412
470
  }
413
- async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
471
+ // eslint-disable-next-line camelcase
472
+ async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
414
473
  const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
415
- await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
474
+ await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
416
475
  return toForeignCallResult([]);
417
476
  }
418
- async utilityValidateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot) {
477
+ // eslint-disable-next-line camelcase
478
+ async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen) {
419
479
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
420
480
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
421
481
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
422
- await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot);
482
+ const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
483
+ const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
484
+ await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen);
423
485
  return toForeignCallResult([]);
424
486
  }
425
- async utilityBulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
487
+ // eslint-disable-next-line camelcase
488
+ async aztec_utl_bulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
426
489
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
427
490
  const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
428
491
  const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
429
- await this.handlerAsUtility().utilityBulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
492
+ await this.handlerAsUtility().bulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
493
+ return toForeignCallResult([]);
494
+ }
495
+ // eslint-disable-next-line camelcase
496
+ async aztec_utl_utilityResolveMessageContexts(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot) {
497
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
498
+ const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
499
+ const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
500
+ await this.handlerAsUtility().utilityResolveMessageContexts(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot);
430
501
  return toForeignCallResult([]);
431
502
  }
432
- async utilityStoreCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
503
+ // eslint-disable-next-line camelcase
504
+ async aztec_utl_storeCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
433
505
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
434
506
  const slot = fromSingle(foreignSlot);
435
507
  const capsule = fromArray(foreignCapsule);
436
- await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
508
+ await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
437
509
  return toForeignCallResult([]);
438
510
  }
439
- async utilityLoadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
511
+ // eslint-disable-next-line camelcase
512
+ async aztec_utl_loadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
440
513
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
441
514
  const slot = fromSingle(foreignSlot);
442
515
  const tSize = fromSingle(foreignTSize).toNumber();
443
- const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
516
+ const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
444
517
  // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
445
518
  // with two fields: `some` (a boolean) and `value` (a field array in this case).
446
519
  if (values === null) {
@@ -457,197 +530,233 @@ export class RPCTranslator {
457
530
  ]);
458
531
  }
459
532
  }
460
- async utilityDeleteCapsule(foreignContractAddress, foreignSlot) {
533
+ // eslint-disable-next-line camelcase
534
+ async aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot) {
461
535
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
462
536
  const slot = fromSingle(foreignSlot);
463
- await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
537
+ await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
464
538
  return toForeignCallResult([]);
465
539
  }
466
- async utilityCopyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
540
+ // eslint-disable-next-line camelcase
541
+ async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
467
542
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
468
543
  const srcSlot = fromSingle(foreignSrcSlot);
469
544
  const dstSlot = fromSingle(foreignDstSlot);
470
545
  const numEntries = fromSingle(foreignNumEntries).toNumber();
471
- await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
546
+ await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
472
547
  return toForeignCallResult([]);
473
548
  }
474
549
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
475
550
  // 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
551
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
477
552
  // existence of a txe_oracle method?
478
- async utilityAes128Decrypt(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
553
+ // eslint-disable-next-line camelcase
554
+ async aztec_utl_aes128Decrypt(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
479
555
  const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
480
556
  const iv = fromUintArray(foreignIv, 8);
481
557
  const symKey = fromUintArray(foreignSymKey, 8);
482
- const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
558
+ const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
483
559
  return toForeignCallResult(arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length));
484
560
  }
485
- async utilityGetSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
561
+ // eslint-disable-next-line camelcase
562
+ async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
486
563
  const address = AztecAddress.fromField(fromSingle(foreignAddress));
487
564
  const ephPK = Point.fromFields([
488
565
  fromSingle(foreignEphPKField0),
489
566
  fromSingle(foreignEphPKField1),
490
567
  fromSingle(foreignEphPKField2)
491
568
  ]);
492
- const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
569
+ const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
493
570
  return toForeignCallResult(secret.toFields().map(toSingle));
494
571
  }
495
- emitOffchainEffect(_foreignData) {
572
+ // eslint-disable-next-line camelcase
573
+ aztec_utl_emitOffchainEffect(_foreignData) {
496
574
  throw new Error('Offchain effects are not yet supported in the TestEnvironment');
497
575
  }
498
576
  // AVM opcodes
499
- avmOpcodeEmitUnencryptedLog(_foreignMessage) {
577
+ // eslint-disable-next-line camelcase
578
+ aztec_avm_emitPublicLog(_foreignMessage) {
500
579
  // TODO(#8811): Implement
501
580
  return toForeignCallResult([]);
502
581
  }
503
- async avmOpcodeStorageRead(foreignSlot, foreignContractAddress) {
582
+ // eslint-disable-next-line camelcase
583
+ async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
504
584
  const slot = fromSingle(foreignSlot);
505
585
  const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
506
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
586
+ const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
507
587
  return toForeignCallResult([
508
588
  toSingle(new Fr(value))
509
589
  ]);
510
590
  }
511
- async avmOpcodeStorageWrite(foreignSlot, foreignValue) {
591
+ // eslint-disable-next-line camelcase
592
+ async aztec_avm_storageWrite(foreignSlot, foreignValue) {
512
593
  const slot = fromSingle(foreignSlot);
513
594
  const value = fromSingle(foreignValue);
514
- await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
595
+ await this.handlerAsAvm().storageWrite(slot, value);
515
596
  return toForeignCallResult([]);
516
597
  }
517
- async avmOpcodeGetContractInstanceDeployer(foreignAddress) {
598
+ // eslint-disable-next-line camelcase
599
+ async aztec_avm_getContractInstanceDeployer(foreignAddress) {
518
600
  const address = addressFromSingle(foreignAddress);
519
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
601
+ const instance = await this.handlerAsUtility().getContractInstance(address);
520
602
  return toForeignCallResult([
521
603
  toSingle(instance.deployer),
522
604
  // AVM requires an extra boolean indicating the instance was found
523
605
  toSingle(new Fr(1))
524
606
  ]);
525
607
  }
526
- async avmOpcodeGetContractInstanceClassId(foreignAddress) {
608
+ // eslint-disable-next-line camelcase
609
+ async aztec_avm_getContractInstanceClassId(foreignAddress) {
527
610
  const address = addressFromSingle(foreignAddress);
528
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
611
+ const instance = await this.handlerAsUtility().getContractInstance(address);
529
612
  return toForeignCallResult([
530
613
  toSingle(instance.currentContractClassId),
531
614
  // AVM requires an extra boolean indicating the instance was found
532
615
  toSingle(new Fr(1))
533
616
  ]);
534
617
  }
535
- async avmOpcodeGetContractInstanceInitializationHash(foreignAddress) {
618
+ // eslint-disable-next-line camelcase
619
+ async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
536
620
  const address = addressFromSingle(foreignAddress);
537
- const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
621
+ const instance = await this.handlerAsUtility().getContractInstance(address);
538
622
  return toForeignCallResult([
539
623
  toSingle(instance.initializationHash),
540
624
  // AVM requires an extra boolean indicating the instance was found
541
625
  toSingle(new Fr(1))
542
626
  ]);
543
627
  }
544
- async avmOpcodeSender() {
545
- const sender = await this.handlerAsAvm().avmOpcodeSender();
628
+ // eslint-disable-next-line camelcase
629
+ async aztec_avm_sender() {
630
+ const sender = await this.handlerAsAvm().sender();
546
631
  return toForeignCallResult([
547
632
  toSingle(sender)
548
633
  ]);
549
634
  }
550
- async avmOpcodeEmitNullifier(foreignNullifier) {
635
+ // eslint-disable-next-line camelcase
636
+ async aztec_avm_emitNullifier(foreignNullifier) {
551
637
  const nullifier = fromSingle(foreignNullifier);
552
- await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
638
+ await this.handlerAsAvm().emitNullifier(nullifier);
553
639
  return toForeignCallResult([]);
554
640
  }
555
- async avmOpcodeEmitNoteHash(foreignNoteHash) {
641
+ // eslint-disable-next-line camelcase
642
+ async aztec_avm_emitNoteHash(foreignNoteHash) {
556
643
  const noteHash = fromSingle(foreignNoteHash);
557
- await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
644
+ await this.handlerAsAvm().emitNoteHash(noteHash);
558
645
  return toForeignCallResult([]);
559
646
  }
560
- async avmOpcodeNullifierExists(foreignSiloedNullifier) {
647
+ // eslint-disable-next-line camelcase
648
+ async aztec_avm_nullifierExists(foreignSiloedNullifier) {
561
649
  const siloedNullifier = fromSingle(foreignSiloedNullifier);
562
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
650
+ const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
563
651
  return toForeignCallResult([
564
652
  toSingle(new Fr(exists))
565
653
  ]);
566
654
  }
567
- async avmOpcodeAddress() {
568
- const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
655
+ // eslint-disable-next-line camelcase
656
+ async aztec_avm_address() {
657
+ const contractAddress = await this.handlerAsAvm().address();
569
658
  return toForeignCallResult([
570
659
  toSingle(contractAddress.toField())
571
660
  ]);
572
661
  }
573
- async avmOpcodeBlockNumber() {
574
- const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
662
+ // eslint-disable-next-line camelcase
663
+ async aztec_avm_blockNumber() {
664
+ const blockNumber = await this.handlerAsAvm().blockNumber();
575
665
  return toForeignCallResult([
576
666
  toSingle(new Fr(blockNumber))
577
667
  ]);
578
668
  }
579
- async avmOpcodeTimestamp() {
580
- const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
669
+ // eslint-disable-next-line camelcase
670
+ async aztec_avm_timestamp() {
671
+ const timestamp = await this.handlerAsAvm().timestamp();
581
672
  return toForeignCallResult([
582
673
  toSingle(new Fr(timestamp))
583
674
  ]);
584
675
  }
585
- async avmOpcodeIsStaticCall() {
586
- const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
676
+ // eslint-disable-next-line camelcase
677
+ async aztec_avm_isStaticCall() {
678
+ const isStaticCall = await this.handlerAsAvm().isStaticCall();
587
679
  return toForeignCallResult([
588
680
  toSingle(new Fr(isStaticCall ? 1 : 0))
589
681
  ]);
590
682
  }
591
- async avmOpcodeChainId() {
592
- const chainId = await this.handlerAsAvm().avmOpcodeChainId();
683
+ // eslint-disable-next-line camelcase
684
+ async aztec_avm_chainId() {
685
+ const chainId = await this.handlerAsAvm().chainId();
593
686
  return toForeignCallResult([
594
687
  toSingle(chainId)
595
688
  ]);
596
689
  }
597
- async avmOpcodeVersion() {
598
- const version = await this.handlerAsAvm().avmOpcodeVersion();
690
+ // eslint-disable-next-line camelcase
691
+ async aztec_avm_version() {
692
+ const version = await this.handlerAsAvm().version();
599
693
  return toForeignCallResult([
600
694
  toSingle(version)
601
695
  ]);
602
696
  }
603
- avmOpcodeReturndataSize() {
697
+ // eslint-disable-next-line camelcase
698
+ aztec_avm_returndataSize() {
604
699
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
605
700
  }
606
- avmOpcodeReturndataCopy(_foreignRdOffset, _foreignCopySize) {
701
+ // eslint-disable-next-line camelcase
702
+ aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
607
703
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
608
704
  }
609
- avmOpcodeCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
705
+ // eslint-disable-next-line camelcase
706
+ aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
610
707
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
611
708
  }
612
- avmOpcodeStaticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
709
+ // eslint-disable-next-line camelcase
710
+ aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
613
711
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
614
712
  }
615
- avmOpcodeSuccessCopy() {
713
+ // eslint-disable-next-line camelcase
714
+ aztec_avm_successCopy() {
616
715
  throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
617
716
  }
618
- async txePrivateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
717
+ // eslint-disable-next-line camelcase
718
+ async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
619
719
  const from = addressFromSingle(foreignFrom);
620
720
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
621
721
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
622
722
  const args = fromArray(foreignArgs);
623
723
  const argsHash = fromSingle(foreignArgsHash);
624
724
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
625
- const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall);
725
+ const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
726
+ // TODO(F-335): Avoid doing the following call here.
727
+ await this.stateHandler.cycleJob();
626
728
  return toForeignCallResult([
627
729
  toArray(returnValues)
628
730
  ]);
629
731
  }
630
- async txeSimulateUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
732
+ // eslint-disable-next-line camelcase
733
+ async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
631
734
  const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
632
735
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
633
736
  const args = fromArray(foreignArgs);
634
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(targetContractAddress, functionSelector, args);
737
+ const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
738
+ // TODO(F-335): Avoid doing the following call here.
739
+ await this.stateHandler.cycleJob();
635
740
  return toForeignCallResult([
636
741
  toArray(returnValues)
637
742
  ]);
638
743
  }
639
- async txePublicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
744
+ // eslint-disable-next-line camelcase
745
+ async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
640
746
  const from = addressFromSingle(foreignFrom);
641
747
  const address = addressFromSingle(foreignAddress);
642
748
  const calldata = fromArray(foreignCalldata);
643
749
  const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
644
- const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
750
+ const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
751
+ // TODO(F-335): Avoid doing the following call here.
752
+ await this.stateHandler.cycleJob();
645
753
  return toForeignCallResult([
646
754
  toArray(returnValues)
647
755
  ]);
648
756
  }
649
- async privateGetSenderForTags() {
650
- const sender = await this.handlerAsPrivate().privateGetSenderForTags();
757
+ // eslint-disable-next-line camelcase
758
+ async aztec_prv_getSenderForTags() {
759
+ const sender = await this.handlerAsPrivate().getSenderForTags();
651
760
  // Return a Noir Option struct with `some` and `value` fields
652
761
  if (sender === undefined) {
653
762
  // No sender found, return Option with some=0 and value=0
@@ -663,15 +772,17 @@ export class RPCTranslator {
663
772
  ]);
664
773
  }
665
774
  }
666
- async privateSetSenderForTags(foreignSenderForTags) {
775
+ // eslint-disable-next-line camelcase
776
+ async aztec_prv_setSenderForTags(foreignSenderForTags) {
667
777
  const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
668
- await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
778
+ await this.handlerAsPrivate().setSenderForTags(senderForTags);
669
779
  return toForeignCallResult([]);
670
780
  }
671
- async privateGetNextAppTagAsSender(foreignSender, foreignRecipient) {
781
+ // eslint-disable-next-line camelcase
782
+ async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
672
783
  const sender = AztecAddress.fromField(fromSingle(foreignSender));
673
784
  const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
674
- const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
785
+ const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
675
786
  return toForeignCallResult([
676
787
  toSingle(nextAppTag.value)
677
788
  ]);