@aztec/txe 0.0.0-test.1 → 0.0.1-commit.b655e406
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.js +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +78 -49
- package/dest/oracle/interfaces.d.ts +54 -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 +124 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +56 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_top_level_context.js +423 -0
- package/dest/rpc_translator.d.ts +237 -0
- package/dest/rpc_translator.d.ts.map +1 -0
- package/dest/rpc_translator.js +617 -0
- package/dest/state_machine/archiver.d.ts +61 -0
- package/dest/state_machine/archiver.d.ts.map +1 -0
- package/dest/state_machine/archiver.js +118 -0
- package/dest/state_machine/dummy_p2p_client.d.ts +52 -0
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
- package/dest/state_machine/dummy_p2p_client.js +133 -0
- package/dest/state_machine/global_variable_builder.d.ts +9 -0
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
- package/dest/state_machine/global_variable_builder.js +10 -0
- package/dest/state_machine/index.d.ts +16 -0
- package/dest/state_machine/index.d.ts.map +1 -0
- package/dest/state_machine/index.js +51 -0
- package/dest/state_machine/mock_epoch_cache.d.ts +25 -0
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -0
- package/dest/state_machine/mock_epoch_cache.js +50 -0
- package/dest/state_machine/synchronizer.d.ts +32 -0
- package/dest/state_machine/synchronizer.d.ts.map +1 -0
- package/dest/state_machine/synchronizer.js +58 -0
- package/dest/txe_session.d.ts +67 -0
- package/dest/txe_session.d.ts.map +1 -0
- package/dest/txe_session.js +253 -0
- package/dest/util/encoding.d.ts +26 -8
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +65 -10
- package/dest/util/txe_contract_data_provider.d.ts +12 -0
- package/dest/util/txe_contract_data_provider.d.ts.map +1 -0
- package/dest/util/txe_contract_data_provider.js +22 -0
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +36 -57
- package/dest/utils/block_creation.d.ts +13 -0
- package/dest/utils/block_creation.d.ts.map +1 -0
- package/dest/utils/block_creation.js +24 -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 +16 -0
- package/package.json +27 -22
- package/src/bin/index.ts +3 -2
- package/src/index.ts +92 -64
- package/src/oracle/interfaces.ts +83 -0
- package/src/oracle/txe_oracle_public_context.ts +165 -0
- package/src/oracle/txe_oracle_top_level_context.ts +658 -0
- package/src/rpc_translator.ts +1013 -0
- package/src/state_machine/archiver.ts +151 -0
- package/src/state_machine/dummy_p2p_client.ts +197 -0
- package/src/state_machine/global_variable_builder.ts +20 -0
- package/src/state_machine/index.ts +77 -0
- package/src/state_machine/mock_epoch_cache.ts +67 -0
- package/src/state_machine/synchronizer.ts +87 -0
- package/src/txe_session.ts +432 -0
- package/src/util/encoding.ts +84 -10
- package/src/util/txe_contract_data_provider.ts +36 -0
- package/src/util/txe_public_contract_data_source.ts +40 -56
- package/src/utils/block_creation.ts +62 -0
- package/src/utils/tx_effect_creation.ts +37 -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_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,1013 @@
|
|
|
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 {
|
|
5
|
+
type IMiscOracle,
|
|
6
|
+
type IPrivateExecutionOracle,
|
|
7
|
+
type IUtilityExecutionOracle,
|
|
8
|
+
packAsRetrievedNote,
|
|
9
|
+
} from '@aztec/pxe/simulator';
|
|
10
|
+
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
+
|
|
14
|
+
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
15
|
+
import type { TXESessionStateHandler } from './txe_session.js';
|
|
16
|
+
import {
|
|
17
|
+
type ForeignCallArray,
|
|
18
|
+
type ForeignCallSingle,
|
|
19
|
+
addressFromSingle,
|
|
20
|
+
arrayOfArraysToBoundedVecOfArrays,
|
|
21
|
+
arrayToBoundedVec,
|
|
22
|
+
bufferToU8Array,
|
|
23
|
+
fromArray,
|
|
24
|
+
fromSingle,
|
|
25
|
+
fromUintArray,
|
|
26
|
+
fromUintBoundedVec,
|
|
27
|
+
toArray,
|
|
28
|
+
toForeignCallResult,
|
|
29
|
+
toSingle,
|
|
30
|
+
} from './util/encoding.js';
|
|
31
|
+
|
|
32
|
+
export class UnavailableOracleError extends Error {
|
|
33
|
+
constructor(oracleName: string) {
|
|
34
|
+
super(`${oracleName} oracles not available with the current handler`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class RPCTranslator {
|
|
39
|
+
/**
|
|
40
|
+
* Create a new instance of `RPCTranslator` that will translate all TXE RPC calls to and from the foreign
|
|
41
|
+
* (`ForeignCallSingle`, `ForeignCallResult`, etc.) and native TS types, delegating actual execution of the oracles
|
|
42
|
+
* to the different handlers.
|
|
43
|
+
* @param stateHandler The handler that will process TXE session state transitions, such as entering a private or
|
|
44
|
+
* public context.
|
|
45
|
+
* @param oracleHandler The handler that will process all other oracle calls that are not directly related to session
|
|
46
|
+
* state.
|
|
47
|
+
*/
|
|
48
|
+
constructor(
|
|
49
|
+
private stateHandler: TXESessionStateHandler,
|
|
50
|
+
private oracleHandler:
|
|
51
|
+
| IMiscOracle
|
|
52
|
+
| IUtilityExecutionOracle
|
|
53
|
+
| IPrivateExecutionOracle
|
|
54
|
+
| IAvmExecutionOracle
|
|
55
|
+
| ITxeExecutionOracle,
|
|
56
|
+
) {}
|
|
57
|
+
|
|
58
|
+
// Note: If you rename the following functions to not start with "handlerAs", you must also update the validation
|
|
59
|
+
// check in `TXESession.processFunction`.
|
|
60
|
+
|
|
61
|
+
private handlerAsMisc(): IMiscOracle {
|
|
62
|
+
if (!('isMisc' in this.oracleHandler)) {
|
|
63
|
+
throw new UnavailableOracleError('Misc');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return this.oracleHandler;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private handlerAsUtility(): IUtilityExecutionOracle {
|
|
70
|
+
if (!('isUtility' in this.oracleHandler)) {
|
|
71
|
+
throw new UnavailableOracleError('Utility');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return this.oracleHandler;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private handlerAsPrivate(): IPrivateExecutionOracle {
|
|
78
|
+
if (!('isPrivate' in this.oracleHandler)) {
|
|
79
|
+
throw new UnavailableOracleError('Private');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return this.oracleHandler;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private handlerAsAvm(): IAvmExecutionOracle {
|
|
86
|
+
if (!('isAvm' in this.oracleHandler)) {
|
|
87
|
+
throw new UnavailableOracleError('Avm');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return this.oracleHandler;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
94
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
95
|
+
throw new UnavailableOracleError('Txe');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.oracleHandler;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// TXE session state transition functions - these get handled by the state handler
|
|
102
|
+
|
|
103
|
+
async txeSetTopLevelTXEContext() {
|
|
104
|
+
await this.stateHandler.enterTopLevelState();
|
|
105
|
+
|
|
106
|
+
return toForeignCallResult([]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async txeSetPrivateTXEContext(
|
|
110
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
111
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
112
|
+
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
113
|
+
foreignAnchorBlockNumberValue: ForeignCallSingle,
|
|
114
|
+
) {
|
|
115
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
116
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
117
|
+
: undefined;
|
|
118
|
+
|
|
119
|
+
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
120
|
+
? fromSingle(foreignAnchorBlockNumberValue).toNumber()
|
|
121
|
+
: undefined;
|
|
122
|
+
|
|
123
|
+
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
124
|
+
|
|
125
|
+
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async txeSetPublicTXEContext(
|
|
129
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
130
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
131
|
+
) {
|
|
132
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
133
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
134
|
+
: undefined;
|
|
135
|
+
|
|
136
|
+
await this.stateHandler.enterPublicState(contractAddress);
|
|
137
|
+
|
|
138
|
+
return toForeignCallResult([]);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async txeSetUtilityTXEContext(
|
|
142
|
+
foreignContractAddressIsSome: ForeignCallSingle,
|
|
143
|
+
foreignContractAddressValue: ForeignCallSingle,
|
|
144
|
+
) {
|
|
145
|
+
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
146
|
+
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
147
|
+
: undefined;
|
|
148
|
+
|
|
149
|
+
await this.stateHandler.enterUtilityState(contractAddress);
|
|
150
|
+
|
|
151
|
+
return toForeignCallResult([]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Other oracles - these get handled by the oracle handler
|
|
155
|
+
|
|
156
|
+
// TXE-specific oracles
|
|
157
|
+
|
|
158
|
+
async txeGetNextBlockNumber() {
|
|
159
|
+
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
160
|
+
|
|
161
|
+
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async txeGetNextBlockTimestamp() {
|
|
165
|
+
const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
|
|
166
|
+
|
|
167
|
+
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
171
|
+
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
172
|
+
|
|
173
|
+
await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
|
|
174
|
+
|
|
175
|
+
return toForeignCallResult([]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
179
|
+
const duration = fromSingle(foreignDuration).toBigInt();
|
|
180
|
+
|
|
181
|
+
this.handlerAsTxe().txeAdvanceTimestampBy(duration);
|
|
182
|
+
|
|
183
|
+
return toForeignCallResult([]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: ForeignCallSingle) {
|
|
187
|
+
const secret = fromSingle(foreignSecret);
|
|
188
|
+
|
|
189
|
+
await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
|
|
190
|
+
|
|
191
|
+
return toForeignCallResult([
|
|
192
|
+
toArray([
|
|
193
|
+
instance.salt,
|
|
194
|
+
instance.deployer.toField(),
|
|
195
|
+
instance.currentContractClassId,
|
|
196
|
+
instance.initializationHash,
|
|
197
|
+
...instance.publicKeys.toFields(),
|
|
198
|
+
]),
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async txeCreateAccount(foreignSecret: ForeignCallSingle) {
|
|
203
|
+
const secret = fromSingle(foreignSecret);
|
|
204
|
+
|
|
205
|
+
const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
|
|
206
|
+
|
|
207
|
+
return toForeignCallResult([
|
|
208
|
+
toSingle(completeAddress.address),
|
|
209
|
+
...completeAddress.publicKeys.toFields().map(toSingle),
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async txeAddAccount(
|
|
214
|
+
artifact: ContractArtifact,
|
|
215
|
+
instance: ContractInstanceWithAddress,
|
|
216
|
+
foreignSecret: ForeignCallSingle,
|
|
217
|
+
) {
|
|
218
|
+
const secret = fromSingle(foreignSecret);
|
|
219
|
+
|
|
220
|
+
const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
|
|
221
|
+
|
|
222
|
+
return toForeignCallResult([
|
|
223
|
+
toSingle(completeAddress.address),
|
|
224
|
+
...completeAddress.publicKeys.toFields().map(toSingle),
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async txeAddAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
|
|
229
|
+
const address = addressFromSingle(foreignAddress);
|
|
230
|
+
const messageHash = fromSingle(foreignMessageHash);
|
|
231
|
+
|
|
232
|
+
await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
|
|
233
|
+
|
|
234
|
+
return toForeignCallResult([]);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// PXE oracles
|
|
238
|
+
|
|
239
|
+
utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
|
|
240
|
+
const version = fromSingle(foreignVersion).toNumber();
|
|
241
|
+
|
|
242
|
+
this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
|
|
243
|
+
|
|
244
|
+
return toForeignCallResult([]);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
utilityGetRandomField() {
|
|
248
|
+
const randomField = this.handlerAsMisc().utilityGetRandomField();
|
|
249
|
+
|
|
250
|
+
return toForeignCallResult([toSingle(randomField)]);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async txeGetLastBlockTimestamp() {
|
|
254
|
+
const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
|
|
255
|
+
|
|
256
|
+
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async txeGetLastTxEffects() {
|
|
260
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
|
|
261
|
+
|
|
262
|
+
return toForeignCallResult([
|
|
263
|
+
toSingle(txHash.hash),
|
|
264
|
+
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
265
|
+
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX),
|
|
266
|
+
]);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Since the argument is a slice, noir automatically adds a length field to oracle call.
|
|
270
|
+
privateStoreInExecutionCache(
|
|
271
|
+
_foreignLength: ForeignCallSingle,
|
|
272
|
+
foreignValues: ForeignCallArray,
|
|
273
|
+
foreignHash: ForeignCallSingle,
|
|
274
|
+
) {
|
|
275
|
+
const values = fromArray(foreignValues);
|
|
276
|
+
const hash = fromSingle(foreignHash);
|
|
277
|
+
|
|
278
|
+
this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
|
|
279
|
+
|
|
280
|
+
return toForeignCallResult([]);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
|
|
284
|
+
const hash = fromSingle(foreignHash);
|
|
285
|
+
|
|
286
|
+
const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
|
|
287
|
+
|
|
288
|
+
return toForeignCallResult([toArray(returns)]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
292
|
+
// When the argument is an array, we add the field length manually to the signature.
|
|
293
|
+
utilityDebugLog(
|
|
294
|
+
foreignLevel: ForeignCallSingle,
|
|
295
|
+
foreignMessage: ForeignCallArray,
|
|
296
|
+
_foreignLength: ForeignCallSingle,
|
|
297
|
+
foreignFields: ForeignCallArray,
|
|
298
|
+
) {
|
|
299
|
+
const level = fromSingle(foreignLevel).toNumber();
|
|
300
|
+
const message = fromArray(foreignMessage)
|
|
301
|
+
.map(field => String.fromCharCode(field.toNumber()))
|
|
302
|
+
.join('');
|
|
303
|
+
const fields = fromArray(foreignFields);
|
|
304
|
+
|
|
305
|
+
this.handlerAsMisc().utilityDebugLog(level, message, fields);
|
|
306
|
+
|
|
307
|
+
return toForeignCallResult([]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async utilityStorageRead(
|
|
311
|
+
foreignContractAddress: ForeignCallSingle,
|
|
312
|
+
foreignStartStorageSlot: ForeignCallSingle,
|
|
313
|
+
foreignBlockNumber: ForeignCallSingle,
|
|
314
|
+
foreignNumberOfElements: ForeignCallSingle,
|
|
315
|
+
) {
|
|
316
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
317
|
+
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
318
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
319
|
+
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
320
|
+
|
|
321
|
+
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
322
|
+
contractAddress,
|
|
323
|
+
startStorageSlot,
|
|
324
|
+
blockNumber,
|
|
325
|
+
numberOfElements,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
return toForeignCallResult([toArray(values)]);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
332
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
333
|
+
const leafSlot = fromSingle(foreignLeafSlot);
|
|
334
|
+
|
|
335
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
|
|
336
|
+
|
|
337
|
+
if (!witness) {
|
|
338
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
|
|
339
|
+
}
|
|
340
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async utilityGetNotes(
|
|
344
|
+
foreignStorageSlot: ForeignCallSingle,
|
|
345
|
+
foreignNumSelects: ForeignCallSingle,
|
|
346
|
+
foreignSelectByIndexes: ForeignCallArray,
|
|
347
|
+
foreignSelectByOffsets: ForeignCallArray,
|
|
348
|
+
foreignSelectByLengths: ForeignCallArray,
|
|
349
|
+
foreignSelectValues: ForeignCallArray,
|
|
350
|
+
foreignSelectComparators: ForeignCallArray,
|
|
351
|
+
foreignSortByIndexes: ForeignCallArray,
|
|
352
|
+
foreignSortByOffsets: ForeignCallArray,
|
|
353
|
+
foreignSortByLengths: ForeignCallArray,
|
|
354
|
+
foreignSortOrder: ForeignCallArray,
|
|
355
|
+
foreignLimit: ForeignCallSingle,
|
|
356
|
+
foreignOffset: ForeignCallSingle,
|
|
357
|
+
foreignStatus: ForeignCallSingle,
|
|
358
|
+
foreignMaxNotes: ForeignCallSingle,
|
|
359
|
+
foreignPackedRetrievedNoteLength: ForeignCallSingle,
|
|
360
|
+
) {
|
|
361
|
+
const storageSlot = fromSingle(foreignStorageSlot);
|
|
362
|
+
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
363
|
+
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
364
|
+
const selectByOffsets = fromArray(foreignSelectByOffsets).map(fr => fr.toNumber());
|
|
365
|
+
const selectByLengths = fromArray(foreignSelectByLengths).map(fr => fr.toNumber());
|
|
366
|
+
const selectValues = fromArray(foreignSelectValues);
|
|
367
|
+
const selectComparators = fromArray(foreignSelectComparators).map(fr => fr.toNumber());
|
|
368
|
+
const sortByIndexes = fromArray(foreignSortByIndexes).map(fr => fr.toNumber());
|
|
369
|
+
const sortByOffsets = fromArray(foreignSortByOffsets).map(fr => fr.toNumber());
|
|
370
|
+
const sortByLengths = fromArray(foreignSortByLengths).map(fr => fr.toNumber());
|
|
371
|
+
const sortOrder = fromArray(foreignSortOrder).map(fr => fr.toNumber());
|
|
372
|
+
const limit = fromSingle(foreignLimit).toNumber();
|
|
373
|
+
const offset = fromSingle(foreignOffset).toNumber();
|
|
374
|
+
const status = fromSingle(foreignStatus).toNumber();
|
|
375
|
+
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
376
|
+
const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
|
|
377
|
+
|
|
378
|
+
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
379
|
+
storageSlot,
|
|
380
|
+
numSelects,
|
|
381
|
+
selectByIndexes,
|
|
382
|
+
selectByOffsets,
|
|
383
|
+
selectByLengths,
|
|
384
|
+
selectValues,
|
|
385
|
+
selectComparators,
|
|
386
|
+
sortByIndexes,
|
|
387
|
+
sortByOffsets,
|
|
388
|
+
sortByLengths,
|
|
389
|
+
sortOrder,
|
|
390
|
+
limit,
|
|
391
|
+
offset,
|
|
392
|
+
status,
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
const returnDataAsArrayOfArrays = noteDatas.map(packAsRetrievedNote);
|
|
396
|
+
|
|
397
|
+
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
398
|
+
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
399
|
+
subArray.map(toSingle),
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// At last we convert the array of arrays to a bounded vec of arrays
|
|
403
|
+
return toForeignCallResult(
|
|
404
|
+
arrayOfArraysToBoundedVecOfArrays(
|
|
405
|
+
returnDataAsArrayOfForeignCallSingleArrays,
|
|
406
|
+
maxNotes,
|
|
407
|
+
packedRetrievedNoteLength,
|
|
408
|
+
),
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
privateNotifyCreatedNote(
|
|
413
|
+
foreignStorageSlot: ForeignCallSingle,
|
|
414
|
+
foreignNoteTypeId: ForeignCallSingle,
|
|
415
|
+
foreignNote: ForeignCallArray,
|
|
416
|
+
foreignNoteHash: ForeignCallSingle,
|
|
417
|
+
foreignCounter: ForeignCallSingle,
|
|
418
|
+
) {
|
|
419
|
+
const storageSlot = fromSingle(foreignStorageSlot);
|
|
420
|
+
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
421
|
+
const note = fromArray(foreignNote);
|
|
422
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
423
|
+
const counter = fromSingle(foreignCounter).toNumber();
|
|
424
|
+
|
|
425
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(storageSlot, noteTypeId, note, noteHash, counter);
|
|
426
|
+
|
|
427
|
+
return toForeignCallResult([]);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async privateNotifyNullifiedNote(
|
|
431
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
432
|
+
foreignNoteHash: ForeignCallSingle,
|
|
433
|
+
foreignCounter: ForeignCallSingle,
|
|
434
|
+
) {
|
|
435
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
436
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
437
|
+
const counter = fromSingle(foreignCounter).toNumber();
|
|
438
|
+
|
|
439
|
+
await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
440
|
+
|
|
441
|
+
return toForeignCallResult([]);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
445
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
446
|
+
|
|
447
|
+
await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
|
|
448
|
+
|
|
449
|
+
return toForeignCallResult([]);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
453
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
454
|
+
|
|
455
|
+
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
|
|
456
|
+
|
|
457
|
+
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
|
|
461
|
+
const address = addressFromSingle(foreignAddress);
|
|
462
|
+
|
|
463
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
464
|
+
|
|
465
|
+
return toForeignCallResult(
|
|
466
|
+
[
|
|
467
|
+
instance.salt,
|
|
468
|
+
instance.deployer.toField(),
|
|
469
|
+
instance.currentContractClassId,
|
|
470
|
+
instance.initializationHash,
|
|
471
|
+
...instance.publicKeys.toFields(),
|
|
472
|
+
].map(toSingle),
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
477
|
+
const address = addressFromSingle(foreignAddress);
|
|
478
|
+
|
|
479
|
+
const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
|
|
480
|
+
|
|
481
|
+
return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
485
|
+
const pkMHash = fromSingle(foreignPkMHash);
|
|
486
|
+
|
|
487
|
+
const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
|
|
488
|
+
|
|
489
|
+
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
privateCallPrivateFunction(
|
|
493
|
+
_foreignTargetContractAddress: ForeignCallSingle,
|
|
494
|
+
_foreignFunctionSelector: ForeignCallSingle,
|
|
495
|
+
_foreignArgsHash: ForeignCallSingle,
|
|
496
|
+
_foreignSideEffectCounter: ForeignCallSingle,
|
|
497
|
+
_foreignIsStaticCall: ForeignCallSingle,
|
|
498
|
+
) {
|
|
499
|
+
throw new Error(
|
|
500
|
+
'Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead',
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async utilityGetNullifierMembershipWitness(
|
|
505
|
+
foreignBlockNumber: ForeignCallSingle,
|
|
506
|
+
foreignNullifier: ForeignCallSingle,
|
|
507
|
+
) {
|
|
508
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
509
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
510
|
+
|
|
511
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
|
|
512
|
+
|
|
513
|
+
if (!witness) {
|
|
514
|
+
throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
|
|
515
|
+
}
|
|
516
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
520
|
+
const messageHash = fromSingle(foreignMessageHash);
|
|
521
|
+
|
|
522
|
+
const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
|
|
523
|
+
|
|
524
|
+
if (!authWitness) {
|
|
525
|
+
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
526
|
+
}
|
|
527
|
+
return toForeignCallResult([toArray(authWitness)]);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
public privateNotifyEnqueuedPublicFunctionCall(
|
|
531
|
+
_foreignTargetContractAddress: ForeignCallSingle,
|
|
532
|
+
_foreignCalldataHash: ForeignCallSingle,
|
|
533
|
+
_foreignSideEffectCounter: ForeignCallSingle,
|
|
534
|
+
_foreignIsStaticCall: ForeignCallSingle,
|
|
535
|
+
) {
|
|
536
|
+
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
public privateNotifySetPublicTeardownFunctionCall(
|
|
540
|
+
_foreignTargetContractAddress: ForeignCallSingle,
|
|
541
|
+
_foreignCalldataHash: ForeignCallSingle,
|
|
542
|
+
_foreignSideEffectCounter: ForeignCallSingle,
|
|
543
|
+
_foreignIsStaticCall: ForeignCallSingle,
|
|
544
|
+
) {
|
|
545
|
+
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
549
|
+
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
async utilityGetUtilityContext() {
|
|
553
|
+
const context = await this.handlerAsUtility().utilityGetUtilityContext();
|
|
554
|
+
|
|
555
|
+
return toForeignCallResult(context.toNoirRepresentation());
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
559
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
560
|
+
|
|
561
|
+
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
562
|
+
|
|
563
|
+
if (!header) {
|
|
564
|
+
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
565
|
+
}
|
|
566
|
+
return toForeignCallResult(header.toFields().map(toSingle));
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
async utilityGetMembershipWitness(
|
|
570
|
+
foreignBlockNumber: ForeignCallSingle,
|
|
571
|
+
foreignTreeId: ForeignCallSingle,
|
|
572
|
+
foreignLeafValue: ForeignCallSingle,
|
|
573
|
+
) {
|
|
574
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
575
|
+
const treeId = fromSingle(foreignTreeId).toNumber();
|
|
576
|
+
const leafValue = fromSingle(foreignLeafValue);
|
|
577
|
+
|
|
578
|
+
const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
|
|
579
|
+
|
|
580
|
+
if (!witness) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
`Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
async utilityGetLowNullifierMembershipWitness(
|
|
589
|
+
foreignBlockNumber: ForeignCallSingle,
|
|
590
|
+
foreignNullifier: ForeignCallSingle,
|
|
591
|
+
) {
|
|
592
|
+
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
593
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
594
|
+
|
|
595
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
|
|
596
|
+
|
|
597
|
+
if (!witness) {
|
|
598
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
|
|
599
|
+
}
|
|
600
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
604
|
+
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
605
|
+
|
|
606
|
+
await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
607
|
+
|
|
608
|
+
return toForeignCallResult([]);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
public async utilityValidateEnqueuedNotesAndEvents(
|
|
612
|
+
foreignContractAddress: ForeignCallSingle,
|
|
613
|
+
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
614
|
+
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
615
|
+
) {
|
|
616
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
617
|
+
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
618
|
+
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
619
|
+
|
|
620
|
+
await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
|
|
621
|
+
contractAddress,
|
|
622
|
+
noteValidationRequestsArrayBaseSlot,
|
|
623
|
+
eventValidationRequestsArrayBaseSlot,
|
|
624
|
+
);
|
|
625
|
+
|
|
626
|
+
return toForeignCallResult([]);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
public async utilityBulkRetrieveLogs(
|
|
630
|
+
foreignContractAddress: ForeignCallSingle,
|
|
631
|
+
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
632
|
+
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
633
|
+
) {
|
|
634
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
635
|
+
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
636
|
+
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
637
|
+
|
|
638
|
+
await this.handlerAsUtility().utilityBulkRetrieveLogs(
|
|
639
|
+
contractAddress,
|
|
640
|
+
logRetrievalRequestsArrayBaseSlot,
|
|
641
|
+
logRetrievalResponsesArrayBaseSlot,
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
return toForeignCallResult([]);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
async utilityStoreCapsule(
|
|
648
|
+
foreignContractAddress: ForeignCallSingle,
|
|
649
|
+
foreignSlot: ForeignCallSingle,
|
|
650
|
+
foreignCapsule: ForeignCallArray,
|
|
651
|
+
) {
|
|
652
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
653
|
+
const slot = fromSingle(foreignSlot);
|
|
654
|
+
const capsule = fromArray(foreignCapsule);
|
|
655
|
+
|
|
656
|
+
await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
|
|
657
|
+
|
|
658
|
+
return toForeignCallResult([]);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
async utilityLoadCapsule(
|
|
662
|
+
foreignContractAddress: ForeignCallSingle,
|
|
663
|
+
foreignSlot: ForeignCallSingle,
|
|
664
|
+
foreignTSize: ForeignCallSingle,
|
|
665
|
+
) {
|
|
666
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
667
|
+
const slot = fromSingle(foreignSlot);
|
|
668
|
+
const tSize = fromSingle(foreignTSize).toNumber();
|
|
669
|
+
|
|
670
|
+
const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
|
|
671
|
+
|
|
672
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
673
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
674
|
+
if (values === null) {
|
|
675
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
676
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(tSize).fill(new Fr(0)))]);
|
|
677
|
+
} else {
|
|
678
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
679
|
+
return toForeignCallResult([toSingle(new Fr(1)), toArray(values)]);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
async utilityDeleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
|
|
684
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
685
|
+
const slot = fromSingle(foreignSlot);
|
|
686
|
+
|
|
687
|
+
await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
|
|
688
|
+
|
|
689
|
+
return toForeignCallResult([]);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
async utilityCopyCapsule(
|
|
693
|
+
foreignContractAddress: ForeignCallSingle,
|
|
694
|
+
foreignSrcSlot: ForeignCallSingle,
|
|
695
|
+
foreignDstSlot: ForeignCallSingle,
|
|
696
|
+
foreignNumEntries: ForeignCallSingle,
|
|
697
|
+
) {
|
|
698
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
699
|
+
const srcSlot = fromSingle(foreignSrcSlot);
|
|
700
|
+
const dstSlot = fromSingle(foreignDstSlot);
|
|
701
|
+
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
702
|
+
|
|
703
|
+
await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
704
|
+
|
|
705
|
+
return toForeignCallResult([]);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
709
|
+
// 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
|
|
710
|
+
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
711
|
+
// existence of a txe_oracle method?
|
|
712
|
+
async utilityAes128Decrypt(
|
|
713
|
+
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
714
|
+
foreignCiphertextLength: ForeignCallSingle,
|
|
715
|
+
foreignIv: ForeignCallArray,
|
|
716
|
+
foreignSymKey: ForeignCallArray,
|
|
717
|
+
) {
|
|
718
|
+
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
719
|
+
const iv = fromUintArray(foreignIv, 8);
|
|
720
|
+
const symKey = fromUintArray(foreignSymKey, 8);
|
|
721
|
+
|
|
722
|
+
const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
|
|
723
|
+
|
|
724
|
+
return toForeignCallResult(
|
|
725
|
+
arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
async utilityGetSharedSecret(
|
|
730
|
+
foreignAddress: ForeignCallSingle,
|
|
731
|
+
foreignEphPKField0: ForeignCallSingle,
|
|
732
|
+
foreignEphPKField1: ForeignCallSingle,
|
|
733
|
+
foreignEphPKField2: ForeignCallSingle,
|
|
734
|
+
) {
|
|
735
|
+
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
736
|
+
const ephPK = Point.fromFields([
|
|
737
|
+
fromSingle(foreignEphPKField0),
|
|
738
|
+
fromSingle(foreignEphPKField1),
|
|
739
|
+
fromSingle(foreignEphPKField2),
|
|
740
|
+
]);
|
|
741
|
+
|
|
742
|
+
const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
|
|
743
|
+
|
|
744
|
+
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
emitOffchainEffect(_foreignData: ForeignCallArray) {
|
|
748
|
+
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// AVM opcodes
|
|
752
|
+
|
|
753
|
+
avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
|
|
754
|
+
// TODO(#8811): Implement
|
|
755
|
+
return toForeignCallResult([]);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
759
|
+
const slot = fromSingle(foreignSlot);
|
|
760
|
+
|
|
761
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
|
|
762
|
+
|
|
763
|
+
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
async avmOpcodeStorageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
767
|
+
const slot = fromSingle(foreignSlot);
|
|
768
|
+
const value = fromSingle(foreignValue);
|
|
769
|
+
|
|
770
|
+
await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
|
|
771
|
+
|
|
772
|
+
return toForeignCallResult([]);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
776
|
+
const address = addressFromSingle(foreignAddress);
|
|
777
|
+
|
|
778
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
779
|
+
|
|
780
|
+
return toForeignCallResult([
|
|
781
|
+
toSingle(instance.deployer),
|
|
782
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
783
|
+
toSingle(new Fr(1)),
|
|
784
|
+
]);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
788
|
+
const address = addressFromSingle(foreignAddress);
|
|
789
|
+
|
|
790
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
791
|
+
|
|
792
|
+
return toForeignCallResult([
|
|
793
|
+
toSingle(instance.currentContractClassId),
|
|
794
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
795
|
+
toSingle(new Fr(1)),
|
|
796
|
+
]);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
800
|
+
const address = addressFromSingle(foreignAddress);
|
|
801
|
+
|
|
802
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
803
|
+
|
|
804
|
+
return toForeignCallResult([
|
|
805
|
+
toSingle(instance.initializationHash),
|
|
806
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
807
|
+
toSingle(new Fr(1)),
|
|
808
|
+
]);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
async avmOpcodeSender() {
|
|
812
|
+
const sender = await this.handlerAsAvm().avmOpcodeSender();
|
|
813
|
+
|
|
814
|
+
return toForeignCallResult([toSingle(sender)]);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
818
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
819
|
+
|
|
820
|
+
await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
|
|
821
|
+
|
|
822
|
+
return toForeignCallResult([]);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
826
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
827
|
+
|
|
828
|
+
await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
|
|
829
|
+
|
|
830
|
+
return toForeignCallResult([]);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
|
|
834
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
835
|
+
const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
|
|
836
|
+
|
|
837
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
|
|
838
|
+
|
|
839
|
+
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
async avmOpcodeAddress() {
|
|
843
|
+
const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
|
|
844
|
+
|
|
845
|
+
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
async avmOpcodeBlockNumber() {
|
|
849
|
+
const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
|
|
850
|
+
|
|
851
|
+
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
async avmOpcodeTimestamp() {
|
|
855
|
+
const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
|
|
856
|
+
|
|
857
|
+
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
async avmOpcodeIsStaticCall() {
|
|
861
|
+
const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
|
|
862
|
+
|
|
863
|
+
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
async avmOpcodeChainId() {
|
|
867
|
+
const chainId = await this.handlerAsAvm().avmOpcodeChainId();
|
|
868
|
+
|
|
869
|
+
return toForeignCallResult([toSingle(chainId)]);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
async avmOpcodeVersion() {
|
|
873
|
+
const version = await this.handlerAsAvm().avmOpcodeVersion();
|
|
874
|
+
|
|
875
|
+
return toForeignCallResult([toSingle(version)]);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
avmOpcodeReturndataSize() {
|
|
879
|
+
throw new Error(
|
|
880
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
avmOpcodeReturndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
885
|
+
throw new Error(
|
|
886
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
avmOpcodeCall(
|
|
891
|
+
_foreignL2Gas: ForeignCallSingle,
|
|
892
|
+
_foreignDaGas: ForeignCallSingle,
|
|
893
|
+
_foreignAddress: ForeignCallSingle,
|
|
894
|
+
_foreignLength: ForeignCallSingle,
|
|
895
|
+
_foreignArgs: ForeignCallArray,
|
|
896
|
+
) {
|
|
897
|
+
throw new Error(
|
|
898
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
avmOpcodeStaticCall(
|
|
903
|
+
_foreignL2Gas: ForeignCallSingle,
|
|
904
|
+
_foreignDaGas: ForeignCallSingle,
|
|
905
|
+
_foreignAddress: ForeignCallSingle,
|
|
906
|
+
_foreignLength: ForeignCallSingle,
|
|
907
|
+
_foreignArgs: ForeignCallArray,
|
|
908
|
+
) {
|
|
909
|
+
throw new Error(
|
|
910
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
avmOpcodeSuccessCopy() {
|
|
915
|
+
throw new Error(
|
|
916
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
async txePrivateCallNewFlow(
|
|
921
|
+
foreignFrom: ForeignCallSingle,
|
|
922
|
+
foreignTargetContractAddress: ForeignCallSingle,
|
|
923
|
+
foreignFunctionSelector: ForeignCallSingle,
|
|
924
|
+
_foreignArgsLength: ForeignCallSingle,
|
|
925
|
+
foreignArgs: ForeignCallArray,
|
|
926
|
+
foreignArgsHash: ForeignCallSingle,
|
|
927
|
+
foreignIsStaticCall: ForeignCallSingle,
|
|
928
|
+
) {
|
|
929
|
+
const from = addressFromSingle(foreignFrom);
|
|
930
|
+
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
931
|
+
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
932
|
+
const args = fromArray(foreignArgs);
|
|
933
|
+
const argsHash = fromSingle(foreignArgsHash);
|
|
934
|
+
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
935
|
+
|
|
936
|
+
const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
|
|
937
|
+
from,
|
|
938
|
+
targetContractAddress,
|
|
939
|
+
functionSelector,
|
|
940
|
+
args,
|
|
941
|
+
argsHash,
|
|
942
|
+
isStaticCall,
|
|
943
|
+
);
|
|
944
|
+
|
|
945
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
async txeSimulateUtilityFunction(
|
|
949
|
+
foreignTargetContractAddress: ForeignCallSingle,
|
|
950
|
+
foreignFunctionSelector: ForeignCallSingle,
|
|
951
|
+
_foreignArgsLength: ForeignCallSingle,
|
|
952
|
+
foreignArgs: ForeignCallArray,
|
|
953
|
+
) {
|
|
954
|
+
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
955
|
+
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
956
|
+
const args = fromArray(foreignArgs);
|
|
957
|
+
|
|
958
|
+
const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
|
|
959
|
+
targetContractAddress,
|
|
960
|
+
functionSelector,
|
|
961
|
+
args,
|
|
962
|
+
);
|
|
963
|
+
|
|
964
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
async txePublicCallNewFlow(
|
|
968
|
+
foreignFrom: ForeignCallSingle,
|
|
969
|
+
foreignAddress: ForeignCallSingle,
|
|
970
|
+
_foreignLength: ForeignCallSingle,
|
|
971
|
+
foreignCalldata: ForeignCallArray,
|
|
972
|
+
foreignIsStaticCall: ForeignCallSingle,
|
|
973
|
+
) {
|
|
974
|
+
const from = addressFromSingle(foreignFrom);
|
|
975
|
+
const address = addressFromSingle(foreignAddress);
|
|
976
|
+
const calldata = fromArray(foreignCalldata);
|
|
977
|
+
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
978
|
+
|
|
979
|
+
const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
|
|
980
|
+
|
|
981
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
async privateGetSenderForTags() {
|
|
985
|
+
const sender = await this.handlerAsPrivate().privateGetSenderForTags();
|
|
986
|
+
|
|
987
|
+
// Return a Noir Option struct with `some` and `value` fields
|
|
988
|
+
if (sender === undefined) {
|
|
989
|
+
// No sender found, return Option with some=0 and value=0
|
|
990
|
+
return toForeignCallResult([toSingle(0), toSingle(0)]);
|
|
991
|
+
} else {
|
|
992
|
+
// Sender found, return Option with some=1 and value=sender address
|
|
993
|
+
return toForeignCallResult([toSingle(1), toSingle(sender)]);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
998
|
+
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
999
|
+
|
|
1000
|
+
await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
|
|
1001
|
+
|
|
1002
|
+
return toForeignCallResult([]);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1006
|
+
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1007
|
+
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1008
|
+
|
|
1009
|
+
const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
|
|
1010
|
+
|
|
1011
|
+
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1012
|
+
}
|
|
1013
|
+
}
|