@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +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 +177 -79
- package/dest/rpc_translator.d.ts +30 -18
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +127 -60
- 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 +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +19 -14
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +41 -24
- 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 +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 +9 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +14 -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 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +151 -52
- 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_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 -18
- 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 +213 -124
- package/src/rpc_translator.ts +156 -60
- package/src/state_machine/archiver.ts +59 -114
- package/src/state_machine/dummy_p2p_client.ts +57 -32
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +60 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +207 -100
- 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 -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/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,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);
|
|
@@ -285,7 +328,7 @@ export class RPCTranslator {
|
|
|
285
328
|
|
|
286
329
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
287
330
|
// When the argument is an array, we add the field length manually to the signature.
|
|
288
|
-
|
|
331
|
+
async utilityLog(
|
|
289
332
|
foreignLevel: ForeignCallSingle,
|
|
290
333
|
foreignMessage: ForeignCallArray,
|
|
291
334
|
_foreignLength: ForeignCallSingle,
|
|
@@ -297,45 +340,47 @@ export class RPCTranslator {
|
|
|
297
340
|
.join('');
|
|
298
341
|
const fields = fromArray(foreignFields);
|
|
299
342
|
|
|
300
|
-
this.handlerAsMisc().
|
|
343
|
+
await this.handlerAsMisc().utilityLog(level, message, fields);
|
|
301
344
|
|
|
302
345
|
return toForeignCallResult([]);
|
|
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 = new BlockHash(fromSingle(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 = new BlockHash(fromSingle(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
|
|
|
@@ -470,12 +545,23 @@ export class RPCTranslator {
|
|
|
470
545
|
);
|
|
471
546
|
}
|
|
472
547
|
|
|
473
|
-
async
|
|
548
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
474
549
|
const address = addressFromSingle(foreignAddress);
|
|
475
550
|
|
|
476
|
-
const
|
|
551
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
477
552
|
|
|
478
|
-
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
|
+
}
|
|
479
565
|
}
|
|
480
566
|
|
|
481
567
|
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
@@ -498,17 +584,14 @@ export class RPCTranslator {
|
|
|
498
584
|
);
|
|
499
585
|
}
|
|
500
586
|
|
|
501
|
-
async utilityGetNullifierMembershipWitness(
|
|
502
|
-
|
|
503
|
-
foreignNullifier: ForeignCallSingle,
|
|
504
|
-
) {
|
|
505
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
587
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
588
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
506
589
|
const nullifier = fromSingle(foreignNullifier);
|
|
507
590
|
|
|
508
|
-
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(
|
|
591
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
509
592
|
|
|
510
593
|
if (!witness) {
|
|
511
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
594
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
512
595
|
}
|
|
513
596
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
514
597
|
}
|
|
@@ -552,14 +635,14 @@ export class RPCTranslator {
|
|
|
552
635
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
553
636
|
}
|
|
554
637
|
|
|
555
|
-
|
|
556
|
-
const context =
|
|
638
|
+
utilityGetUtilityContext() {
|
|
639
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
557
640
|
|
|
558
641
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
559
642
|
}
|
|
560
643
|
|
|
561
644
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
562
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
645
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
563
646
|
|
|
564
647
|
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
565
648
|
|
|
@@ -569,36 +652,49 @@ export class RPCTranslator {
|
|
|
569
652
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
570
653
|
}
|
|
571
654
|
|
|
572
|
-
async
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
foreignLeafValue: ForeignCallSingle,
|
|
655
|
+
async utilityGetNoteHashMembershipWitness(
|
|
656
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
657
|
+
foreignNoteHash: ForeignCallSingle,
|
|
576
658
|
) {
|
|
577
|
-
const
|
|
578
|
-
const
|
|
579
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
659
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
660
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
580
661
|
|
|
581
|
-
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);
|
|
582
678
|
|
|
583
679
|
if (!witness) {
|
|
584
680
|
throw new Error(
|
|
585
|
-
`
|
|
681
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
586
682
|
);
|
|
587
683
|
}
|
|
588
|
-
return toForeignCallResult(
|
|
684
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
589
685
|
}
|
|
590
686
|
|
|
591
687
|
async utilityGetLowNullifierMembershipWitness(
|
|
592
|
-
|
|
688
|
+
foreignBlockHash: ForeignCallSingle,
|
|
593
689
|
foreignNullifier: ForeignCallSingle,
|
|
594
690
|
) {
|
|
595
|
-
const
|
|
691
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
596
692
|
const nullifier = fromSingle(foreignNullifier);
|
|
597
693
|
|
|
598
|
-
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
694
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
599
695
|
|
|
600
696
|
if (!witness) {
|
|
601
|
-
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}.`);
|
|
602
698
|
}
|
|
603
699
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
604
700
|
}
|
|
@@ -611,7 +707,7 @@ export class RPCTranslator {
|
|
|
611
707
|
return toForeignCallResult([]);
|
|
612
708
|
}
|
|
613
709
|
|
|
614
|
-
public async
|
|
710
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
615
711
|
foreignContractAddress: ForeignCallSingle,
|
|
616
712
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
617
713
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
@@ -620,7 +716,7 @@ export class RPCTranslator {
|
|
|
620
716
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
621
717
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
622
718
|
|
|
623
|
-
await this.handlerAsUtility().
|
|
719
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
624
720
|
contractAddress,
|
|
625
721
|
noteValidationRequestsArrayBaseSlot,
|
|
626
722
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -753,15 +849,16 @@ export class RPCTranslator {
|
|
|
753
849
|
|
|
754
850
|
// AVM opcodes
|
|
755
851
|
|
|
756
|
-
|
|
852
|
+
avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
757
853
|
// TODO(#8811): Implement
|
|
758
854
|
return toForeignCallResult([]);
|
|
759
855
|
}
|
|
760
856
|
|
|
761
|
-
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
857
|
+
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
762
858
|
const slot = fromSingle(foreignSlot);
|
|
859
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
763
860
|
|
|
764
|
-
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
|
|
861
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
|
|
765
862
|
|
|
766
863
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
767
864
|
}
|
|
@@ -833,11 +930,10 @@ export class RPCTranslator {
|
|
|
833
930
|
return toForeignCallResult([]);
|
|
834
931
|
}
|
|
835
932
|
|
|
836
|
-
async avmOpcodeNullifierExists(
|
|
837
|
-
const
|
|
838
|
-
const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
|
|
933
|
+
async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
934
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
839
935
|
|
|
840
|
-
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(
|
|
936
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
|
|
841
937
|
|
|
842
938
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
843
939
|
}
|
|
@@ -947,7 +1043,7 @@ export class RPCTranslator {
|
|
|
947
1043
|
return toForeignCallResult([toArray(returnValues)]);
|
|
948
1044
|
}
|
|
949
1045
|
|
|
950
|
-
async
|
|
1046
|
+
async txeExecuteUtilityFunction(
|
|
951
1047
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
952
1048
|
foreignFunctionSelector: ForeignCallSingle,
|
|
953
1049
|
foreignArgs: ForeignCallArray,
|
|
@@ -956,7 +1052,7 @@ export class RPCTranslator {
|
|
|
956
1052
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
957
1053
|
const args = fromArray(foreignArgs);
|
|
958
1054
|
|
|
959
|
-
const returnValues = await this.handlerAsTxe().
|
|
1055
|
+
const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
|
|
960
1056
|
targetContractAddress,
|
|
961
1057
|
functionSelector,
|
|
962
1058
|
args,
|
|
@@ -1,152 +1,97 @@
|
|
|
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
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
63
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
64
|
+
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
|
|
65
|
+
if (checkpoint.length === 0) {
|
|
66
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
67
|
+
}
|
|
68
|
+
const blockId: L2BlockId = { number, hash };
|
|
69
|
+
const checkpointId: CheckpointId = {
|
|
70
|
+
number: checkpoint[0].checkpointNumber,
|
|
71
|
+
hash: checkpoint[0].header.hash().toString(),
|
|
72
|
+
};
|
|
73
|
+
const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
74
|
+
return {
|
|
75
|
+
proposed: blockId,
|
|
76
|
+
proven: tipId,
|
|
77
|
+
finalized: tipId,
|
|
78
|
+
checkpointed: tipId,
|
|
79
|
+
};
|
|
91
80
|
}
|
|
92
81
|
|
|
93
82
|
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
94
83
|
throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
|
|
95
84
|
}
|
|
96
85
|
|
|
97
|
-
public getL2EpochNumber(): Promise<EpochNumber> {
|
|
86
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
98
87
|
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
99
88
|
}
|
|
100
89
|
|
|
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
90
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
110
91
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
111
92
|
}
|
|
112
93
|
|
|
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
94
|
public syncImmediate(): Promise<void> {
|
|
126
95
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
127
96
|
}
|
|
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
97
|
}
|