@aztec/txe 0.0.1-commit.c80b6263 → 0.0.1-commit.cd76b27
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/oracle/interfaces.d.ts +2 -2
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.d.ts +3 -3
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +83 -24
- package/dest/rpc_translator.d.ts +8 -8
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +39 -27
- package/dest/state_machine/archiver.d.ts +1 -1
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +2 -0
- package/dest/state_machine/dummy_p2p_client.d.ts +15 -11
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +27 -15
- 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 +15 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +4 -0
- package/dest/txe_session.d.ts +1 -1
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +68 -9
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/package.json +15 -15
- package/src/oracle/interfaces.ts +1 -1
- package/src/oracle/txe_oracle_top_level_context.ts +86 -76
- package/src/rpc_translator.ts +41 -22
- package/src/state_machine/archiver.ts +2 -0
- package/src/state_machine/dummy_p2p_client.ts +39 -21
- package/src/state_machine/index.ts +25 -9
- package/src/state_machine/mock_epoch_cache.ts +5 -0
- package/src/txe_session.ts +70 -66
- package/src/utils/block_creation.ts +3 -1
|
@@ -12,6 +12,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
12
12
|
import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
14
14
|
import type { KeyStore } from '@aztec/key-store';
|
|
15
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
15
16
|
import {
|
|
16
17
|
AddressStore,
|
|
17
18
|
CapsuleStore,
|
|
@@ -22,7 +23,6 @@ import {
|
|
|
22
23
|
SenderAddressBookStore,
|
|
23
24
|
SenderTaggingStore,
|
|
24
25
|
enrichPublicSimulationError,
|
|
25
|
-
syncState,
|
|
26
26
|
} from '@aztec/pxe/server';
|
|
27
27
|
import {
|
|
28
28
|
ExecutionNoteCache,
|
|
@@ -132,13 +132,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
135
|
-
|
|
135
|
+
utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
136
136
|
if (!LogLevels[level]) {
|
|
137
|
-
throw new Error(`Invalid
|
|
137
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
138
138
|
}
|
|
139
139
|
const levelName = LogLevels[level];
|
|
140
140
|
|
|
141
141
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
|
|
142
|
+
return Promise.resolve();
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
txeGetDefaultAddress(): AztecAddress {
|
|
@@ -297,12 +298,24 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
297
298
|
throw new Error(message);
|
|
298
299
|
}
|
|
299
300
|
|
|
301
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
302
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
303
|
+
const effectiveScopes = from.isZero() ? [] : [from];
|
|
304
|
+
|
|
300
305
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
301
|
-
const utilityExecutor = async (call: FunctionCall) => {
|
|
302
|
-
await this.executeUtilityCall(call);
|
|
306
|
+
const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
|
|
307
|
+
await this.executeUtilityCall(call, execScopes);
|
|
303
308
|
};
|
|
304
309
|
|
|
305
|
-
await
|
|
310
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
311
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
312
|
+
targetContractAddress,
|
|
313
|
+
functionSelector,
|
|
314
|
+
utilityExecutor,
|
|
315
|
+
blockHeader,
|
|
316
|
+
this.jobId,
|
|
317
|
+
effectiveScopes,
|
|
318
|
+
);
|
|
306
319
|
|
|
307
320
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
308
321
|
|
|
@@ -314,8 +327,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
314
327
|
|
|
315
328
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
316
329
|
|
|
317
|
-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
318
|
-
|
|
319
330
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
320
331
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
321
332
|
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
@@ -327,43 +338,37 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
327
338
|
|
|
328
339
|
const simulator = new WASMSimulator();
|
|
329
340
|
|
|
330
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
341
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
331
342
|
argsHash,
|
|
332
343
|
txContext,
|
|
333
344
|
callContext,
|
|
334
|
-
|
|
335
|
-
blockHeader,
|
|
345
|
+
anchorBlockHeader: blockHeader,
|
|
336
346
|
utilityExecutor,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
[],
|
|
341
|
-
HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
347
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
348
|
+
capsules: [],
|
|
349
|
+
executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
342
350
|
noteCache,
|
|
343
351
|
taggingIndexCache,
|
|
344
|
-
this.contractStore,
|
|
345
|
-
this.noteStore,
|
|
346
|
-
this.keyStore,
|
|
347
|
-
this.addressStore,
|
|
348
|
-
this.stateMachine.node,
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
this.jobId,
|
|
356
|
-
0,
|
|
357
|
-
minRevertibleSideEffectCounter,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
* contract would perform, including setting senderForTags.
|
|
363
|
-
*/
|
|
364
|
-
from,
|
|
352
|
+
contractStore: this.contractStore,
|
|
353
|
+
noteStore: this.noteStore,
|
|
354
|
+
keyStore: this.keyStore,
|
|
355
|
+
addressStore: this.addressStore,
|
|
356
|
+
aztecNode: this.stateMachine.node,
|
|
357
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
358
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
359
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
360
|
+
capsuleStore: this.capsuleStore,
|
|
361
|
+
privateEventStore: this.privateEventStore,
|
|
362
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
363
|
+
jobId: this.jobId,
|
|
364
|
+
totalPublicCalldataCount: 0,
|
|
365
|
+
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
366
|
+
scopes: effectiveScopes,
|
|
367
|
+
// In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
368
|
+
// contract would perform, including setting senderForTags.
|
|
369
|
+
senderForTags: from,
|
|
365
370
|
simulator,
|
|
366
|
-
);
|
|
371
|
+
});
|
|
367
372
|
|
|
368
373
|
// Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
|
|
369
374
|
let result: PrivateExecutionResult;
|
|
@@ -402,7 +407,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
402
407
|
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
403
408
|
const { publicInputs } = await generateSimulatedProvingResult(
|
|
404
409
|
result,
|
|
405
|
-
this.contractStore,
|
|
410
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
411
|
+
this.stateMachine.node,
|
|
406
412
|
minRevertibleSideEffectCounter,
|
|
407
413
|
);
|
|
408
414
|
|
|
@@ -585,7 +591,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
585
591
|
constantData,
|
|
586
592
|
/*gasUsed=*/ new Gas(0, 0),
|
|
587
593
|
/*feePayer=*/ AztecAddress.zero(),
|
|
588
|
-
/*
|
|
594
|
+
/*expirationTimestamp=*/ 0n,
|
|
589
595
|
inputsForPublic,
|
|
590
596
|
undefined,
|
|
591
597
|
);
|
|
@@ -653,36 +659,40 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
653
659
|
return returnValues ?? [];
|
|
654
660
|
}
|
|
655
661
|
|
|
656
|
-
async
|
|
657
|
-
targetContractAddress: AztecAddress,
|
|
658
|
-
functionSelector: FunctionSelector,
|
|
659
|
-
args: Fr[],
|
|
660
|
-
) {
|
|
662
|
+
async txeExecuteUtilityFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, args: Fr[]) {
|
|
661
663
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
662
664
|
if (!artifact) {
|
|
663
665
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
664
666
|
}
|
|
665
667
|
|
|
666
668
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
667
|
-
await
|
|
668
|
-
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
const call = new FunctionCall(
|
|
672
|
-
artifact.name,
|
|
669
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
670
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
673
671
|
targetContractAddress,
|
|
674
672
|
functionSelector,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
673
|
+
async (call, execScopes) => {
|
|
674
|
+
await this.executeUtilityCall(call, execScopes);
|
|
675
|
+
},
|
|
676
|
+
blockHeader,
|
|
677
|
+
this.jobId,
|
|
678
|
+
'ALL_SCOPES',
|
|
680
679
|
);
|
|
681
680
|
|
|
682
|
-
|
|
681
|
+
const call = FunctionCall.from({
|
|
682
|
+
name: artifact.name,
|
|
683
|
+
to: targetContractAddress,
|
|
684
|
+
selector: functionSelector,
|
|
685
|
+
type: FunctionType.UTILITY,
|
|
686
|
+
hideMsgSender: false,
|
|
687
|
+
isStatic: false,
|
|
688
|
+
args,
|
|
689
|
+
returnTypes: [],
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
return this.executeUtilityCall(call, 'ALL_SCOPES');
|
|
683
693
|
}
|
|
684
694
|
|
|
685
|
-
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
695
|
+
private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes): Promise<Fr[]> {
|
|
686
696
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
687
697
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
688
698
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -695,23 +705,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
695
705
|
|
|
696
706
|
try {
|
|
697
707
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
698
|
-
const oracle = new UtilityExecutionOracle(
|
|
699
|
-
call.to,
|
|
700
|
-
[],
|
|
701
|
-
[],
|
|
708
|
+
const oracle = new UtilityExecutionOracle({
|
|
709
|
+
contractAddress: call.to,
|
|
710
|
+
authWitnesses: [],
|
|
711
|
+
capsules: [],
|
|
702
712
|
anchorBlockHeader,
|
|
703
|
-
this.contractStore,
|
|
704
|
-
this.noteStore,
|
|
705
|
-
this.keyStore,
|
|
706
|
-
this.addressStore,
|
|
707
|
-
this.stateMachine.node,
|
|
708
|
-
this.
|
|
709
|
-
this.
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
712
|
-
this.
|
|
713
|
-
|
|
714
|
-
);
|
|
713
|
+
contractStore: this.contractStore,
|
|
714
|
+
noteStore: this.noteStore,
|
|
715
|
+
keyStore: this.keyStore,
|
|
716
|
+
addressStore: this.addressStore,
|
|
717
|
+
aztecNode: this.stateMachine.node,
|
|
718
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
719
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
720
|
+
capsuleStore: this.capsuleStore,
|
|
721
|
+
privateEventStore: this.privateEventStore,
|
|
722
|
+
jobId: this.jobId,
|
|
723
|
+
scopes,
|
|
724
|
+
});
|
|
715
725
|
const acirExecutionResult = await new WASMSimulator()
|
|
716
726
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
717
727
|
.catch((err: Error) => {
|
|
@@ -727,10 +737,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
727
737
|
);
|
|
728
738
|
});
|
|
729
739
|
|
|
730
|
-
this.logger.verbose(`Utility
|
|
740
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
731
741
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
732
742
|
} catch (err) {
|
|
733
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
743
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
734
744
|
}
|
|
735
745
|
}
|
|
736
746
|
|
package/src/rpc_translator.ts
CHANGED
|
@@ -328,7 +328,7 @@ export class RPCTranslator {
|
|
|
328
328
|
|
|
329
329
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
330
330
|
// When the argument is an array, we add the field length manually to the signature.
|
|
331
|
-
|
|
331
|
+
async utilityLog(
|
|
332
332
|
foreignLevel: ForeignCallSingle,
|
|
333
333
|
foreignMessage: ForeignCallArray,
|
|
334
334
|
_foreignLength: ForeignCallSingle,
|
|
@@ -340,7 +340,7 @@ export class RPCTranslator {
|
|
|
340
340
|
.join('');
|
|
341
341
|
const fields = fromArray(foreignFields);
|
|
342
342
|
|
|
343
|
-
this.handlerAsMisc().
|
|
343
|
+
await this.handlerAsMisc().utilityLog(level, message, fields);
|
|
344
344
|
|
|
345
345
|
return toForeignCallResult([]);
|
|
346
346
|
}
|
|
@@ -351,7 +351,7 @@ export class RPCTranslator {
|
|
|
351
351
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
352
352
|
foreignNumberOfElements: ForeignCallSingle,
|
|
353
353
|
) {
|
|
354
|
-
const blockHash = BlockHash
|
|
354
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
355
355
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
356
356
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
357
357
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
@@ -367,7 +367,7 @@ export class RPCTranslator {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
370
|
-
const blockHash = BlockHash
|
|
370
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
371
371
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
372
372
|
|
|
373
373
|
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
@@ -545,12 +545,23 @@ export class RPCTranslator {
|
|
|
545
545
|
);
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
-
async
|
|
548
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
549
549
|
const address = addressFromSingle(foreignAddress);
|
|
550
550
|
|
|
551
|
-
const
|
|
551
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
552
552
|
|
|
553
|
-
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
|
+
}
|
|
554
565
|
}
|
|
555
566
|
|
|
556
567
|
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
@@ -574,7 +585,7 @@ export class RPCTranslator {
|
|
|
574
585
|
}
|
|
575
586
|
|
|
576
587
|
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
577
|
-
const blockHash = BlockHash
|
|
588
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
578
589
|
const nullifier = fromSingle(foreignNullifier);
|
|
579
590
|
|
|
580
591
|
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
@@ -641,26 +652,34 @@ export class RPCTranslator {
|
|
|
641
652
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
642
653
|
}
|
|
643
654
|
|
|
644
|
-
async utilityGetNoteHashMembershipWitness(
|
|
645
|
-
|
|
646
|
-
|
|
655
|
+
async utilityGetNoteHashMembershipWitness(
|
|
656
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
657
|
+
foreignNoteHash: ForeignCallSingle,
|
|
658
|
+
) {
|
|
659
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
660
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
647
661
|
|
|
648
|
-
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash,
|
|
662
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
|
|
649
663
|
|
|
650
664
|
if (!witness) {
|
|
651
|
-
throw new Error(`Note hash ${
|
|
665
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
652
666
|
}
|
|
653
667
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
654
668
|
}
|
|
655
669
|
|
|
656
|
-
async
|
|
657
|
-
|
|
658
|
-
|
|
670
|
+
async utilityGetBlockHashMembershipWitness(
|
|
671
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
672
|
+
foreignBlockHash: ForeignCallSingle,
|
|
673
|
+
) {
|
|
674
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
675
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
659
676
|
|
|
660
|
-
const witness = await this.handlerAsUtility().
|
|
677
|
+
const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
661
678
|
|
|
662
679
|
if (!witness) {
|
|
663
|
-
throw new Error(
|
|
680
|
+
throw new Error(
|
|
681
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
682
|
+
);
|
|
664
683
|
}
|
|
665
684
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
666
685
|
}
|
|
@@ -669,7 +688,7 @@ export class RPCTranslator {
|
|
|
669
688
|
foreignBlockHash: ForeignCallSingle,
|
|
670
689
|
foreignNullifier: ForeignCallSingle,
|
|
671
690
|
) {
|
|
672
|
-
const blockHash = BlockHash
|
|
691
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
673
692
|
const nullifier = fromSingle(foreignNullifier);
|
|
674
693
|
|
|
675
694
|
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
@@ -830,7 +849,7 @@ export class RPCTranslator {
|
|
|
830
849
|
|
|
831
850
|
// AVM opcodes
|
|
832
851
|
|
|
833
|
-
|
|
852
|
+
avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
834
853
|
// TODO(#8811): Implement
|
|
835
854
|
return toForeignCallResult([]);
|
|
836
855
|
}
|
|
@@ -1024,7 +1043,7 @@ export class RPCTranslator {
|
|
|
1024
1043
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1025
1044
|
}
|
|
1026
1045
|
|
|
1027
|
-
async
|
|
1046
|
+
async txeExecuteUtilityFunction(
|
|
1028
1047
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1029
1048
|
foreignFunctionSelector: ForeignCallSingle,
|
|
1030
1049
|
foreignArgs: ForeignCallArray,
|
|
@@ -1033,7 +1052,7 @@ export class RPCTranslator {
|
|
|
1033
1052
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1034
1053
|
const args = fromArray(foreignArgs);
|
|
1035
1054
|
|
|
1036
|
-
const returnValues = await this.handlerAsTxe().
|
|
1055
|
+
const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
|
|
1037
1056
|
targetContractAddress,
|
|
1038
1057
|
functionSelector,
|
|
1039
1058
|
args,
|
|
@@ -59,6 +59,8 @@ export class TXEArchiver extends ArchiverDataSourceBase {
|
|
|
59
59
|
if (!checkpointedBlock) {
|
|
60
60
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
61
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.
|
|
62
64
|
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
|
|
63
65
|
if (checkpoint.length === 0) {
|
|
64
66
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
7
|
P2PCheckpointReceivedCallback,
|
|
8
8
|
P2PConfig,
|
|
9
|
+
P2PDuplicateAttestationCallback,
|
|
10
|
+
P2PDuplicateProposalCallback,
|
|
9
11
|
P2PSyncState,
|
|
10
12
|
PeerId,
|
|
11
13
|
ReqRespSubProtocol,
|
|
@@ -14,9 +16,9 @@ import type {
|
|
|
14
16
|
StatusMessage,
|
|
15
17
|
} from '@aztec/p2p';
|
|
16
18
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
17
|
-
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
18
|
-
import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
19
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
19
|
+
import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
|
|
21
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
20
22
|
|
|
21
23
|
export class DummyP2P implements P2P {
|
|
22
24
|
public validate(_txs: Tx[]): Promise<void> {
|
|
@@ -39,6 +41,10 @@ export class DummyP2P implements P2P {
|
|
|
39
41
|
throw new Error('DummyP2P does not implement "getPeers"');
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
|
|
45
|
+
return Promise.resolve(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
public broadcastProposal(_proposal: BlockProposal): Promise<void> {
|
|
43
49
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
44
50
|
}
|
|
@@ -71,8 +77,8 @@ export class DummyP2P implements P2P {
|
|
|
71
77
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
public
|
|
75
|
-
throw new Error('DummyP2P does not implement "
|
|
80
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
81
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -97,6 +103,10 @@ export class DummyP2P implements P2P {
|
|
|
97
103
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
107
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
public getPendingTxCount(): Promise<number> {
|
|
101
111
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
102
112
|
}
|
|
@@ -125,6 +135,10 @@ export class DummyP2P implements P2P {
|
|
|
125
135
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
public getTxProvider(): ITxProvider {
|
|
139
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
129
143
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
130
144
|
}
|
|
@@ -133,8 +147,8 @@ export class DummyP2P implements P2P {
|
|
|
133
147
|
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
134
148
|
}
|
|
135
149
|
|
|
136
|
-
public
|
|
137
|
-
throw new Error('DummyP2P does not implement "
|
|
150
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -157,14 +171,6 @@ export class DummyP2P implements P2P {
|
|
|
157
171
|
throw new Error('DummyP2P does not implement "sync"');
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
161
|
-
throw new Error('DummyP2P does not implement "requestTxsByHash"');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
165
|
-
throw new Error('DummyP2P does not implement "getTxs"');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
174
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
169
175
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
170
176
|
}
|
|
@@ -173,10 +179,6 @@ export class DummyP2P implements P2P {
|
|
|
173
179
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
174
180
|
}
|
|
175
181
|
|
|
176
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
177
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
182
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
181
183
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
182
184
|
}
|
|
@@ -189,8 +191,12 @@ export class DummyP2P implements P2P {
|
|
|
189
191
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
190
192
|
}
|
|
191
193
|
|
|
192
|
-
|
|
193
|
-
throw new Error('DummyP2P does not implement "
|
|
194
|
+
protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
195
|
+
throw new Error('DummyP2P does not implement "protectTxs".');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
199
|
+
return Promise.resolve();
|
|
194
200
|
}
|
|
195
201
|
|
|
196
202
|
addReqRespSubProtocol(
|
|
@@ -206,4 +212,16 @@ export class DummyP2P implements P2P {
|
|
|
206
212
|
|
|
207
213
|
//This is no-op
|
|
208
214
|
public registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
215
|
+
|
|
216
|
+
public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
|
|
217
|
+
throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
|
|
221
|
+
throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
|
|
226
|
+
}
|
|
209
227
|
}
|
|
@@ -3,8 +3,7 @@ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
|
3
3
|
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import type
|
|
7
|
-
import { AnchorBlockStore } from '@aztec/pxe/server';
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
8
7
|
import { L2Block } from '@aztec/stdlib/block';
|
|
9
8
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
10
9
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
@@ -26,13 +25,16 @@ export class TXEStateMachine {
|
|
|
26
25
|
public synchronizer: TXESynchronizer,
|
|
27
26
|
public archiver: TXEArchiver,
|
|
28
27
|
public anchorBlockStore: AnchorBlockStore,
|
|
28
|
+
public contractSyncService: ContractSyncService,
|
|
29
29
|
) {}
|
|
30
30
|
|
|
31
|
-
public static async create(
|
|
32
|
-
|
|
31
|
+
public static async create(
|
|
32
|
+
archiver: TXEArchiver,
|
|
33
|
+
anchorBlockStore: AnchorBlockStore,
|
|
34
|
+
contractStore: ContractStore,
|
|
35
|
+
noteStore: NoteStore,
|
|
36
|
+
) {
|
|
33
37
|
const synchronizer = await TXESynchronizer.create();
|
|
34
|
-
const anchorBlockStore = new AnchorBlockStore(db);
|
|
35
|
-
|
|
36
38
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
37
39
|
|
|
38
40
|
const log = createLogger('txe_node');
|
|
@@ -48,6 +50,7 @@ export class TXEStateMachine {
|
|
|
48
50
|
undefined,
|
|
49
51
|
undefined,
|
|
50
52
|
undefined,
|
|
53
|
+
undefined,
|
|
51
54
|
VERSION,
|
|
52
55
|
CHAIN_ID,
|
|
53
56
|
new TXEGlobalVariablesBuilder(),
|
|
@@ -58,11 +61,21 @@ export class TXEStateMachine {
|
|
|
58
61
|
log,
|
|
59
62
|
);
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
const contractSyncService = new ContractSyncService(
|
|
65
|
+
node,
|
|
66
|
+
contractStore,
|
|
67
|
+
noteStore,
|
|
68
|
+
createLogger('txe:contract_sync'),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
public async handleL2Block(block: L2Block) {
|
|
65
|
-
// Create a checkpoint from the block manually
|
|
75
|
+
// Create a checkpoint from the block manually.
|
|
76
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
77
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
78
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
66
79
|
const checkpoint = new Checkpoint(
|
|
67
80
|
block.archive,
|
|
68
81
|
CheckpointHeader.from({
|
|
@@ -79,7 +92,7 @@ export class TXEStateMachine {
|
|
|
79
92
|
totalManaUsed: block.header.totalManaUsed,
|
|
80
93
|
}),
|
|
81
94
|
[block],
|
|
82
|
-
|
|
95
|
+
checkpointNumber,
|
|
83
96
|
);
|
|
84
97
|
|
|
85
98
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
@@ -91,6 +104,9 @@ export class TXEStateMachine {
|
|
|
91
104
|
),
|
|
92
105
|
[],
|
|
93
106
|
);
|
|
107
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
108
|
+
this.contractSyncService.wipe();
|
|
109
|
+
|
|
94
110
|
await Promise.all([
|
|
95
111
|
this.synchronizer.handleL2Block(block),
|
|
96
112
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
|
|
2
2
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
|
|
@@ -64,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
64
65
|
filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
|
|
65
66
|
return Promise.resolve([]);
|
|
66
67
|
}
|
|
68
|
+
|
|
69
|
+
getL1Constants(): L1RollupConstants {
|
|
70
|
+
return EmptyL1RollupConstants;
|
|
71
|
+
}
|
|
67
72
|
}
|