@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.7cf39cb55
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/contract_function_simulator/contract_function_simulator.d.ts +51 -28
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +168 -64
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -18
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +53 -32
- package/dest/contract_sync/contract_sync_service.d.ts +3 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +32 -17
- package/dest/debug/pxe_debug_utils.d.ts +2 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -4
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +9 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +4 -9
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +67 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +49 -34
- package/dest/storage/contract_store/contract_store.js +5 -5
- package/dest/storage/note_store/note_store.d.ts +1 -2
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +4 -2
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +314 -121
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +91 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +94 -31
- package/src/contract_sync/contract_sync_service.ts +41 -25
- package/src/debug/pxe_debug_utils.ts +4 -8
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +4 -13
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +114 -71
- package/src/storage/contract_store/contract_store.ts +4 -4
- package/src/storage/note_store/note_store.ts +5 -2
|
@@ -2,7 +2,6 @@ import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS, PRIVATE_CONTEXT_INPUTS_LENGTH }
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import type { KeyStore } from '@aztec/key-store';
|
|
6
5
|
import { type CircuitSimulator, toACVMWitness } from '@aztec/simulator/client';
|
|
7
6
|
import {
|
|
8
7
|
type FunctionAbi,
|
|
@@ -12,18 +11,14 @@ import {
|
|
|
12
11
|
type NoteSelector,
|
|
13
12
|
countArgumentsSize,
|
|
14
13
|
} from '@aztec/stdlib/abi';
|
|
15
|
-
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
16
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
17
15
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
18
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
19
16
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
20
17
|
import { type ContractClassLog, DirectionalAppTaggingSecret, type PreTag } from '@aztec/stdlib/logs';
|
|
21
18
|
import { Tag } from '@aztec/stdlib/logs';
|
|
22
19
|
import { Note, type NoteStatus } from '@aztec/stdlib/note';
|
|
23
20
|
import {
|
|
24
|
-
type BlockHeader,
|
|
25
21
|
CallContext,
|
|
26
|
-
Capsule,
|
|
27
22
|
CountedContractClassLog,
|
|
28
23
|
NoteAndSlot,
|
|
29
24
|
PrivateCallExecutionResult,
|
|
@@ -32,13 +27,6 @@ import {
|
|
|
32
27
|
|
|
33
28
|
import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
34
29
|
import { NoteService } from '../../notes/note_service.js';
|
|
35
|
-
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
36
|
-
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
|
|
37
|
-
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
|
|
38
|
-
import type { NoteStore } from '../../storage/note_store/note_store.js';
|
|
39
|
-
import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
|
|
40
|
-
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
41
|
-
import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_address_book_store.js';
|
|
42
30
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
43
31
|
import { syncSenderTaggingIndexes } from '../../tagging/index.js';
|
|
44
32
|
import type { ExecutionNoteCache } from '../execution_note_cache.js';
|
|
@@ -47,7 +35,25 @@ import type { HashedValuesCache } from '../hashed_values_cache.js';
|
|
|
47
35
|
import { pickNotes } from '../pick_notes.js';
|
|
48
36
|
import type { IPrivateExecutionOracle, NoteData } from './interfaces.js';
|
|
49
37
|
import { executePrivateFunction } from './private_execution.js';
|
|
50
|
-
import { UtilityExecutionOracle } from './utility_execution_oracle.js';
|
|
38
|
+
import { UtilityExecutionOracle, type UtilityExecutionOracleArgs } from './utility_execution_oracle.js';
|
|
39
|
+
|
|
40
|
+
/** Args for PrivateExecutionOracle constructor. */
|
|
41
|
+
export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contractAddress'> & {
|
|
42
|
+
argsHash: Fr;
|
|
43
|
+
txContext: TxContext;
|
|
44
|
+
callContext: CallContext;
|
|
45
|
+
/** Needed to trigger contract synchronization before nested calls */
|
|
46
|
+
utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
|
|
47
|
+
executionCache: HashedValuesCache;
|
|
48
|
+
noteCache: ExecutionNoteCache;
|
|
49
|
+
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
50
|
+
senderTaggingStore: SenderTaggingStore;
|
|
51
|
+
contractSyncService: ContractSyncService;
|
|
52
|
+
totalPublicCalldataCount?: number;
|
|
53
|
+
sideEffectCounter?: number;
|
|
54
|
+
senderForTags?: AztecAddress;
|
|
55
|
+
simulator?: CircuitSimulator;
|
|
56
|
+
};
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
59
|
* The execution oracle for the private part of a transaction.
|
|
@@ -69,57 +75,39 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
69
75
|
private offchainEffects: { data: Fr[] }[] = [];
|
|
70
76
|
private nestedExecutionResults: PrivateCallExecutionResult[] = [];
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
super(
|
|
106
|
-
callContext.contractAddress,
|
|
107
|
-
authWitnesses,
|
|
108
|
-
capsules,
|
|
109
|
-
anchorBlockHeader,
|
|
110
|
-
contractStore,
|
|
111
|
-
noteStore,
|
|
112
|
-
keyStore,
|
|
113
|
-
addressStore,
|
|
114
|
-
aztecNode,
|
|
115
|
-
recipientTaggingStore,
|
|
116
|
-
senderAddressBookStore,
|
|
117
|
-
capsuleStore,
|
|
118
|
-
privateEventStore,
|
|
119
|
-
jobId,
|
|
120
|
-
log,
|
|
121
|
-
scopes,
|
|
122
|
-
);
|
|
78
|
+
private readonly argsHash: Fr;
|
|
79
|
+
private readonly txContext: TxContext;
|
|
80
|
+
private readonly callContext: CallContext;
|
|
81
|
+
private readonly utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
|
|
82
|
+
private readonly executionCache: HashedValuesCache;
|
|
83
|
+
private readonly noteCache: ExecutionNoteCache;
|
|
84
|
+
private readonly taggingIndexCache: ExecutionTaggingIndexCache;
|
|
85
|
+
private readonly senderTaggingStore: SenderTaggingStore;
|
|
86
|
+
private readonly contractSyncService: ContractSyncService;
|
|
87
|
+
private totalPublicCalldataCount: number;
|
|
88
|
+
protected sideEffectCounter: number;
|
|
89
|
+
private senderForTags?: AztecAddress;
|
|
90
|
+
private readonly simulator?: CircuitSimulator;
|
|
91
|
+
|
|
92
|
+
constructor(args: PrivateExecutionOracleArgs) {
|
|
93
|
+
super({
|
|
94
|
+
...args,
|
|
95
|
+
contractAddress: args.callContext.contractAddress,
|
|
96
|
+
log: args.log ?? createLogger('simulator:client_execution_context'),
|
|
97
|
+
});
|
|
98
|
+
this.argsHash = args.argsHash;
|
|
99
|
+
this.txContext = args.txContext;
|
|
100
|
+
this.callContext = args.callContext;
|
|
101
|
+
this.utilityExecutor = args.utilityExecutor;
|
|
102
|
+
this.executionCache = args.executionCache;
|
|
103
|
+
this.noteCache = args.noteCache;
|
|
104
|
+
this.taggingIndexCache = args.taggingIndexCache;
|
|
105
|
+
this.senderTaggingStore = args.senderTaggingStore;
|
|
106
|
+
this.contractSyncService = args.contractSyncService;
|
|
107
|
+
this.totalPublicCalldataCount = args.totalPublicCalldataCount ?? 0;
|
|
108
|
+
this.sideEffectCounter = args.sideEffectCounter ?? 0;
|
|
109
|
+
this.senderForTags = args.senderForTags;
|
|
110
|
+
this.simulator = args.simulator;
|
|
123
111
|
}
|
|
124
112
|
|
|
125
113
|
public getPrivateContextInputs(): PrivateContextInputs {
|
|
@@ -538,12 +526,22 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
538
526
|
|
|
539
527
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
540
528
|
|
|
529
|
+
// When scopes are set and the target contract is a registered account (has keys in the keyStore),
|
|
530
|
+
// expand scopes to include it so nested private calls can sync and read the contract's own notes.
|
|
531
|
+
// We only expand for registered accounts because the log service needs the recipient's keys to derive
|
|
532
|
+
// tagging secrets, which are only available for registered accounts.
|
|
533
|
+
const expandedScopes =
|
|
534
|
+
this.scopes && (await this.keyStore.hasAccount(targetContractAddress))
|
|
535
|
+
? [...this.scopes, targetContractAddress]
|
|
536
|
+
: this.scopes;
|
|
537
|
+
|
|
541
538
|
await this.contractSyncService.ensureContractSynced(
|
|
542
539
|
targetContractAddress,
|
|
543
540
|
functionSelector,
|
|
544
541
|
this.utilityExecutor,
|
|
545
542
|
this.anchorBlockHeader,
|
|
546
543
|
this.jobId,
|
|
544
|
+
expandedScopes,
|
|
547
545
|
);
|
|
548
546
|
|
|
549
547
|
const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
|
|
@@ -555,41 +553,41 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
555
553
|
|
|
556
554
|
const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
|
|
557
555
|
|
|
558
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
556
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
559
557
|
argsHash,
|
|
560
|
-
derivedTxContext,
|
|
561
|
-
derivedCallContext,
|
|
562
|
-
this.anchorBlockHeader,
|
|
563
|
-
this.utilityExecutor,
|
|
564
|
-
this.authWitnesses,
|
|
565
|
-
this.capsules,
|
|
566
|
-
this.executionCache,
|
|
567
|
-
this.noteCache,
|
|
568
|
-
this.taggingIndexCache,
|
|
569
|
-
this.contractStore,
|
|
570
|
-
this.noteStore,
|
|
571
|
-
this.keyStore,
|
|
572
|
-
this.addressStore,
|
|
573
|
-
this.aztecNode,
|
|
574
|
-
this.senderTaggingStore,
|
|
575
|
-
this.recipientTaggingStore,
|
|
576
|
-
this.senderAddressBookStore,
|
|
577
|
-
this.capsuleStore,
|
|
578
|
-
this.privateEventStore,
|
|
579
|
-
this.contractSyncService,
|
|
580
|
-
this.jobId,
|
|
581
|
-
this.totalPublicCalldataCount,
|
|
558
|
+
txContext: derivedTxContext,
|
|
559
|
+
callContext: derivedCallContext,
|
|
560
|
+
anchorBlockHeader: this.anchorBlockHeader,
|
|
561
|
+
utilityExecutor: this.utilityExecutor,
|
|
562
|
+
authWitnesses: this.authWitnesses,
|
|
563
|
+
capsules: this.capsules,
|
|
564
|
+
executionCache: this.executionCache,
|
|
565
|
+
noteCache: this.noteCache,
|
|
566
|
+
taggingIndexCache: this.taggingIndexCache,
|
|
567
|
+
contractStore: this.contractStore,
|
|
568
|
+
noteStore: this.noteStore,
|
|
569
|
+
keyStore: this.keyStore,
|
|
570
|
+
addressStore: this.addressStore,
|
|
571
|
+
aztecNode: this.aztecNode,
|
|
572
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
573
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
574
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
575
|
+
capsuleStore: this.capsuleStore,
|
|
576
|
+
privateEventStore: this.privateEventStore,
|
|
577
|
+
contractSyncService: this.contractSyncService,
|
|
578
|
+
jobId: this.jobId,
|
|
579
|
+
totalPublicCalldataCount: this.totalPublicCalldataCount,
|
|
582
580
|
sideEffectCounter,
|
|
583
|
-
this.log,
|
|
584
|
-
|
|
585
|
-
this.senderForTags,
|
|
586
|
-
this.simulator
|
|
587
|
-
);
|
|
581
|
+
log: this.log,
|
|
582
|
+
scopes: expandedScopes,
|
|
583
|
+
senderForTags: this.senderForTags,
|
|
584
|
+
simulator: this.simulator!,
|
|
585
|
+
});
|
|
588
586
|
|
|
589
587
|
const setupTime = simulatorSetupTimer.ms();
|
|
590
588
|
|
|
591
589
|
const childExecutionResult = await executePrivateFunction(
|
|
592
|
-
this.simulator
|
|
590
|
+
this.simulator!,
|
|
593
591
|
privateExecutionOracle,
|
|
594
592
|
targetArtifact,
|
|
595
593
|
targetContractAddress,
|
|
@@ -3,7 +3,7 @@ import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
3
3
|
import { Aes128 } from '@aztec/foundation/crypto/aes128';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
6
|
-
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
8
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
9
9
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
@@ -40,6 +40,27 @@ import { pickNotes } from '../pick_notes.js';
|
|
|
40
40
|
import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
|
|
41
41
|
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
42
42
|
|
|
43
|
+
/** Args for UtilityExecutionOracle constructor. */
|
|
44
|
+
export type UtilityExecutionOracleArgs = {
|
|
45
|
+
contractAddress: AztecAddress;
|
|
46
|
+
/** List of transient auth witnesses to be used during this simulation */
|
|
47
|
+
authWitnesses: AuthWitness[];
|
|
48
|
+
capsules: Capsule[]; // TODO(#12425): Rename to transientCapsules
|
|
49
|
+
anchorBlockHeader: BlockHeader;
|
|
50
|
+
contractStore: ContractStore;
|
|
51
|
+
noteStore: NoteStore;
|
|
52
|
+
keyStore: KeyStore;
|
|
53
|
+
addressStore: AddressStore;
|
|
54
|
+
aztecNode: AztecNode;
|
|
55
|
+
recipientTaggingStore: RecipientTaggingStore;
|
|
56
|
+
senderAddressBookStore: SenderAddressBookStore;
|
|
57
|
+
capsuleStore: CapsuleStore;
|
|
58
|
+
privateEventStore: PrivateEventStore;
|
|
59
|
+
jobId: string;
|
|
60
|
+
log?: ReturnType<typeof createLogger>;
|
|
61
|
+
scopes?: AztecAddress[];
|
|
62
|
+
};
|
|
63
|
+
|
|
43
64
|
/**
|
|
44
65
|
* The oracle for an execution of utility contract functions.
|
|
45
66
|
*/
|
|
@@ -47,27 +68,43 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
47
68
|
isMisc = true as const;
|
|
48
69
|
isUtility = true as const;
|
|
49
70
|
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
private contractLogger: Logger | undefined;
|
|
72
|
+
|
|
73
|
+
protected readonly contractAddress: AztecAddress;
|
|
74
|
+
protected readonly authWitnesses: AuthWitness[];
|
|
75
|
+
protected readonly capsules: Capsule[];
|
|
76
|
+
protected readonly anchorBlockHeader: BlockHeader;
|
|
77
|
+
protected readonly contractStore: ContractStore;
|
|
78
|
+
protected readonly noteStore: NoteStore;
|
|
79
|
+
protected readonly keyStore: KeyStore;
|
|
80
|
+
protected readonly addressStore: AddressStore;
|
|
81
|
+
protected readonly aztecNode: AztecNode;
|
|
82
|
+
protected readonly recipientTaggingStore: RecipientTaggingStore;
|
|
83
|
+
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
84
|
+
protected readonly capsuleStore: CapsuleStore;
|
|
85
|
+
protected readonly privateEventStore: PrivateEventStore;
|
|
86
|
+
protected readonly jobId: string;
|
|
87
|
+
protected log: ReturnType<typeof createLogger>;
|
|
88
|
+
protected readonly scopes?: AztecAddress[];
|
|
89
|
+
|
|
90
|
+
constructor(args: UtilityExecutionOracleArgs) {
|
|
91
|
+
this.contractAddress = args.contractAddress;
|
|
92
|
+
this.authWitnesses = args.authWitnesses;
|
|
93
|
+
this.capsules = args.capsules;
|
|
94
|
+
this.anchorBlockHeader = args.anchorBlockHeader;
|
|
95
|
+
this.contractStore = args.contractStore;
|
|
96
|
+
this.noteStore = args.noteStore;
|
|
97
|
+
this.keyStore = args.keyStore;
|
|
98
|
+
this.addressStore = args.addressStore;
|
|
99
|
+
this.aztecNode = args.aztecNode;
|
|
100
|
+
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
101
|
+
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
102
|
+
this.capsuleStore = args.capsuleStore;
|
|
103
|
+
this.privateEventStore = args.privateEventStore;
|
|
104
|
+
this.jobId = args.jobId;
|
|
105
|
+
this.log = args.log ?? createLogger('simulator:client_view_context');
|
|
106
|
+
this.scopes = args.scopes;
|
|
107
|
+
}
|
|
71
108
|
|
|
72
109
|
public utilityAssertCompatibleOracleVersion(version: number): void {
|
|
73
110
|
if (version !== ORACLE_VERSION) {
|
|
@@ -91,11 +128,16 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
91
128
|
* @throws If scopes are defined and the account is not in the scopes.
|
|
92
129
|
*/
|
|
93
130
|
public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
94
|
-
// If scopes are defined, check that the key belongs to an account in the scopes
|
|
131
|
+
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
95
132
|
if (this.scopes && this.scopes.length > 0) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
133
|
+
let hasAccess = false;
|
|
134
|
+
for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
|
|
135
|
+
if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
|
|
136
|
+
hasAccess = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!hasAccess) {
|
|
140
|
+
throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
|
|
99
141
|
}
|
|
100
142
|
}
|
|
101
143
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
@@ -297,8 +339,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
297
339
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
298
340
|
*/
|
|
299
341
|
public async utilityCheckNullifierExists(innerNullifier: Fr) {
|
|
300
|
-
const nullifier = await
|
|
301
|
-
|
|
342
|
+
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
343
|
+
siloNullifier(this.contractAddress, innerNullifier!),
|
|
344
|
+
this.anchorBlockHeader.hash(),
|
|
345
|
+
]);
|
|
346
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [
|
|
347
|
+
nullifier,
|
|
348
|
+
]);
|
|
302
349
|
return leafIndex?.data !== undefined;
|
|
303
350
|
}
|
|
304
351
|
|
|
@@ -349,12 +396,28 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
349
396
|
return values;
|
|
350
397
|
}
|
|
351
398
|
|
|
352
|
-
|
|
399
|
+
/**
|
|
400
|
+
* Returns a per-contract logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
|
|
401
|
+
*/
|
|
402
|
+
async #getContractLogger(): Promise<Logger> {
|
|
403
|
+
if (!this.contractLogger) {
|
|
404
|
+
const addrAbbrev = this.contractAddress.toString().slice(0, 10);
|
|
405
|
+
const name = await this.contractStore.getDebugContractName(this.contractAddress);
|
|
406
|
+
const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`;
|
|
407
|
+
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
408
|
+
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
409
|
+
this.contractLogger = createLogger(module, { instanceId: this.jobId });
|
|
410
|
+
}
|
|
411
|
+
return this.contractLogger;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
353
415
|
if (!LogLevels[level]) {
|
|
354
|
-
throw new Error(`Invalid
|
|
416
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
355
417
|
}
|
|
356
418
|
const levelName = LogLevels[level];
|
|
357
|
-
this
|
|
419
|
+
const logger = await this.#getContractLogger();
|
|
420
|
+
logger[levelName](`${applyStringFormatting(message, fields)}`);
|
|
358
421
|
}
|
|
359
422
|
|
|
360
423
|
public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
@@ -18,8 +18,9 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
18
18
|
export class ContractSyncService implements StagedStore {
|
|
19
19
|
readonly storeName = 'contract_sync';
|
|
20
20
|
|
|
21
|
-
// Tracks contracts synced since last wipe.
|
|
22
|
-
//
|
|
21
|
+
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
22
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for undefined scopes (all accounts).
|
|
23
|
+
// The value is a promise that resolves when the contract is synced.
|
|
23
24
|
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
24
25
|
|
|
25
26
|
// Per-job overridden contract addresses - these contracts should not be synced.
|
|
@@ -44,43 +45,50 @@ export class ContractSyncService implements StagedStore {
|
|
|
44
45
|
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
45
46
|
* not sync_state itself).
|
|
46
47
|
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
48
|
+
* @param scopes - Scopes to pass through to the utility executor (affects which notes are discovered).
|
|
47
49
|
*/
|
|
48
50
|
async ensureContractSynced(
|
|
49
51
|
contractAddress: AztecAddress,
|
|
50
52
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
51
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
53
|
+
utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<any>,
|
|
52
54
|
anchorBlockHeader: BlockHeader,
|
|
53
55
|
jobId: string,
|
|
56
|
+
scopes: undefined | AztecAddress[],
|
|
54
57
|
): Promise<void> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Skip sync if this contract has an override for this job
|
|
58
|
+
// Skip sync if this contract has an override for this job (overrides are keyed by contract address only)
|
|
58
59
|
const overrides = this.overriddenContracts.get(jobId);
|
|
59
|
-
if (overrides?.has(
|
|
60
|
+
if (overrides?.has(contractAddress.toString())) {
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// Skip sync if we already synced for "all scopes", or if we have an empty list of scopes
|
|
65
|
+
const allScopesKey = toKey(contractAddress, undefined);
|
|
66
|
+
const allScopesExisting = this.syncedContracts.get(allScopesKey);
|
|
67
|
+
if (allScopesExisting || (scopes && scopes.length == 0)) {
|
|
68
|
+
return;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
const unsyncedScopes = scopes?.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
72
|
+
const unsyncedScopesKeys = toKeys(contractAddress, unsyncedScopes);
|
|
73
|
+
|
|
74
|
+
if (unsyncedScopesKeys.length > 0) {
|
|
75
|
+
// Start sync and store the promise for all unsynced scopes
|
|
76
|
+
const promise = this.#doSync(
|
|
77
|
+
contractAddress,
|
|
78
|
+
functionToInvokeAfterSync,
|
|
79
|
+
call => utilityExecutor(call, unsyncedScopes),
|
|
80
|
+
anchorBlockHeader,
|
|
81
|
+
jobId,
|
|
82
|
+
).catch(err => {
|
|
83
|
+
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
84
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.delete(key));
|
|
85
|
+
throw err;
|
|
86
|
+
});
|
|
87
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.set(key, promise));
|
|
83
88
|
}
|
|
89
|
+
|
|
90
|
+
const promises = toKeys(contractAddress, scopes).map(key => this.syncedContracts.get(key)!);
|
|
91
|
+
await Promise.all(promises);
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
async #doSync(
|
|
@@ -127,3 +135,11 @@ export class ContractSyncService implements StagedStore {
|
|
|
127
135
|
return Promise.resolve();
|
|
128
136
|
}
|
|
129
137
|
}
|
|
138
|
+
|
|
139
|
+
function toKeys(contract: AztecAddress, scopes: undefined | AztecAddress[]) {
|
|
140
|
+
return scopes === undefined ? [toKey(contract, undefined)] : scopes.map(scope => toKey(contract, scope));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function toKey(contract: AztecAddress, scope: AztecAddress | undefined) {
|
|
144
|
+
return scope === undefined ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
|
|
145
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ContractOverrides } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
7
|
import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
|
|
8
8
|
import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
|
|
@@ -71,21 +71,17 @@ export class PXEDebugUtils {
|
|
|
71
71
|
await this.contractSyncService.ensureContractSynced(
|
|
72
72
|
filter.contractAddress,
|
|
73
73
|
null,
|
|
74
|
-
async privateSyncCall =>
|
|
75
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
74
|
+
async (privateSyncCall, execScopes) =>
|
|
75
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
76
76
|
anchorBlockHeader,
|
|
77
77
|
jobId,
|
|
78
|
+
filter.scopes,
|
|
78
79
|
);
|
|
79
80
|
|
|
80
81
|
return this.noteStore.getNotes(filter, jobId);
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/** Returns the block header up to which the PXE has synced. */
|
|
85
|
-
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
86
|
-
return this.anchorBlockStore.getBlockHeader();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
85
|
/**
|
|
90
86
|
* Triggers a sync of the PXE with the node.
|
|
91
87
|
* Blocks until the sync is complete.
|
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new LazyProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -58,14 +58,14 @@ export async function createPXE(
|
|
|
58
58
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
59
59
|
|
|
60
60
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
61
|
-
const pxe = await PXE.create(
|
|
62
|
-
aztecNode,
|
|
63
|
-
options.store,
|
|
64
|
-
prover,
|
|
61
|
+
const pxe = await PXE.create({
|
|
62
|
+
node: aztecNode,
|
|
63
|
+
store: options.store,
|
|
64
|
+
proofCreator: prover,
|
|
65
65
|
simulator,
|
|
66
66
|
protocolContractsProvider,
|
|
67
|
-
configWithContracts,
|
|
68
|
-
pxeLogger,
|
|
69
|
-
);
|
|
67
|
+
config: configWithContracts,
|
|
68
|
+
loggerOrSuffix: pxeLogger,
|
|
69
|
+
});
|
|
70
70
|
return pxe;
|
|
71
71
|
}
|
package/src/logs/log_service.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { KeyStore } from '@aztec/key-store';
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
6
5
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
7
6
|
import { DirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
8
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
@@ -159,7 +158,10 @@ export class LogService {
|
|
|
159
158
|
contractAddress: AztecAddress,
|
|
160
159
|
recipient: AztecAddress,
|
|
161
160
|
): Promise<DirectionalAppTaggingSecret[]> {
|
|
162
|
-
const recipientCompleteAddress = await this
|
|
161
|
+
const recipientCompleteAddress = await this.addressStore.getCompleteAddress(recipient);
|
|
162
|
+
if (!recipientCompleteAddress) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
163
165
|
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
164
166
|
|
|
165
167
|
// We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
|
|
@@ -206,15 +208,4 @@ export class LogService {
|
|
|
206
208
|
// TODO: This looks like it could belong more at the oracle interface level
|
|
207
209
|
return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs, this.jobId);
|
|
208
210
|
}
|
|
209
|
-
|
|
210
|
-
async #getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
|
|
211
|
-
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
212
|
-
if (!completeAddress) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`No public key registered for address ${account}.
|
|
215
|
-
Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
return completeAddress;
|
|
219
|
-
}
|
|
220
211
|
}
|