@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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/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 +3 -2
- package/dest/oracle/interfaces.d.ts +10 -7
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +6 -6
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +7 -8
- package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +108 -71
- package/dest/rpc_translator.d.ts +24 -12
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +98 -42
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +61 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +16 -11
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- 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 +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +31 -19
- package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +10 -7
- 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 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +94 -47
- package/dest/util/encoding.d.ts +618 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +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_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- 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 +36 -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 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +9 -6
- package/src/oracle/txe_oracle_public_context.ts +9 -14
- package/src/oracle/txe_oracle_top_level_context.ts +159 -98
- package/src/rpc_translator.ts +128 -50
- package/src/state_machine/archiver.ts +57 -114
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +40 -17
- package/src/state_machine/mock_epoch_cache.ts +10 -11
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +192 -81
- 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_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +13 -12
- package/src/utils/block_creation.ts +47 -15
- 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/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 { L2BlockHash } 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,6 +276,39 @@ export class RPCTranslator {
|
|
|
266
276
|
]);
|
|
267
277
|
}
|
|
268
278
|
|
|
279
|
+
async txeGetPrivateEvents(
|
|
280
|
+
foreignSelector: ForeignCallSingle,
|
|
281
|
+
foreignContractAddress: ForeignCallSingle,
|
|
282
|
+
foreignScope: ForeignCallSingle,
|
|
283
|
+
) {
|
|
284
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
285
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
|
+
const scope = addressFromSingle(foreignScope);
|
|
287
|
+
|
|
288
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
289
|
+
|
|
290
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
295
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
299
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
300
|
+
const rawArrayStorage = events
|
|
301
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
302
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
303
|
+
.flat();
|
|
304
|
+
const eventLengths = events
|
|
305
|
+
.map(e => new Fr(e.length))
|
|
306
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
307
|
+
const queryLength = new Fr(events.length);
|
|
308
|
+
|
|
309
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
310
|
+
}
|
|
311
|
+
|
|
269
312
|
privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
270
313
|
const values = fromArray(foreignValues);
|
|
271
314
|
const hash = fromSingle(foreignHash);
|
|
@@ -303,39 +346,41 @@ export class RPCTranslator {
|
|
|
303
346
|
}
|
|
304
347
|
|
|
305
348
|
async utilityStorageRead(
|
|
349
|
+
foreignBlockHash: ForeignCallSingle,
|
|
306
350
|
foreignContractAddress: ForeignCallSingle,
|
|
307
351
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
308
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
309
352
|
foreignNumberOfElements: ForeignCallSingle,
|
|
310
353
|
) {
|
|
354
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
311
355
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
312
356
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
313
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
314
357
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
315
358
|
|
|
316
359
|
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
360
|
+
blockHash,
|
|
317
361
|
contractAddress,
|
|
318
362
|
startStorageSlot,
|
|
319
|
-
blockNumber,
|
|
320
363
|
numberOfElements,
|
|
321
364
|
);
|
|
322
365
|
|
|
323
366
|
return toForeignCallResult([toArray(values)]);
|
|
324
367
|
}
|
|
325
368
|
|
|
326
|
-
async utilityGetPublicDataWitness(
|
|
327
|
-
const
|
|
369
|
+
async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
370
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
328
371
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
329
372
|
|
|
330
|
-
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(
|
|
373
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
331
374
|
|
|
332
375
|
if (!witness) {
|
|
333
|
-
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()}.`);
|
|
334
377
|
}
|
|
335
378
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
336
379
|
}
|
|
337
380
|
|
|
338
381
|
async utilityGetNotes(
|
|
382
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
339
384
|
foreignStorageSlot: ForeignCallSingle,
|
|
340
385
|
foreignNumSelects: ForeignCallSingle,
|
|
341
386
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -351,8 +396,12 @@ export class RPCTranslator {
|
|
|
351
396
|
foreignOffset: ForeignCallSingle,
|
|
352
397
|
foreignStatus: ForeignCallSingle,
|
|
353
398
|
foreignMaxNotes: ForeignCallSingle,
|
|
354
|
-
|
|
399
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
355
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;
|
|
356
405
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
357
406
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
358
407
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -368,9 +417,10 @@ export class RPCTranslator {
|
|
|
368
417
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
369
418
|
const status = fromSingle(foreignStatus).toNumber();
|
|
370
419
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
371
|
-
const
|
|
420
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
372
421
|
|
|
373
422
|
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
423
|
+
owner,
|
|
374
424
|
storageSlot,
|
|
375
425
|
numSelects,
|
|
376
426
|
selectByIndexes,
|
|
@@ -387,7 +437,17 @@ export class RPCTranslator {
|
|
|
387
437
|
status,
|
|
388
438
|
);
|
|
389
439
|
|
|
390
|
-
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
|
+
);
|
|
391
451
|
|
|
392
452
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
393
453
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -396,15 +456,12 @@ export class RPCTranslator {
|
|
|
396
456
|
|
|
397
457
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
398
458
|
return toForeignCallResult(
|
|
399
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
400
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
401
|
-
maxNotes,
|
|
402
|
-
packedRetrievedNoteLength,
|
|
403
|
-
),
|
|
459
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
404
460
|
);
|
|
405
461
|
}
|
|
406
462
|
|
|
407
463
|
privateNotifyCreatedNote(
|
|
464
|
+
foreignOwner: ForeignCallSingle,
|
|
408
465
|
foreignStorageSlot: ForeignCallSingle,
|
|
409
466
|
foreignRandomness: ForeignCallSingle,
|
|
410
467
|
foreignNoteTypeId: ForeignCallSingle,
|
|
@@ -412,6 +469,7 @@ export class RPCTranslator {
|
|
|
412
469
|
foreignNoteHash: ForeignCallSingle,
|
|
413
470
|
foreignCounter: ForeignCallSingle,
|
|
414
471
|
) {
|
|
472
|
+
const owner = addressFromSingle(foreignOwner);
|
|
415
473
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
416
474
|
const randomness = fromSingle(foreignRandomness);
|
|
417
475
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
@@ -419,7 +477,15 @@ export class RPCTranslator {
|
|
|
419
477
|
const noteHash = fromSingle(foreignNoteHash);
|
|
420
478
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
421
479
|
|
|
422
|
-
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
480
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
481
|
+
owner,
|
|
482
|
+
storageSlot,
|
|
483
|
+
randomness,
|
|
484
|
+
noteTypeId,
|
|
485
|
+
note,
|
|
486
|
+
noteHash,
|
|
487
|
+
counter,
|
|
488
|
+
);
|
|
423
489
|
|
|
424
490
|
return toForeignCallResult([]);
|
|
425
491
|
}
|
|
@@ -446,6 +512,15 @@ export class RPCTranslator {
|
|
|
446
512
|
return toForeignCallResult([]);
|
|
447
513
|
}
|
|
448
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
|
+
|
|
449
524
|
async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
450
525
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
451
526
|
|
|
@@ -498,17 +573,14 @@ export class RPCTranslator {
|
|
|
498
573
|
);
|
|
499
574
|
}
|
|
500
575
|
|
|
501
|
-
async utilityGetNullifierMembershipWitness(
|
|
502
|
-
|
|
503
|
-
foreignNullifier: ForeignCallSingle,
|
|
504
|
-
) {
|
|
505
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
576
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
577
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
506
578
|
const nullifier = fromSingle(foreignNullifier);
|
|
507
579
|
|
|
508
|
-
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(
|
|
580
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
509
581
|
|
|
510
582
|
if (!witness) {
|
|
511
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
583
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
512
584
|
}
|
|
513
585
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
514
586
|
}
|
|
@@ -552,14 +624,14 @@ export class RPCTranslator {
|
|
|
552
624
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
553
625
|
}
|
|
554
626
|
|
|
555
|
-
|
|
556
|
-
const context =
|
|
627
|
+
utilityGetUtilityContext() {
|
|
628
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
557
629
|
|
|
558
630
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
559
631
|
}
|
|
560
632
|
|
|
561
633
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
562
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
634
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
563
635
|
|
|
564
636
|
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
565
637
|
|
|
@@ -569,36 +641,41 @@ export class RPCTranslator {
|
|
|
569
641
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
570
642
|
}
|
|
571
643
|
|
|
572
|
-
async
|
|
573
|
-
|
|
574
|
-
foreignTreeId: ForeignCallSingle,
|
|
575
|
-
foreignLeafValue: ForeignCallSingle,
|
|
576
|
-
) {
|
|
577
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
578
|
-
const treeId = fromSingle(foreignTreeId).toNumber();
|
|
644
|
+
async utilityGetNoteHashMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignLeafValue: ForeignCallSingle) {
|
|
645
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
579
646
|
const leafValue = fromSingle(foreignLeafValue);
|
|
580
647
|
|
|
581
|
-
const witness = await this.handlerAsUtility().
|
|
648
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, leafValue);
|
|
582
649
|
|
|
583
650
|
if (!witness) {
|
|
584
|
-
throw new Error(
|
|
585
|
-
`Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
|
|
586
|
-
);
|
|
651
|
+
throw new Error(`Note hash ${leafValue} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
587
652
|
}
|
|
588
|
-
return toForeignCallResult(
|
|
653
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
async utilityGetArchiveMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignLeafValue: ForeignCallSingle) {
|
|
657
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
658
|
+
const leafValue = fromSingle(foreignLeafValue);
|
|
659
|
+
|
|
660
|
+
const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(blockHash, leafValue);
|
|
661
|
+
|
|
662
|
+
if (!witness) {
|
|
663
|
+
throw new Error(`Block hash ${leafValue} not found in the archive tree at block ${blockHash.toString()}.`);
|
|
664
|
+
}
|
|
665
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
589
666
|
}
|
|
590
667
|
|
|
591
668
|
async utilityGetLowNullifierMembershipWitness(
|
|
592
|
-
|
|
669
|
+
foreignBlockHash: ForeignCallSingle,
|
|
593
670
|
foreignNullifier: ForeignCallSingle,
|
|
594
671
|
) {
|
|
595
|
-
const
|
|
672
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
596
673
|
const nullifier = fromSingle(foreignNullifier);
|
|
597
674
|
|
|
598
|
-
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
675
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
599
676
|
|
|
600
677
|
if (!witness) {
|
|
601
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
678
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
602
679
|
}
|
|
603
680
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
604
681
|
}
|
|
@@ -611,7 +688,7 @@ export class RPCTranslator {
|
|
|
611
688
|
return toForeignCallResult([]);
|
|
612
689
|
}
|
|
613
690
|
|
|
614
|
-
public async
|
|
691
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
615
692
|
foreignContractAddress: ForeignCallSingle,
|
|
616
693
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
617
694
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
@@ -620,7 +697,7 @@ export class RPCTranslator {
|
|
|
620
697
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
621
698
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
622
699
|
|
|
623
|
-
await this.handlerAsUtility().
|
|
700
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
624
701
|
contractAddress,
|
|
625
702
|
noteValidationRequestsArrayBaseSlot,
|
|
626
703
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -758,10 +835,11 @@ export class RPCTranslator {
|
|
|
758
835
|
return toForeignCallResult([]);
|
|
759
836
|
}
|
|
760
837
|
|
|
761
|
-
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
838
|
+
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
762
839
|
const slot = fromSingle(foreignSlot);
|
|
840
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
763
841
|
|
|
764
|
-
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
|
|
842
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
|
|
765
843
|
|
|
766
844
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
767
845
|
}
|
|
@@ -1,152 +1,95 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
8
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
10
9
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
12
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/**
|
|
12
|
+
* TXE Archiver implementation.
|
|
13
|
+
* Provides most of the endpoints needed by the node for reading from and writing to state,
|
|
14
|
+
* without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
|
|
15
|
+
*/
|
|
16
|
+
export class TXEArchiver extends ArchiverDataSourceBase {
|
|
17
|
+
private readonly updater = new ArchiverDataStoreUpdater(this.store);
|
|
18
|
+
|
|
18
19
|
constructor(db: AztecAsyncKVStore) {
|
|
19
|
-
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
|
|
21
|
+
super(store);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
public
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.store.addBlocks(blocks),
|
|
26
|
-
]);
|
|
24
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
|
|
25
|
+
await this.updater.addCheckpoints(checkpoints, result);
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
29
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
34
|
-
*/
|
|
35
|
-
public getBlockNumber(): Promise<number> {
|
|
36
|
-
return this.store.getSynchedL2BlockNumber();
|
|
32
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
42
|
-
*/
|
|
43
|
-
public getProvenBlockNumber(): Promise<number> {
|
|
44
|
-
return this.store.getSynchedL2BlockNumber();
|
|
36
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
45
38
|
}
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* @param number - The block number to return (inclusive).
|
|
50
|
-
* @returns The requested L2 block.
|
|
51
|
-
*/
|
|
52
|
-
public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
53
|
-
// If the number provided is -ve, then return the latest block.
|
|
54
|
-
if (number < 0) {
|
|
55
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
56
|
-
}
|
|
57
|
-
if (number == 0) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const blocks = await this.store.getPublishedBlocks(number, 1);
|
|
61
|
-
return blocks.length === 0 ? undefined : blocks[0];
|
|
40
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
41
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
62
42
|
}
|
|
63
43
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param number - The block number to return (inclusive).
|
|
67
|
-
* @returns The requested L2 block.
|
|
68
|
-
*/
|
|
69
|
-
public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
|
|
70
|
-
return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
|
|
44
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
45
|
+
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
71
46
|
}
|
|
72
47
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (number === 'latest') {
|
|
80
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
48
|
+
public async getL2Tips(): Promise<L2Tips> {
|
|
49
|
+
// In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
|
|
50
|
+
// and 'finalized' to the latest block.
|
|
51
|
+
const blockHeader = await this.getBlockHeader('latest');
|
|
52
|
+
if (!blockHeader) {
|
|
53
|
+
throw new Error('L2Tips requested from TXE Archiver but no block header found');
|
|
81
54
|
}
|
|
82
|
-
if (number === 0) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
const headers = await this.store.getBlockHeaders(number, 1);
|
|
86
|
-
return headers.length === 0 ? undefined : headers[0];
|
|
87
|
-
}
|
|
88
55
|
|
|
89
|
-
|
|
90
|
-
|
|
56
|
+
const number = blockHeader.globalVariables.blockNumber;
|
|
57
|
+
const hash = (await blockHeader.hash()).toString();
|
|
58
|
+
const checkpointedBlock = await this.getCheckpointedBlock(number);
|
|
59
|
+
if (!checkpointedBlock) {
|
|
60
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
61
|
+
}
|
|
62
|
+
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
|
|
63
|
+
if (checkpoint.length === 0) {
|
|
64
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
65
|
+
}
|
|
66
|
+
const blockId: L2BlockId = { number, hash };
|
|
67
|
+
const checkpointId: CheckpointId = {
|
|
68
|
+
number: checkpoint[0].checkpointNumber,
|
|
69
|
+
hash: checkpoint[0].header.hash().toString(),
|
|
70
|
+
};
|
|
71
|
+
const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
72
|
+
return {
|
|
73
|
+
proposed: blockId,
|
|
74
|
+
proven: tipId,
|
|
75
|
+
finalized: tipId,
|
|
76
|
+
checkpointed: tipId,
|
|
77
|
+
};
|
|
91
78
|
}
|
|
92
79
|
|
|
93
80
|
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
94
81
|
throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
|
|
95
82
|
}
|
|
96
83
|
|
|
97
|
-
public getL2EpochNumber(): Promise<EpochNumber> {
|
|
84
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
98
85
|
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
99
86
|
}
|
|
100
87
|
|
|
101
|
-
public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
|
|
102
|
-
throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
106
|
-
throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
88
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
110
89
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
111
90
|
}
|
|
112
91
|
|
|
113
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
114
|
-
throw new Error('TXE Archiver does not implement "getL2Tips"');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public getL1Constants(): Promise<L1RollupConstants> {
|
|
118
|
-
throw new Error('TXE Archiver does not implement "getL2Constants"');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
122
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
92
|
public syncImmediate(): Promise<void> {
|
|
126
93
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
127
94
|
}
|
|
128
|
-
|
|
129
|
-
public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
130
|
-
throw new Error('TXE Archiver does not implement "getContract"');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public getRollupAddress(): Promise<EthAddress> {
|
|
134
|
-
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public getRegistryAddress(): Promise<EthAddress> {
|
|
138
|
-
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
142
|
-
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public isPendingChainInvalid(): Promise<boolean> {
|
|
146
|
-
return Promise.resolve(false);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
|
|
150
|
-
return Promise.resolve({ valid: true });
|
|
151
|
-
}
|
|
152
95
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ENR,
|
|
5
5
|
P2P,
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
|
+
P2PCheckpointReceivedCallback,
|
|
7
8
|
P2PConfig,
|
|
8
9
|
P2PSyncState,
|
|
9
10
|
PeerId,
|
|
@@ -14,14 +15,10 @@ import type {
|
|
|
14
15
|
} from '@aztec/p2p';
|
|
15
16
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
16
17
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
17
|
-
import type {
|
|
18
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
18
19
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
19
20
|
|
|
20
21
|
export class DummyP2P implements P2P {
|
|
21
|
-
public broadcastAttestations(_attestations: BlockAttestation[]): Promise<void> {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
22
|
public validate(_txs: Tx[]): Promise<void> {
|
|
26
23
|
return Promise.resolve();
|
|
27
24
|
}
|
|
@@ -46,10 +43,22 @@ export class DummyP2P implements P2P {
|
|
|
46
43
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
47
44
|
}
|
|
48
45
|
|
|
46
|
+
public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
|
|
47
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
51
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
|
|
50
55
|
throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
59
|
+
throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
54
63
|
throw new Error('DummyP2P does not implement "requestTxs"');
|
|
55
64
|
}
|
|
@@ -79,7 +88,9 @@ export class DummyP2P implements P2P {
|
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
82
|
-
|
|
91
|
+
// In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
|
|
92
|
+
// tx status for any tx hash.
|
|
93
|
+
return Promise.resolve('mined');
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
public iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
@@ -118,16 +129,12 @@ export class DummyP2P implements P2P {
|
|
|
118
129
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
public
|
|
122
|
-
throw new Error('DummyP2P does not implement "
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
|
|
126
|
-
return Promise.resolve();
|
|
132
|
+
public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
|
|
133
|
+
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
public
|
|
130
|
-
throw new Error('DummyP2P does not implement "
|
|
136
|
+
public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
137
|
+
throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|