@aztec/pxe 0.0.1-commit.87a0206 → 0.0.1-commit.8f9871590
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +53 -29
- 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 +35 -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 +31 -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 +49 -31
- package/dest/contract_sync/contract_sync_service.d.ts +4 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +34 -19
- package/dest/contract_sync/helpers.d.ts +3 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +3 -3
- package/dest/debug/pxe_debug_utils.d.ts +5 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- 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/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- 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/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +5 -10
- package/dest/notes/note_service.d.ts +4 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +3 -2
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +6 -6
- package/dest/pxe.d.ts +57 -22
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +42 -35
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/package.json +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +315 -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 +92 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +89 -30
- package/src/contract_sync/contract_sync_service.ts +49 -26
- package/src/contract_sync/helpers.ts +7 -2
- package/src/debug/pxe_debug_utils.ts +8 -6
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +7 -19
- package/src/notes/note_service.ts +4 -3
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -6
- package/src/pxe.ts +104 -74
- package/src/storage/note_store/note_store.ts +8 -5
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -417,7 +417,7 @@ export class Oracle {
|
|
|
417
417
|
return Promise.resolve([]);
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
-
|
|
420
|
+
async utilityLog(
|
|
421
421
|
level: ACVMField[],
|
|
422
422
|
message: ACVMField[],
|
|
423
423
|
_ignoredFieldsSize: ACVMField[],
|
|
@@ -426,8 +426,8 @@ export class Oracle {
|
|
|
426
426
|
const levelFr = Fr.fromString(level[0]);
|
|
427
427
|
const messageStr = message.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
428
428
|
const fieldsFr = fields.map(Fr.fromString);
|
|
429
|
-
this.handlerAsMisc().
|
|
430
|
-
return
|
|
429
|
+
await this.handlerAsMisc().utilityLog(levelFr.toNumber(), messageStr, fieldsFr);
|
|
430
|
+
return [];
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
// This function's name is directly hardcoded in `circuit_recorder.ts`. Don't forget to update it there if you
|
|
@@ -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,33 +11,23 @@ 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,
|
|
30
25
|
type TxContext,
|
|
31
26
|
} from '@aztec/stdlib/tx';
|
|
32
27
|
|
|
28
|
+
import type { AccessScopes } from '../../access_scopes.js';
|
|
33
29
|
import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
34
30
|
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
31
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
43
32
|
import { syncSenderTaggingIndexes } from '../../tagging/index.js';
|
|
44
33
|
import type { ExecutionNoteCache } from '../execution_note_cache.js';
|
|
@@ -47,7 +36,25 @@ import type { HashedValuesCache } from '../hashed_values_cache.js';
|
|
|
47
36
|
import { pickNotes } from '../pick_notes.js';
|
|
48
37
|
import type { IPrivateExecutionOracle, NoteData } from './interfaces.js';
|
|
49
38
|
import { executePrivateFunction } from './private_execution.js';
|
|
50
|
-
import { UtilityExecutionOracle } from './utility_execution_oracle.js';
|
|
39
|
+
import { UtilityExecutionOracle, type UtilityExecutionOracleArgs } from './utility_execution_oracle.js';
|
|
40
|
+
|
|
41
|
+
/** Args for PrivateExecutionOracle constructor. */
|
|
42
|
+
export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contractAddress'> & {
|
|
43
|
+
argsHash: Fr;
|
|
44
|
+
txContext: TxContext;
|
|
45
|
+
callContext: CallContext;
|
|
46
|
+
/** Needed to trigger contract synchronization before nested calls */
|
|
47
|
+
utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
|
|
48
|
+
executionCache: HashedValuesCache;
|
|
49
|
+
noteCache: ExecutionNoteCache;
|
|
50
|
+
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
51
|
+
senderTaggingStore: SenderTaggingStore;
|
|
52
|
+
contractSyncService: ContractSyncService;
|
|
53
|
+
totalPublicCalldataCount?: number;
|
|
54
|
+
sideEffectCounter?: number;
|
|
55
|
+
senderForTags?: AztecAddress;
|
|
56
|
+
simulator?: CircuitSimulator;
|
|
57
|
+
};
|
|
51
58
|
|
|
52
59
|
/**
|
|
53
60
|
* The execution oracle for the private part of a transaction.
|
|
@@ -69,57 +76,39 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
69
76
|
private offchainEffects: { data: Fr[] }[] = [];
|
|
70
77
|
private nestedExecutionResults: PrivateCallExecutionResult[] = [];
|
|
71
78
|
|
|
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
|
-
);
|
|
79
|
+
private readonly argsHash: Fr;
|
|
80
|
+
private readonly txContext: TxContext;
|
|
81
|
+
private readonly callContext: CallContext;
|
|
82
|
+
private readonly utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
|
|
83
|
+
private readonly executionCache: HashedValuesCache;
|
|
84
|
+
private readonly noteCache: ExecutionNoteCache;
|
|
85
|
+
private readonly taggingIndexCache: ExecutionTaggingIndexCache;
|
|
86
|
+
private readonly senderTaggingStore: SenderTaggingStore;
|
|
87
|
+
private readonly contractSyncService: ContractSyncService;
|
|
88
|
+
private totalPublicCalldataCount: number;
|
|
89
|
+
protected sideEffectCounter: number;
|
|
90
|
+
private senderForTags?: AztecAddress;
|
|
91
|
+
private readonly simulator?: CircuitSimulator;
|
|
92
|
+
|
|
93
|
+
constructor(args: PrivateExecutionOracleArgs) {
|
|
94
|
+
super({
|
|
95
|
+
...args,
|
|
96
|
+
contractAddress: args.callContext.contractAddress,
|
|
97
|
+
log: args.log ?? createLogger('simulator:client_execution_context'),
|
|
98
|
+
});
|
|
99
|
+
this.argsHash = args.argsHash;
|
|
100
|
+
this.txContext = args.txContext;
|
|
101
|
+
this.callContext = args.callContext;
|
|
102
|
+
this.utilityExecutor = args.utilityExecutor;
|
|
103
|
+
this.executionCache = args.executionCache;
|
|
104
|
+
this.noteCache = args.noteCache;
|
|
105
|
+
this.taggingIndexCache = args.taggingIndexCache;
|
|
106
|
+
this.senderTaggingStore = args.senderTaggingStore;
|
|
107
|
+
this.contractSyncService = args.contractSyncService;
|
|
108
|
+
this.totalPublicCalldataCount = args.totalPublicCalldataCount ?? 0;
|
|
109
|
+
this.sideEffectCounter = args.sideEffectCounter ?? 0;
|
|
110
|
+
this.senderForTags = args.senderForTags;
|
|
111
|
+
this.simulator = args.simulator;
|
|
123
112
|
}
|
|
124
113
|
|
|
125
114
|
public getPrivateContextInputs(): PrivateContextInputs {
|
|
@@ -538,12 +527,22 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
538
527
|
|
|
539
528
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
540
529
|
|
|
530
|
+
// When scopes are set and the target contract is a registered account (has keys in the keyStore),
|
|
531
|
+
// expand scopes to include it so nested private calls can sync and read the contract's own notes.
|
|
532
|
+
// We only expand for registered accounts because the log service needs the recipient's keys to derive
|
|
533
|
+
// tagging secrets, which are only available for registered accounts.
|
|
534
|
+
const expandedScopes =
|
|
535
|
+
this.scopes !== 'ALL_SCOPES' && (await this.keyStore.hasAccount(targetContractAddress))
|
|
536
|
+
? [...this.scopes, targetContractAddress]
|
|
537
|
+
: this.scopes;
|
|
538
|
+
|
|
541
539
|
await this.contractSyncService.ensureContractSynced(
|
|
542
540
|
targetContractAddress,
|
|
543
541
|
functionSelector,
|
|
544
542
|
this.utilityExecutor,
|
|
545
543
|
this.anchorBlockHeader,
|
|
546
544
|
this.jobId,
|
|
545
|
+
expandedScopes,
|
|
547
546
|
);
|
|
548
547
|
|
|
549
548
|
const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
|
|
@@ -555,41 +554,41 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
555
554
|
|
|
556
555
|
const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
|
|
557
556
|
|
|
558
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
557
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
559
558
|
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,
|
|
559
|
+
txContext: derivedTxContext,
|
|
560
|
+
callContext: derivedCallContext,
|
|
561
|
+
anchorBlockHeader: this.anchorBlockHeader,
|
|
562
|
+
utilityExecutor: this.utilityExecutor,
|
|
563
|
+
authWitnesses: this.authWitnesses,
|
|
564
|
+
capsules: this.capsules,
|
|
565
|
+
executionCache: this.executionCache,
|
|
566
|
+
noteCache: this.noteCache,
|
|
567
|
+
taggingIndexCache: this.taggingIndexCache,
|
|
568
|
+
contractStore: this.contractStore,
|
|
569
|
+
noteStore: this.noteStore,
|
|
570
|
+
keyStore: this.keyStore,
|
|
571
|
+
addressStore: this.addressStore,
|
|
572
|
+
aztecNode: this.aztecNode,
|
|
573
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
574
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
575
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
576
|
+
capsuleStore: this.capsuleStore,
|
|
577
|
+
privateEventStore: this.privateEventStore,
|
|
578
|
+
contractSyncService: this.contractSyncService,
|
|
579
|
+
jobId: this.jobId,
|
|
580
|
+
totalPublicCalldataCount: this.totalPublicCalldataCount,
|
|
582
581
|
sideEffectCounter,
|
|
583
|
-
this.log,
|
|
584
|
-
|
|
585
|
-
this.senderForTags,
|
|
586
|
-
this.simulator
|
|
587
|
-
);
|
|
582
|
+
log: this.log,
|
|
583
|
+
scopes: expandedScopes,
|
|
584
|
+
senderForTags: this.senderForTags,
|
|
585
|
+
simulator: this.simulator!,
|
|
586
|
+
});
|
|
588
587
|
|
|
589
588
|
const setupTime = simulatorSetupTimer.ms();
|
|
590
589
|
|
|
591
590
|
const childExecutionResult = await executePrivateFunction(
|
|
592
|
-
this.simulator
|
|
591
|
+
this.simulator!,
|
|
593
592
|
privateExecutionOracle,
|
|
594
593
|
targetArtifact,
|
|
595
594
|
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';
|
|
@@ -20,6 +20,7 @@ import type { NoteStatus } from '@aztec/stdlib/note';
|
|
|
20
20
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
21
21
|
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
22
22
|
|
|
23
|
+
import type { AccessScopes } from '../../access_scopes.js';
|
|
23
24
|
import { EventService } from '../../events/event_service.js';
|
|
24
25
|
import { LogService } from '../../logs/log_service.js';
|
|
25
26
|
import { NoteService } from '../../notes/note_service.js';
|
|
@@ -40,6 +41,27 @@ import { pickNotes } from '../pick_notes.js';
|
|
|
40
41
|
import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
|
|
41
42
|
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
42
43
|
|
|
44
|
+
/** Args for UtilityExecutionOracle constructor. */
|
|
45
|
+
export type UtilityExecutionOracleArgs = {
|
|
46
|
+
contractAddress: AztecAddress;
|
|
47
|
+
/** List of transient auth witnesses to be used during this simulation */
|
|
48
|
+
authWitnesses: AuthWitness[];
|
|
49
|
+
capsules: Capsule[]; // TODO(#12425): Rename to transientCapsules
|
|
50
|
+
anchorBlockHeader: BlockHeader;
|
|
51
|
+
contractStore: ContractStore;
|
|
52
|
+
noteStore: NoteStore;
|
|
53
|
+
keyStore: KeyStore;
|
|
54
|
+
addressStore: AddressStore;
|
|
55
|
+
aztecNode: AztecNode;
|
|
56
|
+
recipientTaggingStore: RecipientTaggingStore;
|
|
57
|
+
senderAddressBookStore: SenderAddressBookStore;
|
|
58
|
+
capsuleStore: CapsuleStore;
|
|
59
|
+
privateEventStore: PrivateEventStore;
|
|
60
|
+
jobId: string;
|
|
61
|
+
log?: ReturnType<typeof createLogger>;
|
|
62
|
+
scopes: AccessScopes;
|
|
63
|
+
};
|
|
64
|
+
|
|
43
65
|
/**
|
|
44
66
|
* The oracle for an execution of utility contract functions.
|
|
45
67
|
*/
|
|
@@ -47,27 +69,43 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
47
69
|
isMisc = true as const;
|
|
48
70
|
isUtility = true as const;
|
|
49
71
|
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
private contractLogger: Logger | undefined;
|
|
73
|
+
|
|
74
|
+
protected readonly contractAddress: AztecAddress;
|
|
75
|
+
protected readonly authWitnesses: AuthWitness[];
|
|
76
|
+
protected readonly capsules: Capsule[];
|
|
77
|
+
protected readonly anchorBlockHeader: BlockHeader;
|
|
78
|
+
protected readonly contractStore: ContractStore;
|
|
79
|
+
protected readonly noteStore: NoteStore;
|
|
80
|
+
protected readonly keyStore: KeyStore;
|
|
81
|
+
protected readonly addressStore: AddressStore;
|
|
82
|
+
protected readonly aztecNode: AztecNode;
|
|
83
|
+
protected readonly recipientTaggingStore: RecipientTaggingStore;
|
|
84
|
+
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
85
|
+
protected readonly capsuleStore: CapsuleStore;
|
|
86
|
+
protected readonly privateEventStore: PrivateEventStore;
|
|
87
|
+
protected readonly jobId: string;
|
|
88
|
+
protected log: ReturnType<typeof createLogger>;
|
|
89
|
+
protected readonly scopes: AccessScopes;
|
|
90
|
+
|
|
91
|
+
constructor(args: UtilityExecutionOracleArgs) {
|
|
92
|
+
this.contractAddress = args.contractAddress;
|
|
93
|
+
this.authWitnesses = args.authWitnesses;
|
|
94
|
+
this.capsules = args.capsules;
|
|
95
|
+
this.anchorBlockHeader = args.anchorBlockHeader;
|
|
96
|
+
this.contractStore = args.contractStore;
|
|
97
|
+
this.noteStore = args.noteStore;
|
|
98
|
+
this.keyStore = args.keyStore;
|
|
99
|
+
this.addressStore = args.addressStore;
|
|
100
|
+
this.aztecNode = args.aztecNode;
|
|
101
|
+
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
102
|
+
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
103
|
+
this.capsuleStore = args.capsuleStore;
|
|
104
|
+
this.privateEventStore = args.privateEventStore;
|
|
105
|
+
this.jobId = args.jobId;
|
|
106
|
+
this.log = args.log ?? createLogger('simulator:client_view_context');
|
|
107
|
+
this.scopes = args.scopes;
|
|
108
|
+
}
|
|
71
109
|
|
|
72
110
|
public utilityAssertCompatibleOracleVersion(version: number): void {
|
|
73
111
|
if (version !== ORACLE_VERSION) {
|
|
@@ -91,11 +129,16 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
91
129
|
* @throws If scopes are defined and the account is not in the scopes.
|
|
92
130
|
*/
|
|
93
131
|
public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
94
|
-
// If scopes are defined, check that the key belongs to an account in the scopes
|
|
95
|
-
if (this.scopes && this.scopes.length > 0) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
132
|
+
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
133
|
+
if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
|
|
134
|
+
let hasAccess = false;
|
|
135
|
+
for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
|
|
136
|
+
if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
|
|
137
|
+
hasAccess = true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!hasAccess) {
|
|
141
|
+
throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
|
|
99
142
|
}
|
|
100
143
|
}
|
|
101
144
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
@@ -354,12 +397,28 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
354
397
|
return values;
|
|
355
398
|
}
|
|
356
399
|
|
|
357
|
-
|
|
400
|
+
/**
|
|
401
|
+
* Returns a per-contract logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
|
|
402
|
+
*/
|
|
403
|
+
async #getContractLogger(): Promise<Logger> {
|
|
404
|
+
if (!this.contractLogger) {
|
|
405
|
+
const addrAbbrev = this.contractAddress.toString().slice(0, 10);
|
|
406
|
+
const name = await this.contractStore.getDebugContractName(this.contractAddress);
|
|
407
|
+
const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`;
|
|
408
|
+
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
409
|
+
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
410
|
+
this.contractLogger = createLogger(module, { instanceId: this.jobId });
|
|
411
|
+
}
|
|
412
|
+
return this.contractLogger;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
358
416
|
if (!LogLevels[level]) {
|
|
359
|
-
throw new Error(`Invalid
|
|
417
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
360
418
|
}
|
|
361
419
|
const levelName = LogLevels[level];
|
|
362
|
-
this
|
|
420
|
+
const logger = await this.#getContractLogger();
|
|
421
|
+
logger[levelName](`${applyStringFormatting(message, fields)}`);
|
|
363
422
|
}
|
|
364
423
|
|
|
365
424
|
public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
@@ -4,6 +4,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
4
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
5
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
+
import type { AccessScopes } from '../access_scopes.js';
|
|
7
8
|
import type { StagedStore } from '../job_coordinator/job_coordinator.js';
|
|
8
9
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
9
10
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -18,8 +19,9 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
18
19
|
export class ContractSyncService implements StagedStore {
|
|
19
20
|
readonly storeName = 'contract_sync';
|
|
20
21
|
|
|
21
|
-
// Tracks contracts synced since last wipe.
|
|
22
|
-
//
|
|
22
|
+
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
23
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for undefined scopes (all accounts).
|
|
24
|
+
// The value is a promise that resolves when the contract is synced.
|
|
23
25
|
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
24
26
|
|
|
25
27
|
// Per-job overridden contract addresses - these contracts should not be synced.
|
|
@@ -44,51 +46,63 @@ export class ContractSyncService implements StagedStore {
|
|
|
44
46
|
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
45
47
|
* not sync_state itself).
|
|
46
48
|
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
49
|
+
* @param scopes - Access scopes to pass through to the utility executor (affects whose account's private state is discovered).
|
|
47
50
|
*/
|
|
48
51
|
async ensureContractSynced(
|
|
49
52
|
contractAddress: AztecAddress,
|
|
50
53
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
51
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
54
|
+
utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<any>,
|
|
52
55
|
anchorBlockHeader: BlockHeader,
|
|
53
56
|
jobId: string,
|
|
57
|
+
scopes: AccessScopes,
|
|
54
58
|
): Promise<void> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Skip sync if this contract has an override for this job
|
|
59
|
+
// Skip sync if this contract has an override for this job (overrides are keyed by contract address only)
|
|
58
60
|
const overrides = this.overriddenContracts.get(jobId);
|
|
59
|
-
if (overrides?.has(
|
|
61
|
+
if (overrides?.has(contractAddress.toString())) {
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
// Skip sync if we already synced for "all scopes", or if we have an empty list of scopes
|
|
66
|
+
const allScopesKey = toKey(contractAddress, 'ALL_SCOPES');
|
|
67
|
+
const allScopesExisting = this.syncedContracts.get(allScopesKey);
|
|
68
|
+
if (allScopesExisting || (scopes !== 'ALL_SCOPES' && scopes.length == 0)) {
|
|
69
|
+
return;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
const unsyncedScopes =
|
|
73
|
+
scopes === 'ALL_SCOPES'
|
|
74
|
+
? scopes
|
|
75
|
+
: scopes.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
76
|
+
const unsyncedScopesKeys = toKeys(contractAddress, unsyncedScopes);
|
|
77
|
+
|
|
78
|
+
if (unsyncedScopesKeys.length > 0) {
|
|
79
|
+
// Start sync and store the promise for all unsynced scopes
|
|
80
|
+
const promise = this.#doSync(
|
|
81
|
+
contractAddress,
|
|
82
|
+
functionToInvokeAfterSync,
|
|
83
|
+
utilityExecutor,
|
|
84
|
+
anchorBlockHeader,
|
|
85
|
+
jobId,
|
|
86
|
+
unsyncedScopes,
|
|
87
|
+
).catch(err => {
|
|
88
|
+
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
89
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.delete(key));
|
|
90
|
+
throw err;
|
|
91
|
+
});
|
|
92
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.set(key, promise));
|
|
83
93
|
}
|
|
94
|
+
|
|
95
|
+
const promises = toKeys(contractAddress, scopes).map(key => this.syncedContracts.get(key)!);
|
|
96
|
+
await Promise.all(promises);
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
async #doSync(
|
|
87
100
|
contractAddress: AztecAddress,
|
|
88
101
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
89
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
102
|
+
utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<any>,
|
|
90
103
|
anchorBlockHeader: BlockHeader,
|
|
91
104
|
jobId: string,
|
|
105
|
+
scopes: AccessScopes,
|
|
92
106
|
): Promise<void> {
|
|
93
107
|
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
94
108
|
await Promise.all([
|
|
@@ -101,6 +115,7 @@ export class ContractSyncService implements StagedStore {
|
|
|
101
115
|
this.aztecNode,
|
|
102
116
|
anchorBlockHeader,
|
|
103
117
|
jobId,
|
|
118
|
+
scopes,
|
|
104
119
|
),
|
|
105
120
|
verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
106
121
|
]);
|
|
@@ -127,3 +142,11 @@ export class ContractSyncService implements StagedStore {
|
|
|
127
142
|
return Promise.resolve();
|
|
128
143
|
}
|
|
129
144
|
}
|
|
145
|
+
|
|
146
|
+
function toKeys(contract: AztecAddress, scopes: AccessScopes) {
|
|
147
|
+
return scopes === 'ALL_SCOPES' ? [toKey(contract, scopes)] : scopes.map(scope => toKey(contract, scope));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function toKey(contract: AztecAddress, scope: AztecAddress | 'ALL_SCOPES') {
|
|
151
|
+
return scope === 'ALL_SCOPES' ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
|
|
152
|
+
}
|
|
@@ -6,6 +6,7 @@ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '
|
|
|
6
6
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
|
+
import type { AccessScopes } from '../access_scopes.js';
|
|
9
10
|
import { NoteService } from '../notes/note_service.js';
|
|
10
11
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
11
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -42,11 +43,12 @@ export async function syncState(
|
|
|
42
43
|
contractAddress: AztecAddress,
|
|
43
44
|
contractStore: ContractStore,
|
|
44
45
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
45
|
-
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
46
|
+
utilityExecutor: (privateSyncCall: FunctionCall, scopes: AccessScopes) => Promise<any>,
|
|
46
47
|
noteStore: NoteStore,
|
|
47
48
|
aztecNode: AztecNode,
|
|
48
49
|
anchorBlockHeader: BlockHeader,
|
|
49
50
|
jobId: string,
|
|
51
|
+
scopes: AccessScopes,
|
|
50
52
|
) {
|
|
51
53
|
// Protocol contracts don't have private state to sync
|
|
52
54
|
if (!isProtocolContract(contractAddress)) {
|
|
@@ -61,7 +63,10 @@ export async function syncState(
|
|
|
61
63
|
|
|
62
64
|
// Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
|
|
63
65
|
// because note store is designed to handle concurrent operations.
|
|
64
|
-
await Promise.all([
|
|
66
|
+
await Promise.all([
|
|
67
|
+
utilityExecutor(syncStateFunctionCall, scopes),
|
|
68
|
+
noteService.syncNoteNullifiers(contractAddress, scopes),
|
|
69
|
+
]);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
|
-
import type {
|
|
4
|
-
import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
|
|
3
|
+
import type { NoteDao } from '@aztec/stdlib/note';
|
|
5
4
|
import type { ContractOverrides } from '@aztec/stdlib/tx';
|
|
6
5
|
|
|
6
|
+
import type { AccessScopes } from '../access_scopes.js';
|
|
7
7
|
import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
|
|
8
8
|
import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
|
|
9
9
|
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
10
|
+
import type { NotesFilter } from '../notes_filter.js';
|
|
10
11
|
import type { AnchorBlockStore } from '../storage/index.js';
|
|
11
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
12
13
|
|
|
@@ -21,7 +22,7 @@ export class PXEDebugUtils {
|
|
|
21
22
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
22
23
|
call: FunctionCall,
|
|
23
24
|
authWitnesses: AuthWitness[] | undefined,
|
|
24
|
-
scopes:
|
|
25
|
+
scopes: AccessScopes,
|
|
25
26
|
jobId: string,
|
|
26
27
|
) => Promise<any>;
|
|
27
28
|
|
|
@@ -40,7 +41,7 @@ export class PXEDebugUtils {
|
|
|
40
41
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
41
42
|
call: FunctionCall,
|
|
42
43
|
authWitnesses: AuthWitness[] | undefined,
|
|
43
|
-
scopes:
|
|
44
|
+
scopes: AccessScopes,
|
|
44
45
|
jobId: string,
|
|
45
46
|
) => Promise<any>,
|
|
46
47
|
) {
|
|
@@ -71,10 +72,11 @@ export class PXEDebugUtils {
|
|
|
71
72
|
await this.contractSyncService.ensureContractSynced(
|
|
72
73
|
filter.contractAddress,
|
|
73
74
|
null,
|
|
74
|
-
async privateSyncCall =>
|
|
75
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
75
|
+
async (privateSyncCall, execScopes) =>
|
|
76
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
76
77
|
anchorBlockHeader,
|
|
77
78
|
jobId,
|
|
79
|
+
filter.scopes,
|
|
78
80
|
);
|
|
79
81
|
|
|
80
82
|
return this.noteStore.getNotes(filter, jobId);
|