@aztec/txe 0.0.0-test.1 → 0.0.1-commit.001888fc
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.
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +3 -2
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +146 -82
- package/dest/oracle/interfaces.d.ts +58 -0
- package/dest/oracle/interfaces.d.ts.map +1 -0
- package/dest/oracle/interfaces.js +3 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +34 -0
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_public_context.js +122 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +65 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_top_level_context.js +542 -0
- package/dest/rpc_translator.d.ts +254 -0
- package/dest/rpc_translator.d.ts.map +1 -0
- package/dest/rpc_translator.js +791 -0
- package/dest/state_machine/archiver.d.ts +31 -0
- package/dest/state_machine/archiver.d.ts.map +1 -0
- package/dest/state_machine/archiver.js +85 -0
- package/dest/state_machine/dummy_p2p_client.d.ts +59 -0
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
- package/dest/state_machine/dummy_p2p_client.js +153 -0
- package/dest/state_machine/global_variable_builder.d.ts +11 -0
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
- package/dest/state_machine/global_variable_builder.js +22 -0
- package/dest/state_machine/index.d.ts +18 -0
- package/dest/state_machine/index.d.ts.map +1 -0
- package/dest/state_machine/index.js +72 -0
- package/dest/state_machine/mock_epoch_cache.d.ts +29 -0
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -0
- package/dest/state_machine/mock_epoch_cache.js +58 -0
- package/dest/state_machine/synchronizer.d.ts +33 -0
- package/dest/state_machine/synchronizer.d.ts.map +1 -0
- package/dest/state_machine/synchronizer.js +59 -0
- package/dest/txe_session.d.ts +78 -0
- package/dest/txe_session.d.ts.map +1 -0
- package/dest/txe_session.js +364 -0
- package/dest/util/encoding.d.ts +641 -24
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +66 -11
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +11 -11
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +21 -59
- package/dest/utils/block_creation.d.ts +28 -0
- package/dest/utils/block_creation.d.ts.map +1 -0
- package/dest/utils/block_creation.js +58 -0
- package/dest/utils/tx_effect_creation.d.ts +5 -0
- package/dest/utils/tx_effect_creation.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.js +13 -0
- package/package.json +30 -24
- package/src/bin/index.ts +3 -2
- package/src/constants.ts +3 -0
- package/src/index.ts +171 -103
- package/src/oracle/interfaces.ts +87 -0
- package/src/oracle/txe_oracle_public_context.ts +158 -0
- package/src/oracle/txe_oracle_top_level_context.ts +782 -0
- package/src/rpc_translator.ts +1218 -0
- package/src/state_machine/archiver.ts +97 -0
- package/src/state_machine/dummy_p2p_client.ts +227 -0
- package/src/state_machine/global_variable_builder.ts +38 -0
- package/src/state_machine/index.ts +120 -0
- package/src/state_machine/mock_epoch_cache.ts +72 -0
- package/src/state_machine/synchronizer.ts +88 -0
- package/src/txe_session.ts +556 -0
- package/src/util/encoding.ts +85 -11
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +28 -69
- package/src/utils/block_creation.ts +97 -0
- package/src/utils/tx_effect_creation.ts +30 -0
- package/dest/node/txe_node.d.ts +0 -358
- package/dest/node/txe_node.d.ts.map +0 -1
- package/dest/node/txe_node.js +0 -504
- package/dest/oracle/txe_oracle.d.ts +0 -152
- package/dest/oracle/txe_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_oracle.js +0 -833
- package/dest/txe_service/txe_service.d.ts +0 -212
- package/dest/txe_service/txe_service.d.ts.map +0 -1
- package/dest/txe_service/txe_service.js +0 -572
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_world_state_db.d.ts +0 -14
- package/dest/util/txe_world_state_db.d.ts.map +0 -1
- package/dest/util/txe_world_state_db.js +0 -27
- package/src/node/txe_node.ts +0 -725
- package/src/oracle/txe_oracle.ts +0 -1241
- package/src/txe_service/txe_service.ts +0 -749
- package/src/util/txe_world_state_db.ts +0 -38
|
@@ -0,0 +1,1218 @@
|
|
|
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';
|
|
14
|
+
|
|
15
|
+
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
16
|
+
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 = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
34
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
|
+
|
|
36
|
+
export class UnavailableOracleError extends Error {
|
|
37
|
+
constructor(oracleName: string) {
|
|
38
|
+
super(`${oracleName} oracles not available with the current handler`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class RPCTranslator {
|
|
43
|
+
/**
|
|
44
|
+
* Create a new instance of `RPCTranslator` that will translate all TXE RPC calls to and from the foreign
|
|
45
|
+
* (`ForeignCallSingle`, `ForeignCallResult`, etc.) and native TS types, delegating actual execution of the oracles
|
|
46
|
+
* to the different handlers.
|
|
47
|
+
* @param stateHandler The handler that will process TXE session state transitions, such as entering a private or
|
|
48
|
+
* public context.
|
|
49
|
+
* @param oracleHandler The handler that will process all other oracle calls that are not directly related to session
|
|
50
|
+
* state.
|
|
51
|
+
*/
|
|
52
|
+
constructor(
|
|
53
|
+
private stateHandler: TXESessionStateHandler,
|
|
54
|
+
private oracleHandler:
|
|
55
|
+
| IMiscOracle
|
|
56
|
+
| IUtilityExecutionOracle
|
|
57
|
+
| IPrivateExecutionOracle
|
|
58
|
+
| IAvmExecutionOracle
|
|
59
|
+
| ITxeExecutionOracle,
|
|
60
|
+
) {}
|
|
61
|
+
|
|
62
|
+
// Note: If you rename the following functions to not start with "handlerAs", you must also update the validation
|
|
63
|
+
// check in `TXESession.processFunction`.
|
|
64
|
+
|
|
65
|
+
private handlerAsMisc(): IMiscOracle {
|
|
66
|
+
if (!('isMisc' in this.oracleHandler)) {
|
|
67
|
+
throw new UnavailableOracleError('Misc');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.oracleHandler;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private handlerAsUtility(): IUtilityExecutionOracle {
|
|
74
|
+
if (!('isUtility' in this.oracleHandler)) {
|
|
75
|
+
throw new UnavailableOracleError('Utility');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return this.oracleHandler;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private handlerAsPrivate(): IPrivateExecutionOracle {
|
|
82
|
+
if (!('isPrivate' in this.oracleHandler)) {
|
|
83
|
+
throw new UnavailableOracleError('Private');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this.oracleHandler;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private handlerAsAvm(): IAvmExecutionOracle {
|
|
90
|
+
if (!('isAvm' in this.oracleHandler)) {
|
|
91
|
+
throw new UnavailableOracleError('Avm');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return this.oracleHandler;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
98
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
99
|
+
throw new UnavailableOracleError('Txe');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return this.oracleHandler;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// TXE session state transition functions - these get handled by the state handler
|
|
106
|
+
|
|
107
|
+
// eslint-disable-next-line camelcase
|
|
108
|
+
async aztec_txe_setTopLevelTXEContext() {
|
|
109
|
+
await this.stateHandler.enterTopLevelState();
|
|
110
|
+
|
|
111
|
+
return toForeignCallResult([]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line camelcase
|
|
115
|
+
async aztec_txe_setPrivateTXEContext(
|
|
116
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
117
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
118
|
+
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
119
|
+
foreignAnchorBlockNumberValue: ForeignCallSingle,
|
|
120
|
+
) {
|
|
121
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
122
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
123
|
+
: undefined;
|
|
124
|
+
|
|
125
|
+
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
126
|
+
? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
|
|
127
|
+
: undefined;
|
|
128
|
+
|
|
129
|
+
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
130
|
+
|
|
131
|
+
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// eslint-disable-next-line camelcase
|
|
135
|
+
async aztec_txe_setPublicTXEContext(
|
|
136
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
137
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
138
|
+
) {
|
|
139
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
140
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
141
|
+
: undefined;
|
|
142
|
+
|
|
143
|
+
await this.stateHandler.enterPublicState(contractAddress);
|
|
144
|
+
|
|
145
|
+
return toForeignCallResult([]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// eslint-disable-next-line camelcase
|
|
149
|
+
async aztec_txe_setUtilityTXEContext(
|
|
150
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
151
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
152
|
+
) {
|
|
153
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
154
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
155
|
+
: undefined;
|
|
156
|
+
|
|
157
|
+
await this.stateHandler.enterUtilityState(contractAddress);
|
|
158
|
+
|
|
159
|
+
return toForeignCallResult([]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Other oracles - these get handled by the oracle handler
|
|
163
|
+
|
|
164
|
+
// TXE-specific oracles
|
|
165
|
+
|
|
166
|
+
// eslint-disable-next-line camelcase
|
|
167
|
+
aztec_txe_getDefaultAddress() {
|
|
168
|
+
const defaultAddress = this.handlerAsTxe().getDefaultAddress();
|
|
169
|
+
|
|
170
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// eslint-disable-next-line camelcase
|
|
174
|
+
async aztec_txe_getNextBlockNumber() {
|
|
175
|
+
const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
|
|
176
|
+
|
|
177
|
+
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// eslint-disable-next-line camelcase
|
|
181
|
+
async aztec_txe_getNextBlockTimestamp() {
|
|
182
|
+
const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
|
|
183
|
+
|
|
184
|
+
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// eslint-disable-next-line camelcase
|
|
188
|
+
async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
189
|
+
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
190
|
+
|
|
191
|
+
await this.handlerAsTxe().advanceBlocksBy(blocks);
|
|
192
|
+
|
|
193
|
+
return toForeignCallResult([]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// eslint-disable-next-line camelcase
|
|
197
|
+
aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
198
|
+
const duration = fromSingle(foreignDuration).toBigInt();
|
|
199
|
+
|
|
200
|
+
this.handlerAsTxe().advanceTimestampBy(duration);
|
|
201
|
+
|
|
202
|
+
return toForeignCallResult([]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// eslint-disable-next-line camelcase
|
|
206
|
+
async aztec_txe_deploy(
|
|
207
|
+
artifact: ContractArtifact,
|
|
208
|
+
instance: ContractInstanceWithAddress,
|
|
209
|
+
foreignSecret: ForeignCallSingle,
|
|
210
|
+
) {
|
|
211
|
+
const secret = fromSingle(foreignSecret);
|
|
212
|
+
|
|
213
|
+
await this.handlerAsTxe().deploy(artifact, instance, secret);
|
|
214
|
+
|
|
215
|
+
return toForeignCallResult([
|
|
216
|
+
toArray([
|
|
217
|
+
instance.salt,
|
|
218
|
+
instance.deployer.toField(),
|
|
219
|
+
instance.currentContractClassId,
|
|
220
|
+
instance.initializationHash,
|
|
221
|
+
...instance.publicKeys.toFields(),
|
|
222
|
+
]),
|
|
223
|
+
]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// eslint-disable-next-line camelcase
|
|
227
|
+
async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
|
|
228
|
+
const secret = fromSingle(foreignSecret);
|
|
229
|
+
|
|
230
|
+
const completeAddress = await this.handlerAsTxe().createAccount(secret);
|
|
231
|
+
|
|
232
|
+
return toForeignCallResult([
|
|
233
|
+
toSingle(completeAddress.address),
|
|
234
|
+
...completeAddress.publicKeys.toFields().map(toSingle),
|
|
235
|
+
]);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// eslint-disable-next-line camelcase
|
|
239
|
+
async aztec_txe_addAccount(
|
|
240
|
+
artifact: ContractArtifact,
|
|
241
|
+
instance: ContractInstanceWithAddress,
|
|
242
|
+
foreignSecret: ForeignCallSingle,
|
|
243
|
+
) {
|
|
244
|
+
const secret = fromSingle(foreignSecret);
|
|
245
|
+
|
|
246
|
+
const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
|
|
247
|
+
|
|
248
|
+
return toForeignCallResult([
|
|
249
|
+
toSingle(completeAddress.address),
|
|
250
|
+
...completeAddress.publicKeys.toFields().map(toSingle),
|
|
251
|
+
]);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// eslint-disable-next-line camelcase
|
|
255
|
+
async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
|
|
256
|
+
const address = addressFromSingle(foreignAddress);
|
|
257
|
+
const messageHash = fromSingle(foreignMessageHash);
|
|
258
|
+
|
|
259
|
+
await this.handlerAsTxe().addAuthWitness(address, messageHash);
|
|
260
|
+
|
|
261
|
+
return toForeignCallResult([]);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// PXE oracles
|
|
265
|
+
|
|
266
|
+
// eslint-disable-next-line camelcase
|
|
267
|
+
aztec_utl_assertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
|
|
268
|
+
const version = fromSingle(foreignVersion).toNumber();
|
|
269
|
+
|
|
270
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(version);
|
|
271
|
+
|
|
272
|
+
return toForeignCallResult([]);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// eslint-disable-next-line camelcase
|
|
276
|
+
aztec_utl_getRandomField() {
|
|
277
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
278
|
+
|
|
279
|
+
return toForeignCallResult([toSingle(randomField)]);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// eslint-disable-next-line camelcase
|
|
283
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
284
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
285
|
+
|
|
286
|
+
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// eslint-disable-next-line camelcase
|
|
290
|
+
async aztec_txe_getLastTxEffects() {
|
|
291
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
292
|
+
|
|
293
|
+
return toForeignCallResult([
|
|
294
|
+
toSingle(txHash.hash),
|
|
295
|
+
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
296
|
+
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX),
|
|
297
|
+
]);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// eslint-disable-next-line camelcase
|
|
301
|
+
async aztec_txe_getPrivateEvents(
|
|
302
|
+
foreignSelector: ForeignCallSingle,
|
|
303
|
+
foreignContractAddress: ForeignCallSingle,
|
|
304
|
+
foreignScope: ForeignCallSingle,
|
|
305
|
+
) {
|
|
306
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
307
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
308
|
+
const scope = addressFromSingle(foreignScope);
|
|
309
|
+
|
|
310
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
311
|
+
{
|
|
312
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
313
|
+
// We cycle job to commit the stores after the contract sync.
|
|
314
|
+
await this.stateHandler.cycleJob();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
318
|
+
|
|
319
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
320
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
324
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
328
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
329
|
+
const rawArrayStorage = events
|
|
330
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
331
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
332
|
+
.flat();
|
|
333
|
+
const eventLengths = events
|
|
334
|
+
.map(e => new Fr(e.length))
|
|
335
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
336
|
+
const queryLength = new Fr(events.length);
|
|
337
|
+
|
|
338
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// eslint-disable-next-line camelcase
|
|
342
|
+
aztec_prv_storeInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
343
|
+
const values = fromArray(foreignValues);
|
|
344
|
+
const hash = fromSingle(foreignHash);
|
|
345
|
+
|
|
346
|
+
this.handlerAsPrivate().storeInExecutionCache(values, hash);
|
|
347
|
+
|
|
348
|
+
return toForeignCallResult([]);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// eslint-disable-next-line camelcase
|
|
352
|
+
async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
|
|
353
|
+
const hash = fromSingle(foreignHash);
|
|
354
|
+
|
|
355
|
+
const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
|
|
356
|
+
|
|
357
|
+
return toForeignCallResult([toArray(returns)]);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
361
|
+
// When the argument is an array, we add the field length manually to the signature.
|
|
362
|
+
// eslint-disable-next-line camelcase
|
|
363
|
+
async aztec_utl_log(
|
|
364
|
+
foreignLevel: ForeignCallSingle,
|
|
365
|
+
foreignMessage: ForeignCallArray,
|
|
366
|
+
_foreignLength: ForeignCallSingle,
|
|
367
|
+
foreignFields: ForeignCallArray,
|
|
368
|
+
) {
|
|
369
|
+
const level = fromSingle(foreignLevel).toNumber();
|
|
370
|
+
const message = fromArray(foreignMessage)
|
|
371
|
+
.map(field => String.fromCharCode(field.toNumber()))
|
|
372
|
+
.join('');
|
|
373
|
+
const fields = fromArray(foreignFields);
|
|
374
|
+
|
|
375
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
376
|
+
|
|
377
|
+
return toForeignCallResult([]);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// eslint-disable-next-line camelcase
|
|
381
|
+
async aztec_utl_storageRead(
|
|
382
|
+
foreignBlockHash: ForeignCallSingle,
|
|
383
|
+
foreignContractAddress: ForeignCallSingle,
|
|
384
|
+
foreignStartStorageSlot: ForeignCallSingle,
|
|
385
|
+
foreignNumberOfElements: ForeignCallSingle,
|
|
386
|
+
) {
|
|
387
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
388
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
389
|
+
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
390
|
+
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
391
|
+
|
|
392
|
+
const values = await this.handlerAsUtility().storageRead(
|
|
393
|
+
blockHash,
|
|
394
|
+
contractAddress,
|
|
395
|
+
startStorageSlot,
|
|
396
|
+
numberOfElements,
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
return toForeignCallResult([toArray(values)]);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// eslint-disable-next-line camelcase
|
|
403
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
404
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
405
|
+
const leafSlot = fromSingle(foreignLeafSlot);
|
|
406
|
+
|
|
407
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
408
|
+
|
|
409
|
+
if (!witness) {
|
|
410
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
411
|
+
}
|
|
412
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// eslint-disable-next-line camelcase
|
|
416
|
+
async aztec_utl_getNotes(
|
|
417
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
418
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
419
|
+
foreignStorageSlot: ForeignCallSingle,
|
|
420
|
+
foreignNumSelects: ForeignCallSingle,
|
|
421
|
+
foreignSelectByIndexes: ForeignCallArray,
|
|
422
|
+
foreignSelectByOffsets: ForeignCallArray,
|
|
423
|
+
foreignSelectByLengths: ForeignCallArray,
|
|
424
|
+
foreignSelectValues: ForeignCallArray,
|
|
425
|
+
foreignSelectComparators: ForeignCallArray,
|
|
426
|
+
foreignSortByIndexes: ForeignCallArray,
|
|
427
|
+
foreignSortByOffsets: ForeignCallArray,
|
|
428
|
+
foreignSortByLengths: ForeignCallArray,
|
|
429
|
+
foreignSortOrder: ForeignCallArray,
|
|
430
|
+
foreignLimit: ForeignCallSingle,
|
|
431
|
+
foreignOffset: ForeignCallSingle,
|
|
432
|
+
foreignStatus: ForeignCallSingle,
|
|
433
|
+
foreignMaxNotes: ForeignCallSingle,
|
|
434
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
435
|
+
) {
|
|
436
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
437
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
438
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
439
|
+
: undefined;
|
|
440
|
+
const storageSlot = fromSingle(foreignStorageSlot);
|
|
441
|
+
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
442
|
+
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
443
|
+
const selectByOffsets = fromArray(foreignSelectByOffsets).map(fr => fr.toNumber());
|
|
444
|
+
const selectByLengths = fromArray(foreignSelectByLengths).map(fr => fr.toNumber());
|
|
445
|
+
const selectValues = fromArray(foreignSelectValues);
|
|
446
|
+
const selectComparators = fromArray(foreignSelectComparators).map(fr => fr.toNumber());
|
|
447
|
+
const sortByIndexes = fromArray(foreignSortByIndexes).map(fr => fr.toNumber());
|
|
448
|
+
const sortByOffsets = fromArray(foreignSortByOffsets).map(fr => fr.toNumber());
|
|
449
|
+
const sortByLengths = fromArray(foreignSortByLengths).map(fr => fr.toNumber());
|
|
450
|
+
const sortOrder = fromArray(foreignSortOrder).map(fr => fr.toNumber());
|
|
451
|
+
const limit = fromSingle(foreignLimit).toNumber();
|
|
452
|
+
const offset = fromSingle(foreignOffset).toNumber();
|
|
453
|
+
const status = fromSingle(foreignStatus).toNumber();
|
|
454
|
+
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
455
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
456
|
+
|
|
457
|
+
const noteDatas = await this.handlerAsUtility().getNotes(
|
|
458
|
+
owner,
|
|
459
|
+
storageSlot,
|
|
460
|
+
numSelects,
|
|
461
|
+
selectByIndexes,
|
|
462
|
+
selectByOffsets,
|
|
463
|
+
selectByLengths,
|
|
464
|
+
selectValues,
|
|
465
|
+
selectComparators,
|
|
466
|
+
sortByIndexes,
|
|
467
|
+
sortByOffsets,
|
|
468
|
+
sortByLengths,
|
|
469
|
+
sortOrder,
|
|
470
|
+
limit,
|
|
471
|
+
offset,
|
|
472
|
+
status,
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
476
|
+
packAsHintedNote({
|
|
477
|
+
contractAddress: noteData.contractAddress,
|
|
478
|
+
owner: noteData.owner,
|
|
479
|
+
randomness: noteData.randomness,
|
|
480
|
+
storageSlot: noteData.storageSlot,
|
|
481
|
+
noteNonce: noteData.noteNonce,
|
|
482
|
+
isPending: noteData.isPending,
|
|
483
|
+
note: noteData.note,
|
|
484
|
+
}),
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
488
|
+
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
489
|
+
subArray.map(toSingle),
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
// At last we convert the array of arrays to a bounded vec of arrays
|
|
493
|
+
return toForeignCallResult(
|
|
494
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
aztec_prv_notifyCreatedNote(
|
|
500
|
+
foreignOwner: ForeignCallSingle,
|
|
501
|
+
foreignStorageSlot: ForeignCallSingle,
|
|
502
|
+
foreignRandomness: ForeignCallSingle,
|
|
503
|
+
foreignNoteTypeId: ForeignCallSingle,
|
|
504
|
+
foreignNote: ForeignCallArray,
|
|
505
|
+
foreignNoteHash: ForeignCallSingle,
|
|
506
|
+
foreignCounter: ForeignCallSingle,
|
|
507
|
+
) {
|
|
508
|
+
const owner = addressFromSingle(foreignOwner);
|
|
509
|
+
const storageSlot = fromSingle(foreignStorageSlot);
|
|
510
|
+
const randomness = fromSingle(foreignRandomness);
|
|
511
|
+
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
512
|
+
const note = fromArray(foreignNote);
|
|
513
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
514
|
+
const counter = fromSingle(foreignCounter).toNumber();
|
|
515
|
+
|
|
516
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
517
|
+
|
|
518
|
+
return toForeignCallResult([]);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// eslint-disable-next-line camelcase
|
|
522
|
+
async aztec_prv_notifyNullifiedNote(
|
|
523
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
524
|
+
foreignNoteHash: ForeignCallSingle,
|
|
525
|
+
foreignCounter: ForeignCallSingle,
|
|
526
|
+
) {
|
|
527
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
528
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
529
|
+
const counter = fromSingle(foreignCounter).toNumber();
|
|
530
|
+
|
|
531
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
532
|
+
|
|
533
|
+
return toForeignCallResult([]);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// eslint-disable-next-line camelcase
|
|
537
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
538
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
539
|
+
|
|
540
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
541
|
+
|
|
542
|
+
return toForeignCallResult([]);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// eslint-disable-next-line camelcase
|
|
546
|
+
async aztec_prv_isNullifierPending(
|
|
547
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
548
|
+
foreignContractAddress: ForeignCallSingle,
|
|
549
|
+
) {
|
|
550
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
551
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
552
|
+
|
|
553
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
554
|
+
|
|
555
|
+
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// eslint-disable-next-line camelcase
|
|
559
|
+
async aztec_utl_checkNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
560
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
561
|
+
|
|
562
|
+
const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
|
|
563
|
+
|
|
564
|
+
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// eslint-disable-next-line camelcase
|
|
568
|
+
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
|
|
569
|
+
const address = addressFromSingle(foreignAddress);
|
|
570
|
+
|
|
571
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
572
|
+
|
|
573
|
+
return toForeignCallResult(
|
|
574
|
+
[
|
|
575
|
+
instance.salt,
|
|
576
|
+
instance.deployer.toField(),
|
|
577
|
+
instance.currentContractClassId,
|
|
578
|
+
instance.initializationHash,
|
|
579
|
+
...instance.publicKeys.toFields(),
|
|
580
|
+
].map(toSingle),
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// eslint-disable-next-line camelcase
|
|
585
|
+
async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
586
|
+
const address = addressFromSingle(foreignAddress);
|
|
587
|
+
|
|
588
|
+
const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
|
|
589
|
+
|
|
590
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
591
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
592
|
+
if (result === undefined) {
|
|
593
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
594
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
|
|
595
|
+
} else {
|
|
596
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
597
|
+
return toForeignCallResult([
|
|
598
|
+
toSingle(new Fr(1)),
|
|
599
|
+
toArray([...result.publicKeys.toFields(), result.partialAddress]),
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// eslint-disable-next-line camelcase
|
|
605
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
606
|
+
const pkMHash = fromSingle(foreignPkMHash);
|
|
607
|
+
|
|
608
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
609
|
+
|
|
610
|
+
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// eslint-disable-next-line camelcase
|
|
614
|
+
aztec_prv_callPrivateFunction(
|
|
615
|
+
_foreignTargetContractAddress: ForeignCallSingle,
|
|
616
|
+
_foreignFunctionSelector: ForeignCallSingle,
|
|
617
|
+
_foreignArgsHash: ForeignCallSingle,
|
|
618
|
+
_foreignSideEffectCounter: ForeignCallSingle,
|
|
619
|
+
_foreignIsStaticCall: ForeignCallSingle,
|
|
620
|
+
) {
|
|
621
|
+
throw new Error(
|
|
622
|
+
'Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead',
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// eslint-disable-next-line camelcase
|
|
627
|
+
async aztec_utl_getNullifierMembershipWitness(
|
|
628
|
+
foreignBlockHash: ForeignCallSingle,
|
|
629
|
+
foreignNullifier: ForeignCallSingle,
|
|
630
|
+
) {
|
|
631
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
632
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
633
|
+
|
|
634
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
635
|
+
|
|
636
|
+
if (!witness) {
|
|
637
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
638
|
+
}
|
|
639
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// eslint-disable-next-line camelcase
|
|
643
|
+
async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
644
|
+
const messageHash = fromSingle(foreignMessageHash);
|
|
645
|
+
|
|
646
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
647
|
+
|
|
648
|
+
if (!authWitness) {
|
|
649
|
+
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
650
|
+
}
|
|
651
|
+
return toForeignCallResult([toArray(authWitness)]);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
|
|
656
|
+
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// eslint-disable-next-line camelcase
|
|
660
|
+
public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
661
|
+
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// eslint-disable-next-line camelcase
|
|
665
|
+
public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
|
|
666
|
+
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
667
|
+
const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
|
|
668
|
+
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// eslint-disable-next-line camelcase
|
|
672
|
+
aztec_utl_getUtilityContext() {
|
|
673
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
674
|
+
|
|
675
|
+
return toForeignCallResult(context.toNoirRepresentation());
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// eslint-disable-next-line camelcase
|
|
679
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
680
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
681
|
+
|
|
682
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
683
|
+
|
|
684
|
+
if (!header) {
|
|
685
|
+
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
686
|
+
}
|
|
687
|
+
return toForeignCallResult(header.toFields().map(toSingle));
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// eslint-disable-next-line camelcase
|
|
691
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
692
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
693
|
+
foreignNoteHash: ForeignCallSingle,
|
|
694
|
+
) {
|
|
695
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
696
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
697
|
+
|
|
698
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
699
|
+
|
|
700
|
+
if (!witness) {
|
|
701
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
702
|
+
}
|
|
703
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_utl_getBlockHashMembershipWitness(
|
|
708
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
709
|
+
foreignBlockHash: ForeignCallSingle,
|
|
710
|
+
) {
|
|
711
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
712
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
713
|
+
|
|
714
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
715
|
+
|
|
716
|
+
if (!witness) {
|
|
717
|
+
throw new Error(
|
|
718
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// eslint-disable-next-line camelcase
|
|
725
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
726
|
+
foreignBlockHash: ForeignCallSingle,
|
|
727
|
+
foreignNullifier: ForeignCallSingle,
|
|
728
|
+
) {
|
|
729
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
730
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
731
|
+
|
|
732
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
733
|
+
|
|
734
|
+
if (!witness) {
|
|
735
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
736
|
+
}
|
|
737
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// eslint-disable-next-line camelcase
|
|
741
|
+
async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
742
|
+
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
743
|
+
|
|
744
|
+
await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
745
|
+
|
|
746
|
+
return toForeignCallResult([]);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// eslint-disable-next-line camelcase
|
|
750
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
|
|
751
|
+
foreignContractAddress: ForeignCallSingle,
|
|
752
|
+
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
753
|
+
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
754
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
755
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
756
|
+
) {
|
|
757
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
758
|
+
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
759
|
+
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
760
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
761
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
762
|
+
|
|
763
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
764
|
+
contractAddress,
|
|
765
|
+
noteValidationRequestsArrayBaseSlot,
|
|
766
|
+
eventValidationRequestsArrayBaseSlot,
|
|
767
|
+
maxNotePackedLen,
|
|
768
|
+
maxEventSerializedLen,
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
return toForeignCallResult([]);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// eslint-disable-next-line camelcase
|
|
775
|
+
public async aztec_utl_bulkRetrieveLogs(
|
|
776
|
+
foreignContractAddress: ForeignCallSingle,
|
|
777
|
+
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
778
|
+
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
779
|
+
) {
|
|
780
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
781
|
+
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
782
|
+
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
783
|
+
|
|
784
|
+
await this.handlerAsUtility().bulkRetrieveLogs(
|
|
785
|
+
contractAddress,
|
|
786
|
+
logRetrievalRequestsArrayBaseSlot,
|
|
787
|
+
logRetrievalResponsesArrayBaseSlot,
|
|
788
|
+
);
|
|
789
|
+
|
|
790
|
+
return toForeignCallResult([]);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// eslint-disable-next-line camelcase
|
|
794
|
+
public async aztec_utl_utilityResolveMessageContexts(
|
|
795
|
+
foreignContractAddress: ForeignCallSingle,
|
|
796
|
+
foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
|
|
797
|
+
foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
|
|
798
|
+
) {
|
|
799
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
800
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
801
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
802
|
+
|
|
803
|
+
await this.handlerAsUtility().utilityResolveMessageContexts(
|
|
804
|
+
contractAddress,
|
|
805
|
+
messageContextRequestsArrayBaseSlot,
|
|
806
|
+
messageContextResponsesArrayBaseSlot,
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
return toForeignCallResult([]);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// eslint-disable-next-line camelcase
|
|
813
|
+
async aztec_utl_storeCapsule(
|
|
814
|
+
foreignContractAddress: ForeignCallSingle,
|
|
815
|
+
foreignSlot: ForeignCallSingle,
|
|
816
|
+
foreignCapsule: ForeignCallArray,
|
|
817
|
+
) {
|
|
818
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
819
|
+
const slot = fromSingle(foreignSlot);
|
|
820
|
+
const capsule = fromArray(foreignCapsule);
|
|
821
|
+
|
|
822
|
+
await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
|
|
823
|
+
|
|
824
|
+
return toForeignCallResult([]);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// eslint-disable-next-line camelcase
|
|
828
|
+
async aztec_utl_loadCapsule(
|
|
829
|
+
foreignContractAddress: ForeignCallSingle,
|
|
830
|
+
foreignSlot: ForeignCallSingle,
|
|
831
|
+
foreignTSize: ForeignCallSingle,
|
|
832
|
+
) {
|
|
833
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
834
|
+
const slot = fromSingle(foreignSlot);
|
|
835
|
+
const tSize = fromSingle(foreignTSize).toNumber();
|
|
836
|
+
|
|
837
|
+
const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
|
|
838
|
+
|
|
839
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
840
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
841
|
+
if (values === null) {
|
|
842
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
843
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(tSize).fill(new Fr(0)))]);
|
|
844
|
+
} else {
|
|
845
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
846
|
+
return toForeignCallResult([toSingle(new Fr(1)), toArray(values)]);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// eslint-disable-next-line camelcase
|
|
851
|
+
async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
|
|
852
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
853
|
+
const slot = fromSingle(foreignSlot);
|
|
854
|
+
|
|
855
|
+
await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
|
|
856
|
+
|
|
857
|
+
return toForeignCallResult([]);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// eslint-disable-next-line camelcase
|
|
861
|
+
async aztec_utl_copyCapsule(
|
|
862
|
+
foreignContractAddress: ForeignCallSingle,
|
|
863
|
+
foreignSrcSlot: ForeignCallSingle,
|
|
864
|
+
foreignDstSlot: ForeignCallSingle,
|
|
865
|
+
foreignNumEntries: ForeignCallSingle,
|
|
866
|
+
) {
|
|
867
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
868
|
+
const srcSlot = fromSingle(foreignSrcSlot);
|
|
869
|
+
const dstSlot = fromSingle(foreignDstSlot);
|
|
870
|
+
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
871
|
+
|
|
872
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
873
|
+
|
|
874
|
+
return toForeignCallResult([]);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
878
|
+
// 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
|
|
879
|
+
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
880
|
+
// existence of a txe_oracle method?
|
|
881
|
+
// TODO(F-452): Return Option and wrap in try/catch so BB exceptions don't crash TXE.
|
|
882
|
+
// eslint-disable-next-line camelcase
|
|
883
|
+
async aztec_utl_aes128Decrypt(
|
|
884
|
+
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
885
|
+
foreignCiphertextLength: ForeignCallSingle,
|
|
886
|
+
foreignIv: ForeignCallArray,
|
|
887
|
+
foreignSymKey: ForeignCallArray,
|
|
888
|
+
) {
|
|
889
|
+
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
890
|
+
const iv = fromUintArray(foreignIv, 8);
|
|
891
|
+
const symKey = fromUintArray(foreignSymKey, 8);
|
|
892
|
+
|
|
893
|
+
const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
|
|
894
|
+
|
|
895
|
+
return toForeignCallResult(
|
|
896
|
+
arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// eslint-disable-next-line camelcase
|
|
901
|
+
async aztec_utl_getSharedSecret(
|
|
902
|
+
foreignAddress: ForeignCallSingle,
|
|
903
|
+
foreignEphPKField0: ForeignCallSingle,
|
|
904
|
+
foreignEphPKField1: ForeignCallSingle,
|
|
905
|
+
foreignEphPKField2: ForeignCallSingle,
|
|
906
|
+
) {
|
|
907
|
+
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
908
|
+
const ephPK = Point.fromFields([
|
|
909
|
+
fromSingle(foreignEphPKField0),
|
|
910
|
+
fromSingle(foreignEphPKField1),
|
|
911
|
+
fromSingle(foreignEphPKField2),
|
|
912
|
+
]);
|
|
913
|
+
|
|
914
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
|
|
915
|
+
|
|
916
|
+
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// eslint-disable-next-line camelcase
|
|
920
|
+
aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
|
|
921
|
+
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// AVM opcodes
|
|
925
|
+
|
|
926
|
+
// eslint-disable-next-line camelcase
|
|
927
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
928
|
+
// TODO(#8811): Implement
|
|
929
|
+
return toForeignCallResult([]);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// eslint-disable-next-line camelcase
|
|
933
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
934
|
+
const slot = fromSingle(foreignSlot);
|
|
935
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
936
|
+
|
|
937
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
938
|
+
|
|
939
|
+
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// eslint-disable-next-line camelcase
|
|
943
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
944
|
+
const slot = fromSingle(foreignSlot);
|
|
945
|
+
const value = fromSingle(foreignValue);
|
|
946
|
+
|
|
947
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
948
|
+
|
|
949
|
+
return toForeignCallResult([]);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// eslint-disable-next-line camelcase
|
|
953
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
954
|
+
const address = addressFromSingle(foreignAddress);
|
|
955
|
+
|
|
956
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
957
|
+
|
|
958
|
+
return toForeignCallResult([
|
|
959
|
+
toSingle(instance.deployer),
|
|
960
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
961
|
+
toSingle(new Fr(1)),
|
|
962
|
+
]);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// eslint-disable-next-line camelcase
|
|
966
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
967
|
+
const address = addressFromSingle(foreignAddress);
|
|
968
|
+
|
|
969
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
970
|
+
|
|
971
|
+
return toForeignCallResult([
|
|
972
|
+
toSingle(instance.currentContractClassId),
|
|
973
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
974
|
+
toSingle(new Fr(1)),
|
|
975
|
+
]);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// eslint-disable-next-line camelcase
|
|
979
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
980
|
+
const address = addressFromSingle(foreignAddress);
|
|
981
|
+
|
|
982
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
983
|
+
|
|
984
|
+
return toForeignCallResult([
|
|
985
|
+
toSingle(instance.initializationHash),
|
|
986
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
987
|
+
toSingle(new Fr(1)),
|
|
988
|
+
]);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// eslint-disable-next-line camelcase
|
|
992
|
+
async aztec_avm_sender() {
|
|
993
|
+
const sender = await this.handlerAsAvm().sender();
|
|
994
|
+
|
|
995
|
+
return toForeignCallResult([toSingle(sender)]);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// eslint-disable-next-line camelcase
|
|
999
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
1000
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
1001
|
+
|
|
1002
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
1003
|
+
|
|
1004
|
+
return toForeignCallResult([]);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// eslint-disable-next-line camelcase
|
|
1008
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
1009
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
1010
|
+
|
|
1011
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
1012
|
+
|
|
1013
|
+
return toForeignCallResult([]);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// eslint-disable-next-line camelcase
|
|
1017
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
1018
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
1019
|
+
|
|
1020
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
1021
|
+
|
|
1022
|
+
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// eslint-disable-next-line camelcase
|
|
1026
|
+
async aztec_avm_address() {
|
|
1027
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
1028
|
+
|
|
1029
|
+
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// eslint-disable-next-line camelcase
|
|
1033
|
+
async aztec_avm_blockNumber() {
|
|
1034
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
1035
|
+
|
|
1036
|
+
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// eslint-disable-next-line camelcase
|
|
1040
|
+
async aztec_avm_timestamp() {
|
|
1041
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
1042
|
+
|
|
1043
|
+
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// eslint-disable-next-line camelcase
|
|
1047
|
+
async aztec_avm_isStaticCall() {
|
|
1048
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
1049
|
+
|
|
1050
|
+
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// eslint-disable-next-line camelcase
|
|
1054
|
+
async aztec_avm_chainId() {
|
|
1055
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
1056
|
+
|
|
1057
|
+
return toForeignCallResult([toSingle(chainId)]);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// eslint-disable-next-line camelcase
|
|
1061
|
+
async aztec_avm_version() {
|
|
1062
|
+
const version = await this.handlerAsAvm().version();
|
|
1063
|
+
|
|
1064
|
+
return toForeignCallResult([toSingle(version)]);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// eslint-disable-next-line camelcase
|
|
1068
|
+
aztec_avm_returndataSize() {
|
|
1069
|
+
throw new Error(
|
|
1070
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// eslint-disable-next-line camelcase
|
|
1075
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
1076
|
+
throw new Error(
|
|
1077
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// eslint-disable-next-line camelcase
|
|
1082
|
+
aztec_avm_call(
|
|
1083
|
+
_foreignL2Gas: ForeignCallSingle,
|
|
1084
|
+
_foreignDaGas: ForeignCallSingle,
|
|
1085
|
+
_foreignAddress: ForeignCallSingle,
|
|
1086
|
+
_foreignLength: ForeignCallSingle,
|
|
1087
|
+
_foreignArgs: ForeignCallArray,
|
|
1088
|
+
) {
|
|
1089
|
+
throw new Error(
|
|
1090
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// eslint-disable-next-line camelcase
|
|
1095
|
+
aztec_avm_staticCall(
|
|
1096
|
+
_foreignL2Gas: ForeignCallSingle,
|
|
1097
|
+
_foreignDaGas: ForeignCallSingle,
|
|
1098
|
+
_foreignAddress: ForeignCallSingle,
|
|
1099
|
+
_foreignLength: ForeignCallSingle,
|
|
1100
|
+
_foreignArgs: ForeignCallArray,
|
|
1101
|
+
) {
|
|
1102
|
+
throw new Error(
|
|
1103
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// eslint-disable-next-line camelcase
|
|
1108
|
+
aztec_avm_successCopy() {
|
|
1109
|
+
throw new Error(
|
|
1110
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// eslint-disable-next-line camelcase
|
|
1115
|
+
async aztec_txe_privateCallNewFlow(
|
|
1116
|
+
foreignFrom: ForeignCallSingle,
|
|
1117
|
+
foreignTargetContractAddress: ForeignCallSingle,
|
|
1118
|
+
foreignFunctionSelector: ForeignCallSingle,
|
|
1119
|
+
foreignArgs: ForeignCallArray,
|
|
1120
|
+
foreignArgsHash: ForeignCallSingle,
|
|
1121
|
+
foreignIsStaticCall: ForeignCallSingle,
|
|
1122
|
+
) {
|
|
1123
|
+
const from = addressFromSingle(foreignFrom);
|
|
1124
|
+
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
1125
|
+
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1126
|
+
const args = fromArray(foreignArgs);
|
|
1127
|
+
const argsHash = fromSingle(foreignArgsHash);
|
|
1128
|
+
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1129
|
+
|
|
1130
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(
|
|
1131
|
+
from,
|
|
1132
|
+
targetContractAddress,
|
|
1133
|
+
functionSelector,
|
|
1134
|
+
args,
|
|
1135
|
+
argsHash,
|
|
1136
|
+
isStaticCall,
|
|
1137
|
+
this.stateHandler.getCurrentJob(),
|
|
1138
|
+
);
|
|
1139
|
+
|
|
1140
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1141
|
+
await this.stateHandler.cycleJob();
|
|
1142
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// eslint-disable-next-line camelcase
|
|
1146
|
+
async aztec_txe_executeUtilityFunction(
|
|
1147
|
+
foreignTargetContractAddress: ForeignCallSingle,
|
|
1148
|
+
foreignFunctionSelector: ForeignCallSingle,
|
|
1149
|
+
foreignArgs: ForeignCallArray,
|
|
1150
|
+
) {
|
|
1151
|
+
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
1152
|
+
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1153
|
+
const args = fromArray(foreignArgs);
|
|
1154
|
+
|
|
1155
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(
|
|
1156
|
+
targetContractAddress,
|
|
1157
|
+
functionSelector,
|
|
1158
|
+
args,
|
|
1159
|
+
this.stateHandler.getCurrentJob(),
|
|
1160
|
+
);
|
|
1161
|
+
|
|
1162
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1163
|
+
await this.stateHandler.cycleJob();
|
|
1164
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// eslint-disable-next-line camelcase
|
|
1168
|
+
async aztec_txe_publicCallNewFlow(
|
|
1169
|
+
foreignFrom: ForeignCallSingle,
|
|
1170
|
+
foreignAddress: ForeignCallSingle,
|
|
1171
|
+
foreignCalldata: ForeignCallArray,
|
|
1172
|
+
foreignIsStaticCall: ForeignCallSingle,
|
|
1173
|
+
) {
|
|
1174
|
+
const from = addressFromSingle(foreignFrom);
|
|
1175
|
+
const address = addressFromSingle(foreignAddress);
|
|
1176
|
+
const calldata = fromArray(foreignCalldata);
|
|
1177
|
+
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1178
|
+
|
|
1179
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1180
|
+
|
|
1181
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1182
|
+
await this.stateHandler.cycleJob();
|
|
1183
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// eslint-disable-next-line camelcase
|
|
1187
|
+
async aztec_prv_getSenderForTags() {
|
|
1188
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
1189
|
+
|
|
1190
|
+
// Return a Noir Option struct with `some` and `value` fields
|
|
1191
|
+
if (sender === undefined) {
|
|
1192
|
+
// No sender found, return Option with some=0 and value=0
|
|
1193
|
+
return toForeignCallResult([toSingle(0), toSingle(0)]);
|
|
1194
|
+
} else {
|
|
1195
|
+
// Sender found, return Option with some=1 and value=sender address
|
|
1196
|
+
return toForeignCallResult([toSingle(1), toSingle(sender)]);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// eslint-disable-next-line camelcase
|
|
1201
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
1202
|
+
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
1203
|
+
|
|
1204
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1205
|
+
|
|
1206
|
+
return toForeignCallResult([]);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// eslint-disable-next-line camelcase
|
|
1210
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1211
|
+
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1212
|
+
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1213
|
+
|
|
1214
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1215
|
+
|
|
1216
|
+
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1217
|
+
}
|
|
1218
|
+
}
|