@aztec/txe 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa

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