@aztec/pxe 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2d9cb6034
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 +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +15 -3
- 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 +60 -31
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +201 -74
- 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 +211 -109
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -79
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +109 -87
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +100 -57
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +243 -128
- 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 +44 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +104 -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} +19 -13
- package/dest/debug/pxe_debug_utils.d.ts +14 -10
- 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/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 +21 -7
- 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 +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +3 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -1
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +5 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +20 -9
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +9 -8
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +46 -54
- 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 +7 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -14
- 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 +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- 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 +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- 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 +73 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +130 -76
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- 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 +39 -36
- 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 +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- 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/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- 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 +233 -137
- 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 +25 -16
- package/src/block_synchronizer/block_synchronizer.ts +27 -12
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +360 -133
- 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 +69 -60
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +98 -0
- package/src/contract_function_simulator/oracle/oracle.ts +245 -144
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +135 -184
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +410 -145
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +170 -0
- package/src/contract_sync/{index.ts → helpers.ts} +22 -22
- package/src/debug/pxe_debug_utils.ts +48 -18
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +2 -1
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +21 -10
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +87 -79
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +24 -15
- 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 +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +242 -129
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +42 -34
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +166 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
- 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/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- 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,30 +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,
|
|
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 {
|
|
29
|
-
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
|
|
32
|
+
import type { CapsuleService } from '../../storage/capsule_store/capsule_service.js';
|
|
30
33
|
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
|
|
31
34
|
import type { NoteStore } from '../../storage/note_store/note_store.js';
|
|
32
35
|
import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
|
|
@@ -41,6 +44,29 @@ import { pickNotes } from '../pick_notes.js';
|
|
|
41
44
|
import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
|
|
42
45
|
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
43
46
|
|
|
47
|
+
/** Args for UtilityExecutionOracle constructor. */
|
|
48
|
+
export type UtilityExecutionOracleArgs = {
|
|
49
|
+
contractAddress: AztecAddress;
|
|
50
|
+
/** List of transient auth witnesses to be used during this simulation */
|
|
51
|
+
authWitnesses: AuthWitness[];
|
|
52
|
+
capsules: Capsule[]; // TODO(#12425): Rename to transientCapsules
|
|
53
|
+
anchorBlockHeader: BlockHeader;
|
|
54
|
+
contractStore: ContractStore;
|
|
55
|
+
noteStore: NoteStore;
|
|
56
|
+
keyStore: KeyStore;
|
|
57
|
+
addressStore: AddressStore;
|
|
58
|
+
aztecNode: AztecNode;
|
|
59
|
+
recipientTaggingStore: RecipientTaggingStore;
|
|
60
|
+
senderAddressBookStore: SenderAddressBookStore;
|
|
61
|
+
capsuleService: CapsuleService;
|
|
62
|
+
privateEventStore: PrivateEventStore;
|
|
63
|
+
messageContextService: MessageContextService;
|
|
64
|
+
contractSyncService: ContractSyncService;
|
|
65
|
+
jobId: string;
|
|
66
|
+
log?: ReturnType<typeof createLogger>;
|
|
67
|
+
scopes: AztecAddress[];
|
|
68
|
+
};
|
|
69
|
+
|
|
44
70
|
/**
|
|
45
71
|
* The oracle for an execution of utility contract functions.
|
|
46
72
|
*/
|
|
@@ -48,40 +74,86 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
48
74
|
isMisc = true as const;
|
|
49
75
|
isUtility = true as const;
|
|
50
76
|
|
|
51
|
-
private
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
private contractLogger: Logger | undefined;
|
|
78
|
+
private aztecnrLogger: Logger | undefined;
|
|
79
|
+
private offchainEffects: OffchainEffect[] = [];
|
|
80
|
+
|
|
81
|
+
protected readonly contractAddress: AztecAddress;
|
|
82
|
+
protected readonly authWitnesses: AuthWitness[];
|
|
83
|
+
protected readonly capsules: Capsule[];
|
|
84
|
+
protected readonly anchorBlockHeader: BlockHeader;
|
|
85
|
+
protected readonly contractStore: ContractStore;
|
|
86
|
+
protected readonly noteStore: NoteStore;
|
|
87
|
+
protected readonly keyStore: KeyStore;
|
|
88
|
+
protected readonly addressStore: AddressStore;
|
|
89
|
+
protected readonly aztecNode: AztecNode;
|
|
90
|
+
protected readonly recipientTaggingStore: RecipientTaggingStore;
|
|
91
|
+
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
92
|
+
protected readonly capsuleService: CapsuleService;
|
|
93
|
+
protected readonly privateEventStore: PrivateEventStore;
|
|
94
|
+
protected readonly messageContextService: MessageContextService;
|
|
95
|
+
protected readonly contractSyncService: ContractSyncService;
|
|
96
|
+
protected readonly jobId: string;
|
|
97
|
+
protected logger: ReturnType<typeof createLogger>;
|
|
98
|
+
protected readonly scopes: AztecAddress[];
|
|
99
|
+
|
|
100
|
+
constructor(args: UtilityExecutionOracleArgs) {
|
|
101
|
+
this.contractAddress = args.contractAddress;
|
|
102
|
+
this.authWitnesses = args.authWitnesses;
|
|
103
|
+
this.capsules = args.capsules;
|
|
104
|
+
this.anchorBlockHeader = args.anchorBlockHeader;
|
|
105
|
+
this.contractStore = args.contractStore;
|
|
106
|
+
this.noteStore = args.noteStore;
|
|
107
|
+
this.keyStore = args.keyStore;
|
|
108
|
+
this.addressStore = args.addressStore;
|
|
109
|
+
this.aztecNode = args.aztecNode;
|
|
110
|
+
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
111
|
+
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
112
|
+
this.capsuleService = args.capsuleService;
|
|
113
|
+
this.privateEventStore = args.privateEventStore;
|
|
114
|
+
this.messageContextService = args.messageContextService;
|
|
115
|
+
this.contractSyncService = args.contractSyncService;
|
|
116
|
+
this.jobId = args.jobId;
|
|
117
|
+
this.logger = args.log ?? createLogger('simulator:client_view_context');
|
|
118
|
+
this.scopes = args.scopes;
|
|
119
|
+
}
|
|
120
|
+
|
|
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
|
+
|
|
75
141
|
if (version !== ORACLE_VERSION) {
|
|
76
|
-
|
|
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
|
+
);
|
|
77
149
|
}
|
|
78
150
|
}
|
|
79
151
|
|
|
80
|
-
public
|
|
152
|
+
public getRandomField(): Fr {
|
|
81
153
|
return Fr.random();
|
|
82
154
|
}
|
|
83
155
|
|
|
84
|
-
public
|
|
156
|
+
public getUtilityContext(): UtilityContext {
|
|
85
157
|
return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
|
|
86
158
|
}
|
|
87
159
|
|
|
@@ -90,35 +162,58 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
90
162
|
* @param pkMHash - The master public key hash.
|
|
91
163
|
* @returns A Promise that resolves to nullifier keys.
|
|
92
164
|
* @throws If the keys are not registered in the key store.
|
|
165
|
+
* @throws If scopes are defined and the account is not in the scopes.
|
|
93
166
|
*/
|
|
94
|
-
public
|
|
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;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!hasAccess) {
|
|
175
|
+
throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
|
|
176
|
+
}
|
|
95
177
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
96
178
|
}
|
|
97
179
|
|
|
98
180
|
/**
|
|
99
181
|
* Fetches the index and sibling path of a leaf at a given block from the note hash tree.
|
|
100
|
-
* @param blockHash - The block hash
|
|
101
|
-
*
|
|
182
|
+
* @param blockHash - The hash of a block that contains the note hash tree root in which to find the
|
|
183
|
+
* membership witness.
|
|
184
|
+
* @param noteHash - The note hash to find in the note hash tree.
|
|
102
185
|
* @returns The membership witness containing the leaf index and sibling path
|
|
103
186
|
*/
|
|
104
|
-
public
|
|
187
|
+
public getNoteHashMembershipWitness(
|
|
105
188
|
blockHash: BlockHash,
|
|
106
|
-
|
|
189
|
+
noteHash: Fr,
|
|
107
190
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
108
|
-
return this
|
|
191
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
192
|
+
this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash),
|
|
193
|
+
);
|
|
109
194
|
}
|
|
110
195
|
|
|
111
196
|
/**
|
|
112
|
-
* Fetches the index and sibling path of a
|
|
113
|
-
*
|
|
114
|
-
*
|
|
197
|
+
* Fetches the index and sibling path of a block hash in the archive tree.
|
|
198
|
+
*
|
|
199
|
+
* Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
|
|
200
|
+
* its block hash is appended as a new leaf to the archive tree.
|
|
201
|
+
*
|
|
202
|
+
* @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
|
|
203
|
+
* witness.
|
|
204
|
+
* @param blockHash - The block hash to find in the archive tree.
|
|
115
205
|
* @returns The membership witness containing the leaf index and sibling path
|
|
116
206
|
*/
|
|
117
|
-
public
|
|
207
|
+
public getBlockHashMembershipWitness(
|
|
208
|
+
referenceBlockHash: BlockHash,
|
|
118
209
|
blockHash: BlockHash,
|
|
119
|
-
leafValue: Fr,
|
|
120
210
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
121
|
-
|
|
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
|
+
);
|
|
122
217
|
}
|
|
123
218
|
|
|
124
219
|
/**
|
|
@@ -127,11 +222,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
127
222
|
* @param nullifier - Nullifier we try to find witness for.
|
|
128
223
|
* @returns The nullifier membership witness (if found).
|
|
129
224
|
*/
|
|
130
|
-
public
|
|
225
|
+
public getNullifierMembershipWitness(
|
|
131
226
|
blockHash: BlockHash,
|
|
132
227
|
nullifier: Fr,
|
|
133
228
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
134
|
-
return this
|
|
229
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
230
|
+
this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier),
|
|
231
|
+
);
|
|
135
232
|
}
|
|
136
233
|
|
|
137
234
|
/**
|
|
@@ -143,11 +240,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
143
240
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
144
241
|
* we are trying to prove non-inclusion for.
|
|
145
242
|
*/
|
|
146
|
-
public
|
|
243
|
+
public getLowNullifierMembershipWitness(
|
|
147
244
|
blockHash: BlockHash,
|
|
148
245
|
nullifier: Fr,
|
|
149
246
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
150
|
-
return this
|
|
247
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
248
|
+
this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier),
|
|
249
|
+
);
|
|
151
250
|
}
|
|
152
251
|
|
|
153
252
|
/**
|
|
@@ -156,8 +255,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
156
255
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
157
256
|
* @returns - The witness
|
|
158
257
|
*/
|
|
159
|
-
public
|
|
160
|
-
return this
|
|
258
|
+
public getPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
259
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
260
|
+
this.aztecNode.getPublicDataWitness(blockHash, leafSlot),
|
|
261
|
+
);
|
|
161
262
|
}
|
|
162
263
|
|
|
163
264
|
/**
|
|
@@ -165,8 +266,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
165
266
|
* @param blockNumber - The number of a block of which to get the block header.
|
|
166
267
|
* @returns Block extracted from a block with block number `blockNumber`.
|
|
167
268
|
*/
|
|
168
|
-
public async
|
|
169
|
-
const anchorBlockNumber =
|
|
269
|
+
public async getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
|
|
270
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
170
271
|
if (blockNumber > anchorBlockNumber) {
|
|
171
272
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
172
273
|
}
|
|
@@ -176,16 +277,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
176
277
|
}
|
|
177
278
|
|
|
178
279
|
/**
|
|
179
|
-
* Retrieve the
|
|
280
|
+
* Retrieve the public keys and partial address associated to a given address.
|
|
180
281
|
* @param account - The account address.
|
|
181
|
-
* @returns
|
|
182
|
-
* @throws An error if the account is not registered in the database.
|
|
282
|
+
* @returns The public keys and partial address, or `undefined` if the account is not registered.
|
|
183
283
|
*/
|
|
184
|
-
public
|
|
185
|
-
|
|
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 };
|
|
186
292
|
}
|
|
187
293
|
|
|
188
|
-
protected async
|
|
294
|
+
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
189
295
|
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
190
296
|
if (!completeAddress) {
|
|
191
297
|
throw new Error(
|
|
@@ -201,11 +307,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
201
307
|
* @param address - Address.
|
|
202
308
|
* @returns A contract instance.
|
|
203
309
|
*/
|
|
204
|
-
public
|
|
205
|
-
return this.getContractInstance(address);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
protected async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
310
|
+
public async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
209
311
|
const instance = await this.contractStore.getContractInstance(address);
|
|
210
312
|
if (!instance) {
|
|
211
313
|
throw new Error(`No contract instance found for address ${address.toString()}`);
|
|
@@ -219,7 +321,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
219
321
|
* @param messageHash - Hash of the message to authenticate.
|
|
220
322
|
* @returns Authentication witness for the requested message hash.
|
|
221
323
|
*/
|
|
222
|
-
public
|
|
324
|
+
public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
223
325
|
return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
|
|
224
326
|
}
|
|
225
327
|
|
|
@@ -245,7 +347,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
245
347
|
* @param status - The status of notes to fetch.
|
|
246
348
|
* @returns Array of note data.
|
|
247
349
|
*/
|
|
248
|
-
public async
|
|
350
|
+
public async getNotes(
|
|
249
351
|
owner: AztecAddress | undefined,
|
|
250
352
|
storageSlot: Fr,
|
|
251
353
|
numSelects: number,
|
|
@@ -262,7 +364,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
262
364
|
offset: number,
|
|
263
365
|
status: NoteStatus,
|
|
264
366
|
): Promise<NoteData[]> {
|
|
265
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.
|
|
367
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
266
368
|
|
|
267
369
|
const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
|
|
268
370
|
return pickNotes<NoteData>(dbNotes, {
|
|
@@ -285,26 +387,32 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
285
387
|
* @param innerNullifier - The inner nullifier.
|
|
286
388
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
287
389
|
*/
|
|
288
|
-
public async
|
|
289
|
-
const nullifier = await
|
|
290
|
-
|
|
390
|
+
public async doesNullifierExist(innerNullifier: Fr) {
|
|
391
|
+
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
392
|
+
siloNullifier(this.contractAddress, innerNullifier!),
|
|
393
|
+
this.anchorBlockHeader.hash(),
|
|
394
|
+
]);
|
|
395
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [
|
|
396
|
+
nullifier,
|
|
397
|
+
]);
|
|
291
398
|
return leafIndex?.data !== undefined;
|
|
292
399
|
}
|
|
293
400
|
|
|
294
401
|
/**
|
|
295
|
-
*
|
|
402
|
+
* Returns the membership witness of an un-nullified L1 to L2 message.
|
|
296
403
|
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
297
404
|
* @param messageHash - Hash of the message.
|
|
298
405
|
* @param secret - Secret used to compute a nullifier.
|
|
299
406
|
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
300
407
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
301
408
|
*/
|
|
302
|
-
public async
|
|
409
|
+
public async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
303
410
|
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
304
411
|
this.aztecNode,
|
|
305
412
|
contractAddress,
|
|
306
413
|
messageHash,
|
|
307
414
|
secret,
|
|
415
|
+
await this.anchorBlockHeader.hash(),
|
|
308
416
|
);
|
|
309
417
|
|
|
310
418
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
@@ -317,57 +425,88 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
317
425
|
* @param startStorageSlot - The starting storage slot.
|
|
318
426
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
319
427
|
*/
|
|
320
|
-
public
|
|
428
|
+
public getFromPublicStorage(
|
|
321
429
|
blockHash: BlockHash,
|
|
322
430
|
contractAddress: AztecAddress,
|
|
323
431
|
startStorageSlot: Fr,
|
|
324
432
|
numberOfElements: number,
|
|
325
433
|
) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
434
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, async () => {
|
|
435
|
+
const slots = Array(numberOfElements)
|
|
436
|
+
.fill(0)
|
|
437
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
329
438
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
439
|
+
const values = await Promise.all(
|
|
440
|
+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
|
|
441
|
+
);
|
|
333
442
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
443
|
+
this.logger.debug(
|
|
444
|
+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
return values;
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Returns a per-contract logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
|
|
453
|
+
*/
|
|
454
|
+
async #getContractLogger(): Promise<Logger> {
|
|
455
|
+
if (!this.contractLogger) {
|
|
456
|
+
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
457
|
+
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
458
|
+
this.contractLogger = await createContractLogger(
|
|
459
|
+
this.contractAddress,
|
|
460
|
+
addr => this.contractStore.getDebugContractName(addr),
|
|
461
|
+
'user',
|
|
462
|
+
{ instanceId: this.jobId },
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
return this.contractLogger;
|
|
466
|
+
}
|
|
337
467
|
|
|
338
|
-
|
|
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;
|
|
339
483
|
}
|
|
340
484
|
|
|
341
|
-
public
|
|
485
|
+
public async log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
342
486
|
if (!LogLevels[level]) {
|
|
343
|
-
throw new Error(`Invalid
|
|
487
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
344
488
|
}
|
|
345
|
-
|
|
346
|
-
|
|
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);
|
|
347
494
|
}
|
|
348
495
|
|
|
349
|
-
public async
|
|
496
|
+
public async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress) {
|
|
350
497
|
const logService = new LogService(
|
|
351
498
|
this.aztecNode,
|
|
352
|
-
this.
|
|
499
|
+
this.anchorBlockHeader,
|
|
353
500
|
this.keyStore,
|
|
354
|
-
this.
|
|
501
|
+
this.capsuleService,
|
|
355
502
|
this.recipientTaggingStore,
|
|
356
503
|
this.senderAddressBookStore,
|
|
357
504
|
this.addressStore,
|
|
358
505
|
this.jobId,
|
|
506
|
+
this.logger.getBindings(),
|
|
359
507
|
);
|
|
360
508
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// It is acceptable to run the following operations in parallel for several reasons:
|
|
364
|
-
// 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
|
|
365
|
-
// which is then processed in Noir after this handler returns.
|
|
366
|
-
// 2. Even if syncTaggedLogs did write to the note store, it would not cause inconsistent state.
|
|
367
|
-
await Promise.all([
|
|
368
|
-
logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes),
|
|
369
|
-
noteService.syncNoteNullifiers(this.contractAddress),
|
|
370
|
-
]);
|
|
509
|
+
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, scope);
|
|
371
510
|
}
|
|
372
511
|
|
|
373
512
|
/**
|
|
@@ -380,10 +519,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
380
519
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
381
520
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
382
521
|
*/
|
|
383
|
-
public async
|
|
522
|
+
public async validateAndStoreEnqueuedNotesAndEvents(
|
|
384
523
|
contractAddress: AztecAddress,
|
|
385
524
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
386
525
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
526
|
+
maxNotePackedLen: number,
|
|
527
|
+
maxEventSerializedLen: number,
|
|
528
|
+
scope: AztecAddress,
|
|
387
529
|
) {
|
|
388
530
|
// TODO(#10727): allow other contracts to store notes
|
|
389
531
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -393,14 +535,24 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
393
535
|
// We read all note and event validation requests and process them all concurrently. This makes the process much
|
|
394
536
|
// faster as we don't need to wait for the network round-trip.
|
|
395
537
|
const noteValidationRequests = (
|
|
396
|
-
await this.
|
|
397
|
-
|
|
538
|
+
await this.capsuleService.readCapsuleArray(
|
|
539
|
+
contractAddress,
|
|
540
|
+
noteValidationRequestsArrayBaseSlot,
|
|
541
|
+
this.jobId,
|
|
542
|
+
scope,
|
|
543
|
+
)
|
|
544
|
+
).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
|
|
398
545
|
|
|
399
546
|
const eventValidationRequests = (
|
|
400
|
-
await this.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
547
|
+
await this.capsuleService.readCapsuleArray(
|
|
548
|
+
contractAddress,
|
|
549
|
+
eventValidationRequestsArrayBaseSlot,
|
|
550
|
+
this.jobId,
|
|
551
|
+
scope,
|
|
552
|
+
)
|
|
553
|
+
).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
|
|
554
|
+
|
|
555
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
404
556
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
405
557
|
noteService.validateAndStoreNote(
|
|
406
558
|
request.contractAddress,
|
|
@@ -412,11 +564,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
412
564
|
request.noteHash,
|
|
413
565
|
request.nullifier,
|
|
414
566
|
request.txHash,
|
|
415
|
-
|
|
567
|
+
scope,
|
|
416
568
|
),
|
|
417
569
|
);
|
|
418
570
|
|
|
419
|
-
const eventService = new EventService(this.
|
|
571
|
+
const eventService = new EventService(this.anchorBlockHeader, this.aztecNode, this.privateEventStore, this.jobId);
|
|
420
572
|
const eventStorePromises = eventValidationRequests.map(request =>
|
|
421
573
|
eventService.validateAndStoreEvent(
|
|
422
574
|
request.contractAddress,
|
|
@@ -425,21 +577,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
425
577
|
request.serializedEvent,
|
|
426
578
|
request.eventCommitment,
|
|
427
579
|
request.txHash,
|
|
428
|
-
|
|
580
|
+
scope,
|
|
429
581
|
),
|
|
430
582
|
);
|
|
431
583
|
|
|
432
584
|
await Promise.all([...noteStorePromises, ...eventStorePromises]);
|
|
433
585
|
|
|
434
586
|
// Requests are cleared once we're done.
|
|
435
|
-
await this.
|
|
436
|
-
|
|
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
|
+
);
|
|
437
601
|
}
|
|
438
602
|
|
|
439
|
-
public async
|
|
603
|
+
public async getLogsByTag(
|
|
440
604
|
contractAddress: AztecAddress,
|
|
441
605
|
logRetrievalRequestsArrayBaseSlot: Fr,
|
|
442
606
|
logRetrievalResponsesArrayBaseSlot: Fr,
|
|
607
|
+
scope: AztecAddress,
|
|
443
608
|
) {
|
|
444
609
|
// TODO(#10727): allow other contracts to process partial notes
|
|
445
610
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -449,100 +614,200 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
449
614
|
// We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
|
|
450
615
|
// don't need to wait for the network round-trip.
|
|
451
616
|
const logRetrievalRequests = (
|
|
452
|
-
await this.
|
|
617
|
+
await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)
|
|
453
618
|
).map(LogRetrievalRequest.fromFields);
|
|
454
619
|
|
|
455
620
|
const logService = new LogService(
|
|
456
621
|
this.aztecNode,
|
|
457
|
-
this.
|
|
622
|
+
this.anchorBlockHeader,
|
|
458
623
|
this.keyStore,
|
|
459
|
-
this.
|
|
624
|
+
this.capsuleService,
|
|
460
625
|
this.recipientTaggingStore,
|
|
461
626
|
this.senderAddressBookStore,
|
|
462
627
|
this.addressStore,
|
|
463
628
|
this.jobId,
|
|
629
|
+
this.logger.getBindings(),
|
|
464
630
|
);
|
|
465
631
|
|
|
466
|
-
const maybeLogRetrievalResponses = await logService.
|
|
632
|
+
const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
|
|
467
633
|
|
|
468
634
|
// Requests are cleared once we're done.
|
|
469
|
-
await this.
|
|
635
|
+
await this.capsuleService.setCapsuleArray(
|
|
636
|
+
contractAddress,
|
|
637
|
+
logRetrievalRequestsArrayBaseSlot,
|
|
638
|
+
[],
|
|
639
|
+
this.jobId,
|
|
640
|
+
scope,
|
|
641
|
+
);
|
|
470
642
|
|
|
471
643
|
// The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
|
|
472
|
-
await this.
|
|
644
|
+
await this.capsuleService.setCapsuleArray(
|
|
473
645
|
contractAddress,
|
|
474
646
|
logRetrievalResponsesArrayBaseSlot,
|
|
475
647
|
maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
|
|
476
648
|
this.jobId,
|
|
649
|
+
scope,
|
|
477
650
|
);
|
|
478
651
|
}
|
|
479
652
|
|
|
480
|
-
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 {
|
|
481
709
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
482
710
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
483
711
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
484
712
|
}
|
|
485
|
-
this.
|
|
486
|
-
return Promise.resolve();
|
|
713
|
+
this.capsuleService.setCapsule(contractAddress, slot, capsule, this.jobId, scope);
|
|
487
714
|
}
|
|
488
715
|
|
|
489
|
-
public
|
|
716
|
+
public getCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): Promise<Fr[] | null> {
|
|
490
717
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
491
718
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
492
719
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
493
720
|
}
|
|
494
|
-
return (
|
|
495
|
-
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
496
|
-
this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
|
|
497
|
-
(await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId))
|
|
498
|
-
);
|
|
721
|
+
return this.capsuleService.getCapsule(contractAddress, slot, this.jobId, scope, this.capsules);
|
|
499
722
|
}
|
|
500
723
|
|
|
501
|
-
public
|
|
724
|
+
public deleteCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): void {
|
|
502
725
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
503
726
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
504
727
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
505
728
|
}
|
|
506
|
-
this.
|
|
507
|
-
return Promise.resolve();
|
|
729
|
+
this.capsuleService.deleteCapsule(contractAddress, slot, this.jobId, scope);
|
|
508
730
|
}
|
|
509
731
|
|
|
510
|
-
public
|
|
732
|
+
public copyCapsule(
|
|
511
733
|
contractAddress: AztecAddress,
|
|
512
734
|
srcSlot: Fr,
|
|
513
735
|
dstSlot: Fr,
|
|
514
736
|
numEntries: number,
|
|
737
|
+
scope: AztecAddress,
|
|
515
738
|
): Promise<void> {
|
|
516
739
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
517
740
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
518
741
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
519
742
|
}
|
|
520
|
-
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);
|
|
521
755
|
}
|
|
522
756
|
|
|
523
757
|
// TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
|
|
524
|
-
public
|
|
758
|
+
public decryptAes128(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
|
|
525
759
|
const aes128 = new Aes128();
|
|
526
760
|
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
527
761
|
}
|
|
528
762
|
|
|
529
763
|
/**
|
|
530
|
-
* 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.
|
|
531
765
|
* @param address - The address to get the secret for.
|
|
532
766
|
* @param ephPk - The ephemeral public key to get the secret for.
|
|
533
|
-
* @
|
|
767
|
+
* @param contractAddress - The contract address for app-siloing (validated against execution context).
|
|
768
|
+
* @returns The app-siloed shared secret as a Field.
|
|
534
769
|
*/
|
|
535
|
-
public
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const recipientCompleteAddress = await this.
|
|
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
|
+
}
|
|
776
|
+
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
542
777
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
543
778
|
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
544
779
|
);
|
|
545
780
|
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
546
|
-
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;
|
|
547
812
|
}
|
|
548
813
|
}
|