@aztec/txe 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/index.d.ts +1 -1
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +85 -52
- package/dest/oracle/interfaces.d.ts +12 -9
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +10 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -14
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +194 -87
- package/dest/rpc_translator.d.ts +35 -20
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +138 -64
- package/dest/state_machine/archiver.d.ts +21 -51
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +41 -21
- package/dest/state_machine/global_variable_builder.d.ts +6 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +7 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +40 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +21 -13
- package/dest/state_machine/synchronizer.d.ts +3 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +21 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +154 -53
- package/dest/util/encoding.d.ts +615 -16
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -17
- package/src/constants.ts +3 -0
- package/src/index.ts +97 -60
- package/src/oracle/interfaces.ts +11 -8
- package/src/oracle/txe_oracle_public_context.ts +12 -19
- package/src/oracle/txe_oracle_top_level_context.ts +229 -131
- package/src/rpc_translator.ts +164 -68
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -28
- package/src/state_machine/global_variable_builder.ts +22 -4
- package/src/state_machine/index.ts +60 -21
- package/src/state_machine/mock_epoch_cache.ts +25 -20
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +210 -101
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -45
- package/src/utils/block_creation.ts +49 -14
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
package/src/rpc_translator.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
|
|
2
2
|
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
3
3
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
4
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import {
|
|
5
6
|
type IMiscOracle,
|
|
6
7
|
type IPrivateExecutionOracle,
|
|
7
8
|
type IUtilityExecutionOracle,
|
|
8
|
-
|
|
9
|
+
packAsHintedNote,
|
|
9
10
|
} from '@aztec/pxe/simulator';
|
|
10
|
-
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
-
import {
|
|
13
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
13
14
|
|
|
14
15
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
15
16
|
import type { TXESessionStateHandler } from './txe_session.js';
|
|
@@ -29,6 +30,9 @@ import {
|
|
|
29
30
|
toSingle,
|
|
30
31
|
} from './util/encoding.js';
|
|
31
32
|
|
|
33
|
+
const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
|
|
34
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
|
+
|
|
32
36
|
export class UnavailableOracleError extends Error {
|
|
33
37
|
constructor(oracleName: string) {
|
|
34
38
|
super(`${oracleName} oracles not available with the current handler`);
|
|
@@ -117,7 +121,7 @@ export class RPCTranslator {
|
|
|
117
121
|
: undefined;
|
|
118
122
|
|
|
119
123
|
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
120
|
-
? fromSingle(foreignAnchorBlockNumberValue).toNumber()
|
|
124
|
+
? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
|
|
121
125
|
: undefined;
|
|
122
126
|
|
|
123
127
|
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
@@ -155,6 +159,12 @@ export class RPCTranslator {
|
|
|
155
159
|
|
|
156
160
|
// TXE-specific oracles
|
|
157
161
|
|
|
162
|
+
txeGetDefaultAddress() {
|
|
163
|
+
const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
|
|
164
|
+
|
|
165
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
async txeGetNextBlockNumber() {
|
|
159
169
|
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
160
170
|
|
|
@@ -266,12 +276,40 @@ export class RPCTranslator {
|
|
|
266
276
|
]);
|
|
267
277
|
}
|
|
268
278
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
foreignHash: ForeignCallSingle,
|
|
279
|
+
async txeGetPrivateEvents(
|
|
280
|
+
foreignSelector: ForeignCallSingle,
|
|
281
|
+
foreignContractAddress: ForeignCallSingle,
|
|
282
|
+
foreignScope: ForeignCallSingle,
|
|
274
283
|
) {
|
|
284
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
285
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
|
+
const scope = addressFromSingle(foreignScope);
|
|
287
|
+
|
|
288
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
289
|
+
|
|
290
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
295
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
299
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
300
|
+
const rawArrayStorage = events
|
|
301
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
302
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
303
|
+
.flat();
|
|
304
|
+
const eventLengths = events
|
|
305
|
+
.map(e => new Fr(e.length))
|
|
306
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
307
|
+
const queryLength = new Fr(events.length);
|
|
308
|
+
|
|
309
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
275
313
|
const values = fromArray(foreignValues);
|
|
276
314
|
const hash = fromSingle(foreignHash);
|
|
277
315
|
|
|
@@ -290,7 +328,7 @@ export class RPCTranslator {
|
|
|
290
328
|
|
|
291
329
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
292
330
|
// When the argument is an array, we add the field length manually to the signature.
|
|
293
|
-
|
|
331
|
+
async utilityLog(
|
|
294
332
|
foreignLevel: ForeignCallSingle,
|
|
295
333
|
foreignMessage: ForeignCallArray,
|
|
296
334
|
_foreignLength: ForeignCallSingle,
|
|
@@ -302,45 +340,47 @@ export class RPCTranslator {
|
|
|
302
340
|
.join('');
|
|
303
341
|
const fields = fromArray(foreignFields);
|
|
304
342
|
|
|
305
|
-
this.handlerAsMisc().
|
|
343
|
+
await this.handlerAsMisc().utilityLog(level, message, fields);
|
|
306
344
|
|
|
307
345
|
return toForeignCallResult([]);
|
|
308
346
|
}
|
|
309
347
|
|
|
310
348
|
async utilityStorageRead(
|
|
349
|
+
foreignBlockHash: ForeignCallSingle,
|
|
311
350
|
foreignContractAddress: ForeignCallSingle,
|
|
312
351
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
313
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
314
352
|
foreignNumberOfElements: ForeignCallSingle,
|
|
315
353
|
) {
|
|
354
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
316
355
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
317
356
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
318
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
319
357
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
320
358
|
|
|
321
359
|
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
360
|
+
blockHash,
|
|
322
361
|
contractAddress,
|
|
323
362
|
startStorageSlot,
|
|
324
|
-
blockNumber,
|
|
325
363
|
numberOfElements,
|
|
326
364
|
);
|
|
327
365
|
|
|
328
366
|
return toForeignCallResult([toArray(values)]);
|
|
329
367
|
}
|
|
330
368
|
|
|
331
|
-
async utilityGetPublicDataWitness(
|
|
332
|
-
const
|
|
369
|
+
async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
370
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
333
371
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
334
372
|
|
|
335
|
-
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(
|
|
373
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
336
374
|
|
|
337
375
|
if (!witness) {
|
|
338
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
376
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
339
377
|
}
|
|
340
378
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
341
379
|
}
|
|
342
380
|
|
|
343
381
|
async utilityGetNotes(
|
|
382
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
344
384
|
foreignStorageSlot: ForeignCallSingle,
|
|
345
385
|
foreignNumSelects: ForeignCallSingle,
|
|
346
386
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -356,8 +396,12 @@ export class RPCTranslator {
|
|
|
356
396
|
foreignOffset: ForeignCallSingle,
|
|
357
397
|
foreignStatus: ForeignCallSingle,
|
|
358
398
|
foreignMaxNotes: ForeignCallSingle,
|
|
359
|
-
|
|
399
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
360
400
|
) {
|
|
401
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
402
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
403
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
404
|
+
: undefined;
|
|
361
405
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
362
406
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
363
407
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -373,9 +417,10 @@ export class RPCTranslator {
|
|
|
373
417
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
374
418
|
const status = fromSingle(foreignStatus).toNumber();
|
|
375
419
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
376
|
-
const
|
|
420
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
377
421
|
|
|
378
422
|
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
423
|
+
owner,
|
|
379
424
|
storageSlot,
|
|
380
425
|
numSelects,
|
|
381
426
|
selectByIndexes,
|
|
@@ -392,7 +437,17 @@ export class RPCTranslator {
|
|
|
392
437
|
status,
|
|
393
438
|
);
|
|
394
439
|
|
|
395
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
440
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
441
|
+
packAsHintedNote({
|
|
442
|
+
contractAddress: noteData.contractAddress,
|
|
443
|
+
owner: noteData.owner,
|
|
444
|
+
randomness: noteData.randomness,
|
|
445
|
+
storageSlot: noteData.storageSlot,
|
|
446
|
+
noteNonce: noteData.noteNonce,
|
|
447
|
+
isPending: noteData.isPending,
|
|
448
|
+
note: noteData.note,
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
396
451
|
|
|
397
452
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
398
453
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -401,28 +456,36 @@ export class RPCTranslator {
|
|
|
401
456
|
|
|
402
457
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
403
458
|
return toForeignCallResult(
|
|
404
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
405
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
406
|
-
maxNotes,
|
|
407
|
-
packedRetrievedNoteLength,
|
|
408
|
-
),
|
|
459
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
409
460
|
);
|
|
410
461
|
}
|
|
411
462
|
|
|
412
463
|
privateNotifyCreatedNote(
|
|
464
|
+
foreignOwner: ForeignCallSingle,
|
|
413
465
|
foreignStorageSlot: ForeignCallSingle,
|
|
466
|
+
foreignRandomness: ForeignCallSingle,
|
|
414
467
|
foreignNoteTypeId: ForeignCallSingle,
|
|
415
468
|
foreignNote: ForeignCallArray,
|
|
416
469
|
foreignNoteHash: ForeignCallSingle,
|
|
417
470
|
foreignCounter: ForeignCallSingle,
|
|
418
471
|
) {
|
|
472
|
+
const owner = addressFromSingle(foreignOwner);
|
|
419
473
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
474
|
+
const randomness = fromSingle(foreignRandomness);
|
|
420
475
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
421
476
|
const note = fromArray(foreignNote);
|
|
422
477
|
const noteHash = fromSingle(foreignNoteHash);
|
|
423
478
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
424
479
|
|
|
425
|
-
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
480
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
481
|
+
owner,
|
|
482
|
+
storageSlot,
|
|
483
|
+
randomness,
|
|
484
|
+
noteTypeId,
|
|
485
|
+
note,
|
|
486
|
+
noteHash,
|
|
487
|
+
counter,
|
|
488
|
+
);
|
|
426
489
|
|
|
427
490
|
return toForeignCallResult([]);
|
|
428
491
|
}
|
|
@@ -449,6 +512,15 @@ export class RPCTranslator {
|
|
|
449
512
|
return toForeignCallResult([]);
|
|
450
513
|
}
|
|
451
514
|
|
|
515
|
+
async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
516
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
517
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
518
|
+
|
|
519
|
+
const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
|
|
520
|
+
|
|
521
|
+
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
522
|
+
}
|
|
523
|
+
|
|
452
524
|
async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
453
525
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
454
526
|
|
|
@@ -473,12 +545,23 @@ export class RPCTranslator {
|
|
|
473
545
|
);
|
|
474
546
|
}
|
|
475
547
|
|
|
476
|
-
async
|
|
548
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
477
549
|
const address = addressFromSingle(foreignAddress);
|
|
478
550
|
|
|
479
|
-
const
|
|
551
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
480
552
|
|
|
481
|
-
return
|
|
553
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
554
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
555
|
+
if (result === undefined) {
|
|
556
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
557
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
|
|
558
|
+
} else {
|
|
559
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
560
|
+
return toForeignCallResult([
|
|
561
|
+
toSingle(new Fr(1)),
|
|
562
|
+
toArray([...result.publicKeys.toFields(), result.partialAddress]),
|
|
563
|
+
]);
|
|
564
|
+
}
|
|
482
565
|
}
|
|
483
566
|
|
|
484
567
|
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
@@ -501,17 +584,14 @@ export class RPCTranslator {
|
|
|
501
584
|
);
|
|
502
585
|
}
|
|
503
586
|
|
|
504
|
-
async utilityGetNullifierMembershipWitness(
|
|
505
|
-
|
|
506
|
-
foreignNullifier: ForeignCallSingle,
|
|
507
|
-
) {
|
|
508
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
587
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
588
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
509
589
|
const nullifier = fromSingle(foreignNullifier);
|
|
510
590
|
|
|
511
|
-
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(
|
|
591
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
512
592
|
|
|
513
593
|
if (!witness) {
|
|
514
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
594
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
515
595
|
}
|
|
516
596
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
517
597
|
}
|
|
@@ -549,14 +629,20 @@ export class RPCTranslator {
|
|
|
549
629
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
550
630
|
}
|
|
551
631
|
|
|
552
|
-
async
|
|
553
|
-
const
|
|
632
|
+
public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
|
|
633
|
+
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
634
|
+
const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
|
|
635
|
+
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
utilityGetUtilityContext() {
|
|
639
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
554
640
|
|
|
555
641
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
556
642
|
}
|
|
557
643
|
|
|
558
644
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
559
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
645
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
560
646
|
|
|
561
647
|
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
562
648
|
|
|
@@ -566,36 +652,49 @@ export class RPCTranslator {
|
|
|
566
652
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
567
653
|
}
|
|
568
654
|
|
|
569
|
-
async
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
foreignLeafValue: ForeignCallSingle,
|
|
655
|
+
async utilityGetNoteHashMembershipWitness(
|
|
656
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
657
|
+
foreignNoteHash: ForeignCallSingle,
|
|
573
658
|
) {
|
|
574
|
-
const
|
|
575
|
-
const
|
|
576
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
659
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
660
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
577
661
|
|
|
578
|
-
const witness = await this.handlerAsUtility().
|
|
662
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
|
|
663
|
+
|
|
664
|
+
if (!witness) {
|
|
665
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
666
|
+
}
|
|
667
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async utilityGetBlockHashMembershipWitness(
|
|
671
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
672
|
+
foreignBlockHash: ForeignCallSingle,
|
|
673
|
+
) {
|
|
674
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
675
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
676
|
+
|
|
677
|
+
const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
579
678
|
|
|
580
679
|
if (!witness) {
|
|
581
680
|
throw new Error(
|
|
582
|
-
`
|
|
681
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
583
682
|
);
|
|
584
683
|
}
|
|
585
|
-
return toForeignCallResult(
|
|
684
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
586
685
|
}
|
|
587
686
|
|
|
588
687
|
async utilityGetLowNullifierMembershipWitness(
|
|
589
|
-
|
|
688
|
+
foreignBlockHash: ForeignCallSingle,
|
|
590
689
|
foreignNullifier: ForeignCallSingle,
|
|
591
690
|
) {
|
|
592
|
-
const
|
|
691
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
593
692
|
const nullifier = fromSingle(foreignNullifier);
|
|
594
693
|
|
|
595
|
-
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
694
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
596
695
|
|
|
597
696
|
if (!witness) {
|
|
598
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
697
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
599
698
|
}
|
|
600
699
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
601
700
|
}
|
|
@@ -608,7 +707,7 @@ export class RPCTranslator {
|
|
|
608
707
|
return toForeignCallResult([]);
|
|
609
708
|
}
|
|
610
709
|
|
|
611
|
-
public async
|
|
710
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
612
711
|
foreignContractAddress: ForeignCallSingle,
|
|
613
712
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
614
713
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
@@ -617,7 +716,7 @@ export class RPCTranslator {
|
|
|
617
716
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
618
717
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
619
718
|
|
|
620
|
-
await this.handlerAsUtility().
|
|
719
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
621
720
|
contractAddress,
|
|
622
721
|
noteValidationRequestsArrayBaseSlot,
|
|
623
722
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -750,15 +849,16 @@ export class RPCTranslator {
|
|
|
750
849
|
|
|
751
850
|
// AVM opcodes
|
|
752
851
|
|
|
753
|
-
|
|
852
|
+
avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
754
853
|
// TODO(#8811): Implement
|
|
755
854
|
return toForeignCallResult([]);
|
|
756
855
|
}
|
|
757
856
|
|
|
758
|
-
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
857
|
+
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
759
858
|
const slot = fromSingle(foreignSlot);
|
|
859
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
760
860
|
|
|
761
|
-
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
|
|
861
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
|
|
762
862
|
|
|
763
863
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
764
864
|
}
|
|
@@ -830,11 +930,10 @@ export class RPCTranslator {
|
|
|
830
930
|
return toForeignCallResult([]);
|
|
831
931
|
}
|
|
832
932
|
|
|
833
|
-
async avmOpcodeNullifierExists(
|
|
834
|
-
const
|
|
835
|
-
const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
|
|
933
|
+
async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
934
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
836
935
|
|
|
837
|
-
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(
|
|
936
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
|
|
838
937
|
|
|
839
938
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
840
939
|
}
|
|
@@ -921,7 +1020,6 @@ export class RPCTranslator {
|
|
|
921
1020
|
foreignFrom: ForeignCallSingle,
|
|
922
1021
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
923
1022
|
foreignFunctionSelector: ForeignCallSingle,
|
|
924
|
-
_foreignArgsLength: ForeignCallSingle,
|
|
925
1023
|
foreignArgs: ForeignCallArray,
|
|
926
1024
|
foreignArgsHash: ForeignCallSingle,
|
|
927
1025
|
foreignIsStaticCall: ForeignCallSingle,
|
|
@@ -945,17 +1043,16 @@ export class RPCTranslator {
|
|
|
945
1043
|
return toForeignCallResult([toArray(returnValues)]);
|
|
946
1044
|
}
|
|
947
1045
|
|
|
948
|
-
async
|
|
1046
|
+
async txeExecuteUtilityFunction(
|
|
949
1047
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
950
1048
|
foreignFunctionSelector: ForeignCallSingle,
|
|
951
|
-
_foreignArgsLength: ForeignCallSingle,
|
|
952
1049
|
foreignArgs: ForeignCallArray,
|
|
953
1050
|
) {
|
|
954
1051
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
955
1052
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
956
1053
|
const args = fromArray(foreignArgs);
|
|
957
1054
|
|
|
958
|
-
const returnValues = await this.handlerAsTxe().
|
|
1055
|
+
const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
|
|
959
1056
|
targetContractAddress,
|
|
960
1057
|
functionSelector,
|
|
961
1058
|
args,
|
|
@@ -967,7 +1064,6 @@ export class RPCTranslator {
|
|
|
967
1064
|
async txePublicCallNewFlow(
|
|
968
1065
|
foreignFrom: ForeignCallSingle,
|
|
969
1066
|
foreignAddress: ForeignCallSingle,
|
|
970
|
-
_foreignLength: ForeignCallSingle,
|
|
971
1067
|
foreignCalldata: ForeignCallArray,
|
|
972
1068
|
foreignIsStaticCall: ForeignCallSingle,
|
|
973
1069
|
) {
|