@aztec/txe 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

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 (144) hide show
  1. package/dest/AuthRegistry-QVGDDH5X.js +3 -0
  2. package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
  3. package/dest/ContractClassRegistry-PVNCKGG7.js +3 -0
  4. package/dest/ContractClassRegistry-PVNCKGG7.js.map +7 -0
  5. package/dest/ContractInstanceRegistry-WLOZKTR6.js +3 -0
  6. package/dest/ContractInstanceRegistry-WLOZKTR6.js.map +7 -0
  7. package/dest/FeeJuice-MAQJU53K.js +3 -0
  8. package/dest/FeeJuice-MAQJU53K.js.map +7 -0
  9. package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
  10. package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
  11. package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
  12. package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
  13. package/dest/SchnorrAccount-ADD65DYA.js +3 -0
  14. package/dest/SchnorrAccount-ADD65DYA.js.map +7 -0
  15. package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js +3 -0
  16. package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js.map +7 -0
  17. package/dest/bin/check_txe_oracle_version.js +9 -19
  18. package/dest/bin/index.js +1 -1
  19. package/dest/bin/oracle_test_server.d.ts +3 -0
  20. package/dest/bin/oracle_test_server.d.ts.map +1 -0
  21. package/dest/bin/oracle_test_server.js +41 -0
  22. package/dest/chunk-32UHX7YY.js +3 -0
  23. package/dest/{chunk-DF6RMOC6.js → chunk-RVEPNDEP.js} +2 -2
  24. package/dest/{chunk-DF6RMOC6.js.map → chunk-RVEPNDEP.js.map} +3 -3
  25. package/dest/chunk-XWIMXLKD.js +258 -0
  26. package/dest/chunk-XWIMXLKD.js.map +7 -0
  27. package/dest/constants.d.ts +3 -1
  28. package/dest/constants.d.ts.map +1 -1
  29. package/dest/constants.js +5 -2
  30. package/dest/dispatcher_pool.d.ts +2 -2
  31. package/dest/dispatcher_pool.d.ts.map +1 -1
  32. package/dest/dispatcher_pool.js +5 -3
  33. package/dest/index.d.ts +6 -143
  34. package/dest/index.d.ts.map +1 -1
  35. package/dest/index.js +12 -169
  36. package/dest/metafile.json +10267 -9581
  37. package/dest/oracle/interfaces.d.ts +38 -11
  38. package/dest/oracle/interfaces.d.ts.map +1 -1
  39. package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
  40. package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
  41. package/dest/oracle/tagging_secret_strategy.js +12 -0
  42. package/dest/oracle/test-resolver/default_fixtures.d.ts +16 -0
  43. package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
  44. package/dest/oracle/test-resolver/default_fixtures.js +200 -0
  45. package/dest/oracle/test-resolver/index.d.ts +9 -0
  46. package/dest/oracle/test-resolver/index.d.ts.map +1 -0
  47. package/dest/oracle/test-resolver/index.js +32 -0
  48. package/dest/oracle/test-resolver/resolver.d.ts +48 -0
  49. package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
  50. package/dest/oracle/test-resolver/resolver.js +181 -0
  51. package/dest/oracle/txe_oracle_public_context.d.ts +25 -6
  52. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  53. package/dest/oracle/txe_oracle_public_context.js +34 -1
  54. package/dest/oracle/txe_oracle_registry.d.ts +172 -0
  55. package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
  56. package/dest/oracle/txe_oracle_registry.js +767 -0
  57. package/dest/oracle/txe_oracle_top_level_context.d.ts +39 -14
  58. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  59. package/dest/oracle/txe_oracle_top_level_context.js +489 -289
  60. package/dest/{txe_oracle_version.d.ts → oracle/txe_oracle_version.d.ts} +5 -5
  61. package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
  62. package/dest/{txe_oracle_version.js → oracle/txe_oracle_version.js} +4 -4
  63. package/dest/rpc_translator.d.ts +116 -284
  64. package/dest/rpc_translator.d.ts.map +1 -1
  65. package/dest/rpc_translator.js +809 -860
  66. package/dest/server.bundle.js +1 -1
  67. package/dest/state_machine/archiver.d.ts +3 -2
  68. package/dest/state_machine/archiver.d.ts.map +1 -1
  69. package/dest/state_machine/archiver.js +9 -3
  70. package/dest/state_machine/dummy_p2p_client.d.ts +5 -2
  71. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  72. package/dest/state_machine/dummy_p2p_client.js +9 -0
  73. package/dest/state_machine/global_variable_builder.d.ts +3 -4
  74. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  75. package/dest/state_machine/global_variable_builder.js +0 -3
  76. package/dest/state_machine/index.d.ts +8 -6
  77. package/dest/state_machine/index.d.ts.map +1 -1
  78. package/dest/state_machine/index.js +41 -19
  79. package/dest/state_machine/mock_epoch_cache.d.ts +2 -3
  80. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  81. package/dest/state_machine/mock_epoch_cache.js +3 -6
  82. package/dest/state_machine/synchronizer.d.ts +10 -2
  83. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  84. package/dest/state_machine/synchronizer.js +18 -5
  85. package/dest/txe_session.d.ts +43 -28
  86. package/dest/txe_session.d.ts.map +1 -1
  87. package/dest/txe_session.js +183 -47
  88. package/dest/utils/block_creation.d.ts +2 -2
  89. package/dest/utils/block_creation.d.ts.map +1 -1
  90. package/dest/utils/block_creation.js +2 -2
  91. package/dest/utils/encoding.d.ts +8 -5
  92. package/dest/utils/encoding.d.ts.map +1 -1
  93. package/dest/utils/tx_effect_creation.d.ts +1 -1
  94. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  95. package/dest/utils/tx_effect_creation.js +0 -1
  96. package/dest/utils/txe_artifact_resolver.d.ts +37 -0
  97. package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
  98. package/dest/utils/txe_artifact_resolver.js +161 -0
  99. package/dest/utils/txe_public_contract_data_source.d.ts +1 -1
  100. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -1
  101. package/dest/utils/txe_public_contract_data_source.js +7 -4
  102. package/dest/worker.bundle.js +1 -1
  103. package/package.json +18 -17
  104. package/src/bin/check_txe_oracle_version.ts +11 -17
  105. package/src/bin/oracle_test_server.ts +51 -0
  106. package/src/constants.ts +6 -2
  107. package/src/dispatcher_pool.ts +4 -3
  108. package/src/index.ts +21 -198
  109. package/src/oracle/interfaces.ts +35 -9
  110. package/src/oracle/tagging_secret_strategy.ts +25 -0
  111. package/src/oracle/test-resolver/default_fixtures.ts +271 -0
  112. package/src/oracle/test-resolver/index.ts +44 -0
  113. package/src/oracle/test-resolver/resolver.ts +245 -0
  114. package/src/oracle/txe_oracle_public_context.ts +36 -4
  115. package/src/oracle/txe_oracle_registry.ts +556 -0
  116. package/src/oracle/txe_oracle_top_level_context.ts +249 -66
  117. package/src/{txe_oracle_version.ts → oracle/txe_oracle_version.ts} +4 -4
  118. package/src/rpc_translator.ts +850 -1065
  119. package/src/state_machine/archiver.ts +9 -3
  120. package/src/state_machine/dummy_p2p_client.ts +13 -0
  121. package/src/state_machine/global_variable_builder.ts +2 -16
  122. package/src/state_machine/index.ts +50 -34
  123. package/src/state_machine/mock_epoch_cache.ts +4 -8
  124. package/src/state_machine/synchronizer.ts +26 -5
  125. package/src/txe_session.ts +325 -56
  126. package/src/utils/block_creation.ts +2 -1
  127. package/src/utils/tx_effect_creation.ts +0 -2
  128. package/src/utils/txe_artifact_resolver.ts +217 -0
  129. package/src/utils/txe_public_contract_data_source.ts +6 -4
  130. package/dest/ContractClassRegistry-KKNT527R.js +0 -3
  131. package/dest/ContractClassRegistry-KKNT527R.js.map +0 -7
  132. package/dest/ContractInstanceRegistry-GSKBNL3Q.js +0 -3
  133. package/dest/ContractInstanceRegistry-GSKBNL3Q.js.map +0 -7
  134. package/dest/FeeJuice-GUJ5O6GB.js +0 -3
  135. package/dest/FeeJuice-GUJ5O6GB.js.map +0 -7
  136. package/dest/MultiCallEntrypoint-ZQPCKVKL.js +0 -3
  137. package/dest/MultiCallEntrypoint-ZQPCKVKL.js.map +0 -7
  138. package/dest/SchnorrAccount-QIXE5DXA.js +0 -3
  139. package/dest/SchnorrAccount-QIXE5DXA.js.map +0 -7
  140. package/dest/chunk-BJVAAXNA.js +0 -3
  141. package/dest/chunk-PPJTNNUG.js +0 -265
  142. package/dest/chunk-PPJTNNUG.js.map +0 -7
  143. package/dest/txe_oracle_version.d.ts.map +0 -1
  144. /package/dest/{chunk-BJVAAXNA.js.map → chunk-32UHX7YY.js.map} +0 -0
@@ -1,48 +1,9 @@
1
- import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
2
- import { Fr } from '@aztec/aztec.js/fields';
3
- import {
4
- ARCHIVE_HEIGHT,
5
- MAX_NOTE_HASHES_PER_TX,
6
- MAX_NULLIFIERS_PER_TX,
7
- MAX_PRIVATE_LOGS_PER_TX,
8
- PRIVATE_LOG_SIZE_IN_FIELDS,
9
- } from '@aztec/constants';
10
- import { BlockNumber } from '@aztec/foundation/branded-types';
11
- import { MembershipWitness } from '@aztec/foundation/trees';
12
- import {
13
- BoundedVec,
14
- type IMiscOracle,
15
- type IPrivateExecutionOracle,
16
- type IUtilityExecutionOracle,
17
- Option,
18
- packAsHintedNote,
19
- } from '@aztec/pxe/simulator';
20
- import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
21
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
22
- import { GasSettings } from '@aztec/stdlib/gas';
23
-
24
- import { MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
1
+ import type { IMiscOracle, IPrivateExecutionOracle, IUtilityExecutionOracle } from '@aztec/pxe/simulator';
2
+
25
3
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
4
+ import { callTxeHandler } from './oracle/txe_oracle_registry.js';
26
5
  import type { TXESessionStateHandler } from './txe_session.js';
27
- import {
28
- type ForeignCallArray,
29
- type ForeignCallSingle,
30
- addressFromSingle,
31
- arrayOfArraysToBoundedVecOfArrays,
32
- arrayToBoundedVec,
33
- blockHashFromSingle,
34
- bufferToU8Array,
35
- fromArray,
36
- fromSingle,
37
- fromUintArray,
38
- fromUintBoundedVec,
39
- toArray,
40
- toForeignCallResult,
41
- toSingle,
42
- } from './utils/encoding.js';
43
-
44
- const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
45
- const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
6
+ import type { ForeignCallArgs } from './utils/encoding.js';
46
7
 
47
8
  export class UnavailableOracleError extends Error {
48
9
  constructor(oracleName: string) {
@@ -114,77 +75,53 @@ export class RPCTranslator {
114
75
  }
115
76
 
116
77
  // eslint-disable-next-line camelcase
117
- aztec_txe_assertCompatibleOracleVersion(foreignMajor: ForeignCallSingle, foreignMinor: ForeignCallSingle) {
118
- const major = fromSingle(foreignMajor).toNumber();
119
- const minor = fromSingle(foreignMinor).toNumber();
120
-
121
- this.stateHandler.setTxeOracleVersion(major, minor);
122
-
123
- return toForeignCallResult([]);
78
+ aztec_txe_assertCompatibleOracleVersion(...inputs: ForeignCallArgs) {
79
+ return callTxeHandler({
80
+ oracle: 'aztec_txe_assertCompatibleOracleVersion',
81
+ inputs,
82
+ handler: ([major, minor]) => {
83
+ this.stateHandler.setTxeOracleVersion(major, minor);
84
+ },
85
+ });
124
86
  }
125
87
 
126
88
  // TXE session state transition functions - these get handled by the state handler
127
89
 
128
90
  // eslint-disable-next-line camelcase
129
- async aztec_txe_setTopLevelTXEContext() {
130
- await this.stateHandler.enterTopLevelState();
131
-
132
- return toForeignCallResult([]);
91
+ aztec_txe_setTopLevelTXEContext() {
92
+ return callTxeHandler({
93
+ oracle: 'aztec_txe_setTopLevelTXEContext',
94
+ inputs: [],
95
+ handler: () => this.stateHandler.enterTopLevelState(),
96
+ });
133
97
  }
134
98
 
135
99
  // eslint-disable-next-line camelcase
136
- async aztec_txe_setPrivateTXEContext(
137
- foreignContractAddressIsSome: ForeignCallSingle,
138
- foreignContractAddressValue: ForeignCallSingle,
139
- foreignAnchorBlockNumberIsSome: ForeignCallSingle,
140
- foreignAnchorBlockNumberValue: ForeignCallSingle,
141
- foreignGasSettings: ForeignCallArray,
142
- ) {
143
- const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
144
- ? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
145
- : undefined;
146
-
147
- const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
148
- ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
149
- : undefined;
150
-
151
- const gasSettings = GasSettings.fromFields(fromArray(foreignGasSettings));
152
-
153
- const privateContextInputs = await this.stateHandler.enterPrivateState(
154
- contractAddress,
155
- anchorBlockNumber,
156
- gasSettings,
157
- );
158
-
159
- return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
100
+ aztec_txe_setPrivateTXEContext(...inputs: ForeignCallArgs) {
101
+ return callTxeHandler({
102
+ oracle: 'aztec_txe_setPrivateTXEContext',
103
+ inputs,
104
+ handler: ([contractAddress, anchorBlockNumber, gasSettings]) =>
105
+ this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber, gasSettings),
106
+ });
160
107
  }
161
108
 
162
109
  // eslint-disable-next-line camelcase
163
- async aztec_txe_setPublicTXEContext(
164
- foreignContractAddressIsSome: ForeignCallSingle,
165
- foreignContractAddressValue: ForeignCallSingle,
166
- ) {
167
- const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
168
- ? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
169
- : undefined;
170
-
171
- await this.stateHandler.enterPublicState(contractAddress);
172
-
173
- return toForeignCallResult([]);
110
+ aztec_txe_setPublicTXEContext(...inputs: ForeignCallArgs) {
111
+ return callTxeHandler({
112
+ oracle: 'aztec_txe_setPublicTXEContext',
113
+ inputs,
114
+ handler: ([contractAddress]) => this.stateHandler.enterPublicState(contractAddress),
115
+ });
174
116
  }
175
117
 
176
118
  // eslint-disable-next-line camelcase
177
- async aztec_txe_setUtilityTXEContext(
178
- foreignContractAddressIsSome: ForeignCallSingle,
179
- foreignContractAddressValue: ForeignCallSingle,
180
- ) {
181
- const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
182
- ? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
183
- : undefined;
184
-
185
- await this.stateHandler.enterUtilityState(contractAddress);
186
-
187
- return toForeignCallResult([]);
119
+ aztec_txe_setUtilityTXEContext(...inputs: ForeignCallArgs) {
120
+ return callTxeHandler({
121
+ oracle: 'aztec_txe_setUtilityTXEContext',
122
+ inputs,
123
+ handler: ([contractAddress]) => this.stateHandler.enterUtilityState(contractAddress),
124
+ });
188
125
  }
189
126
 
190
127
  // Other oracles - these get handled by the oracle handler
@@ -193,802 +130,690 @@ export class RPCTranslator {
193
130
 
194
131
  // eslint-disable-next-line camelcase
195
132
  aztec_txe_getDefaultAddress() {
196
- const defaultAddress = this.handlerAsTxe().getDefaultAddress();
197
-
198
- return toForeignCallResult([toSingle(defaultAddress)]);
133
+ return callTxeHandler({
134
+ oracle: 'aztec_txe_getDefaultAddress',
135
+ inputs: [],
136
+ handler: () => this.handlerAsTxe().getDefaultAddress(),
137
+ });
199
138
  }
200
139
 
201
140
  // eslint-disable-next-line camelcase
202
- async aztec_txe_getNextBlockNumber() {
203
- const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
204
-
205
- return toForeignCallResult([toSingle(nextBlockNumber)]);
141
+ aztec_txe_getNextBlockNumber() {
142
+ return callTxeHandler({
143
+ oracle: 'aztec_txe_getNextBlockNumber',
144
+ inputs: [],
145
+ handler: () => this.handlerAsTxe().getNextBlockNumber(),
146
+ });
206
147
  }
207
148
 
208
149
  // eslint-disable-next-line camelcase
209
- async aztec_txe_getNextBlockTimestamp() {
210
- const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
211
-
212
- return toForeignCallResult([toSingle(nextBlockTimestamp)]);
150
+ aztec_txe_getNextBlockTimestamp() {
151
+ return callTxeHandler({
152
+ oracle: 'aztec_txe_getNextBlockTimestamp',
153
+ inputs: [],
154
+ handler: () => this.handlerAsTxe().getNextBlockTimestamp(),
155
+ });
213
156
  }
214
157
 
215
158
  // eslint-disable-next-line camelcase
216
- async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
217
- const blocks = fromSingle(foreignBlocks).toNumber();
218
-
219
- await this.handlerAsTxe().advanceBlocksBy(blocks);
220
-
221
- return toForeignCallResult([]);
159
+ aztec_txe_advanceBlocksBy(...inputs: ForeignCallArgs) {
160
+ return callTxeHandler({
161
+ oracle: 'aztec_txe_advanceBlocksBy',
162
+ inputs,
163
+ handler: ([blocks]) => this.handlerAsTxe().advanceBlocksBy(blocks),
164
+ });
222
165
  }
223
166
 
224
167
  // eslint-disable-next-line camelcase
225
- aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
226
- const duration = fromSingle(foreignDuration).toBigInt();
227
-
228
- this.handlerAsTxe().advanceTimestampBy(duration);
229
-
230
- return toForeignCallResult([]);
168
+ aztec_txe_advanceTimestampBy(...inputs: ForeignCallArgs) {
169
+ return callTxeHandler({
170
+ oracle: 'aztec_txe_advanceTimestampBy',
171
+ inputs,
172
+ handler: ([duration]) => this.handlerAsTxe().advanceTimestampBy(duration),
173
+ });
231
174
  }
232
175
 
233
176
  // eslint-disable-next-line camelcase
234
- async aztec_txe_deploy(
235
- artifact: ContractArtifact,
236
- instance: ContractInstanceWithAddress,
237
- foreignSecret: ForeignCallSingle,
238
- ) {
239
- const secret = fromSingle(foreignSecret);
240
-
241
- await this.handlerAsTxe().deploy(artifact, instance, secret);
242
-
243
- return toForeignCallResult([
244
- toArray([
245
- instance.salt,
246
- instance.deployer.toField(),
247
- instance.currentContractClassId,
248
- instance.initializationHash,
249
- instance.immutablesHash,
250
- ...instance.publicKeys.toFields(),
251
- ]),
252
- ]);
177
+ aztec_txe_deploy(...inputs: ForeignCallArgs) {
178
+ return callTxeHandler({
179
+ oracle: 'aztec_txe_deploy',
180
+ inputs,
181
+ handler: ([contractPath, initializer, _, args, secret, salt, deployer]) =>
182
+ this.handlerAsTxe().deploy(contractPath, initializer, args, secret, salt, deployer),
183
+ });
253
184
  }
254
185
 
255
186
  // eslint-disable-next-line camelcase
256
- async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
257
- const secret = fromSingle(foreignSecret);
258
-
259
- const completeAddress = await this.handlerAsTxe().createAccount(secret);
260
-
261
- return toForeignCallResult([
262
- toSingle(completeAddress.address),
263
- ...completeAddress.publicKeys.toFields().map(toSingle),
264
- ]);
187
+ aztec_txe_createAccount(...inputs: ForeignCallArgs) {
188
+ return callTxeHandler({
189
+ oracle: 'aztec_txe_createAccount',
190
+ inputs,
191
+ handler: ([secret, partialAddress]) => this.handlerAsTxe().createAccount(secret, partialAddress),
192
+ });
265
193
  }
266
194
 
267
195
  // eslint-disable-next-line camelcase
268
- async aztec_txe_addAccount(
269
- artifact: ContractArtifact,
270
- instance: ContractInstanceWithAddress,
271
- foreignSecret: ForeignCallSingle,
272
- ) {
273
- const secret = fromSingle(foreignSecret);
274
-
275
- const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
196
+ aztec_txe_addAccount(...inputs: ForeignCallArgs) {
197
+ return callTxeHandler({
198
+ oracle: 'aztec_txe_addAccount',
199
+ inputs,
200
+ handler: ([secret]) => this.handlerAsTxe().addAccount(secret),
201
+ });
202
+ }
276
203
 
277
- return toForeignCallResult([
278
- toSingle(completeAddress.address),
279
- ...completeAddress.publicKeys.toFields().map(toSingle),
280
- ]);
204
+ // eslint-disable-next-line camelcase
205
+ aztec_txe_addAuthWitness(...inputs: ForeignCallArgs) {
206
+ return callTxeHandler({
207
+ oracle: 'aztec_txe_addAuthWitness',
208
+ inputs,
209
+ handler: ([address, messageHash]) => this.handlerAsTxe().addAuthWitness(address, messageHash),
210
+ });
281
211
  }
282
212
 
283
213
  // eslint-disable-next-line camelcase
284
- async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
285
- const address = addressFromSingle(foreignAddress);
286
- const messageHash = fromSingle(foreignMessageHash);
214
+ aztec_txe_sendL1ToL2Message(...inputs: ForeignCallArgs) {
215
+ return callTxeHandler({
216
+ oracle: 'aztec_txe_sendL1ToL2Message',
217
+ inputs,
218
+ handler: ([content, secretHash, sender, recipient]) =>
219
+ this.handlerAsTxe().sendL1ToL2Message(content, secretHash, sender, recipient),
220
+ });
221
+ }
287
222
 
288
- await this.handlerAsTxe().addAuthWitness(address, messageHash);
223
+ // eslint-disable-next-line camelcase
224
+ aztec_txe_setTaggingSecretStrategies(...inputs: ForeignCallArgs) {
225
+ return callTxeHandler({
226
+ oracle: 'aztec_txe_setTaggingSecretStrategies',
227
+ inputs,
228
+ handler: ([unconstrainedStrategy, constrainedStrategy]) =>
229
+ this.handlerAsTxe().setTaggingSecretStrategies(unconstrainedStrategy, constrainedStrategy),
230
+ });
231
+ }
289
232
 
290
- return toForeignCallResult([]);
233
+ // eslint-disable-next-line camelcase
234
+ aztec_txe_setAuthorizeAllUtilityCallTargets(...inputs: ForeignCallArgs) {
235
+ return callTxeHandler({
236
+ oracle: 'aztec_txe_setAuthorizeAllUtilityCallTargets',
237
+ inputs,
238
+ handler: ([authorizeAll]) => this.handlerAsTxe().setAuthorizeAllUtilityCallTargets(authorizeAll),
239
+ });
291
240
  }
292
241
 
293
242
  // PXE oracles
294
243
 
295
244
  // eslint-disable-next-line camelcase
296
- aztec_utl_assertCompatibleOracleVersion(foreignMajor: ForeignCallSingle, foreignMinor: ForeignCallSingle) {
297
- const major = fromSingle(foreignMajor).toNumber();
298
- const minor = fromSingle(foreignMinor).toNumber();
299
-
300
- this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
301
-
302
- return toForeignCallResult([]);
245
+ aztec_misc_assertCompatibleOracleVersion(...inputs: ForeignCallArgs) {
246
+ return callTxeHandler({
247
+ oracle: 'aztec_misc_assertCompatibleOracleVersion',
248
+ inputs,
249
+ handler: ([major, minor]) => this.handlerAsMisc().assertCompatibleOracleVersion(major, minor),
250
+ });
303
251
  }
304
252
 
305
253
  // eslint-disable-next-line camelcase
306
- aztec_utl_getRandomField() {
307
- const randomField = this.handlerAsMisc().getRandomField();
308
-
309
- return toForeignCallResult([toSingle(randomField)]);
254
+ aztec_misc_getRandomField() {
255
+ return callTxeHandler({
256
+ oracle: 'aztec_misc_getRandomField',
257
+ inputs: [],
258
+ handler: () => this.handlerAsMisc().getRandomField(),
259
+ });
310
260
  }
311
261
 
312
262
  // eslint-disable-next-line camelcase
313
- async aztec_txe_getLastBlockTimestamp() {
314
- const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
315
-
316
- return toForeignCallResult([toSingle(new Fr(timestamp))]);
263
+ aztec_txe_getLastBlockTimestamp() {
264
+ return callTxeHandler({
265
+ oracle: 'aztec_txe_getLastBlockTimestamp',
266
+ inputs: [],
267
+ handler: () => this.handlerAsTxe().getLastBlockTimestamp(),
268
+ });
317
269
  }
318
270
 
319
271
  // eslint-disable-next-line camelcase
320
- async aztec_txe_getLastTxEffects() {
321
- const { txHash, noteHashes, nullifiers, privateLogs } = await this.handlerAsTxe().getLastTxEffects();
322
-
323
- // Same workaround as `aztec_txe_getPrivateEvents`: Noir cannot yet return nested structs with arrays, so we return
324
- // a flat multidimensional array plus per-log lengths and the total count, and reassemble into a
325
- // `BoundedVec<BoundedVec<T>>` on the Noir side. Each log contributes only its emitted fields. The rest
326
- // is zero-padded to `PRIVATE_LOG_SIZE_IN_FIELDS`.
327
- const emittedLogs = privateLogs.map(log => log.getEmittedFields());
328
-
329
- const rawLogStorage = emittedLogs
330
- .map(fields => fields.concat(Array(PRIVATE_LOG_SIZE_IN_FIELDS - fields.length).fill(new Fr(0))))
331
- .concat(
332
- Array(MAX_PRIVATE_LOGS_PER_TX - emittedLogs.length).fill(Array(PRIVATE_LOG_SIZE_IN_FIELDS).fill(new Fr(0))),
333
- )
334
- .flat();
335
-
336
- const logLengths = emittedLogs
337
- .map(fields => new Fr(fields.length))
338
- .concat(Array(MAX_PRIVATE_LOGS_PER_TX - emittedLogs.length).fill(new Fr(0)));
339
-
340
- const logCount = new Fr(emittedLogs.length);
341
-
342
- return toForeignCallResult([
343
- toSingle(txHash.hash),
344
- ...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
345
- ...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX),
346
- toArray(rawLogStorage),
347
- toArray(logLengths),
348
- toSingle(logCount),
349
- ]);
272
+ aztec_txe_getLastTxEffects() {
273
+ return callTxeHandler({
274
+ oracle: 'aztec_txe_getLastTxEffects',
275
+ inputs: [],
276
+ handler: () => this.handlerAsTxe().getLastTxEffects(),
277
+ });
350
278
  }
351
279
 
352
280
  // eslint-disable-next-line camelcase
353
281
  aztec_txe_getLastCallOffchainEffects() {
354
- const { effects } = this.stateHandler.getLastCallOffchainEffects();
355
-
356
- const rawArrayStorage = effects
357
- .map(e => e.concat(Array(MAX_OFFCHAIN_EFFECT_LEN - e.length).fill(new Fr(0))))
358
- .concat(
359
- Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(Array(MAX_OFFCHAIN_EFFECT_LEN).fill(new Fr(0))),
360
- )
361
- .flat();
362
-
363
- const effectLengths = effects
364
- .map(e => new Fr(e.length))
365
- .concat(Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(new Fr(0)));
366
-
367
- const count = new Fr(effects.length);
368
-
369
- return toForeignCallResult([toArray(rawArrayStorage), toArray(effectLengths), toSingle(count)]);
282
+ return callTxeHandler({
283
+ oracle: 'aztec_txe_getLastCallOffchainEffects',
284
+ inputs: [],
285
+ handler: () => this.stateHandler.getLastCallOffchainEffects(),
286
+ });
370
287
  }
371
288
 
372
289
  // eslint-disable-next-line camelcase
373
290
  aztec_txe_getLastCallContext() {
374
- const { txHash, anchorBlockTimestamp } = this.stateHandler.getLastCallContext();
375
- const isSome = txHash.isZero() ? 0 : 1;
376
- return toForeignCallResult([toSingle(isSome), toSingle(txHash), toSingle(new Fr(anchorBlockTimestamp))]);
377
- }
378
-
379
- // eslint-disable-next-line camelcase
380
- async aztec_txe_getPrivateEvents(
381
- foreignSelector: ForeignCallSingle,
382
- foreignContractAddress: ForeignCallSingle,
383
- foreignScope: ForeignCallSingle,
384
- ) {
385
- const selector = EventSelector.fromField(fromSingle(foreignSelector));
386
- const contractAddress = addressFromSingle(foreignContractAddress);
387
- const scope = addressFromSingle(foreignScope);
388
-
389
- // TODO(F-335): Avoid doing the following 2 calls here.
390
- {
391
- await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
392
- // We cycle job to commit the stores after the contract sync.
393
- await this.stateHandler.cycleJob();
394
- }
395
-
396
- const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
397
-
398
- if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
399
- throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
400
- }
401
-
402
- if (events.some(e => e.length > MAX_EVENT_LEN)) {
403
- throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
404
- }
405
-
406
- // This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
407
- // multidimensional array in get_private_events_oracle and create the BoundedVecs here.
408
- const rawArrayStorage = events
409
- .map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
410
- .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
411
- .flat();
412
- const eventLengths = events
413
- .map(e => new Fr(e.length))
414
- .concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
415
- const queryLength = new Fr(events.length);
291
+ return callTxeHandler({
292
+ oracle: 'aztec_txe_getLastCallContext',
293
+ inputs: [],
294
+ handler: () => this.stateHandler.getLastCallContext(),
295
+ });
296
+ }
416
297
 
417
- return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
298
+ // eslint-disable-next-line camelcase
299
+ aztec_txe_getPrivateEvents(...inputs: ForeignCallArgs) {
300
+ return callTxeHandler({
301
+ oracle: 'aztec_txe_getPrivateEvents',
302
+ inputs,
303
+ handler: ([selector, contractAddress, scope]) =>
304
+ this.stateHandler.getPrivateEvents(selector, contractAddress, scope),
305
+ });
418
306
  }
419
307
 
420
308
  // eslint-disable-next-line camelcase
421
- aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
422
- const values = fromArray(foreignValues);
423
- const hash = fromSingle(foreignHash);
424
-
425
- this.handlerAsPrivate().setHashPreimage(values, hash);
426
-
427
- return toForeignCallResult([]);
428
- }
429
-
430
- // eslint-disable-next-line camelcase
431
- async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
432
- const hash = fromSingle(foreignHash);
433
-
434
- const returns = await this.handlerAsPrivate().getHashPreimage(hash);
435
-
436
- return toForeignCallResult([toArray(returns)]);
437
- }
438
-
439
- // When the argument is a slice, noir automatically adds a length field to oracle call.
440
- // When the argument is an array, we add the field length manually to the signature.
441
- // eslint-disable-next-line camelcase
442
- async aztec_utl_log(
443
- foreignLevel: ForeignCallSingle,
444
- foreignMessage: ForeignCallArray,
445
- _foreignLength: ForeignCallSingle,
446
- foreignFields: ForeignCallArray,
447
- ) {
448
- const level = fromSingle(foreignLevel).toNumber();
449
- const message = fromArray(foreignMessage)
450
- .map(field => String.fromCharCode(field.toNumber()))
451
- .join('');
452
- const fields = fromArray(foreignFields);
453
-
454
- await this.handlerAsMisc().log(level, message, fields);
455
-
456
- return toForeignCallResult([]);
457
- }
458
-
459
- // eslint-disable-next-line camelcase
460
- async aztec_utl_getFromPublicStorage(
461
- foreignBlockHash: ForeignCallSingle,
462
- foreignContractAddress: ForeignCallSingle,
463
- foreignStartStorageSlot: ForeignCallSingle,
464
- foreignNumberOfElements: ForeignCallSingle,
465
- ) {
466
- const blockHash = blockHashFromSingle(foreignBlockHash);
467
- const contractAddress = addressFromSingle(foreignContractAddress);
468
- const startStorageSlot = fromSingle(foreignStartStorageSlot);
469
- const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
470
-
471
- const values = await this.handlerAsUtility().getFromPublicStorage(
472
- blockHash,
473
- contractAddress,
474
- startStorageSlot,
475
- numberOfElements,
476
- );
477
-
478
- return toForeignCallResult([toArray(values)]);
479
- }
480
-
481
- // eslint-disable-next-line camelcase
482
- async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
483
- const blockHash = blockHashFromSingle(foreignBlockHash);
484
- const leafSlot = fromSingle(foreignLeafSlot);
485
-
486
- const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
487
- return toForeignCallResult(witness.toNoirRepresentation());
488
- }
489
-
490
- // eslint-disable-next-line camelcase
491
- async aztec_utl_getNotes(
492
- foreignOwnerIsSome: ForeignCallSingle,
493
- foreignOwnerValue: ForeignCallSingle,
494
- foreignStorageSlot: ForeignCallSingle,
495
- foreignNumSelects: ForeignCallSingle,
496
- foreignSelectByIndexes: ForeignCallArray,
497
- foreignSelectByOffsets: ForeignCallArray,
498
- foreignSelectByLengths: ForeignCallArray,
499
- foreignSelectValues: ForeignCallArray,
500
- foreignSelectComparators: ForeignCallArray,
501
- foreignSortByIndexes: ForeignCallArray,
502
- foreignSortByOffsets: ForeignCallArray,
503
- foreignSortByLengths: ForeignCallArray,
504
- foreignSortOrder: ForeignCallArray,
505
- foreignLimit: ForeignCallSingle,
506
- foreignOffset: ForeignCallSingle,
507
- foreignStatus: ForeignCallSingle,
508
- foreignMaxNotes: ForeignCallSingle,
509
- foreignPackedHintedNoteLength: ForeignCallSingle,
510
- ) {
511
- // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
512
- const owner = fromSingle(foreignOwnerIsSome).toBool()
513
- ? Option.some(AztecAddress.fromField(fromSingle(foreignOwnerValue)))
514
- : Option.none(AztecAddress.ZERO);
515
- const storageSlot = fromSingle(foreignStorageSlot);
516
- const numSelects = fromSingle(foreignNumSelects).toNumber();
517
- const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
518
- const selectByOffsets = fromArray(foreignSelectByOffsets).map(fr => fr.toNumber());
519
- const selectByLengths = fromArray(foreignSelectByLengths).map(fr => fr.toNumber());
520
- const selectValues = fromArray(foreignSelectValues);
521
- const selectComparators = fromArray(foreignSelectComparators).map(fr => fr.toNumber());
522
- const sortByIndexes = fromArray(foreignSortByIndexes).map(fr => fr.toNumber());
523
- const sortByOffsets = fromArray(foreignSortByOffsets).map(fr => fr.toNumber());
524
- const sortByLengths = fromArray(foreignSortByLengths).map(fr => fr.toNumber());
525
- const sortOrder = fromArray(foreignSortOrder).map(fr => fr.toNumber());
526
- const limit = fromSingle(foreignLimit).toNumber();
527
- const offset = fromSingle(foreignOffset).toNumber();
528
- const status = fromSingle(foreignStatus).toNumber();
529
- const maxNotes = fromSingle(foreignMaxNotes).toNumber();
530
- const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
531
-
532
- const noteVec = await this.handlerAsUtility().getNotes(
533
- owner,
534
- storageSlot,
535
- numSelects,
536
- selectByIndexes,
537
- selectByOffsets,
538
- selectByLengths,
539
- selectValues,
540
- selectComparators,
541
- sortByIndexes,
542
- sortByOffsets,
543
- sortByLengths,
544
- sortOrder,
545
- limit,
546
- offset,
547
- status,
548
- maxNotes,
549
- packedHintedNoteLength,
550
- );
551
-
552
- const returnDataAsArrayOfArrays = Array.from(noteVec.data).map(noteData =>
553
- packAsHintedNote({
554
- contractAddress: noteData.contractAddress,
555
- owner: noteData.owner,
556
- randomness: noteData.randomness,
557
- storageSlot: noteData.storageSlot,
558
- noteNonce: noteData.noteNonce,
559
- isPending: noteData.isPending,
560
- note: noteData.note,
561
- }),
562
- );
563
-
564
- const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
565
- subArray.map(toSingle),
566
- );
567
-
568
- return toForeignCallResult(
569
- arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
570
- );
571
- }
572
-
573
- // eslint-disable-next-line camelcase
574
- aztec_prv_notifyCreatedNote(
575
- foreignOwner: ForeignCallSingle,
576
- foreignStorageSlot: ForeignCallSingle,
577
- foreignRandomness: ForeignCallSingle,
578
- foreignNoteTypeId: ForeignCallSingle,
579
- foreignNote: ForeignCallArray,
580
- foreignNoteHash: ForeignCallSingle,
581
- foreignCounter: ForeignCallSingle,
582
- ) {
583
- const owner = addressFromSingle(foreignOwner);
584
- const storageSlot = fromSingle(foreignStorageSlot);
585
- const randomness = fromSingle(foreignRandomness);
586
- const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
587
- const note = fromArray(foreignNote);
588
- const noteHash = fromSingle(foreignNoteHash);
589
- const counter = fromSingle(foreignCounter).toNumber();
590
-
591
- this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
592
-
593
- return toForeignCallResult([]);
594
- }
595
-
596
- // eslint-disable-next-line camelcase
597
- async aztec_prv_notifyNullifiedNote(
598
- foreignInnerNullifier: ForeignCallSingle,
599
- foreignNoteHash: ForeignCallSingle,
600
- foreignCounter: ForeignCallSingle,
601
- ) {
602
- const innerNullifier = fromSingle(foreignInnerNullifier);
603
- const noteHash = fromSingle(foreignNoteHash);
604
- const counter = fromSingle(foreignCounter).toNumber();
605
-
606
- await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
607
-
608
- return toForeignCallResult([]);
609
- }
610
-
611
- // eslint-disable-next-line camelcase
612
- async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
613
- const innerNullifier = fromSingle(foreignInnerNullifier);
614
-
615
- await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
616
-
617
- return toForeignCallResult([]);
618
- }
619
-
620
- // eslint-disable-next-line camelcase
621
- async aztec_prv_isNullifierPending(
622
- foreignInnerNullifier: ForeignCallSingle,
623
- foreignContractAddress: ForeignCallSingle,
624
- ) {
625
- const innerNullifier = fromSingle(foreignInnerNullifier);
626
- const contractAddress = addressFromSingle(foreignContractAddress);
627
-
628
- const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
629
-
630
- return toForeignCallResult([toSingle(new Fr(isPending))]);
631
- }
632
-
633
- // eslint-disable-next-line camelcase
634
- async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
635
- const innerNullifier = fromSingle(foreignInnerNullifier);
309
+ aztec_prv_setHashPreimage(...inputs: ForeignCallArgs) {
310
+ return callTxeHandler({
311
+ oracle: 'aztec_prv_setHashPreimage',
312
+ inputs,
313
+ handler: ([values, hash]) => this.handlerAsPrivate().setHashPreimage(values, hash),
314
+ });
315
+ }
636
316
 
637
- const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
317
+ // eslint-disable-next-line camelcase
318
+ aztec_prv_getHashPreimage(...inputs: ForeignCallArgs) {
319
+ return callTxeHandler({
320
+ oracle: 'aztec_prv_getHashPreimage',
321
+ inputs,
322
+ handler: ([hash]) => this.handlerAsPrivate().getHashPreimage(hash),
323
+ });
324
+ }
638
325
 
639
- return toForeignCallResult([toSingle(new Fr(exists))]);
326
+ // eslint-disable-next-line camelcase
327
+ aztec_misc_log(...inputs: ForeignCallArgs) {
328
+ return callTxeHandler({
329
+ oracle: 'aztec_misc_log',
330
+ inputs,
331
+ handler: ([level, message, fieldsSize, fields]) => this.handlerAsMisc().log(level, message, fieldsSize, fields),
332
+ });
640
333
  }
641
334
 
642
335
  // eslint-disable-next-line camelcase
643
- async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
644
- const address = addressFromSingle(foreignAddress);
336
+ aztec_utl_getFromPublicStorage(...inputs: ForeignCallArgs) {
337
+ return callTxeHandler({
338
+ oracle: 'aztec_utl_getFromPublicStorage',
339
+ inputs,
340
+ handler: ([blockHash, contractAddress, startStorageSlot, numberOfElements]) =>
341
+ this.handlerAsUtility().getFromPublicStorage(blockHash, contractAddress, startStorageSlot, numberOfElements),
342
+ });
343
+ }
645
344
 
646
- const instance = await this.handlerAsUtility().getContractInstance(address);
345
+ // eslint-disable-next-line camelcase
346
+ aztec_utl_getPublicDataWitness(...inputs: ForeignCallArgs) {
347
+ return callTxeHandler({
348
+ oracle: 'aztec_utl_getPublicDataWitness',
349
+ inputs,
350
+ handler: ([blockHash, leafSlot]) => this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot),
351
+ });
352
+ }
647
353
 
648
- return toForeignCallResult(
649
- [
650
- instance.salt,
651
- instance.deployer.toField(),
652
- instance.currentContractClassId,
653
- instance.initializationHash,
654
- instance.immutablesHash,
655
- ...instance.publicKeys.toFields(),
656
- ].map(toSingle),
657
- );
354
+ // eslint-disable-next-line camelcase
355
+ aztec_utl_getNotes(...inputs: ForeignCallArgs) {
356
+ return callTxeHandler({
357
+ oracle: 'aztec_utl_getNotes',
358
+ inputs,
359
+ handler: ([
360
+ owner,
361
+ storageSlot,
362
+ numSelects,
363
+ selectByIndexes,
364
+ selectByOffsets,
365
+ selectByLengths,
366
+ selectValues,
367
+ selectComparators,
368
+ sortByIndexes,
369
+ sortByOffsets,
370
+ sortByLengths,
371
+ sortOrder,
372
+ limit,
373
+ offset,
374
+ status,
375
+ maxNotes,
376
+ packedHintedNoteLength,
377
+ ]) =>
378
+ this.handlerAsUtility().getNotes(
379
+ owner,
380
+ storageSlot,
381
+ numSelects,
382
+ selectByIndexes,
383
+ selectByOffsets,
384
+ selectByLengths,
385
+ selectValues,
386
+ selectComparators,
387
+ sortByIndexes,
388
+ sortByOffsets,
389
+ sortByLengths,
390
+ sortOrder,
391
+ limit,
392
+ offset,
393
+ status,
394
+ maxNotes,
395
+ packedHintedNoteLength,
396
+ ),
397
+ });
658
398
  }
659
399
 
660
400
  // eslint-disable-next-line camelcase
661
- async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
662
- const address = addressFromSingle(foreignAddress);
401
+ aztec_prv_notifyCreatedNote(...inputs: ForeignCallArgs) {
402
+ return callTxeHandler({
403
+ oracle: 'aztec_prv_notifyCreatedNote',
404
+ inputs,
405
+ handler: ([owner, storageSlot, randomness, noteTypeId, note, noteHash, counter]) =>
406
+ this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter),
407
+ });
408
+ }
663
409
 
664
- const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
410
+ // eslint-disable-next-line camelcase
411
+ aztec_prv_notifyNullifiedNote(...inputs: ForeignCallArgs) {
412
+ return callTxeHandler({
413
+ oracle: 'aztec_prv_notifyNullifiedNote',
414
+ inputs,
415
+ handler: ([innerNullifier, noteHash, counter]) =>
416
+ this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter),
417
+ });
418
+ }
665
419
 
666
- // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
667
- // with two fields: `some` (a boolean) and `value` (a field array in this case).
668
- if (!result.isSome()) {
669
- // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
670
- // 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.
671
- return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(8).fill(new Fr(0)))]);
672
- } else {
673
- // The Noir side hand-decodes a `[Field; 8]` here (see aztec-nr/aztec/src/oracle/keys.nr), so we
674
- // emit the 7-field PublicKeys shape + partial_address explicitly
675
- // rather than going through `publicKeys.toFields()` (which is the struct-flattened 8-field
676
- // wire for oracle returns that decode via struct shape).
677
- const { publicKeys, partialAddress } = result.value;
678
- return toForeignCallResult([
679
- toSingle(new Fr(1)),
680
- toArray([
681
- publicKeys.npkMHash,
682
- publicKeys.ivpkM.x,
683
- publicKeys.ivpkM.y,
684
- publicKeys.ovpkMHash,
685
- publicKeys.tpkMHash,
686
- publicKeys.mspkMHash,
687
- publicKeys.fbpkMHash,
688
- partialAddress,
689
- ]),
690
- ]);
691
- }
420
+ // eslint-disable-next-line camelcase
421
+ aztec_prv_notifyCreatedNullifier(...inputs: ForeignCallArgs) {
422
+ return callTxeHandler({
423
+ oracle: 'aztec_prv_notifyCreatedNullifier',
424
+ inputs,
425
+ handler: ([innerNullifier]) => this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier),
426
+ });
692
427
  }
693
428
 
694
429
  // eslint-disable-next-line camelcase
695
- async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
696
- const pkMHash = fromSingle(foreignPkMHash);
430
+ aztec_prv_isNullifierPending(...inputs: ForeignCallArgs) {
431
+ return callTxeHandler({
432
+ oracle: 'aztec_prv_isNullifierPending',
433
+ inputs,
434
+ handler: ([innerNullifier, contractAddress]) =>
435
+ this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress),
436
+ });
437
+ }
697
438
 
698
- const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
439
+ // eslint-disable-next-line camelcase
440
+ aztec_utl_doesNullifierExist(...inputs: ForeignCallArgs) {
441
+ return callTxeHandler({
442
+ oracle: 'aztec_utl_doesNullifierExist',
443
+ inputs,
444
+ handler: ([innerNullifier]) => this.handlerAsUtility().doesNullifierExist(innerNullifier),
445
+ });
446
+ }
699
447
 
700
- return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
448
+ // eslint-disable-next-line camelcase
449
+ aztec_utl_getContractInstance(...inputs: ForeignCallArgs) {
450
+ return callTxeHandler({
451
+ oracle: 'aztec_utl_getContractInstance',
452
+ inputs,
453
+ handler: ([address]) => this.handlerAsUtility().getContractInstance(address),
454
+ });
701
455
  }
702
456
 
703
457
  // eslint-disable-next-line camelcase
704
- async aztec_prv_callPrivateFunction(
705
- foreignTargetContractAddress: ForeignCallSingle,
706
- foreignFunctionSelector: ForeignCallSingle,
707
- foreignArgsHash: ForeignCallSingle,
708
- foreignSideEffectCounter: ForeignCallSingle,
709
- foreignIsStaticCall: ForeignCallSingle,
710
- ) {
711
- const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
712
- const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
713
- const argsHash = fromSingle(foreignArgsHash);
714
- const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
715
- const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
458
+ aztec_utl_getPublicKeysAndPartialAddress(...inputs: ForeignCallArgs) {
459
+ return callTxeHandler({
460
+ oracle: 'aztec_utl_getPublicKeysAndPartialAddress',
461
+ inputs,
462
+ handler: ([address]) => this.handlerAsUtility().getPublicKeysAndPartialAddress(address),
463
+ });
464
+ }
716
465
 
717
- const { endSideEffectCounter, returnsHash } = await this.handlerAsPrivate().callPrivateFunction(
718
- targetContractAddress,
719
- functionSelector,
720
- argsHash,
721
- sideEffectCounter,
722
- isStaticCall,
723
- );
724
- return toForeignCallResult([[endSideEffectCounter, returnsHash].map(toSingle)]);
466
+ // eslint-disable-next-line camelcase
467
+ aztec_utl_getKeyValidationRequest(...inputs: ForeignCallArgs) {
468
+ return callTxeHandler({
469
+ oracle: 'aztec_utl_getKeyValidationRequest',
470
+ inputs,
471
+ handler: ([pkMHash, keyIndex]) => this.handlerAsUtility().getKeyValidationRequest(pkMHash, keyIndex),
472
+ });
725
473
  }
726
474
 
727
475
  // eslint-disable-next-line camelcase
728
- async aztec_utl_getNullifierMembershipWitness(
729
- foreignBlockHash: ForeignCallSingle,
730
- foreignNullifier: ForeignCallSingle,
731
- ) {
732
- const blockHash = blockHashFromSingle(foreignBlockHash);
733
- const nullifier = fromSingle(foreignNullifier);
476
+ aztec_prv_callPrivateFunction(...inputs: ForeignCallArgs) {
477
+ return callTxeHandler({
478
+ oracle: 'aztec_prv_callPrivateFunction',
479
+ inputs,
480
+ handler: ([contractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall]) =>
481
+ this.handlerAsPrivate().callPrivateFunction(
482
+ contractAddress,
483
+ functionSelector,
484
+ argsHash,
485
+ sideEffectCounter,
486
+ isStaticCall,
487
+ ),
488
+ });
489
+ }
734
490
 
735
- const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
736
- return toForeignCallResult(witness.toNoirRepresentation());
491
+ // eslint-disable-next-line camelcase
492
+ aztec_utl_getNullifierMembershipWitness(...inputs: ForeignCallArgs) {
493
+ return callTxeHandler({
494
+ oracle: 'aztec_utl_getNullifierMembershipWitness',
495
+ inputs,
496
+ handler: ([blockHash, nullifier]) => this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier),
497
+ });
737
498
  }
738
499
 
739
500
  // eslint-disable-next-line camelcase
740
- async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
741
- const messageHash = fromSingle(foreignMessageHash);
501
+ aztec_utl_getL1ToL2MembershipWitnessV2(...inputs: ForeignCallArgs) {
502
+ return callTxeHandler({
503
+ oracle: 'aztec_utl_getL1ToL2MembershipWitnessV2',
504
+ inputs,
505
+ handler: ([messageHash, nullifier]) =>
506
+ this.handlerAsUtility().getL1ToL2MembershipWitnessV2(messageHash, nullifier),
507
+ });
508
+ }
742
509
 
743
- const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
744
- return toForeignCallResult([toArray(authWitness)]);
510
+ // eslint-disable-next-line camelcase
511
+ aztec_utl_getAuthWitness(...inputs: ForeignCallArgs) {
512
+ return callTxeHandler({
513
+ oracle: 'aztec_utl_getAuthWitness',
514
+ inputs,
515
+ handler: ([messageHash]) => this.handlerAsUtility().getAuthWitness(messageHash),
516
+ });
745
517
  }
746
518
 
747
519
  // eslint-disable-next-line camelcase
748
- public async aztec_prv_assertValidPublicCalldata(foreignCalldataHash: ForeignCallSingle) {
749
- const calldataHash = fromSingle(foreignCalldataHash);
750
- await this.handlerAsPrivate().assertValidPublicCalldata(calldataHash);
751
- return toForeignCallResult([]);
520
+ aztec_prv_assertValidPublicCalldata(...inputs: ForeignCallArgs) {
521
+ return callTxeHandler({
522
+ oracle: 'aztec_prv_assertValidPublicCalldata',
523
+ inputs,
524
+ handler: ([calldataHash]) => this.handlerAsPrivate().assertValidPublicCalldata(calldataHash),
525
+ });
752
526
  }
753
527
 
754
528
  // eslint-disable-next-line camelcase
755
- public async aztec_prv_notifyRevertiblePhaseStart(foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
756
- const minRevertibleSideEffectCounter = fromSingle(foreignMinRevertibleSideEffectCounter).toNumber();
757
- await this.handlerAsPrivate().notifyRevertiblePhaseStart(minRevertibleSideEffectCounter);
758
- return toForeignCallResult([]);
529
+ aztec_prv_notifyRevertiblePhaseStart(...inputs: ForeignCallArgs) {
530
+ return callTxeHandler({
531
+ oracle: 'aztec_prv_notifyRevertiblePhaseStart',
532
+ inputs,
533
+ handler: ([minRevertibleSideEffectCounter]) =>
534
+ this.handlerAsPrivate().notifyRevertiblePhaseStart(minRevertibleSideEffectCounter),
535
+ });
759
536
  }
760
537
 
761
538
  // eslint-disable-next-line camelcase
762
- public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
763
- const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
764
- const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
765
- return toForeignCallResult([toSingle(new Fr(isRevertible))]);
539
+ aztec_prv_isExecutionInRevertiblePhase(...inputs: ForeignCallArgs) {
540
+ return callTxeHandler({
541
+ oracle: 'aztec_prv_isExecutionInRevertiblePhase',
542
+ inputs,
543
+ handler: ([sideEffectCounter]) => this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter),
544
+ });
766
545
  }
767
546
 
768
547
  // eslint-disable-next-line camelcase
769
548
  aztec_utl_getUtilityContext() {
770
- const context = this.handlerAsUtility().getUtilityContext();
771
-
772
- return toForeignCallResult(context.toNoirRepresentation());
549
+ return callTxeHandler({
550
+ oracle: 'aztec_utl_getUtilityContext',
551
+ inputs: [],
552
+ handler: () => this.handlerAsUtility().getUtilityContext(),
553
+ });
773
554
  }
774
555
 
775
556
  // eslint-disable-next-line camelcase
776
- async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
777
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
778
-
779
- const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
780
- return toForeignCallResult(header.toFields().map(toSingle));
557
+ aztec_utl_getBlockHeader(...inputs: ForeignCallArgs) {
558
+ return callTxeHandler({
559
+ oracle: 'aztec_utl_getBlockHeader',
560
+ inputs,
561
+ handler: ([blockNumber]) => this.handlerAsUtility().getBlockHeader(blockNumber),
562
+ });
781
563
  }
782
564
 
783
565
  // eslint-disable-next-line camelcase
784
- async aztec_utl_getNoteHashMembershipWitness(
785
- foreignAnchorBlockHash: ForeignCallSingle,
786
- foreignNoteHash: ForeignCallSingle,
787
- ) {
788
- const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
789
- const noteHash = fromSingle(foreignNoteHash);
790
-
791
- const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
792
- return toForeignCallResult(witness.toNoirRepresentation());
566
+ aztec_utl_getNoteHashMembershipWitness(...inputs: ForeignCallArgs) {
567
+ return callTxeHandler({
568
+ oracle: 'aztec_utl_getNoteHashMembershipWitness',
569
+ inputs,
570
+ handler: ([blockHash, noteHash]) => this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash),
571
+ });
793
572
  }
794
573
 
795
574
  // eslint-disable-next-line camelcase
796
- async aztec_utl_getBlockHashMembershipWitness(
797
- foreignAnchorBlockHash: ForeignCallSingle,
798
- foreignBlockHash: ForeignCallSingle,
799
- ) {
800
- const anchorBlockHash = blockHashFromSingle(foreignAnchorBlockHash);
801
- const blockHash = blockHashFromSingle(foreignBlockHash);
802
-
803
- const witnessOpt = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
804
- const effective = witnessOpt.value ?? MembershipWitness.empty(ARCHIVE_HEIGHT);
805
- return toForeignCallResult([toSingle(new Fr(witnessOpt.isSome() ? 1 : 0)), ...effective.toNoirRepresentation()]);
575
+ aztec_utl_getBlockHashMembershipWitness(...inputs: ForeignCallArgs) {
576
+ return callTxeHandler({
577
+ oracle: 'aztec_utl_getBlockHashMembershipWitness',
578
+ inputs,
579
+ handler: ([anchorBlockHash, blockHash]) =>
580
+ this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash),
581
+ });
806
582
  }
807
583
 
808
584
  // eslint-disable-next-line camelcase
809
- async aztec_utl_getLowNullifierMembershipWitness(
810
- foreignBlockHash: ForeignCallSingle,
811
- foreignNullifier: ForeignCallSingle,
812
- ) {
813
- const blockHash = blockHashFromSingle(foreignBlockHash);
814
- const nullifier = fromSingle(foreignNullifier);
815
-
816
- const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
817
- return toForeignCallResult(witness.toNoirRepresentation());
585
+ aztec_utl_areBlockHashesInArchive(...inputs: ForeignCallArgs) {
586
+ return callTxeHandler({
587
+ oracle: 'aztec_utl_areBlockHashesInArchive',
588
+ inputs,
589
+ handler: ([anchorBlockHash, blockHashes]) =>
590
+ this.handlerAsUtility().areBlockHashesInArchive(anchorBlockHash, blockHashes),
591
+ });
818
592
  }
819
593
 
820
594
  // eslint-disable-next-line camelcase
821
- async aztec_utl_getPendingTaggedLogs(foreignScope: ForeignCallSingle) {
822
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
823
- const slot = await this.handlerAsUtility().getPendingTaggedLogs(scope);
824
- return toForeignCallResult([toSingle(slot)]);
595
+ aztec_utl_getLowNullifierMembershipWitness(...inputs: ForeignCallArgs) {
596
+ return callTxeHandler({
597
+ oracle: 'aztec_utl_getLowNullifierMembershipWitness',
598
+ inputs,
599
+ handler: ([blockHash, nullifier]) =>
600
+ this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier),
601
+ });
825
602
  }
826
603
 
827
604
  // eslint-disable-next-line camelcase
828
- public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
829
- foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
830
- foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
831
- foreignScope: ForeignCallSingle,
832
- ) {
833
- const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
834
- const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
835
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
836
-
837
- await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
838
- noteValidationRequestsArrayBaseSlot,
839
- eventValidationRequestsArrayBaseSlot,
840
- scope,
841
- );
605
+ aztec_utl_getPendingTaggedLogsV2(...inputs: ForeignCallArgs) {
606
+ return callTxeHandler({
607
+ oracle: 'aztec_utl_getPendingTaggedLogsV2',
608
+ inputs,
609
+ handler: ([scope, providedSecrets]) => this.handlerAsUtility().getPendingTaggedLogsV2(scope, providedSecrets),
610
+ });
611
+ }
842
612
 
843
- return toForeignCallResult([]);
613
+ // eslint-disable-next-line camelcase
614
+ aztec_utl_validateAndStoreEnqueuedNotesAndEvents(...inputs: ForeignCallArgs) {
615
+ return callTxeHandler({
616
+ oracle: 'aztec_utl_validateAndStoreEnqueuedNotesAndEvents',
617
+ inputs,
618
+ handler: ([noteValidationRequests, eventValidationRequests, scope]) =>
619
+ this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
620
+ noteValidationRequests,
621
+ eventValidationRequests,
622
+ scope,
623
+ ),
624
+ });
844
625
  }
845
626
 
846
627
  // eslint-disable-next-line camelcase
847
- async aztec_utl_getLogsByTag(foreignRequestArrayBaseSlot: ForeignCallSingle) {
848
- const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
849
- const responseSlot = await this.handlerAsUtility().getLogsByTag(requestArrayBaseSlot);
850
- return toForeignCallResult([toSingle(responseSlot)]);
628
+ aztec_utl_getLogsByTagV2(...inputs: ForeignCallArgs) {
629
+ return callTxeHandler({
630
+ oracle: 'aztec_utl_getLogsByTagV2',
631
+ inputs,
632
+ handler: ([requestArrayBaseSlot]) => this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot),
633
+ });
851
634
  }
852
635
 
853
636
  // eslint-disable-next-line camelcase
854
- async aztec_utl_getMessageContextsByTxHash(foreignRequestArrayBaseSlot: ForeignCallSingle) {
855
- const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
856
- const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHash(requestArrayBaseSlot);
857
- return toForeignCallResult([toSingle(responseSlot)]);
637
+ aztec_utl_getResolvedTxs(...inputs: ForeignCallArgs) {
638
+ return callTxeHandler({
639
+ oracle: 'aztec_utl_getResolvedTxs',
640
+ inputs,
641
+ handler: ([requestArrayBaseSlot]) => this.handlerAsUtility().getResolvedTxs(requestArrayBaseSlot),
642
+ });
858
643
  }
859
644
 
860
645
  // eslint-disable-next-line camelcase
861
- aztec_utl_setCapsule(
862
- foreignContractAddress: ForeignCallSingle,
863
- foreignSlot: ForeignCallSingle,
864
- foreignCapsule: ForeignCallArray,
865
- foreignScope: ForeignCallSingle,
866
- ) {
867
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
868
- const slot = fromSingle(foreignSlot);
869
- const capsule = fromArray(foreignCapsule);
870
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
646
+ aztec_utl_getTxEffects(...inputs: ForeignCallArgs) {
647
+ return callTxeHandler({
648
+ oracle: 'aztec_utl_getTxEffects',
649
+ inputs,
650
+ handler: ([txHashes]) => this.handlerAsUtility().getTxEffects(txHashes),
651
+ });
652
+ }
871
653
 
872
- this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
654
+ // eslint-disable-next-line camelcase
655
+ aztec_utl_setCapsule(...inputs: ForeignCallArgs) {
656
+ return callTxeHandler({
657
+ oracle: 'aztec_utl_setCapsule',
658
+ inputs,
659
+ handler: ([contractAddress, slot, capsule, scope]) =>
660
+ this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope),
661
+ });
662
+ }
873
663
 
874
- return toForeignCallResult([]);
664
+ // eslint-disable-next-line camelcase
665
+ aztec_utl_getCapsule(...inputs: ForeignCallArgs) {
666
+ return callTxeHandler({
667
+ oracle: 'aztec_utl_getCapsule',
668
+ inputs,
669
+ handler: ([contractAddress, slot, tSize, scope]) =>
670
+ this.handlerAsUtility().getCapsule(contractAddress, slot, tSize, scope),
671
+ });
875
672
  }
876
673
 
877
674
  // eslint-disable-next-line camelcase
878
- async aztec_utl_getCapsule(
879
- foreignContractAddress: ForeignCallSingle,
880
- foreignSlot: ForeignCallSingle,
881
- foreignTSize: ForeignCallSingle,
882
- foreignScope: ForeignCallSingle,
883
- ) {
884
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
885
- const slot = fromSingle(foreignSlot);
886
- const tSize = fromSingle(foreignTSize).toNumber();
887
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
675
+ aztec_utl_deleteCapsule(...inputs: ForeignCallArgs) {
676
+ return callTxeHandler({
677
+ oracle: 'aztec_utl_deleteCapsule',
678
+ inputs,
679
+ handler: ([contractAddress, slot, scope]) => this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope),
680
+ });
681
+ }
888
682
 
889
- const opt = await this.handlerAsUtility().getCapsule(contractAddress, slot, tSize, scope);
683
+ // eslint-disable-next-line camelcase
684
+ aztec_utl_copyCapsule(...inputs: ForeignCallArgs) {
685
+ return callTxeHandler({
686
+ oracle: 'aztec_utl_copyCapsule',
687
+ inputs,
688
+ handler: ([contractAddress, srcSlot, dstSlot, numEntries, scope]) =>
689
+ this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope),
690
+ });
691
+ }
890
692
 
891
- // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
892
- // with two fields: `some` (a boolean) and `value` (a field array in this case).
893
- if (opt.isSome()) {
894
- // Data was found so we set `some` to 1 and return it along with `value`.
895
- return toForeignCallResult([toSingle(new Fr(1)), toArray(Array.from(opt.value))]);
896
- } else {
897
- // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
898
- return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(tSize).fill(new Fr(0)))]);
899
- }
693
+ // eslint-disable-next-line camelcase
694
+ aztec_utl_pushEphemeral(...inputs: ForeignCallArgs) {
695
+ return callTxeHandler({
696
+ oracle: 'aztec_utl_pushEphemeral',
697
+ inputs,
698
+ handler: ([slot, elements]) => this.handlerAsUtility().pushEphemeral(slot, elements),
699
+ });
900
700
  }
901
701
 
902
702
  // eslint-disable-next-line camelcase
903
- aztec_utl_deleteCapsule(
904
- foreignContractAddress: ForeignCallSingle,
905
- foreignSlot: ForeignCallSingle,
906
- foreignScope: ForeignCallSingle,
907
- ) {
908
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
909
- const slot = fromSingle(foreignSlot);
910
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
703
+ aztec_utl_popEphemeral(...inputs: ForeignCallArgs) {
704
+ return callTxeHandler({
705
+ oracle: 'aztec_utl_popEphemeral',
706
+ inputs,
707
+ handler: ([slot]) => this.handlerAsUtility().popEphemeral(slot),
708
+ });
709
+ }
911
710
 
912
- this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
711
+ // eslint-disable-next-line camelcase
712
+ aztec_utl_getEphemeral(...inputs: ForeignCallArgs) {
713
+ return callTxeHandler({
714
+ oracle: 'aztec_utl_getEphemeral',
715
+ inputs,
716
+ handler: ([slot, index]) => this.handlerAsUtility().getEphemeral(slot, index),
717
+ });
718
+ }
913
719
 
914
- return toForeignCallResult([]);
720
+ // eslint-disable-next-line camelcase
721
+ aztec_utl_setEphemeral(...inputs: ForeignCallArgs) {
722
+ return callTxeHandler({
723
+ oracle: 'aztec_utl_setEphemeral',
724
+ inputs,
725
+ handler: ([slot, index, elements]) => this.handlerAsUtility().setEphemeral(slot, index, elements),
726
+ });
915
727
  }
916
728
 
917
729
  // eslint-disable-next-line camelcase
918
- async aztec_utl_copyCapsule(
919
- foreignContractAddress: ForeignCallSingle,
920
- foreignSrcSlot: ForeignCallSingle,
921
- foreignDstSlot: ForeignCallSingle,
922
- foreignNumEntries: ForeignCallSingle,
923
- foreignScope: ForeignCallSingle,
924
- ) {
925
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
926
- const srcSlot = fromSingle(foreignSrcSlot);
927
- const dstSlot = fromSingle(foreignDstSlot);
928
- const numEntries = fromSingle(foreignNumEntries).toNumber();
929
- const scope = AztecAddress.fromField(fromSingle(foreignScope));
730
+ aztec_utl_getEphemeralLen(...inputs: ForeignCallArgs) {
731
+ return callTxeHandler({
732
+ oracle: 'aztec_utl_getEphemeralLen',
733
+ inputs,
734
+ handler: ([slot]) => this.handlerAsUtility().getEphemeralLen(slot),
735
+ });
736
+ }
930
737
 
931
- await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
738
+ // eslint-disable-next-line camelcase
739
+ aztec_utl_removeEphemeral(...inputs: ForeignCallArgs) {
740
+ return callTxeHandler({
741
+ oracle: 'aztec_utl_removeEphemeral',
742
+ inputs,
743
+ handler: ([slot, index]) => this.handlerAsUtility().removeEphemeral(slot, index),
744
+ });
745
+ }
932
746
 
933
- return toForeignCallResult([]);
747
+ // eslint-disable-next-line camelcase
748
+ aztec_utl_clearEphemeral(...inputs: ForeignCallArgs) {
749
+ return callTxeHandler({
750
+ oracle: 'aztec_utl_clearEphemeral',
751
+ inputs,
752
+ handler: ([slot]) => this.handlerAsUtility().clearEphemeral(slot),
753
+ });
934
754
  }
935
755
 
936
756
  // eslint-disable-next-line camelcase
937
- aztec_utl_pushEphemeral(foreignSlot: ForeignCallSingle, foreignElements: ForeignCallArray) {
938
- const slot = fromSingle(foreignSlot);
939
- const elements = fromArray(foreignElements);
940
- const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
941
- return toForeignCallResult([toSingle(new Fr(newLen))]);
757
+ aztec_utl_pushTransient(...inputs: ForeignCallArgs) {
758
+ return callTxeHandler({
759
+ oracle: 'aztec_utl_pushTransient',
760
+ inputs,
761
+ handler: ([slot, elements]) => this.handlerAsUtility().pushTransient(slot, elements),
762
+ });
942
763
  }
943
764
 
944
765
  // eslint-disable-next-line camelcase
945
- aztec_utl_popEphemeral(foreignSlot: ForeignCallSingle) {
946
- const slot = fromSingle(foreignSlot);
947
- const element = this.handlerAsUtility().popEphemeral(slot);
948
- return toForeignCallResult([toArray(element)]);
766
+ aztec_utl_popTransient(...inputs: ForeignCallArgs) {
767
+ return callTxeHandler({
768
+ oracle: 'aztec_utl_popTransient',
769
+ inputs,
770
+ handler: ([slot]) => this.handlerAsUtility().popTransient(slot),
771
+ });
949
772
  }
950
773
 
951
774
  // eslint-disable-next-line camelcase
952
- aztec_utl_getEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
953
- const slot = fromSingle(foreignSlot);
954
- const index = fromSingle(foreignIndex).toNumber();
955
- const element = this.handlerAsUtility().getEphemeral(slot, index);
956
- return toForeignCallResult([toArray(element)]);
775
+ aztec_utl_getTransient(...inputs: ForeignCallArgs) {
776
+ return callTxeHandler({
777
+ oracle: 'aztec_utl_getTransient',
778
+ inputs,
779
+ handler: ([slot, index]) => this.handlerAsUtility().getTransient(slot, index),
780
+ });
957
781
  }
958
782
 
959
783
  // eslint-disable-next-line camelcase
960
- aztec_utl_setEphemeral(
961
- foreignSlot: ForeignCallSingle,
962
- foreignIndex: ForeignCallSingle,
963
- foreignElements: ForeignCallArray,
964
- ) {
965
- const slot = fromSingle(foreignSlot);
966
- const index = fromSingle(foreignIndex).toNumber();
967
- const elements = fromArray(foreignElements);
968
- this.handlerAsUtility().setEphemeral(slot, index, elements);
969
- return toForeignCallResult([]);
784
+ aztec_utl_setTransient(...inputs: ForeignCallArgs) {
785
+ return callTxeHandler({
786
+ oracle: 'aztec_utl_setTransient',
787
+ inputs,
788
+ handler: ([slot, index, elements]) => this.handlerAsUtility().setTransient(slot, index, elements),
789
+ });
970
790
  }
971
791
 
972
792
  // eslint-disable-next-line camelcase
973
- aztec_utl_getEphemeralLen(foreignSlot: ForeignCallSingle) {
974
- const slot = fromSingle(foreignSlot);
975
- const len = this.handlerAsUtility().getEphemeralLen(slot);
976
- return toForeignCallResult([toSingle(new Fr(len))]);
793
+ aztec_utl_getTransientLen(...inputs: ForeignCallArgs) {
794
+ return callTxeHandler({
795
+ oracle: 'aztec_utl_getTransientLen',
796
+ inputs,
797
+ handler: ([slot]) => this.handlerAsUtility().getTransientLen(slot),
798
+ });
977
799
  }
978
800
 
979
801
  // eslint-disable-next-line camelcase
980
- aztec_utl_removeEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
981
- const slot = fromSingle(foreignSlot);
982
- const index = fromSingle(foreignIndex).toNumber();
983
- this.handlerAsUtility().removeEphemeral(slot, index);
984
- return toForeignCallResult([]);
802
+ aztec_utl_removeTransient(...inputs: ForeignCallArgs) {
803
+ return callTxeHandler({
804
+ oracle: 'aztec_utl_removeTransient',
805
+ inputs,
806
+ handler: ([slot, index]) => this.handlerAsUtility().removeTransient(slot, index),
807
+ });
985
808
  }
986
809
 
987
810
  // eslint-disable-next-line camelcase
988
- aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
989
- const slot = fromSingle(foreignSlot);
990
- this.handlerAsUtility().clearEphemeral(slot);
991
- return toForeignCallResult([]);
811
+ aztec_utl_clearTransient(...inputs: ForeignCallArgs) {
812
+ return callTxeHandler({
813
+ oracle: 'aztec_utl_clearTransient',
814
+ inputs,
815
+ handler: ([slot]) => this.handlerAsUtility().clearTransient(slot),
816
+ });
992
817
  }
993
818
 
994
819
  // TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
@@ -996,311 +821,316 @@ export class RPCTranslator {
996
821
  // to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
997
822
  // existence of a txe_oracle method?
998
823
  // eslint-disable-next-line camelcase
999
- async aztec_utl_decryptAes128(
1000
- foreignCiphertextBVecStorage: ForeignCallArray,
1001
- foreignCiphertextLength: ForeignCallSingle,
1002
- foreignIv: ForeignCallArray,
1003
- foreignSymKey: ForeignCallArray,
1004
- ) {
1005
- const capacity = foreignCiphertextBVecStorage.length;
1006
- const ciphertextBuf = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
1007
- const ciphertext = BoundedVec.from<number>({ data: [...ciphertextBuf], maxLength: capacity });
1008
- const iv = fromUintArray(foreignIv, 8);
1009
- const symKey = fromUintArray(foreignSymKey, 8);
1010
-
1011
- // Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
1012
- const plaintextOpt = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
1013
- if (plaintextOpt.isSome()) {
1014
- const [storage, length] = arrayToBoundedVec(bufferToU8Array(Buffer.from(plaintextOpt.value.data)), capacity);
1015
- return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
1016
- } else {
1017
- const zeroStorage = toArray(Array(capacity).fill(new Fr(0)));
1018
- return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
1019
- }
824
+ aztec_utl_decryptAes128(...inputs: ForeignCallArgs) {
825
+ return callTxeHandler({
826
+ oracle: 'aztec_utl_decryptAes128',
827
+ inputs,
828
+ handler: ([ciphertext, iv, symKey]) => this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey),
829
+ });
1020
830
  }
1021
831
 
1022
832
  // eslint-disable-next-line camelcase
1023
- async aztec_utl_getSharedSecrets(
1024
- foreignAddress: ForeignCallSingle,
1025
- foreignEphPksSlot: ForeignCallSingle,
1026
- foreignContractAddress: ForeignCallSingle,
1027
- ) {
1028
- const address = AztecAddress.fromField(fromSingle(foreignAddress));
1029
- const ephPksSlot = fromSingle(foreignEphPksSlot);
1030
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
1031
-
1032
- const responseSlot = await this.handlerAsUtility().getSharedSecrets(address, ephPksSlot, contractAddress);
1033
-
1034
- return toForeignCallResult([toSingle(responseSlot)]);
833
+ aztec_utl_getSharedSecrets(...inputs: ForeignCallArgs) {
834
+ return callTxeHandler({
835
+ oracle: 'aztec_utl_getSharedSecrets',
836
+ inputs,
837
+ handler: ([address, ephPksSlot, contractAddress]) =>
838
+ this.handlerAsUtility().getSharedSecrets(address, ephPksSlot, contractAddress),
839
+ });
1035
840
  }
1036
841
 
1037
842
  // eslint-disable-next-line camelcase
1038
- aztec_utl_setContractSyncCacheInvalid(
1039
- foreignContractAddress: ForeignCallSingle,
1040
- foreignScopes: ForeignCallArray,
1041
- foreignScopeCount: ForeignCallSingle,
1042
- ) {
1043
- const contractAddress = addressFromSingle(foreignContractAddress);
1044
- const allFields = fromArray(foreignScopes);
1045
- const count = fromSingle(foreignScopeCount).toNumber();
1046
- const scopes = BoundedVec.from({
1047
- data: allFields.slice(0, count).map(f => new AztecAddress(f)),
1048
- maxLength: allFields.length,
843
+ aztec_utl_setContractSyncCacheInvalid(...inputs: ForeignCallArgs) {
844
+ return callTxeHandler({
845
+ oracle: 'aztec_utl_setContractSyncCacheInvalid',
846
+ inputs,
847
+ handler: ([contractAddress, scopes]) =>
848
+ this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes),
1049
849
  });
1050
-
1051
- this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
1052
-
1053
- return Promise.resolve(toForeignCallResult([]));
1054
850
  }
1055
851
 
1056
852
  // eslint-disable-next-line camelcase
1057
- aztec_utl_emitOffchainEffect(foreignData: ForeignCallArray) {
1058
- // Record the raw payload against the currently-executing top-level call. The Noir side
1059
- // (via `env.offchain_messages()`) is responsible for decoding the protocol-reserved prefix
1060
- // (`OFFCHAIN_MESSAGE_IDENTIFIER`, recipient) and turning each payload into an `OffchainMessage` struct suitable
1061
- // for `offchain_receive`.
1062
- this.stateHandler.recordOffchainEffect(fromArray(foreignData));
1063
- return Promise.resolve(toForeignCallResult([]));
853
+ aztec_utl_emitOffchainEffect(...inputs: ForeignCallArgs) {
854
+ return callTxeHandler({
855
+ oracle: 'aztec_utl_emitOffchainEffect',
856
+ inputs,
857
+ handler: ([data]) => {
858
+ // Record the raw payload against the currently-executing top-level call. The Noir side
859
+ // (via `env.offchain_messages()`) is responsible for decoding the protocol-reserved prefix
860
+ // (`OFFCHAIN_MESSAGE_IDENTIFIER`, recipient) and turning each payload into an `OffchainMessage` struct suitable
861
+ // for `offchain_receive`.
862
+ this.stateHandler.recordOffchainEffect(data);
863
+ },
864
+ });
1064
865
  }
1065
866
 
1066
- // AVM opcodes
1067
-
1068
867
  // eslint-disable-next-line camelcase
1069
- aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
1070
- // TODO(#8811): Implement
1071
- return toForeignCallResult([]);
868
+ aztec_utl_recordFact(...inputs: ForeignCallArgs) {
869
+ return callTxeHandler({
870
+ oracle: 'aztec_utl_recordFact',
871
+ inputs,
872
+ handler: ([contractAddress, scope, factCollectionTypeId, factCollectionId, factTypeId, payload, originBlock]) =>
873
+ this.handlerAsUtility().recordFact(
874
+ contractAddress,
875
+ scope,
876
+ factCollectionTypeId,
877
+ factCollectionId,
878
+ factTypeId,
879
+ payload,
880
+ originBlock,
881
+ ),
882
+ });
1072
883
  }
1073
884
 
1074
885
  // eslint-disable-next-line camelcase
1075
- async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
1076
- const slot = fromSingle(foreignSlot);
1077
- const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
1078
-
1079
- const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
1080
-
1081
- return toForeignCallResult([toSingle(new Fr(value))]);
886
+ aztec_utl_deleteFactCollection(...inputs: ForeignCallArgs) {
887
+ return callTxeHandler({
888
+ oracle: 'aztec_utl_deleteFactCollection',
889
+ inputs,
890
+ handler: ([contractAddress, scope, factCollectionTypeId, factCollectionId]) =>
891
+ this.handlerAsUtility().deleteFactCollection(contractAddress, scope, factCollectionTypeId, factCollectionId),
892
+ });
1082
893
  }
1083
894
 
1084
895
  // eslint-disable-next-line camelcase
1085
- async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
1086
- const slot = fromSingle(foreignSlot);
1087
- const value = fromSingle(foreignValue);
1088
-
1089
- await this.handlerAsAvm().storageWrite(slot, value);
1090
-
1091
- return toForeignCallResult([]);
896
+ aztec_utl_getFactCollection(...inputs: ForeignCallArgs) {
897
+ return callTxeHandler({
898
+ oracle: 'aztec_utl_getFactCollection',
899
+ inputs,
900
+ handler: ([contractAddress, scope, factCollectionTypeId, factCollectionId]) =>
901
+ this.handlerAsUtility().getFactCollection(contractAddress, scope, factCollectionTypeId, factCollectionId),
902
+ });
1092
903
  }
1093
904
 
1094
905
  // eslint-disable-next-line camelcase
1095
- async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
1096
- const address = addressFromSingle(foreignAddress);
1097
-
1098
- const instance = await this.handlerAsUtility().getContractInstance(address);
1099
-
1100
- return toForeignCallResult([
1101
- toSingle(instance.deployer),
1102
- // AVM requires an extra boolean indicating the instance was found
1103
- toSingle(new Fr(1)),
1104
- ]);
906
+ aztec_utl_getFactCollectionsByType(...inputs: ForeignCallArgs) {
907
+ return callTxeHandler({
908
+ oracle: 'aztec_utl_getFactCollectionsByType',
909
+ inputs,
910
+ handler: ([contractAddress, scope, factCollectionTypeId]) =>
911
+ this.handlerAsUtility().getFactCollectionsByType(contractAddress, scope, factCollectionTypeId),
912
+ });
1105
913
  }
1106
914
 
1107
915
  // eslint-disable-next-line camelcase
1108
- async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
1109
- const address = addressFromSingle(foreignAddress);
916
+ aztec_utl_callUtilityFunction(...inputs: ForeignCallArgs) {
917
+ return callTxeHandler({
918
+ oracle: 'aztec_utl_callUtilityFunction',
919
+ inputs,
920
+ handler: ([contractAddress, functionSelector, args]) =>
921
+ this.handlerAsUtility().callUtilityFunction(contractAddress, functionSelector, args),
922
+ });
923
+ }
1110
924
 
1111
- const instance = await this.handlerAsUtility().getContractInstance(address);
925
+ // AVM opcodes
1112
926
 
1113
- return toForeignCallResult([
1114
- toSingle(instance.currentContractClassId),
1115
- // AVM requires an extra boolean indicating the instance was found
1116
- toSingle(new Fr(1)),
1117
- ]);
927
+ // eslint-disable-next-line camelcase
928
+ aztec_avm_emitPublicLog() {
929
+ return callTxeHandler({
930
+ oracle: 'aztec_avm_emitPublicLog',
931
+ inputs: [],
932
+ // TODO(#8811): Implement
933
+ handler: () => {},
934
+ });
1118
935
  }
1119
936
 
1120
937
  // eslint-disable-next-line camelcase
1121
- async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
1122
- const address = addressFromSingle(foreignAddress);
1123
-
1124
- const instance = await this.handlerAsUtility().getContractInstance(address);
1125
-
1126
- return toForeignCallResult([
1127
- toSingle(instance.initializationHash),
1128
- // AVM requires an extra boolean indicating the instance was found
1129
- toSingle(new Fr(1)),
1130
- ]);
938
+ aztec_avm_storageRead(...inputs: ForeignCallArgs) {
939
+ return callTxeHandler({
940
+ oracle: 'aztec_avm_storageRead',
941
+ inputs,
942
+ handler: ([slot, contractAddress]) => this.handlerAsAvm().storageRead(slot, contractAddress),
943
+ });
1131
944
  }
1132
945
 
1133
946
  // eslint-disable-next-line camelcase
1134
- async aztec_avm_getContractInstanceImmutablesHash(foreignAddress: ForeignCallSingle) {
1135
- const address = addressFromSingle(foreignAddress);
1136
-
1137
- const instance = await this.handlerAsUtility().getContractInstance(address);
1138
-
1139
- return toForeignCallResult([
1140
- toSingle(instance.immutablesHash),
1141
- // AVM requires an extra boolean indicating the instance was found
1142
- toSingle(new Fr(1)),
1143
- ]);
947
+ aztec_avm_storageWrite(...inputs: ForeignCallArgs) {
948
+ return callTxeHandler({
949
+ oracle: 'aztec_avm_storageWrite',
950
+ inputs,
951
+ handler: ([slot, value]) => this.handlerAsAvm().storageWrite(slot, value),
952
+ });
1144
953
  }
1145
954
 
1146
955
  // eslint-disable-next-line camelcase
1147
- async aztec_avm_sender() {
1148
- const sender = await this.handlerAsAvm().sender();
1149
-
1150
- return toForeignCallResult([toSingle(sender)]);
956
+ aztec_avm_getContractInstanceDeployer(...inputs: ForeignCallArgs) {
957
+ return callTxeHandler({
958
+ oracle: 'aztec_avm_getContractInstanceDeployer',
959
+ inputs,
960
+ handler: ([address]) => this.handlerAsAvm().getContractInstanceDeployer(address),
961
+ });
1151
962
  }
1152
963
 
1153
964
  // eslint-disable-next-line camelcase
1154
- async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
1155
- const nullifier = fromSingle(foreignNullifier);
1156
-
1157
- await this.handlerAsAvm().emitNullifier(nullifier);
1158
-
1159
- return toForeignCallResult([]);
965
+ aztec_avm_getContractInstanceClassId(...inputs: ForeignCallArgs) {
966
+ return callTxeHandler({
967
+ oracle: 'aztec_avm_getContractInstanceClassId',
968
+ inputs,
969
+ handler: ([address]) => this.handlerAsAvm().getContractInstanceClassId(address),
970
+ });
1160
971
  }
1161
972
 
1162
973
  // eslint-disable-next-line camelcase
1163
- async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
1164
- const noteHash = fromSingle(foreignNoteHash);
1165
-
1166
- await this.handlerAsAvm().emitNoteHash(noteHash);
1167
-
1168
- return toForeignCallResult([]);
974
+ aztec_avm_getContractInstanceInitializationHash(...inputs: ForeignCallArgs) {
975
+ return callTxeHandler({
976
+ oracle: 'aztec_avm_getContractInstanceInitializationHash',
977
+ inputs,
978
+ handler: ([address]) => this.handlerAsAvm().getContractInstanceInitializationHash(address),
979
+ });
1169
980
  }
1170
981
 
1171
982
  // eslint-disable-next-line camelcase
1172
- async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
1173
- const siloedNullifier = fromSingle(foreignSiloedNullifier);
1174
-
1175
- const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
1176
-
1177
- return toForeignCallResult([toSingle(new Fr(exists))]);
983
+ aztec_avm_getContractInstanceImmutablesHash(...inputs: ForeignCallArgs) {
984
+ return callTxeHandler({
985
+ oracle: 'aztec_avm_getContractInstanceImmutablesHash',
986
+ inputs,
987
+ handler: ([address]) => this.handlerAsAvm().getContractInstanceImmutablesHash(address),
988
+ });
1178
989
  }
1179
990
 
1180
991
  // eslint-disable-next-line camelcase
1181
- async aztec_avm_address() {
1182
- const contractAddress = await this.handlerAsAvm().address();
1183
-
1184
- return toForeignCallResult([toSingle(contractAddress.toField())]);
992
+ aztec_avm_sender() {
993
+ return callTxeHandler({
994
+ oracle: 'aztec_avm_sender',
995
+ inputs: [],
996
+ handler: () => this.handlerAsAvm().sender(),
997
+ });
1185
998
  }
1186
999
 
1187
1000
  // eslint-disable-next-line camelcase
1188
- async aztec_avm_blockNumber() {
1189
- const blockNumber = await this.handlerAsAvm().blockNumber();
1190
-
1191
- return toForeignCallResult([toSingle(new Fr(blockNumber))]);
1001
+ aztec_avm_emitNullifier(...inputs: ForeignCallArgs) {
1002
+ return callTxeHandler({
1003
+ oracle: 'aztec_avm_emitNullifier',
1004
+ inputs,
1005
+ handler: ([nullifier]) => this.handlerAsAvm().emitNullifier(nullifier),
1006
+ });
1192
1007
  }
1193
1008
 
1194
1009
  // eslint-disable-next-line camelcase
1195
- async aztec_avm_timestamp() {
1196
- const timestamp = await this.handlerAsAvm().timestamp();
1197
-
1198
- return toForeignCallResult([toSingle(new Fr(timestamp))]);
1010
+ aztec_avm_emitNoteHash(...inputs: ForeignCallArgs) {
1011
+ return callTxeHandler({
1012
+ oracle: 'aztec_avm_emitNoteHash',
1013
+ inputs,
1014
+ handler: ([noteHash]) => this.handlerAsAvm().emitNoteHash(noteHash),
1015
+ });
1199
1016
  }
1200
1017
 
1201
1018
  // eslint-disable-next-line camelcase
1202
- async aztec_avm_isStaticCall() {
1203
- const isStaticCall = await this.handlerAsAvm().isStaticCall();
1019
+ aztec_avm_nullifierExists(...inputs: ForeignCallArgs) {
1020
+ return callTxeHandler({
1021
+ oracle: 'aztec_avm_nullifierExists',
1022
+ inputs,
1023
+ handler: ([siloedNullifier]) => this.handlerAsAvm().nullifierExists(siloedNullifier),
1024
+ });
1025
+ }
1204
1026
 
1205
- return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
1027
+ // eslint-disable-next-line camelcase
1028
+ aztec_avm_address() {
1029
+ return callTxeHandler({
1030
+ oracle: 'aztec_avm_address',
1031
+ inputs: [],
1032
+ handler: () => this.handlerAsAvm().address(),
1033
+ });
1206
1034
  }
1207
1035
 
1208
1036
  // eslint-disable-next-line camelcase
1209
- async aztec_avm_chainId() {
1210
- const chainId = await this.handlerAsAvm().chainId();
1037
+ aztec_avm_blockNumber() {
1038
+ return callTxeHandler({
1039
+ oracle: 'aztec_avm_blockNumber',
1040
+ inputs: [],
1041
+ handler: () => this.handlerAsAvm().blockNumber(),
1042
+ });
1043
+ }
1211
1044
 
1212
- return toForeignCallResult([toSingle(chainId)]);
1045
+ // eslint-disable-next-line camelcase
1046
+ aztec_avm_timestamp() {
1047
+ return callTxeHandler({
1048
+ oracle: 'aztec_avm_timestamp',
1049
+ inputs: [],
1050
+ handler: () => this.handlerAsAvm().timestamp(),
1051
+ });
1213
1052
  }
1214
1053
 
1215
1054
  // eslint-disable-next-line camelcase
1216
- async aztec_avm_version() {
1217
- const version = await this.handlerAsAvm().version();
1055
+ aztec_avm_isStaticCall() {
1056
+ return callTxeHandler({
1057
+ oracle: 'aztec_avm_isStaticCall',
1058
+ inputs: [],
1059
+ handler: () => this.handlerAsAvm().isStaticCall(),
1060
+ });
1061
+ }
1218
1062
 
1219
- return toForeignCallResult([toSingle(version)]);
1063
+ // eslint-disable-next-line camelcase
1064
+ aztec_avm_chainId() {
1065
+ return callTxeHandler({
1066
+ oracle: 'aztec_avm_chainId',
1067
+ inputs: [],
1068
+ handler: () => this.handlerAsAvm().chainId(),
1069
+ });
1220
1070
  }
1221
1071
 
1222
1072
  // eslint-disable-next-line camelcase
1223
- async aztec_avm_returndataSize() {
1224
- const result = await this.handlerAsAvm().returndataSize();
1225
- return toForeignCallResult([toSingle(result)]);
1073
+ aztec_avm_version() {
1074
+ return callTxeHandler({
1075
+ oracle: 'aztec_avm_version',
1076
+ inputs: [],
1077
+ handler: () => this.handlerAsAvm().version(),
1078
+ });
1226
1079
  }
1227
1080
 
1228
1081
  // eslint-disable-next-line camelcase
1229
- async aztec_avm_returndataCopy(foreignRdOffset: ForeignCallSingle, foreignCopySize: ForeignCallSingle) {
1230
- const rdOffset = fromSingle(foreignRdOffset).toNumber();
1231
- const copySize = fromSingle(foreignCopySize).toNumber();
1232
- const result = await this.handlerAsAvm().returndataCopy(rdOffset, copySize);
1233
- return toForeignCallResult([toArray(result)]);
1082
+ aztec_avm_returndataSize() {
1083
+ return callTxeHandler({
1084
+ oracle: 'aztec_avm_returndataSize',
1085
+ inputs: [],
1086
+ handler: () => this.handlerAsAvm().returndataSize(),
1087
+ });
1234
1088
  }
1235
1089
 
1236
1090
  // eslint-disable-next-line camelcase
1237
- async aztec_avm_call(
1238
- foreignL2Gas: ForeignCallSingle,
1239
- foreignDaGas: ForeignCallSingle,
1240
- foreignAddress: ForeignCallSingle,
1241
- foreignLength: ForeignCallSingle,
1242
- foreignArgs: ForeignCallArray,
1243
- ) {
1244
- const l2Gas = fromSingle(foreignL2Gas).toNumber();
1245
- const daGas = fromSingle(foreignDaGas).toNumber();
1246
- const address = addressFromSingle(foreignAddress);
1247
- const argsLength = fromSingle(foreignLength).toNumber();
1248
- const args = fromArray(foreignArgs);
1249
- const result = await this.handlerAsAvm().call(l2Gas, daGas, address, argsLength, args);
1250
- return toForeignCallResult([toArray(result)]);
1091
+ aztec_avm_returndataCopy(...inputs: ForeignCallArgs) {
1092
+ return callTxeHandler({
1093
+ oracle: 'aztec_avm_returndataCopy',
1094
+ inputs,
1095
+ handler: ([rdOffset, copySize]) => this.handlerAsAvm().returndataCopy(rdOffset, copySize),
1096
+ });
1251
1097
  }
1252
1098
 
1253
1099
  // eslint-disable-next-line camelcase
1254
- async aztec_avm_staticCall(
1255
- foreignL2Gas: ForeignCallSingle,
1256
- foreignDaGas: ForeignCallSingle,
1257
- foreignAddress: ForeignCallSingle,
1258
- foreignLength: ForeignCallSingle,
1259
- foreignArgs: ForeignCallArray,
1260
- ) {
1261
- const l2Gas = fromSingle(foreignL2Gas).toNumber();
1262
- const daGas = fromSingle(foreignDaGas).toNumber();
1263
- const address = addressFromSingle(foreignAddress);
1264
- const argsLength = fromSingle(foreignLength).toNumber();
1265
- const args = fromArray(foreignArgs);
1266
- const result = await this.handlerAsAvm().staticCall(l2Gas, daGas, address, argsLength, args);
1267
- return toForeignCallResult([toArray(result)]);
1100
+ aztec_avm_call(...inputs: ForeignCallArgs) {
1101
+ return callTxeHandler({
1102
+ oracle: 'aztec_avm_call',
1103
+ inputs,
1104
+ handler: ([l2Gas, daGas, address, argsLength, args]) =>
1105
+ this.handlerAsAvm().call(l2Gas, daGas, address, argsLength, args),
1106
+ });
1268
1107
  }
1269
1108
 
1270
1109
  // eslint-disable-next-line camelcase
1271
- async aztec_avm_successCopy() {
1272
- const result = await this.handlerAsAvm().successCopy();
1273
- return toForeignCallResult([toSingle(result)]);
1110
+ aztec_avm_staticCall(...inputs: ForeignCallArgs) {
1111
+ return callTxeHandler({
1112
+ oracle: 'aztec_avm_staticCall',
1113
+ inputs,
1114
+ handler: ([l2Gas, daGas, address, argsLength, args]) =>
1115
+ this.handlerAsAvm().staticCall(l2Gas, daGas, address, argsLength, args),
1116
+ });
1274
1117
  }
1275
1118
 
1276
- // TODO(F-674): Move orchestration logic into the handler so the transport layer is pure serialize→delegate→deserialize.
1277
1119
  // eslint-disable-next-line camelcase
1278
- async aztec_txe_privateCallNewFlow(
1279
- foreignFromIsSome: ForeignCallSingle,
1280
- foreignFromValue: ForeignCallSingle,
1281
- foreignTargetContractAddress: ForeignCallSingle,
1282
- foreignFunctionSelector: ForeignCallSingle,
1283
- foreignArgs: ForeignCallArray,
1284
- foreignArgsHash: ForeignCallSingle,
1285
- foreignIsStaticCall: ForeignCallSingle,
1286
- foreignAdditionalScopes: ForeignCallArray,
1287
- foreignAuthorizedUtilityCallTargets: ForeignCallArray,
1288
- foreignGasSettings: ForeignCallArray,
1289
- ) {
1290
- const from = fromSingle(foreignFromIsSome).toBool() ? addressFromSingle(foreignFromValue) : undefined;
1291
- const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
1292
- const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1293
- const args = fromArray(foreignArgs);
1294
- const argsHash = fromSingle(foreignArgsHash);
1295
- const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1296
- const additionalScopes = fromArray(foreignAdditionalScopes).map(field => AztecAddress.fromField(field));
1297
- const authorizedUtilityCallTargets = fromArray(foreignAuthorizedUtilityCallTargets).map(field =>
1298
- AztecAddress.fromField(field),
1299
- );
1300
- const gasSettings = GasSettings.fromFields(fromArray(foreignGasSettings));
1120
+ aztec_avm_successCopy() {
1121
+ return callTxeHandler({
1122
+ oracle: 'aztec_avm_successCopy',
1123
+ inputs: [],
1124
+ handler: () => this.handlerAsAvm().successCopy(),
1125
+ });
1126
+ }
1301
1127
 
1302
- const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1303
- const { returnValues, offchainEffects } = await this.handlerAsTxe().privateCallNewFlow(
1128
+ // eslint-disable-next-line camelcase
1129
+ aztec_txe_privateCallNewFlow(...inputs: ForeignCallArgs) {
1130
+ return callTxeHandler({
1131
+ oracle: 'aztec_txe_privateCallNewFlow',
1132
+ inputs,
1133
+ handler: ([
1304
1134
  from,
1305
1135
  targetContractAddress,
1306
1136
  functionSelector,
@@ -1308,137 +1138,92 @@ export class RPCTranslator {
1308
1138
  argsHash,
1309
1139
  isStaticCall,
1310
1140
  additionalScopes,
1311
- this.stateHandler.getCurrentJob(),
1312
1141
  authorizedUtilityCallTargets,
1313
1142
  gasSettings,
1314
- );
1315
-
1316
- // Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than
1317
- // round-tripping them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty
1318
- // at this point. Drain the effects from the execution tree into the session buffer so the
1319
- // next `env.offchain_messages()` call in the test sees them.
1320
- for (const data of offchainEffects) {
1321
- this.stateHandler.recordOffchainEffect(data);
1322
- }
1323
-
1324
- // TODO(F-335): Avoid doing the following call here.
1325
- await this.stateHandler.cycleJob();
1326
-
1327
- if (isStaticCall) {
1328
- // Static calls revert their checkpoint and mine no block, so there is no tx hash to tag
1329
- // offchain effects with. Querying `getLastTxEffects()` here would return an unrelated
1330
- // predecessor tx.
1331
- return { result: returnValues };
1332
- }
1333
- const { txHash } = await this.handlerAsTxe().getLastTxEffects();
1334
- return { result: returnValues, txHash: txHash.hash };
1143
+ ]) =>
1144
+ this.stateHandler.executePrivateCall(
1145
+ from,
1146
+ targetContractAddress,
1147
+ functionSelector,
1148
+ args,
1149
+ argsHash,
1150
+ isStaticCall,
1151
+ additionalScopes,
1152
+ authorizedUtilityCallTargets,
1153
+ gasSettings,
1154
+ ),
1335
1155
  });
1336
-
1337
- return toForeignCallResult([toArray(returnValues)]);
1338
1156
  }
1339
1157
 
1340
- // TODO(F-674): Move orchestration logic into the handler so the transport layer is pure serialize→delegate→deserialize.
1341
1158
  // eslint-disable-next-line camelcase
1342
- async aztec_txe_executeUtilityFunction(
1343
- foreignTargetContractAddress: ForeignCallSingle,
1344
- foreignFunctionSelector: ForeignCallSingle,
1345
- foreignArgs: ForeignCallArray,
1346
- foreignAuthorizedUtilityCallTargets: ForeignCallArray,
1347
- ) {
1348
- const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
1349
- const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1350
- const args = fromArray(foreignArgs);
1351
- const authorizedUtilityCallTargets = fromArray(foreignAuthorizedUtilityCallTargets).map(field =>
1352
- AztecAddress.fromField(field),
1353
- );
1354
-
1355
- const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1356
- const returnValues = await this.handlerAsTxe().executeUtilityFunction(
1357
- targetContractAddress,
1358
- functionSelector,
1359
- args,
1360
- this.stateHandler.getCurrentJob(),
1361
- authorizedUtilityCallTargets,
1362
- );
1363
-
1364
- // TODO(F-335): Avoid doing the following call here.
1365
- await this.stateHandler.cycleJob();
1366
-
1367
- return { result: returnValues };
1159
+ aztec_txe_executeUtilityFunction(...inputs: ForeignCallArgs) {
1160
+ return callTxeHandler({
1161
+ oracle: 'aztec_txe_executeUtilityFunction',
1162
+ inputs,
1163
+ handler: ([from, targetContractAddress, functionSelector, args, authorizedUtilityCallTargets]) =>
1164
+ this.stateHandler.executeUtilityFunction(
1165
+ from,
1166
+ targetContractAddress,
1167
+ functionSelector,
1168
+ args,
1169
+ authorizedUtilityCallTargets,
1170
+ ),
1368
1171
  });
1369
-
1370
- return toForeignCallResult([toArray(returnValues)]);
1371
1172
  }
1372
1173
 
1373
- // TODO(F-674): Move orchestration logic into the handler so the transport layer is pure serialize→delegate→deserialize.
1374
1174
  // eslint-disable-next-line camelcase
1375
- async aztec_txe_publicCallNewFlow(
1376
- foreignFromIsSome: ForeignCallSingle,
1377
- foreignFromValue: ForeignCallSingle,
1378
- foreignAddress: ForeignCallSingle,
1379
- foreignCalldata: ForeignCallArray,
1380
- foreignIsStaticCall: ForeignCallSingle,
1381
- foreignGasSettings: ForeignCallArray,
1382
- ) {
1383
- const from = fromSingle(foreignFromIsSome).toBool() ? addressFromSingle(foreignFromValue) : undefined;
1384
- const address = addressFromSingle(foreignAddress);
1385
- const calldata = fromArray(foreignCalldata);
1386
- const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
1387
- const gasSettings = GasSettings.fromFields(fromArray(foreignGasSettings));
1388
-
1389
- const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
1390
- const returnValues = await this.handlerAsTxe().publicCallNewFlow(
1391
- from,
1392
- address,
1393
- calldata,
1394
- isStaticCall,
1395
- gasSettings,
1396
- );
1397
-
1398
- // TODO(F-335): Avoid doing the following call here.
1399
- await this.stateHandler.cycleJob();
1400
-
1401
- if (isStaticCall) {
1402
- // See equivalent branch in `aztec_txe_privateCallNewFlow`.
1403
- return { result: returnValues };
1404
- }
1405
- const { txHash } = await this.handlerAsTxe().getLastTxEffects();
1406
- return { result: returnValues, txHash: txHash.hash };
1175
+ aztec_txe_publicCallNewFlow(...inputs: ForeignCallArgs) {
1176
+ return callTxeHandler({
1177
+ oracle: 'aztec_txe_publicCallNewFlow',
1178
+ inputs,
1179
+ handler: ([from, address, calldata, isStaticCall, gasSettings]) =>
1180
+ this.stateHandler.executePublicCall(from, address, calldata, isStaticCall, gasSettings),
1407
1181
  });
1408
-
1409
- return toForeignCallResult([toArray(returnValues)]);
1410
1182
  }
1411
1183
 
1412
1184
  // eslint-disable-next-line camelcase
1413
- async aztec_prv_getSenderForTags() {
1414
- const senderOpt = await this.handlerAsPrivate().getSenderForTags();
1415
-
1416
- // Return a Noir Option struct with `some` and `value` fields
1417
- if (senderOpt.isSome()) {
1418
- // Sender found, return Option with some=1 and value=sender address
1419
- return toForeignCallResult([toSingle(1), toSingle(senderOpt.value)]);
1420
- } else {
1421
- // No sender found, return Option with some=0 and value=0
1422
- return toForeignCallResult([toSingle(0), toSingle(0)]);
1423
- }
1185
+ aztec_prv_getSenderForTags() {
1186
+ return callTxeHandler({
1187
+ oracle: 'aztec_prv_getSenderForTags',
1188
+ inputs: [],
1189
+ handler: () => this.handlerAsPrivate().getSenderForTags(),
1190
+ });
1424
1191
  }
1425
1192
 
1426
1193
  // eslint-disable-next-line camelcase
1427
- async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
1428
- const sender = AztecAddress.fromField(fromSingle(foreignSender));
1429
- const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
1430
-
1431
- const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
1432
-
1433
- return toForeignCallResult([toSingle(nextAppTag.value)]);
1194
+ aztec_prv_resolveTaggingStrategy(...inputs: ForeignCallArgs) {
1195
+ return callTxeHandler({
1196
+ oracle: 'aztec_prv_resolveTaggingStrategy',
1197
+ inputs,
1198
+ handler: ([sender, recipient, deliveryMode]) =>
1199
+ this.handlerAsPrivate().resolveTaggingStrategy(sender, recipient, deliveryMode),
1200
+ });
1434
1201
  }
1435
1202
 
1436
1203
  // eslint-disable-next-line camelcase
1437
- async aztec_prv_getNextConstrainedTaggingIndex(foreignAppSiloedSecret: ForeignCallSingle) {
1438
- const appSiloedSecret = fromSingle(foreignAppSiloedSecret);
1204
+ aztec_prv_resolveCustomRequest(...inputs: ForeignCallArgs) {
1205
+ return callTxeHandler({
1206
+ oracle: 'aztec_prv_resolveCustomRequest',
1207
+ inputs,
1208
+ handler: ([kind, payload]) => this.handlerAsPrivate().resolveCustomRequest(kind, payload),
1209
+ });
1210
+ }
1439
1211
 
1440
- const index = await this.handlerAsPrivate().getNextConstrainedTaggingIndex(appSiloedSecret);
1212
+ // eslint-disable-next-line camelcase
1213
+ aztec_prv_getAppTaggingSecret(...inputs: ForeignCallArgs) {
1214
+ return callTxeHandler({
1215
+ oracle: 'aztec_prv_getAppTaggingSecret',
1216
+ inputs,
1217
+ handler: ([sender, recipient]) => this.handlerAsPrivate().getAppTaggingSecret(sender, recipient),
1218
+ });
1219
+ }
1441
1220
 
1442
- return toForeignCallResult([toSingle(new Fr(index))]);
1221
+ // eslint-disable-next-line camelcase
1222
+ aztec_prv_getNextTaggingIndex(...inputs: ForeignCallArgs) {
1223
+ return callTxeHandler({
1224
+ oracle: 'aztec_prv_getNextTaggingIndex',
1225
+ inputs,
1226
+ handler: ([secret, deliveryMode]) => this.handlerAsPrivate().getNextTaggingIndex(secret, deliveryMode),
1227
+ });
1443
1228
  }
1444
1229
  }