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