@aztec/txe 0.0.1-commit.2eb6648a → 0.0.1-commit.2f68f620

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