@aztec/txe 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae

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