@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a

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