@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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