@aztec/txe 0.0.1-commit.fffb133c → 0.0.1-dev

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