@aztec/pxe 0.0.1-commit.023c3e5 → 0.0.1-commit.08c5969dc
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/block_synchronizer/block_synchronizer.d.ts +4 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +7 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +52 -27
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +169 -63
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +23 -11
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -35
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -20
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +34 -15
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +64 -44
- package/dest/contract_sync/contract_sync_service.d.ts +42 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +13 -12
- package/dest/debug/pxe_debug_utils.d.ts +12 -9
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +16 -15
- 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/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +2 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +6 -13
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +68 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +68 -42
- 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 +25 -16
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +315 -119
- package/src/contract_function_simulator/oracle/interfaces.ts +2 -2
- package/src/contract_function_simulator/oracle/oracle.ts +14 -7
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +95 -96
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +105 -44
- package/src/contract_sync/contract_sync_service.ts +145 -0
- package/src/contract_sync/{index.ts → helpers.ts} +15 -20
- package/src/debug/pxe_debug_utils.ts +46 -17
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +6 -15
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +146 -83
- package/src/storage/contract_store/contract_store.ts +4 -4
- package/src/storage/note_store/note_store.ts +5 -2
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
|
@@ -248,12 +248,19 @@ export class Oracle {
|
|
|
248
248
|
return [witness.map(toACVMField)];
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
async
|
|
251
|
+
async utilityTryGetPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
|
|
252
252
|
const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
|
|
253
|
-
const
|
|
254
|
-
await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(parsedAddress);
|
|
253
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(parsedAddress);
|
|
255
254
|
|
|
256
|
-
return
|
|
255
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
256
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
257
|
+
if (result === undefined) {
|
|
258
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
259
|
+
return [toACVMField(0), Array(13).fill(toACVMField(0))];
|
|
260
|
+
} else {
|
|
261
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
262
|
+
return [toACVMField(1), [...result.publicKeys.toFields(), result.partialAddress].map(toACVMField)];
|
|
263
|
+
}
|
|
257
264
|
}
|
|
258
265
|
|
|
259
266
|
async utilityGetNotes(
|
|
@@ -410,7 +417,7 @@ export class Oracle {
|
|
|
410
417
|
return Promise.resolve([]);
|
|
411
418
|
}
|
|
412
419
|
|
|
413
|
-
|
|
420
|
+
async utilityLog(
|
|
414
421
|
level: ACVMField[],
|
|
415
422
|
message: ACVMField[],
|
|
416
423
|
_ignoredFieldsSize: ACVMField[],
|
|
@@ -419,8 +426,8 @@ export class Oracle {
|
|
|
419
426
|
const levelFr = Fr.fromString(level[0]);
|
|
420
427
|
const messageStr = message.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
421
428
|
const fieldsFr = fields.map(Fr.fromString);
|
|
422
|
-
this.handlerAsMisc().
|
|
423
|
-
return
|
|
429
|
+
await this.handlerAsMisc().utilityLog(levelFr.toNumber(), messageStr, fieldsFr);
|
|
430
|
+
return [];
|
|
424
431
|
}
|
|
425
432
|
|
|
426
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,22 @@ 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
|
|
|
33
|
-
import {
|
|
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,56 +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
|
-
callContext.contractAddress,
|
|
106
|
-
authWitnesses,
|
|
107
|
-
capsules,
|
|
108
|
-
anchorBlockHeader,
|
|
109
|
-
contractStore,
|
|
110
|
-
noteStore,
|
|
111
|
-
keyStore,
|
|
112
|
-
addressStore,
|
|
113
|
-
aztecNode,
|
|
114
|
-
recipientTaggingStore,
|
|
115
|
-
senderAddressBookStore,
|
|
116
|
-
capsuleStore,
|
|
117
|
-
privateEventStore,
|
|
118
|
-
jobId,
|
|
119
|
-
log,
|
|
120
|
-
scopes,
|
|
121
|
-
);
|
|
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;
|
|
122
111
|
}
|
|
123
112
|
|
|
124
113
|
public getPrivateContextInputs(): PrivateContextInputs {
|
|
@@ -242,7 +231,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
242
231
|
sender: AztecAddress,
|
|
243
232
|
recipient: AztecAddress,
|
|
244
233
|
) {
|
|
245
|
-
const senderCompleteAddress = await this.
|
|
234
|
+
const senderCompleteAddress = await this.getCompleteAddressOrFail(sender);
|
|
246
235
|
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
|
|
247
236
|
return DirectionalAppTaggingSecret.compute(
|
|
248
237
|
senderCompleteAddress,
|
|
@@ -537,13 +526,22 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
537
526
|
|
|
538
527
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
539
528
|
|
|
540
|
-
|
|
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
|
+
|
|
538
|
+
await this.contractSyncService.ensureContractSynced(
|
|
541
539
|
targetContractAddress,
|
|
542
540
|
functionSelector,
|
|
543
541
|
this.utilityExecutor,
|
|
544
|
-
this.aztecNode,
|
|
545
|
-
this.contractStore,
|
|
546
542
|
this.anchorBlockHeader,
|
|
543
|
+
this.jobId,
|
|
544
|
+
expandedScopes,
|
|
547
545
|
);
|
|
548
546
|
|
|
549
547
|
const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
|
|
@@ -555,40 +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.
|
|
580
|
-
this.
|
|
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,
|
|
581
580
|
sideEffectCounter,
|
|
582
|
-
this.log,
|
|
583
|
-
|
|
584
|
-
this.senderForTags,
|
|
585
|
-
this.simulator
|
|
586
|
-
);
|
|
581
|
+
log: this.log,
|
|
582
|
+
scopes: expandedScopes,
|
|
583
|
+
senderForTags: this.senderForTags,
|
|
584
|
+
simulator: this.simulator!,
|
|
585
|
+
});
|
|
587
586
|
|
|
588
587
|
const setupTime = simulatorSetupTimer.ms();
|
|
589
588
|
|
|
590
589
|
const childExecutionResult = await executePrivateFunction(
|
|
591
|
-
this.simulator
|
|
590
|
+
this.simulator!,
|
|
592
591
|
privateExecutionOracle,
|
|
593
592
|
targetArtifact,
|
|
594
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) {
|
|
@@ -88,8 +125,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
88
125
|
* @param pkMHash - The master public key hash.
|
|
89
126
|
* @returns A Promise that resolves to nullifier keys.
|
|
90
127
|
* @throws If the keys are not registered in the key store.
|
|
128
|
+
* @throws If scopes are defined and the account is not in the scopes.
|
|
91
129
|
*/
|
|
92
|
-
public utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
130
|
+
public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
131
|
+
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
132
|
+
if (this.scopes && this.scopes.length > 0) {
|
|
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()}.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
93
143
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
94
144
|
}
|
|
95
145
|
|
|
@@ -182,14 +232,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
182
232
|
/**
|
|
183
233
|
* Retrieve the complete address associated to a given address.
|
|
184
234
|
* @param account - The account address.
|
|
185
|
-
* @returns A complete address associated with the input address.
|
|
186
|
-
* @throws An error if the account is not registered in the database.
|
|
235
|
+
* @returns A complete address associated with the input address, or `undefined` if not registered.
|
|
187
236
|
*/
|
|
188
|
-
public
|
|
189
|
-
return this.getCompleteAddress(account);
|
|
237
|
+
public utilityTryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
238
|
+
return this.addressStore.getCompleteAddress(account);
|
|
190
239
|
}
|
|
191
240
|
|
|
192
|
-
protected async
|
|
241
|
+
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
193
242
|
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
194
243
|
if (!completeAddress) {
|
|
195
244
|
throw new Error(
|
|
@@ -290,8 +339,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
290
339
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
291
340
|
*/
|
|
292
341
|
public async utilityCheckNullifierExists(innerNullifier: Fr) {
|
|
293
|
-
const nullifier = await
|
|
294
|
-
|
|
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
|
+
]);
|
|
295
349
|
return leafIndex?.data !== undefined;
|
|
296
350
|
}
|
|
297
351
|
|
|
@@ -342,12 +396,28 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
342
396
|
return values;
|
|
343
397
|
}
|
|
344
398
|
|
|
345
|
-
|
|
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> {
|
|
346
415
|
if (!LogLevels[level]) {
|
|
347
|
-
throw new Error(`Invalid
|
|
416
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
348
417
|
}
|
|
349
418
|
const levelName = LogLevels[level];
|
|
350
|
-
this
|
|
419
|
+
const logger = await this.#getContractLogger();
|
|
420
|
+
logger[levelName](`${applyStringFormatting(message, fields)}`);
|
|
351
421
|
}
|
|
352
422
|
|
|
353
423
|
public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
@@ -363,16 +433,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
363
433
|
this.log.getBindings(),
|
|
364
434
|
);
|
|
365
435
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// It is acceptable to run the following operations in parallel for several reasons:
|
|
369
|
-
// 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
|
|
370
|
-
// which is then processed in Noir after this handler returns.
|
|
371
|
-
// 2. Even if syncTaggedLogs did write to the note store, it would not cause inconsistent state.
|
|
372
|
-
await Promise.all([
|
|
373
|
-
logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes),
|
|
374
|
-
noteService.syncNoteNullifiers(this.contractAddress),
|
|
375
|
-
]);
|
|
436
|
+
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
376
437
|
}
|
|
377
438
|
|
|
378
439
|
/**
|
|
@@ -544,7 +605,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
544
605
|
|
|
545
606
|
protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
546
607
|
// TODO(#12656): return an app-siloed secret
|
|
547
|
-
const recipientCompleteAddress = await this.
|
|
608
|
+
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
548
609
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
549
610
|
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
550
611
|
);
|