@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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