@aztec/pxe 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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 +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +6 -0
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +14 -7
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +138 -45
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -5
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -6
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +5 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +50 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +38 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +64 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +187 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +23 -48
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +50 -81
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +66 -46
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +190 -99
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +9 -2
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +7 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +45 -38
- package/dest/contract_sync/helpers.d.ts +2 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +9 -4
- package/dest/debug/pxe_debug_utils.d.ts +4 -3
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -4
- 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 +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -2
- 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 +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +2 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +2 -2
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/logs/log_service.d.ts +6 -6
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +34 -32
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +24 -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 +3 -3
- 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/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
- package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +18 -14
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +74 -48
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +33 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +140 -64
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -2
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- 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/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +254 -65
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -8
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -9
- package/src/contract_function_simulator/oracle/interfaces.ts +63 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +223 -139
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +58 -102
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +320 -122
- package/src/contract_function_simulator/pick_notes.ts +9 -2
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +79 -54
- package/src/contract_sync/helpers.ts +8 -3
- package/src/debug/pxe_debug_utils.ts +8 -7
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +2 -3
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +68 -51
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +19 -8
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +3 -3
- 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/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +104 -61
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +34 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +170 -71
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +4 -3
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +7 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- 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
|
@@ -3,29 +3,33 @@ 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, type Logger,
|
|
6
|
+
import { LogLevels, type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
8
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
9
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
9
10
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
10
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
12
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
12
|
-
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
13
|
+
import type { CompleteAddress, ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
|
|
13
14
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
14
15
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
15
16
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
16
|
-
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
17
|
-
import {
|
|
17
|
+
import { type PublicKeys, computeAddressSecret } from '@aztec/stdlib/keys';
|
|
18
|
+
import { MessageContext, deriveAppSiloedSharedSecret } from '@aztec/stdlib/logs';
|
|
18
19
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
19
20
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
20
21
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
21
|
-
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
22
|
+
import type { BlockHeader, Capsule, OffchainEffect } from '@aztec/stdlib/tx';
|
|
22
23
|
|
|
24
|
+
import { createContractLogger, logContractMessage, stripAztecnrLogPrefix } from '../../contract_logging.js';
|
|
25
|
+
import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
23
26
|
import { EventService } from '../../events/event_service.js';
|
|
24
27
|
import { LogService } from '../../logs/log_service.js';
|
|
28
|
+
import { MessageContextService } from '../../messages/message_context_service.js';
|
|
25
29
|
import { NoteService } from '../../notes/note_service.js';
|
|
26
30
|
import { ORACLE_VERSION } from '../../oracle_version.js';
|
|
27
31
|
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
28
|
-
import type {
|
|
32
|
+
import type { CapsuleService } from '../../storage/capsule_store/capsule_service.js';
|
|
29
33
|
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
|
|
30
34
|
import type { NoteStore } from '../../storage/note_store/note_store.js';
|
|
31
35
|
import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
|
|
@@ -54,11 +58,13 @@ export type UtilityExecutionOracleArgs = {
|
|
|
54
58
|
aztecNode: AztecNode;
|
|
55
59
|
recipientTaggingStore: RecipientTaggingStore;
|
|
56
60
|
senderAddressBookStore: SenderAddressBookStore;
|
|
57
|
-
|
|
61
|
+
capsuleService: CapsuleService;
|
|
58
62
|
privateEventStore: PrivateEventStore;
|
|
63
|
+
messageContextService: MessageContextService;
|
|
64
|
+
contractSyncService: ContractSyncService;
|
|
59
65
|
jobId: string;
|
|
60
66
|
log?: ReturnType<typeof createLogger>;
|
|
61
|
-
scopes
|
|
67
|
+
scopes: AztecAddress[];
|
|
62
68
|
};
|
|
63
69
|
|
|
64
70
|
/**
|
|
@@ -69,6 +75,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
69
75
|
isUtility = true as const;
|
|
70
76
|
|
|
71
77
|
private contractLogger: Logger | undefined;
|
|
78
|
+
private aztecnrLogger: Logger | undefined;
|
|
79
|
+
private offchainEffects: OffchainEffect[] = [];
|
|
72
80
|
|
|
73
81
|
protected readonly contractAddress: AztecAddress;
|
|
74
82
|
protected readonly authWitnesses: AuthWitness[];
|
|
@@ -81,11 +89,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
81
89
|
protected readonly aztecNode: AztecNode;
|
|
82
90
|
protected readonly recipientTaggingStore: RecipientTaggingStore;
|
|
83
91
|
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
84
|
-
protected readonly
|
|
92
|
+
protected readonly capsuleService: CapsuleService;
|
|
85
93
|
protected readonly privateEventStore: PrivateEventStore;
|
|
94
|
+
protected readonly messageContextService: MessageContextService;
|
|
95
|
+
protected readonly contractSyncService: ContractSyncService;
|
|
86
96
|
protected readonly jobId: string;
|
|
87
|
-
protected
|
|
88
|
-
protected readonly scopes
|
|
97
|
+
protected logger: ReturnType<typeof createLogger>;
|
|
98
|
+
protected readonly scopes: AztecAddress[];
|
|
89
99
|
|
|
90
100
|
constructor(args: UtilityExecutionOracleArgs) {
|
|
91
101
|
this.contractAddress = args.contractAddress;
|
|
@@ -99,24 +109,51 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
99
109
|
this.aztecNode = args.aztecNode;
|
|
100
110
|
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
101
111
|
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
102
|
-
this.
|
|
112
|
+
this.capsuleService = args.capsuleService;
|
|
103
113
|
this.privateEventStore = args.privateEventStore;
|
|
114
|
+
this.messageContextService = args.messageContextService;
|
|
115
|
+
this.contractSyncService = args.contractSyncService;
|
|
104
116
|
this.jobId = args.jobId;
|
|
105
|
-
this.
|
|
117
|
+
this.logger = args.log ?? createLogger('simulator:client_view_context');
|
|
106
118
|
this.scopes = args.scopes;
|
|
107
119
|
}
|
|
108
120
|
|
|
109
|
-
public
|
|
121
|
+
public assertCompatibleOracleVersion(version: number): void {
|
|
122
|
+
// TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
|
|
123
|
+
// Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
|
|
124
|
+
// the expected pinned version or the current one. We want to allow for both the pinned and the current versions
|
|
125
|
+
// because we want this code to work with both the pinned and unpinned version since some branches do not have the
|
|
126
|
+
// pinned contracts (like e.g. next)
|
|
127
|
+
const LEGACY_ORACLE_VERSION = 12;
|
|
128
|
+
if (isProtocolContract(this.contractAddress)) {
|
|
129
|
+
if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
|
|
130
|
+
const hint =
|
|
131
|
+
version > ORACLE_VERSION
|
|
132
|
+
? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
|
|
133
|
+
: 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${LEGACY_ORACLE_VERSION} or ${ORACLE_VERSION}, got ${version})`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
110
141
|
if (version !== ORACLE_VERSION) {
|
|
111
|
-
|
|
142
|
+
const hint =
|
|
143
|
+
version > ORACLE_VERSION
|
|
144
|
+
? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.'
|
|
145
|
+
: 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${ORACLE_VERSION}, got ${version})`,
|
|
148
|
+
);
|
|
112
149
|
}
|
|
113
150
|
}
|
|
114
151
|
|
|
115
|
-
public
|
|
152
|
+
public getRandomField(): Fr {
|
|
116
153
|
return Fr.random();
|
|
117
154
|
}
|
|
118
155
|
|
|
119
|
-
public
|
|
156
|
+
public getUtilityContext(): UtilityContext {
|
|
120
157
|
return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
|
|
121
158
|
}
|
|
122
159
|
|
|
@@ -127,34 +164,33 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
127
164
|
* @throws If the keys are not registered in the key store.
|
|
128
165
|
* @throws If scopes are defined and the account is not in the scopes.
|
|
129
166
|
*/
|
|
130
|
-
public async
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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()}.`);
|
|
167
|
+
public async getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
168
|
+
let hasAccess = false;
|
|
169
|
+
for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
|
|
170
|
+
if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
|
|
171
|
+
hasAccess = true;
|
|
141
172
|
}
|
|
142
173
|
}
|
|
174
|
+
if (!hasAccess) {
|
|
175
|
+
throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
|
|
176
|
+
}
|
|
143
177
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
144
178
|
}
|
|
145
179
|
|
|
146
180
|
/**
|
|
147
181
|
* Fetches the index and sibling path of a leaf at a given block from the note hash tree.
|
|
148
|
-
* @param
|
|
149
|
-
* witness.
|
|
182
|
+
* @param blockHash - The hash of a block that contains the note hash tree root in which to find the
|
|
183
|
+
* membership witness.
|
|
150
184
|
* @param noteHash - The note hash to find in the note hash tree.
|
|
151
185
|
* @returns The membership witness containing the leaf index and sibling path
|
|
152
186
|
*/
|
|
153
|
-
public
|
|
154
|
-
|
|
187
|
+
public getNoteHashMembershipWitness(
|
|
188
|
+
blockHash: BlockHash,
|
|
155
189
|
noteHash: Fr,
|
|
156
190
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
157
|
-
return this
|
|
191
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
192
|
+
this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash),
|
|
193
|
+
);
|
|
158
194
|
}
|
|
159
195
|
|
|
160
196
|
/**
|
|
@@ -163,16 +199,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
163
199
|
* Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
|
|
164
200
|
* its block hash is appended as a new leaf to the archive tree.
|
|
165
201
|
*
|
|
166
|
-
* @param
|
|
202
|
+
* @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
|
|
167
203
|
* witness.
|
|
168
204
|
* @param blockHash - The block hash to find in the archive tree.
|
|
169
205
|
* @returns The membership witness containing the leaf index and sibling path
|
|
170
206
|
*/
|
|
171
|
-
public
|
|
172
|
-
|
|
207
|
+
public getBlockHashMembershipWitness(
|
|
208
|
+
referenceBlockHash: BlockHash,
|
|
173
209
|
blockHash: BlockHash,
|
|
174
210
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
175
|
-
|
|
211
|
+
// Note that we validate that the reference block hash is at or before the anchor block - we don't test the block
|
|
212
|
+
// hash at all. If the block hash did not exist by the reference block hash, then the node will not return the
|
|
213
|
+
// membership witness as there is none.
|
|
214
|
+
return this.#queryWithBlockHashNotAfterAnchor(referenceBlockHash, () =>
|
|
215
|
+
this.aztecNode.getBlockHashMembershipWitness(referenceBlockHash, blockHash),
|
|
216
|
+
);
|
|
176
217
|
}
|
|
177
218
|
|
|
178
219
|
/**
|
|
@@ -181,11 +222,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
181
222
|
* @param nullifier - Nullifier we try to find witness for.
|
|
182
223
|
* @returns The nullifier membership witness (if found).
|
|
183
224
|
*/
|
|
184
|
-
public
|
|
225
|
+
public getNullifierMembershipWitness(
|
|
185
226
|
blockHash: BlockHash,
|
|
186
227
|
nullifier: Fr,
|
|
187
228
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
188
|
-
return this
|
|
229
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
230
|
+
this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier),
|
|
231
|
+
);
|
|
189
232
|
}
|
|
190
233
|
|
|
191
234
|
/**
|
|
@@ -197,11 +240,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
197
240
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
198
241
|
* we are trying to prove non-inclusion for.
|
|
199
242
|
*/
|
|
200
|
-
public
|
|
243
|
+
public getLowNullifierMembershipWitness(
|
|
201
244
|
blockHash: BlockHash,
|
|
202
245
|
nullifier: Fr,
|
|
203
246
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
204
|
-
return this
|
|
247
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
248
|
+
this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier),
|
|
249
|
+
);
|
|
205
250
|
}
|
|
206
251
|
|
|
207
252
|
/**
|
|
@@ -210,8 +255,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
210
255
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
211
256
|
* @returns - The witness
|
|
212
257
|
*/
|
|
213
|
-
public
|
|
214
|
-
return this
|
|
258
|
+
public getPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
259
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
260
|
+
this.aztecNode.getPublicDataWitness(blockHash, leafSlot),
|
|
261
|
+
);
|
|
215
262
|
}
|
|
216
263
|
|
|
217
264
|
/**
|
|
@@ -219,7 +266,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
219
266
|
* @param blockNumber - The number of a block of which to get the block header.
|
|
220
267
|
* @returns Block extracted from a block with block number `blockNumber`.
|
|
221
268
|
*/
|
|
222
|
-
public async
|
|
269
|
+
public async getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
|
|
223
270
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
224
271
|
if (blockNumber > anchorBlockNumber) {
|
|
225
272
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
@@ -230,12 +277,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
230
277
|
}
|
|
231
278
|
|
|
232
279
|
/**
|
|
233
|
-
* Retrieve the
|
|
280
|
+
* Retrieve the public keys and partial address associated to a given address.
|
|
234
281
|
* @param account - The account address.
|
|
235
|
-
* @returns
|
|
282
|
+
* @returns The public keys and partial address, or `undefined` if the account is not registered.
|
|
236
283
|
*/
|
|
237
|
-
public
|
|
238
|
-
|
|
284
|
+
public async getPublicKeysAndPartialAddress(
|
|
285
|
+
account: AztecAddress,
|
|
286
|
+
): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
|
|
287
|
+
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
288
|
+
if (!completeAddress) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
return { publicKeys: completeAddress.publicKeys, partialAddress: completeAddress.partialAddress };
|
|
239
292
|
}
|
|
240
293
|
|
|
241
294
|
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
@@ -254,11 +307,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
254
307
|
* @param address - Address.
|
|
255
308
|
* @returns A contract instance.
|
|
256
309
|
*/
|
|
257
|
-
public
|
|
258
|
-
return this.getContractInstance(address);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
protected async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
310
|
+
public async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
262
311
|
const instance = await this.contractStore.getContractInstance(address);
|
|
263
312
|
if (!instance) {
|
|
264
313
|
throw new Error(`No contract instance found for address ${address.toString()}`);
|
|
@@ -272,7 +321,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
272
321
|
* @param messageHash - Hash of the message to authenticate.
|
|
273
322
|
* @returns Authentication witness for the requested message hash.
|
|
274
323
|
*/
|
|
275
|
-
public
|
|
324
|
+
public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
276
325
|
return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
|
|
277
326
|
}
|
|
278
327
|
|
|
@@ -298,7 +347,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
298
347
|
* @param status - The status of notes to fetch.
|
|
299
348
|
* @returns Array of note data.
|
|
300
349
|
*/
|
|
301
|
-
public async
|
|
350
|
+
public async getNotes(
|
|
302
351
|
owner: AztecAddress | undefined,
|
|
303
352
|
storageSlot: Fr,
|
|
304
353
|
numSelects: number,
|
|
@@ -338,7 +387,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
338
387
|
* @param innerNullifier - The inner nullifier.
|
|
339
388
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
340
389
|
*/
|
|
341
|
-
public async
|
|
390
|
+
public async doesNullifierExist(innerNullifier: Fr) {
|
|
342
391
|
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
343
392
|
siloNullifier(this.contractAddress, innerNullifier!),
|
|
344
393
|
this.anchorBlockHeader.hash(),
|
|
@@ -350,19 +399,20 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
350
399
|
}
|
|
351
400
|
|
|
352
401
|
/**
|
|
353
|
-
*
|
|
402
|
+
* Returns the membership witness of an un-nullified L1 to L2 message.
|
|
354
403
|
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
355
404
|
* @param messageHash - Hash of the message.
|
|
356
405
|
* @param secret - Secret used to compute a nullifier.
|
|
357
406
|
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
358
407
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
359
408
|
*/
|
|
360
|
-
public async
|
|
409
|
+
public async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
361
410
|
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
362
411
|
this.aztecNode,
|
|
363
412
|
contractAddress,
|
|
364
413
|
messageHash,
|
|
365
414
|
secret,
|
|
415
|
+
await this.anchorBlockHeader.hash(),
|
|
366
416
|
);
|
|
367
417
|
|
|
368
418
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
@@ -375,65 +425,88 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
375
425
|
* @param startStorageSlot - The starting storage slot.
|
|
376
426
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
377
427
|
*/
|
|
378
|
-
public
|
|
428
|
+
public getFromPublicStorage(
|
|
379
429
|
blockHash: BlockHash,
|
|
380
430
|
contractAddress: AztecAddress,
|
|
381
431
|
startStorageSlot: Fr,
|
|
382
432
|
numberOfElements: number,
|
|
383
433
|
) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
434
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, async () => {
|
|
435
|
+
const slots = Array(numberOfElements)
|
|
436
|
+
.fill(0)
|
|
437
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
387
438
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
439
|
+
const values = await Promise.all(
|
|
440
|
+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
|
|
441
|
+
);
|
|
391
442
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
443
|
+
this.logger.debug(
|
|
444
|
+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
|
|
445
|
+
);
|
|
395
446
|
|
|
396
|
-
|
|
447
|
+
return values;
|
|
448
|
+
});
|
|
397
449
|
}
|
|
398
450
|
|
|
399
451
|
/**
|
|
400
|
-
* Returns a per-contract logger whose output is prefixed with `
|
|
452
|
+
* Returns a per-contract logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
|
|
401
453
|
*/
|
|
402
454
|
async #getContractLogger(): Promise<Logger> {
|
|
403
455
|
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
456
|
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
408
457
|
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
409
|
-
this.contractLogger =
|
|
458
|
+
this.contractLogger = await createContractLogger(
|
|
459
|
+
this.contractAddress,
|
|
460
|
+
addr => this.contractStore.getDebugContractName(addr),
|
|
461
|
+
'user',
|
|
462
|
+
{ instanceId: this.jobId },
|
|
463
|
+
);
|
|
410
464
|
}
|
|
411
465
|
return this.contractLogger;
|
|
412
466
|
}
|
|
413
467
|
|
|
414
|
-
|
|
468
|
+
/**
|
|
469
|
+
* Returns a per-contract logger whose output is prefixed with `aztecnr:<name>(<addrAbbrev>)`.
|
|
470
|
+
*/
|
|
471
|
+
async #getAztecnrLogger(): Promise<Logger> {
|
|
472
|
+
if (!this.aztecnrLogger) {
|
|
473
|
+
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
474
|
+
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
475
|
+
this.aztecnrLogger = await createContractLogger(
|
|
476
|
+
this.contractAddress,
|
|
477
|
+
addr => this.contractStore.getDebugContractName(addr),
|
|
478
|
+
'aztecnr',
|
|
479
|
+
{ instanceId: this.jobId },
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
return this.aztecnrLogger;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
public async log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
415
486
|
if (!LogLevels[level]) {
|
|
416
487
|
throw new Error(`Invalid log level: ${level}`);
|
|
417
488
|
}
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
|
|
489
|
+
|
|
490
|
+
const { kind, message: strippedMessage } = stripAztecnrLogPrefix(message);
|
|
491
|
+
|
|
492
|
+
const logger = kind == 'aztecnr' ? await this.#getAztecnrLogger() : await this.#getContractLogger();
|
|
493
|
+
logContractMessage(logger, LogLevels[level], strippedMessage, fields);
|
|
421
494
|
}
|
|
422
495
|
|
|
423
|
-
public async
|
|
496
|
+
public async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress) {
|
|
424
497
|
const logService = new LogService(
|
|
425
498
|
this.aztecNode,
|
|
426
499
|
this.anchorBlockHeader,
|
|
427
500
|
this.keyStore,
|
|
428
|
-
this.
|
|
501
|
+
this.capsuleService,
|
|
429
502
|
this.recipientTaggingStore,
|
|
430
503
|
this.senderAddressBookStore,
|
|
431
504
|
this.addressStore,
|
|
432
505
|
this.jobId,
|
|
433
|
-
this.
|
|
506
|
+
this.logger.getBindings(),
|
|
434
507
|
);
|
|
435
508
|
|
|
436
|
-
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot,
|
|
509
|
+
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, scope);
|
|
437
510
|
}
|
|
438
511
|
|
|
439
512
|
/**
|
|
@@ -446,10 +519,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
446
519
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
447
520
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
448
521
|
*/
|
|
449
|
-
public async
|
|
522
|
+
public async validateAndStoreEnqueuedNotesAndEvents(
|
|
450
523
|
contractAddress: AztecAddress,
|
|
451
524
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
452
525
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
526
|
+
maxNotePackedLen: number,
|
|
527
|
+
maxEventSerializedLen: number,
|
|
528
|
+
scope: AztecAddress,
|
|
453
529
|
) {
|
|
454
530
|
// TODO(#10727): allow other contracts to store notes
|
|
455
531
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -459,12 +535,22 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
459
535
|
// We read all note and event validation requests and process them all concurrently. This makes the process much
|
|
460
536
|
// faster as we don't need to wait for the network round-trip.
|
|
461
537
|
const noteValidationRequests = (
|
|
462
|
-
await this.
|
|
463
|
-
|
|
538
|
+
await this.capsuleService.readCapsuleArray(
|
|
539
|
+
contractAddress,
|
|
540
|
+
noteValidationRequestsArrayBaseSlot,
|
|
541
|
+
this.jobId,
|
|
542
|
+
scope,
|
|
543
|
+
)
|
|
544
|
+
).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
|
|
464
545
|
|
|
465
546
|
const eventValidationRequests = (
|
|
466
|
-
await this.
|
|
467
|
-
|
|
547
|
+
await this.capsuleService.readCapsuleArray(
|
|
548
|
+
contractAddress,
|
|
549
|
+
eventValidationRequestsArrayBaseSlot,
|
|
550
|
+
this.jobId,
|
|
551
|
+
scope,
|
|
552
|
+
)
|
|
553
|
+
).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
|
|
468
554
|
|
|
469
555
|
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
470
556
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
@@ -478,7 +564,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
478
564
|
request.noteHash,
|
|
479
565
|
request.nullifier,
|
|
480
566
|
request.txHash,
|
|
481
|
-
|
|
567
|
+
scope,
|
|
482
568
|
),
|
|
483
569
|
);
|
|
484
570
|
|
|
@@ -491,21 +577,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
491
577
|
request.serializedEvent,
|
|
492
578
|
request.eventCommitment,
|
|
493
579
|
request.txHash,
|
|
494
|
-
|
|
580
|
+
scope,
|
|
495
581
|
),
|
|
496
582
|
);
|
|
497
583
|
|
|
498
584
|
await Promise.all([...noteStorePromises, ...eventStorePromises]);
|
|
499
585
|
|
|
500
586
|
// Requests are cleared once we're done.
|
|
501
|
-
await this.
|
|
502
|
-
|
|
587
|
+
await this.capsuleService.setCapsuleArray(
|
|
588
|
+
contractAddress,
|
|
589
|
+
noteValidationRequestsArrayBaseSlot,
|
|
590
|
+
[],
|
|
591
|
+
this.jobId,
|
|
592
|
+
scope,
|
|
593
|
+
);
|
|
594
|
+
await this.capsuleService.setCapsuleArray(
|
|
595
|
+
contractAddress,
|
|
596
|
+
eventValidationRequestsArrayBaseSlot,
|
|
597
|
+
[],
|
|
598
|
+
this.jobId,
|
|
599
|
+
scope,
|
|
600
|
+
);
|
|
503
601
|
}
|
|
504
602
|
|
|
505
|
-
public async
|
|
603
|
+
public async getLogsByTag(
|
|
506
604
|
contractAddress: AztecAddress,
|
|
507
605
|
logRetrievalRequestsArrayBaseSlot: Fr,
|
|
508
606
|
logRetrievalResponsesArrayBaseSlot: Fr,
|
|
607
|
+
scope: AztecAddress,
|
|
509
608
|
) {
|
|
510
609
|
// TODO(#10727): allow other contracts to process partial notes
|
|
511
610
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -515,101 +614,200 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
515
614
|
// We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
|
|
516
615
|
// don't need to wait for the network round-trip.
|
|
517
616
|
const logRetrievalRequests = (
|
|
518
|
-
await this.
|
|
617
|
+
await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)
|
|
519
618
|
).map(LogRetrievalRequest.fromFields);
|
|
520
619
|
|
|
521
620
|
const logService = new LogService(
|
|
522
621
|
this.aztecNode,
|
|
523
622
|
this.anchorBlockHeader,
|
|
524
623
|
this.keyStore,
|
|
525
|
-
this.
|
|
624
|
+
this.capsuleService,
|
|
526
625
|
this.recipientTaggingStore,
|
|
527
626
|
this.senderAddressBookStore,
|
|
528
627
|
this.addressStore,
|
|
529
628
|
this.jobId,
|
|
530
|
-
this.
|
|
629
|
+
this.logger.getBindings(),
|
|
531
630
|
);
|
|
532
631
|
|
|
533
|
-
const maybeLogRetrievalResponses = await logService.
|
|
632
|
+
const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
|
|
534
633
|
|
|
535
634
|
// Requests are cleared once we're done.
|
|
536
|
-
await this.
|
|
635
|
+
await this.capsuleService.setCapsuleArray(
|
|
636
|
+
contractAddress,
|
|
637
|
+
logRetrievalRequestsArrayBaseSlot,
|
|
638
|
+
[],
|
|
639
|
+
this.jobId,
|
|
640
|
+
scope,
|
|
641
|
+
);
|
|
537
642
|
|
|
538
643
|
// The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
|
|
539
|
-
await this.
|
|
644
|
+
await this.capsuleService.setCapsuleArray(
|
|
540
645
|
contractAddress,
|
|
541
646
|
logRetrievalResponsesArrayBaseSlot,
|
|
542
647
|
maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
|
|
543
648
|
this.jobId,
|
|
649
|
+
scope,
|
|
544
650
|
);
|
|
545
651
|
}
|
|
546
652
|
|
|
547
|
-
public
|
|
653
|
+
public async getMessageContextsByTxHash(
|
|
654
|
+
contractAddress: AztecAddress,
|
|
655
|
+
messageContextRequestsArrayBaseSlot: Fr,
|
|
656
|
+
messageContextResponsesArrayBaseSlot: Fr,
|
|
657
|
+
scope: AztecAddress,
|
|
658
|
+
) {
|
|
659
|
+
try {
|
|
660
|
+
if (!this.contractAddress.equals(contractAddress)) {
|
|
661
|
+
throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// TODO(@mverzilli): this is a prime example of where using a volatile array would make much more sense, we don't
|
|
665
|
+
// need scopes here, we just need a bit of shared memory to cross boundaries between Noir and TS.
|
|
666
|
+
// At the same time, we don't want to allow any global scope access other than where backwards compatibility
|
|
667
|
+
// forces us to. Hence we need the scope here to be artificial.
|
|
668
|
+
const requestCapsules = await this.capsuleService.readCapsuleArray(
|
|
669
|
+
contractAddress,
|
|
670
|
+
messageContextRequestsArrayBaseSlot,
|
|
671
|
+
this.jobId,
|
|
672
|
+
scope,
|
|
673
|
+
);
|
|
674
|
+
|
|
675
|
+
const txHashes = requestCapsules.map((fields, i) => {
|
|
676
|
+
if (fields.length !== 1) {
|
|
677
|
+
throw new Error(
|
|
678
|
+
`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return fields[0];
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(
|
|
685
|
+
txHashes,
|
|
686
|
+
this.anchorBlockHeader.getBlockNumber(),
|
|
687
|
+
);
|
|
688
|
+
|
|
689
|
+
// Leave response in response capsule array.
|
|
690
|
+
await this.capsuleService.setCapsuleArray(
|
|
691
|
+
contractAddress,
|
|
692
|
+
messageContextResponsesArrayBaseSlot,
|
|
693
|
+
maybeMessageContexts.map(MessageContext.toSerializedOption),
|
|
694
|
+
this.jobId,
|
|
695
|
+
scope,
|
|
696
|
+
);
|
|
697
|
+
} finally {
|
|
698
|
+
await this.capsuleService.setCapsuleArray(
|
|
699
|
+
contractAddress,
|
|
700
|
+
messageContextRequestsArrayBaseSlot,
|
|
701
|
+
[],
|
|
702
|
+
this.jobId,
|
|
703
|
+
scope,
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): void {
|
|
548
709
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
549
710
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
550
711
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
551
712
|
}
|
|
552
|
-
this.
|
|
553
|
-
return Promise.resolve();
|
|
713
|
+
this.capsuleService.setCapsule(contractAddress, slot, capsule, this.jobId, scope);
|
|
554
714
|
}
|
|
555
715
|
|
|
556
|
-
public
|
|
716
|
+
public getCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): Promise<Fr[] | null> {
|
|
557
717
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
558
718
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
559
719
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
560
720
|
}
|
|
561
|
-
return (
|
|
562
|
-
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
563
|
-
this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
|
|
564
|
-
(await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId))
|
|
565
|
-
);
|
|
721
|
+
return this.capsuleService.getCapsule(contractAddress, slot, this.jobId, scope, this.capsules);
|
|
566
722
|
}
|
|
567
723
|
|
|
568
|
-
public
|
|
724
|
+
public deleteCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): void {
|
|
569
725
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
570
726
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
571
727
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
572
728
|
}
|
|
573
|
-
this.
|
|
574
|
-
return Promise.resolve();
|
|
729
|
+
this.capsuleService.deleteCapsule(contractAddress, slot, this.jobId, scope);
|
|
575
730
|
}
|
|
576
731
|
|
|
577
|
-
public
|
|
732
|
+
public copyCapsule(
|
|
578
733
|
contractAddress: AztecAddress,
|
|
579
734
|
srcSlot: Fr,
|
|
580
735
|
dstSlot: Fr,
|
|
581
736
|
numEntries: number,
|
|
737
|
+
scope: AztecAddress,
|
|
582
738
|
): Promise<void> {
|
|
583
739
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
584
740
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
585
741
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
586
742
|
}
|
|
587
|
-
return this.
|
|
743
|
+
return this.capsuleService.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, this.jobId, scope);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
|
|
748
|
+
* stored notes or events are discovered.
|
|
749
|
+
*/
|
|
750
|
+
public setContractSyncCacheInvalid(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
|
|
751
|
+
if (!contractAddress.equals(this.contractAddress)) {
|
|
752
|
+
throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
|
|
753
|
+
}
|
|
754
|
+
this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
|
|
588
755
|
}
|
|
589
756
|
|
|
590
757
|
// TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
|
|
591
|
-
public
|
|
758
|
+
public decryptAes128(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
|
|
592
759
|
const aes128 = new Aes128();
|
|
593
760
|
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
594
761
|
}
|
|
595
762
|
|
|
596
763
|
/**
|
|
597
|
-
* Retrieves the shared secret for a given address and ephemeral public key.
|
|
764
|
+
* Retrieves the app-siloed shared secret for a given address and ephemeral public key.
|
|
598
765
|
* @param address - The address to get the secret for.
|
|
599
766
|
* @param ephPk - The ephemeral public key to get the secret for.
|
|
600
|
-
* @
|
|
767
|
+
* @param contractAddress - The contract address for app-siloing (validated against execution context).
|
|
768
|
+
* @returns The app-siloed shared secret as a Field.
|
|
601
769
|
*/
|
|
602
|
-
public
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
770
|
+
public async getSharedSecret(address: AztecAddress, ephPk: Point, contractAddress: AztecAddress): Promise<Fr> {
|
|
771
|
+
if (!contractAddress.equals(this.contractAddress)) {
|
|
772
|
+
throw new Error(
|
|
773
|
+
`getSharedSecret called with contract address ${contractAddress}, expected ${this.contractAddress}`,
|
|
774
|
+
);
|
|
775
|
+
}
|
|
608
776
|
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
609
777
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
610
778
|
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
611
779
|
);
|
|
612
780
|
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
613
|
-
return
|
|
781
|
+
return deriveAppSiloedSharedSecret(addressSecret, ephPk, this.contractAddress);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
public emitOffchainEffect(data: Fr[]): Promise<void> {
|
|
785
|
+
this.offchainEffects.push({ data, contractAddress: this.contractAddress });
|
|
786
|
+
return Promise.resolve();
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/** Returns offchain effects collected during execution. */
|
|
790
|
+
public getOffchainEffects(): OffchainEffect[] {
|
|
791
|
+
return this.offchainEffects;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
|
|
795
|
+
async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
|
|
796
|
+
const [response] = await Promise.all([
|
|
797
|
+
query(),
|
|
798
|
+
(async () => {
|
|
799
|
+
const header = await this.aztecNode.getBlockHeader(blockHash);
|
|
800
|
+
if (!header) {
|
|
801
|
+
throw new Error(`Could not find block header for block hash ${blockHash}`);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
|
|
805
|
+
throw new Error(
|
|
806
|
+
`Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${await this.anchorBlockHeader.hash()}).`,
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
})(),
|
|
810
|
+
]);
|
|
811
|
+
return response;
|
|
614
812
|
}
|
|
615
813
|
}
|