@aztec/pxe 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -16
- package/dest/config/index.d.ts +4 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +18 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +61 -31
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +201 -78
- 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 -4
- 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 +6 -5
- 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/message_tx_context.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -5
- 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 +4 -6
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +54 -46
- 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 +42 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +45 -42
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +201 -110
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -40
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +60 -77
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +110 -86
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +104 -54
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +216 -119
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +45 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +114 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -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 +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -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 +4 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -0
- 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 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +6 -7
- 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 +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +28 -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 +9 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -16
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +5 -4
- 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 +8 -4
- 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 +74 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +134 -80
- 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_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -84
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +47 -49
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +278 -252
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +198 -147
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- 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 +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +60 -0
- package/dest/tagging/index.d.ts +4 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -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 +7 -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 +16 -12
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -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 +23 -16
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -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 +42 -27
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +76 -33
- package/src/config/index.ts +15 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +361 -142
- 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 +9 -6
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -7
- package/src/contract_function_simulator/oracle/interfaces.ts +67 -58
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
- package/src/contract_function_simulator/oracle/oracle.ts +217 -149
- package/src/contract_function_simulator/oracle/private_execution.ts +5 -64
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +150 -182
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +330 -134
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +181 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -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 +3 -0
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +5 -7
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +48 -39
- package/src/messages/message_context_service.ts +45 -0
- package/src/notes/note_service.ts +24 -22
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +5 -4
- 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 +9 -9
- package/src/pxe.ts +261 -126
- 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_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -96
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +321 -318
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +250 -190
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- 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 +92 -0
- package/src/tagging/index.ts +3 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +17 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +29 -26
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +39 -29
- 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
- package/dest/tree_membership/tree_membership_service.d.ts +0 -50
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -75
- package/src/tree_membership/tree_membership_service.ts +0 -97
package/src/pxe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
22
21
|
import {
|
|
23
22
|
CompleteAddress,
|
|
24
23
|
type ContractInstanceWithAddress,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -47,11 +47,12 @@ import {
|
|
|
47
47
|
TxProfileResult,
|
|
48
48
|
TxProvingResult,
|
|
49
49
|
TxSimulationResult,
|
|
50
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
51
51
|
} from '@aztec/stdlib/tx';
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
55
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
57
|
import type { PXEConfig } from './config/index.js';
|
|
57
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -59,12 +60,15 @@ import {
|
|
|
59
60
|
ContractFunctionSimulator,
|
|
60
61
|
generateSimulatedProvingResult,
|
|
61
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
|
-
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
63
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
65
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
66
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
67
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
68
72
|
import {
|
|
69
73
|
PrivateKernelExecutionProver,
|
|
70
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -85,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
89
|
eventSelector: EventSelector;
|
|
86
90
|
};
|
|
87
91
|
|
|
92
|
+
/** Options for PXE.profileTx. */
|
|
93
|
+
export type ProfileTxOpts = {
|
|
94
|
+
/** The profiling mode to use. */
|
|
95
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
96
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
97
|
+
skipProofGeneration?: boolean;
|
|
98
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
99
|
+
scopes: AccessScopes;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Options for PXE.simulateTx. */
|
|
103
|
+
export type SimulateTxOpts = {
|
|
104
|
+
/** Whether to simulate the public part of the transaction. */
|
|
105
|
+
simulatePublic: boolean;
|
|
106
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
107
|
+
skipTxValidation?: boolean;
|
|
108
|
+
/** If false, fees are enforced. */
|
|
109
|
+
skipFeeEnforcement?: boolean;
|
|
110
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
111
|
+
skipKernels?: boolean;
|
|
112
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
113
|
+
overrides?: SimulationOverrides;
|
|
114
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
115
|
+
scopes: AccessScopes;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** Options for PXE.executeUtility. */
|
|
119
|
+
export type ExecuteUtilityOpts = {
|
|
120
|
+
/** The authentication witnesses required for the function call. */
|
|
121
|
+
authwits?: AuthWitness[];
|
|
122
|
+
/** The accounts whose notes we can access in this call */
|
|
123
|
+
scopes: AccessScopes;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Args for PXE.create. */
|
|
127
|
+
export type PXECreateArgs = {
|
|
128
|
+
/** The Aztec node to connect to. */
|
|
129
|
+
node: AztecNode;
|
|
130
|
+
/** The key-value store for persisting PXE state. */
|
|
131
|
+
store: AztecAsyncKVStore;
|
|
132
|
+
/** The prover for generating private kernel proofs. */
|
|
133
|
+
proofCreator: PrivateKernelProver;
|
|
134
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
135
|
+
simulator: CircuitSimulator;
|
|
136
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
137
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
138
|
+
/** PXE configuration options. */
|
|
139
|
+
config: PXEConfig;
|
|
140
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
141
|
+
loggerOrSuffix?: string | Logger;
|
|
142
|
+
};
|
|
143
|
+
|
|
88
144
|
/**
|
|
89
145
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
146
|
* manage private state of users.
|
|
@@ -92,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
148
|
export class PXE {
|
|
93
149
|
private constructor(
|
|
94
150
|
private node: AztecNode,
|
|
151
|
+
private db: AztecAsyncKVStore,
|
|
95
152
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
153
|
private keyStore: KeyStore,
|
|
97
154
|
private contractStore: ContractStore,
|
|
@@ -103,6 +160,8 @@ export class PXE {
|
|
|
103
160
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
161
|
private addressStore: AddressStore,
|
|
105
162
|
private privateEventStore: PrivateEventStore,
|
|
163
|
+
private contractSyncService: ContractSyncService,
|
|
164
|
+
private messageContextService: MessageContextService,
|
|
106
165
|
private simulator: CircuitSimulator,
|
|
107
166
|
private proverEnabled: boolean,
|
|
108
167
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,25 +179,31 @@ export class PXE {
|
|
|
120
179
|
*
|
|
121
180
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
181
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
182
|
+
public static async create({
|
|
183
|
+
node,
|
|
184
|
+
store,
|
|
185
|
+
proofCreator,
|
|
186
|
+
simulator,
|
|
187
|
+
protocolContractsProvider,
|
|
188
|
+
config,
|
|
189
|
+
loggerOrSuffix,
|
|
190
|
+
}: PXECreateArgs) {
|
|
191
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
192
|
+
const bindings: LoggerBindings | undefined =
|
|
193
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
194
|
+
|
|
132
195
|
const log =
|
|
133
196
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
197
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
135
198
|
: loggerOrSuffix;
|
|
136
199
|
|
|
137
|
-
const
|
|
200
|
+
const info = await node.getNodeInfo();
|
|
201
|
+
|
|
202
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
138
203
|
const addressStore = new AddressStore(store);
|
|
139
204
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
205
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
206
|
+
const noteStore = new NoteStore(store);
|
|
142
207
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
208
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
209
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,6 +211,14 @@ export class PXE {
|
|
|
146
211
|
const capsuleStore = new CapsuleStore(store);
|
|
147
212
|
const keyStore = new KeyStore(store);
|
|
148
213
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
214
|
+
const contractSyncService = new ContractSyncService(
|
|
215
|
+
node,
|
|
216
|
+
contractStore,
|
|
217
|
+
noteStore,
|
|
218
|
+
createLogger('pxe:contract_sync', bindings),
|
|
219
|
+
);
|
|
220
|
+
const messageContextService = new MessageContextService(node);
|
|
221
|
+
|
|
149
222
|
const synchronizer = new BlockSynchronizer(
|
|
150
223
|
node,
|
|
151
224
|
store,
|
|
@@ -153,19 +226,28 @@ export class PXE {
|
|
|
153
226
|
noteStore,
|
|
154
227
|
privateEventStore,
|
|
155
228
|
tipsStore,
|
|
229
|
+
contractSyncService,
|
|
156
230
|
config,
|
|
157
|
-
|
|
231
|
+
bindings,
|
|
158
232
|
);
|
|
159
233
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
-
jobCoordinator.registerStores([
|
|
234
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
235
|
+
jobCoordinator.registerStores([
|
|
236
|
+
capsuleStore,
|
|
237
|
+
senderTaggingStore,
|
|
238
|
+
recipientTaggingStore,
|
|
239
|
+
privateEventStore,
|
|
240
|
+
noteStore,
|
|
241
|
+
contractSyncService,
|
|
242
|
+
]);
|
|
162
243
|
|
|
163
|
-
const debugUtils = new PXEDebugUtils(
|
|
244
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
164
245
|
|
|
165
246
|
const jobQueue = new SerialQueue();
|
|
166
247
|
|
|
167
248
|
const pxe = new PXE(
|
|
168
249
|
node,
|
|
250
|
+
store,
|
|
169
251
|
synchronizer,
|
|
170
252
|
keyStore,
|
|
171
253
|
contractStore,
|
|
@@ -177,6 +259,8 @@ export class PXE {
|
|
|
177
259
|
recipientTaggingStore,
|
|
178
260
|
addressStore,
|
|
179
261
|
privateEventStore,
|
|
262
|
+
contractSyncService,
|
|
263
|
+
messageContextService,
|
|
180
264
|
simulator,
|
|
181
265
|
proverEnabled,
|
|
182
266
|
proofCreator,
|
|
@@ -187,12 +271,15 @@ export class PXE {
|
|
|
187
271
|
debugUtils,
|
|
188
272
|
);
|
|
189
273
|
|
|
190
|
-
debugUtils.
|
|
274
|
+
debugUtils.setPXEHelpers(
|
|
275
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
276
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
277
|
+
pxe.#executeUtility.bind(pxe),
|
|
278
|
+
);
|
|
191
279
|
|
|
192
280
|
pxe.jobQueue.start();
|
|
193
281
|
|
|
194
282
|
await pxe.#registerProtocolContracts();
|
|
195
|
-
const info = await node.getNodeInfo();
|
|
196
283
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
197
284
|
return pxe;
|
|
198
285
|
}
|
|
@@ -202,20 +289,21 @@ export class PXE {
|
|
|
202
289
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
203
290
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
204
291
|
|
|
205
|
-
return new ContractFunctionSimulator(
|
|
206
|
-
proxyContractStore,
|
|
207
|
-
this.noteStore,
|
|
208
|
-
this.keyStore,
|
|
209
|
-
this.addressStore,
|
|
210
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
|
|
292
|
+
return new ContractFunctionSimulator({
|
|
293
|
+
contractStore: proxyContractStore,
|
|
294
|
+
noteStore: this.noteStore,
|
|
295
|
+
keyStore: this.keyStore,
|
|
296
|
+
addressStore: this.addressStore,
|
|
297
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
298
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
299
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
300
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
301
|
+
capsuleStore: this.capsuleStore,
|
|
302
|
+
privateEventStore: this.privateEventStore,
|
|
303
|
+
simulator: this.simulator,
|
|
304
|
+
contractSyncService: this.contractSyncService,
|
|
305
|
+
messageContextService: this.messageContextService,
|
|
306
|
+
});
|
|
219
307
|
}
|
|
220
308
|
|
|
221
309
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -267,9 +355,8 @@ export class PXE {
|
|
|
267
355
|
async #registerProtocolContracts() {
|
|
268
356
|
const registered: Record<string, string> = {};
|
|
269
357
|
for (const name of protocolContractNames) {
|
|
270
|
-
const { address,
|
|
271
|
-
|
|
272
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
358
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
359
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
273
360
|
await this.contractStore.addContractInstance(instance);
|
|
274
361
|
registered[name] = address.toString();
|
|
275
362
|
}
|
|
@@ -281,7 +368,7 @@ export class PXE {
|
|
|
281
368
|
async #executePrivate(
|
|
282
369
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
283
370
|
txRequest: TxExecutionRequest,
|
|
284
|
-
scopes:
|
|
371
|
+
scopes: AccessScopes,
|
|
285
372
|
jobId: string,
|
|
286
373
|
): Promise<PrivateExecutionResult> {
|
|
287
374
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -289,18 +376,23 @@ export class PXE {
|
|
|
289
376
|
try {
|
|
290
377
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
291
378
|
|
|
292
|
-
|
|
293
|
-
txRequest,
|
|
379
|
+
await this.contractSyncService.ensureContractSynced(
|
|
294
380
|
contractAddress,
|
|
295
381
|
functionSelector,
|
|
296
|
-
|
|
382
|
+
(privateSyncCall, execScopes) =>
|
|
383
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
297
384
|
anchorBlockHeader,
|
|
298
|
-
// The sender for tags is set by contracts, typically by an account
|
|
299
|
-
// contract entrypoint
|
|
300
|
-
undefined, // senderForTags
|
|
301
|
-
scopes,
|
|
302
385
|
jobId,
|
|
386
|
+
scopes,
|
|
303
387
|
);
|
|
388
|
+
|
|
389
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
390
|
+
contractAddress,
|
|
391
|
+
selector: functionSelector,
|
|
392
|
+
anchorBlockHeader,
|
|
393
|
+
scopes,
|
|
394
|
+
jobId,
|
|
395
|
+
});
|
|
304
396
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
305
397
|
return result;
|
|
306
398
|
} catch (err) {
|
|
@@ -312,25 +404,32 @@ export class PXE {
|
|
|
312
404
|
}
|
|
313
405
|
|
|
314
406
|
/**
|
|
315
|
-
*
|
|
407
|
+
* Execute a utility function call on the given contract.
|
|
316
408
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
317
409
|
* @param call - The function call to execute.
|
|
318
410
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
319
411
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
320
412
|
* accounts if not specified.
|
|
321
413
|
* @param jobId - The job ID for staged writes.
|
|
322
|
-
* @returns The
|
|
414
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
323
415
|
*/
|
|
324
|
-
async #
|
|
416
|
+
async #executeUtility(
|
|
325
417
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
326
418
|
call: FunctionCall,
|
|
327
419
|
authWitnesses: AuthWitness[] | undefined,
|
|
328
|
-
scopes:
|
|
420
|
+
scopes: AccessScopes,
|
|
329
421
|
jobId: string,
|
|
330
422
|
) {
|
|
331
423
|
try {
|
|
332
424
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
333
|
-
|
|
425
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
426
|
+
call,
|
|
427
|
+
authWitnesses ?? [],
|
|
428
|
+
anchorBlockHeader,
|
|
429
|
+
scopes,
|
|
430
|
+
jobId,
|
|
431
|
+
);
|
|
432
|
+
return { result, offchainEffects };
|
|
334
433
|
} catch (err) {
|
|
335
434
|
if (err instanceof SimulationError) {
|
|
336
435
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -384,15 +483,33 @@ export class PXE {
|
|
|
384
483
|
config: PrivateKernelExecutionProverConfig,
|
|
385
484
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
386
485
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
-
const anchorBlockHash =
|
|
486
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
388
487
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
389
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
488
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
489
|
+
kernelOracle,
|
|
490
|
+
proofCreator,
|
|
491
|
+
!this.proverEnabled,
|
|
492
|
+
this.log.getBindings(),
|
|
493
|
+
);
|
|
390
494
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
391
495
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
392
496
|
}
|
|
393
497
|
|
|
394
498
|
// Public API
|
|
395
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Returns the block header up to which the PXE has synced.
|
|
502
|
+
* @returns The synced block header
|
|
503
|
+
*/
|
|
504
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
505
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
510
|
+
* @param address - The contract address.
|
|
511
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
512
|
+
*/
|
|
396
513
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
397
514
|
return this.contractStore.getContractInstance(address);
|
|
398
515
|
}
|
|
@@ -428,7 +545,6 @@ export class PXE {
|
|
|
428
545
|
}
|
|
429
546
|
|
|
430
547
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
431
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
432
548
|
return accountCompleteAddress;
|
|
433
549
|
}
|
|
434
550
|
|
|
@@ -453,6 +569,9 @@ export class PXE {
|
|
|
453
569
|
|
|
454
570
|
if (wasAdded) {
|
|
455
571
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
572
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
573
|
+
// all contracts must re-sync to discover them.
|
|
574
|
+
this.contractSyncService.wipe();
|
|
456
575
|
} else {
|
|
457
576
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
458
577
|
}
|
|
@@ -502,8 +621,7 @@ export class PXE {
|
|
|
502
621
|
* @param artifact - The build artifact for the contract class.
|
|
503
622
|
*/
|
|
504
623
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
505
|
-
const
|
|
506
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
624
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
507
625
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
508
626
|
}
|
|
509
627
|
|
|
@@ -522,17 +640,17 @@ export class PXE {
|
|
|
522
640
|
if (artifact) {
|
|
523
641
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
524
642
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
525
|
-
|
|
526
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
643
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
527
644
|
throw new Error(
|
|
528
|
-
`Artifact does not match expected class id (computed ${
|
|
645
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
529
646
|
);
|
|
530
647
|
}
|
|
531
648
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
532
649
|
if (!computedAddress.equals(instance.address)) {
|
|
533
650
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
534
651
|
}
|
|
535
|
-
|
|
652
|
+
|
|
653
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
536
654
|
|
|
537
655
|
const publicFunctionSignatures = artifact.functions
|
|
538
656
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -581,15 +699,16 @@ export class PXE {
|
|
|
581
699
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
582
700
|
}
|
|
583
701
|
|
|
584
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
585
|
-
|
|
586
702
|
const publicFunctionSignatures = artifact.functions
|
|
587
703
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
588
704
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
589
705
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
590
706
|
|
|
591
707
|
currentInstance.currentContractClassId = contractClass.id;
|
|
592
|
-
await
|
|
708
|
+
await Promise.all([
|
|
709
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
710
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
711
|
+
]);
|
|
593
712
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
594
713
|
});
|
|
595
714
|
}
|
|
@@ -607,11 +726,12 @@ export class PXE {
|
|
|
607
726
|
* (where validators prove the public portion).
|
|
608
727
|
*
|
|
609
728
|
* @param txRequest - An authenticated tx request ready for proving
|
|
729
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
610
730
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
611
731
|
* @throws If contract code not found, or public simulation reverts.
|
|
612
732
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
613
733
|
*/
|
|
614
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
734
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
615
735
|
let privateExecutionResult: PrivateExecutionResult;
|
|
616
736
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
617
737
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -622,7 +742,7 @@ export class PXE {
|
|
|
622
742
|
await this.blockStateSynchronizer.sync();
|
|
623
743
|
const syncTime = syncTimer.ms();
|
|
624
744
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
625
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
745
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
626
746
|
|
|
627
747
|
const {
|
|
628
748
|
publicInputs,
|
|
@@ -664,17 +784,17 @@ export class PXE {
|
|
|
664
784
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
665
785
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
666
786
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
667
|
-
const
|
|
668
|
-
if (
|
|
787
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
788
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
669
789
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
670
790
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
671
791
|
|
|
672
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
673
|
-
this.log.debug(`Stored used
|
|
674
|
-
|
|
792
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
793
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
794
|
+
taggingIndexRangesUsedInTheTx,
|
|
675
795
|
});
|
|
676
796
|
} else {
|
|
677
|
-
this.log.debug(`No
|
|
797
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
678
798
|
}
|
|
679
799
|
|
|
680
800
|
return txProvingResult;
|
|
@@ -686,17 +806,13 @@ export class PXE {
|
|
|
686
806
|
|
|
687
807
|
/**
|
|
688
808
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
689
|
-
*
|
|
690
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
691
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
692
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
809
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
693
810
|
* @returns A trace of the program execution with gate counts.
|
|
694
811
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
695
812
|
*/
|
|
696
813
|
public profileTx(
|
|
697
814
|
txRequest: TxExecutionRequest,
|
|
698
|
-
profileMode
|
|
699
|
-
skipProofGeneration: boolean = true,
|
|
815
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
700
816
|
): Promise<TxProfileResult> {
|
|
701
817
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
702
818
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -719,12 +835,7 @@ export class PXE {
|
|
|
719
835
|
const syncTime = syncTimer.ms();
|
|
720
836
|
|
|
721
837
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
722
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
723
|
-
contractFunctionSimulator,
|
|
724
|
-
txRequest,
|
|
725
|
-
undefined,
|
|
726
|
-
jobId,
|
|
727
|
-
);
|
|
838
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
728
839
|
|
|
729
840
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
730
841
|
txRequest,
|
|
@@ -781,12 +892,7 @@ export class PXE {
|
|
|
781
892
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
782
893
|
*
|
|
783
894
|
*
|
|
784
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
785
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
786
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
787
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
788
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
789
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
895
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
790
896
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
791
897
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
792
898
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -795,11 +901,14 @@ export class PXE {
|
|
|
795
901
|
*/
|
|
796
902
|
public simulateTx(
|
|
797
903
|
txRequest: TxExecutionRequest,
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
904
|
+
{
|
|
905
|
+
simulatePublic,
|
|
906
|
+
skipTxValidation = false,
|
|
907
|
+
skipFeeEnforcement = false,
|
|
908
|
+
skipKernels = true,
|
|
909
|
+
overrides,
|
|
910
|
+
scopes,
|
|
911
|
+
}: SimulateTxOpts,
|
|
803
912
|
): Promise<TxSimulationResult> {
|
|
804
913
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
805
914
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -823,11 +932,21 @@ export class PXE {
|
|
|
823
932
|
await this.blockStateSynchronizer.sync();
|
|
824
933
|
const syncTime = syncTimer.ms();
|
|
825
934
|
|
|
935
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
936
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
937
|
+
|
|
938
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
939
|
+
throw new Error(
|
|
940
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
941
|
+
);
|
|
942
|
+
}
|
|
826
943
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
944
|
+
|
|
945
|
+
if (hasOverriddenContracts) {
|
|
946
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
947
|
+
// We exclude them so the sync service skips them entirely.
|
|
948
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
949
|
+
}
|
|
831
950
|
|
|
832
951
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
833
952
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -838,7 +957,8 @@ export class PXE {
|
|
|
838
957
|
if (skipKernels) {
|
|
839
958
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
840
959
|
privateExecutionResult,
|
|
841
|
-
this.contractStore,
|
|
960
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
961
|
+
this.node,
|
|
842
962
|
));
|
|
843
963
|
} else {
|
|
844
964
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -857,6 +977,9 @@ export class PXE {
|
|
|
857
977
|
const publicSimulationTimer = new Timer();
|
|
858
978
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
859
979
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
980
|
+
if (publicOutput?.debugLogs?.length) {
|
|
981
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
982
|
+
}
|
|
860
983
|
}
|
|
861
984
|
|
|
862
985
|
let validationTime: number | undefined;
|
|
@@ -865,7 +988,8 @@ export class PXE {
|
|
|
865
988
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
866
989
|
validationTime = validationTimer.ms();
|
|
867
990
|
if (validationResult.result === 'invalid') {
|
|
868
|
-
|
|
991
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
992
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
869
993
|
}
|
|
870
994
|
}
|
|
871
995
|
|
|
@@ -916,29 +1040,23 @@ export class PXE {
|
|
|
916
1040
|
inspect(txRequest),
|
|
917
1041
|
`simulatePublic=${simulatePublic}`,
|
|
918
1042
|
`skipTxValidation=${skipTxValidation}`,
|
|
919
|
-
`scopes=${scopes
|
|
1043
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
920
1044
|
);
|
|
921
1045
|
}
|
|
922
1046
|
});
|
|
923
1047
|
}
|
|
924
1048
|
|
|
925
1049
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
1050
|
+
* Executes a contract utility function.
|
|
928
1051
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
929
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
930
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
931
|
-
* default to all.
|
|
932
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
933
1052
|
*/
|
|
934
|
-
public
|
|
1053
|
+
public executeUtility(
|
|
935
1054
|
call: FunctionCall,
|
|
936
|
-
authwits
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1055
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1056
|
+
): Promise<UtilityExecutionResult> {
|
|
1057
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
940
1058
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
941
|
-
// delete the same read value, or reading values that another
|
|
1059
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
942
1060
|
return this.#putInJobQueue(async jobId => {
|
|
943
1061
|
try {
|
|
944
1062
|
const totalTimer = new Timer();
|
|
@@ -948,11 +1066,18 @@ export class PXE {
|
|
|
948
1066
|
const functionTimer = new Timer();
|
|
949
1067
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
950
1068
|
|
|
951
|
-
await this.
|
|
952
|
-
|
|
1069
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1070
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1071
|
+
call.to,
|
|
1072
|
+
call.selector,
|
|
1073
|
+
(privateSyncCall, execScopes) =>
|
|
1074
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1075
|
+
anchorBlockHeader,
|
|
1076
|
+
jobId,
|
|
1077
|
+
scopes,
|
|
953
1078
|
);
|
|
954
1079
|
|
|
955
|
-
const executionResult = await this.#
|
|
1080
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
956
1081
|
contractFunctionSimulator,
|
|
957
1082
|
call,
|
|
958
1083
|
authwits ?? [],
|
|
@@ -973,14 +1098,19 @@ export class PXE {
|
|
|
973
1098
|
};
|
|
974
1099
|
|
|
975
1100
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
976
|
-
return {
|
|
1101
|
+
return {
|
|
1102
|
+
result: executionResult,
|
|
1103
|
+
offchainEffects,
|
|
1104
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1105
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1106
|
+
};
|
|
977
1107
|
} catch (err: any) {
|
|
978
1108
|
const { to, name, args } = call;
|
|
979
1109
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
980
1110
|
throw this.#contextualizeError(
|
|
981
1111
|
err,
|
|
982
|
-
`
|
|
983
|
-
`scopes=${scopes
|
|
1112
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1113
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
984
1114
|
);
|
|
985
1115
|
}
|
|
986
1116
|
});
|
|
@@ -1008,15 +1138,19 @@ export class PXE {
|
|
|
1008
1138
|
await this.#putInJobQueue(async jobId => {
|
|
1009
1139
|
await this.blockStateSynchronizer.sync();
|
|
1010
1140
|
|
|
1011
|
-
|
|
1141
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1142
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1012
1143
|
|
|
1013
1144
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
1145
|
|
|
1015
|
-
await this.
|
|
1146
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1016
1147
|
filter.contractAddress,
|
|
1017
1148
|
null,
|
|
1018
|
-
async privateSyncCall =>
|
|
1019
|
-
await this.#
|
|
1149
|
+
async (privateSyncCall, execScopes) =>
|
|
1150
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1151
|
+
anchorBlockHeader,
|
|
1152
|
+
jobId,
|
|
1153
|
+
filter.scopes,
|
|
1020
1154
|
);
|
|
1021
1155
|
});
|
|
1022
1156
|
|
|
@@ -1031,9 +1165,10 @@ export class PXE {
|
|
|
1031
1165
|
}
|
|
1032
1166
|
|
|
1033
1167
|
/**
|
|
1034
|
-
* Stops the PXE's job queue.
|
|
1168
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1035
1169
|
*/
|
|
1036
|
-
public stop(): Promise<void> {
|
|
1037
|
-
|
|
1170
|
+
public async stop(): Promise<void> {
|
|
1171
|
+
await this.jobQueue.end();
|
|
1172
|
+
await this.db.close();
|
|
1038
1173
|
}
|
|
1039
1174
|
}
|