@aztec/pxe 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448
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/bin/check_oracle_version.js +4 -4
- 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 +17 -5
- 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/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- 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 +4 -6
- 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 +8 -10
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- 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 +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
- 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 +6 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +62 -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 +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +310 -113
- 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 -89
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +124 -67
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +326 -140
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +9 -2
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- 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} +20 -16
- 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 -18
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +23 -9
- 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 +3 -3
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +24 -10
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +4 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -2
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +30 -11
- 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 +8 -9
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +38 -62
- 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 -15
- 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 +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- 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 +73 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +131 -78
- 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.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/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 +4 -4
- 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 +5 -6
- 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 -8
- 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 +5 -9
- 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 +6 -8
- 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/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +29 -19
- 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/ephemeral_array_service.ts +110 -0
- 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 -9
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
- package/src/contract_function_simulator/oracle/interfaces.ts +90 -62
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +391 -150
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +136 -187
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +544 -174
- package/src/contract_function_simulator/pick_notes.ts +9 -2
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- 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} +23 -25
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +18 -18
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +19 -18
- package/src/entrypoints/pxe_creation_options.ts +9 -1
- package/src/entrypoints/server/index.ts +3 -2
- package/src/entrypoints/server/utils.ts +24 -29
- package/src/events/event_service.ts +21 -10
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +72 -106
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +24 -16
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -10
- 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 +243 -131
- 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 +3 -3
- 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 +31 -7
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
- 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 +30 -29
- 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
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,7 +47,7 @@ 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';
|
|
@@ -60,11 +60,14 @@ import {
|
|
|
60
60
|
generateSimulatedProvingResult,
|
|
61
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
-
import {
|
|
63
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
64
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
65
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
66
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
67
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
68
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
67
69
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
70
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
68
71
|
import {
|
|
69
72
|
PrivateKernelExecutionProver,
|
|
70
73
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -85,6 +88,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
88
|
eventSelector: EventSelector;
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
/** Options for PXE.profileTx. */
|
|
92
|
+
export type ProfileTxOpts = {
|
|
93
|
+
/** The profiling mode to use. */
|
|
94
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
95
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
96
|
+
skipProofGeneration?: boolean;
|
|
97
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
|
+
scopes: AztecAddress[];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Options for PXE.simulateTx. */
|
|
102
|
+
export type SimulateTxOpts = {
|
|
103
|
+
/** Whether to simulate the public part of the transaction. */
|
|
104
|
+
simulatePublic: boolean;
|
|
105
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
106
|
+
skipTxValidation?: boolean;
|
|
107
|
+
/** If false, fees are enforced. */
|
|
108
|
+
skipFeeEnforcement?: boolean;
|
|
109
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
110
|
+
skipKernels?: boolean;
|
|
111
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
112
|
+
overrides?: SimulationOverrides;
|
|
113
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
114
|
+
scopes: AztecAddress[];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Options for PXE.executeUtility. */
|
|
118
|
+
export type ExecuteUtilityOpts = {
|
|
119
|
+
/** The authentication witnesses required for the function call. */
|
|
120
|
+
authwits?: AuthWitness[];
|
|
121
|
+
/** The accounts whose notes we can access in this call */
|
|
122
|
+
scopes: AztecAddress[];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** Args for PXE.create. */
|
|
126
|
+
export type PXECreateArgs = {
|
|
127
|
+
/** The Aztec node to connect to. */
|
|
128
|
+
node: AztecNode;
|
|
129
|
+
/** The key-value store for persisting PXE state. */
|
|
130
|
+
store: AztecAsyncKVStore;
|
|
131
|
+
/** The prover for generating private kernel proofs. */
|
|
132
|
+
proofCreator: PrivateKernelProver;
|
|
133
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
134
|
+
simulator: CircuitSimulator;
|
|
135
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
136
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
137
|
+
/** PXE configuration options. */
|
|
138
|
+
config: PXEConfig;
|
|
139
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
140
|
+
loggerOrSuffix?: string | Logger;
|
|
141
|
+
};
|
|
142
|
+
|
|
88
143
|
/**
|
|
89
144
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
145
|
* manage private state of users.
|
|
@@ -92,6 +147,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
147
|
export class PXE {
|
|
93
148
|
private constructor(
|
|
94
149
|
private node: AztecNode,
|
|
150
|
+
private db: AztecAsyncKVStore,
|
|
95
151
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
152
|
private keyStore: KeyStore,
|
|
97
153
|
private contractStore: ContractStore,
|
|
@@ -103,6 +159,8 @@ export class PXE {
|
|
|
103
159
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
160
|
private addressStore: AddressStore,
|
|
105
161
|
private privateEventStore: PrivateEventStore,
|
|
162
|
+
private contractSyncService: ContractSyncService,
|
|
163
|
+
private messageContextService: MessageContextService,
|
|
106
164
|
private simulator: CircuitSimulator,
|
|
107
165
|
private proverEnabled: boolean,
|
|
108
166
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,21 +178,27 @@ export class PXE {
|
|
|
120
178
|
*
|
|
121
179
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
180
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
181
|
+
public static async create({
|
|
182
|
+
node,
|
|
183
|
+
store,
|
|
184
|
+
proofCreator,
|
|
185
|
+
simulator,
|
|
186
|
+
protocolContractsProvider,
|
|
187
|
+
config,
|
|
188
|
+
loggerOrSuffix,
|
|
189
|
+
}: PXECreateArgs) {
|
|
190
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
191
|
+
const bindings: LoggerBindings | undefined =
|
|
192
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
193
|
+
|
|
132
194
|
const log =
|
|
133
195
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
196
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
135
197
|
: loggerOrSuffix;
|
|
136
198
|
|
|
137
|
-
const
|
|
199
|
+
const info = await node.getNodeInfo();
|
|
200
|
+
|
|
201
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
138
202
|
const addressStore = new AddressStore(store);
|
|
139
203
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
204
|
const contractStore = new ContractStore(store);
|
|
@@ -146,6 +210,14 @@ export class PXE {
|
|
|
146
210
|
const capsuleStore = new CapsuleStore(store);
|
|
147
211
|
const keyStore = new KeyStore(store);
|
|
148
212
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
213
|
+
const contractSyncService = new ContractSyncService(
|
|
214
|
+
node,
|
|
215
|
+
contractStore,
|
|
216
|
+
noteStore,
|
|
217
|
+
createLogger('pxe:contract_sync', bindings),
|
|
218
|
+
);
|
|
219
|
+
const messageContextService = new MessageContextService(node);
|
|
220
|
+
|
|
149
221
|
const synchronizer = new BlockSynchronizer(
|
|
150
222
|
node,
|
|
151
223
|
store,
|
|
@@ -153,25 +225,28 @@ export class PXE {
|
|
|
153
225
|
noteStore,
|
|
154
226
|
privateEventStore,
|
|
155
227
|
tipsStore,
|
|
228
|
+
contractSyncService,
|
|
156
229
|
config,
|
|
157
|
-
|
|
230
|
+
bindings,
|
|
158
231
|
);
|
|
159
232
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
233
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
161
234
|
jobCoordinator.registerStores([
|
|
162
235
|
capsuleStore,
|
|
163
236
|
senderTaggingStore,
|
|
164
237
|
recipientTaggingStore,
|
|
165
238
|
privateEventStore,
|
|
166
239
|
noteStore,
|
|
240
|
+
contractSyncService,
|
|
167
241
|
]);
|
|
168
242
|
|
|
169
|
-
const debugUtils = new PXEDebugUtils(
|
|
243
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
170
244
|
|
|
171
245
|
const jobQueue = new SerialQueue();
|
|
172
246
|
|
|
173
247
|
const pxe = new PXE(
|
|
174
248
|
node,
|
|
249
|
+
store,
|
|
175
250
|
synchronizer,
|
|
176
251
|
keyStore,
|
|
177
252
|
contractStore,
|
|
@@ -183,6 +258,8 @@ export class PXE {
|
|
|
183
258
|
recipientTaggingStore,
|
|
184
259
|
addressStore,
|
|
185
260
|
privateEventStore,
|
|
261
|
+
contractSyncService,
|
|
262
|
+
messageContextService,
|
|
186
263
|
simulator,
|
|
187
264
|
proverEnabled,
|
|
188
265
|
proofCreator,
|
|
@@ -193,12 +270,15 @@ export class PXE {
|
|
|
193
270
|
debugUtils,
|
|
194
271
|
);
|
|
195
272
|
|
|
196
|
-
debugUtils.
|
|
273
|
+
debugUtils.setPXEHelpers(
|
|
274
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
275
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
276
|
+
pxe.#executeUtility.bind(pxe),
|
|
277
|
+
);
|
|
197
278
|
|
|
198
279
|
pxe.jobQueue.start();
|
|
199
280
|
|
|
200
281
|
await pxe.#registerProtocolContracts();
|
|
201
|
-
const info = await node.getNodeInfo();
|
|
202
282
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
203
283
|
return pxe;
|
|
204
284
|
}
|
|
@@ -208,20 +288,21 @@ export class PXE {
|
|
|
208
288
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
209
289
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
210
290
|
|
|
211
|
-
return new ContractFunctionSimulator(
|
|
212
|
-
proxyContractStore,
|
|
213
|
-
this.noteStore,
|
|
214
|
-
this.keyStore,
|
|
215
|
-
this.addressStore,
|
|
216
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
223
|
-
this.
|
|
224
|
-
|
|
291
|
+
return new ContractFunctionSimulator({
|
|
292
|
+
contractStore: proxyContractStore,
|
|
293
|
+
noteStore: this.noteStore,
|
|
294
|
+
keyStore: this.keyStore,
|
|
295
|
+
addressStore: this.addressStore,
|
|
296
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
297
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
298
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
299
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
300
|
+
capsuleStore: this.capsuleStore,
|
|
301
|
+
privateEventStore: this.privateEventStore,
|
|
302
|
+
simulator: this.simulator,
|
|
303
|
+
contractSyncService: this.contractSyncService,
|
|
304
|
+
messageContextService: this.messageContextService,
|
|
305
|
+
});
|
|
225
306
|
}
|
|
226
307
|
|
|
227
308
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -273,9 +354,8 @@ export class PXE {
|
|
|
273
354
|
async #registerProtocolContracts() {
|
|
274
355
|
const registered: Record<string, string> = {};
|
|
275
356
|
for (const name of protocolContractNames) {
|
|
276
|
-
const { address,
|
|
277
|
-
|
|
278
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
357
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
358
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
279
359
|
await this.contractStore.addContractInstance(instance);
|
|
280
360
|
registered[name] = address.toString();
|
|
281
361
|
}
|
|
@@ -287,7 +367,7 @@ export class PXE {
|
|
|
287
367
|
async #executePrivate(
|
|
288
368
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
289
369
|
txRequest: TxExecutionRequest,
|
|
290
|
-
scopes: AztecAddress[]
|
|
370
|
+
scopes: AztecAddress[],
|
|
291
371
|
jobId: string,
|
|
292
372
|
): Promise<PrivateExecutionResult> {
|
|
293
373
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -295,27 +375,23 @@ export class PXE {
|
|
|
295
375
|
try {
|
|
296
376
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
297
377
|
|
|
298
|
-
await ensureContractSynced(
|
|
378
|
+
await this.contractSyncService.ensureContractSynced(
|
|
299
379
|
contractAddress,
|
|
300
380
|
functionSelector,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this.contractStore,
|
|
381
|
+
(privateSyncCall, execScopes) =>
|
|
382
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
304
383
|
anchorBlockHeader,
|
|
384
|
+
jobId,
|
|
385
|
+
scopes,
|
|
305
386
|
);
|
|
306
387
|
|
|
307
|
-
const result = await contractFunctionSimulator.run(
|
|
308
|
-
txRequest,
|
|
388
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
309
389
|
contractAddress,
|
|
310
|
-
functionSelector,
|
|
311
|
-
undefined,
|
|
390
|
+
selector: functionSelector,
|
|
312
391
|
anchorBlockHeader,
|
|
313
|
-
// The sender for tags is set by contracts, typically by an account
|
|
314
|
-
// contract entrypoint
|
|
315
|
-
undefined, // senderForTags
|
|
316
392
|
scopes,
|
|
317
393
|
jobId,
|
|
318
|
-
);
|
|
394
|
+
});
|
|
319
395
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
320
396
|
return result;
|
|
321
397
|
} catch (err) {
|
|
@@ -327,25 +403,32 @@ export class PXE {
|
|
|
327
403
|
}
|
|
328
404
|
|
|
329
405
|
/**
|
|
330
|
-
*
|
|
406
|
+
* Execute a utility function call on the given contract.
|
|
331
407
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
332
408
|
* @param call - The function call to execute.
|
|
333
409
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
334
410
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
335
411
|
* accounts if not specified.
|
|
336
412
|
* @param jobId - The job ID for staged writes.
|
|
337
|
-
* @returns The
|
|
413
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
338
414
|
*/
|
|
339
|
-
async #
|
|
415
|
+
async #executeUtility(
|
|
340
416
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
341
417
|
call: FunctionCall,
|
|
342
418
|
authWitnesses: AuthWitness[] | undefined,
|
|
343
|
-
scopes: AztecAddress[]
|
|
419
|
+
scopes: AztecAddress[],
|
|
344
420
|
jobId: string,
|
|
345
421
|
) {
|
|
346
422
|
try {
|
|
347
423
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
348
|
-
|
|
424
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
425
|
+
call,
|
|
426
|
+
authWitnesses ?? [],
|
|
427
|
+
anchorBlockHeader,
|
|
428
|
+
scopes,
|
|
429
|
+
jobId,
|
|
430
|
+
);
|
|
431
|
+
return { result, offchainEffects };
|
|
349
432
|
} catch (err) {
|
|
350
433
|
if (err instanceof SimulationError) {
|
|
351
434
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -399,15 +482,35 @@ export class PXE {
|
|
|
399
482
|
config: PrivateKernelExecutionProverConfig,
|
|
400
483
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
401
484
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
402
|
-
const anchorBlockHash =
|
|
485
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
403
486
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
404
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
487
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
488
|
+
kernelOracle,
|
|
489
|
+
proofCreator,
|
|
490
|
+
!this.proverEnabled,
|
|
491
|
+
this.log.getBindings(),
|
|
492
|
+
);
|
|
405
493
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
406
494
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
407
495
|
}
|
|
408
496
|
|
|
409
497
|
// Public API
|
|
410
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Returns the block header up to which the PXE has synced.
|
|
501
|
+
* @returns The synced block header
|
|
502
|
+
*/
|
|
503
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
504
|
+
return this.#putInJobQueue(() => {
|
|
505
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
511
|
+
* @param address - The contract address.
|
|
512
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
513
|
+
*/
|
|
411
514
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
412
515
|
return this.contractStore.getContractInstance(address);
|
|
413
516
|
}
|
|
@@ -467,6 +570,9 @@ export class PXE {
|
|
|
467
570
|
|
|
468
571
|
if (wasAdded) {
|
|
469
572
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
573
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
574
|
+
// all contracts must re-sync to discover them.
|
|
575
|
+
this.contractSyncService.wipe();
|
|
470
576
|
} else {
|
|
471
577
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
472
578
|
}
|
|
@@ -516,8 +622,7 @@ export class PXE {
|
|
|
516
622
|
* @param artifact - The build artifact for the contract class.
|
|
517
623
|
*/
|
|
518
624
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
519
|
-
const
|
|
520
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
625
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
521
626
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
522
627
|
}
|
|
523
628
|
|
|
@@ -536,17 +641,17 @@ export class PXE {
|
|
|
536
641
|
if (artifact) {
|
|
537
642
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
538
643
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
539
|
-
|
|
540
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
644
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
541
645
|
throw new Error(
|
|
542
|
-
`Artifact does not match expected class id (computed ${
|
|
646
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
543
647
|
);
|
|
544
648
|
}
|
|
545
649
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
546
650
|
if (!computedAddress.equals(instance.address)) {
|
|
547
651
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
548
652
|
}
|
|
549
|
-
|
|
653
|
+
|
|
654
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
550
655
|
|
|
551
656
|
const publicFunctionSignatures = artifact.functions
|
|
552
657
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -595,15 +700,16 @@ export class PXE {
|
|
|
595
700
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
596
701
|
}
|
|
597
702
|
|
|
598
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
599
|
-
|
|
600
703
|
const publicFunctionSignatures = artifact.functions
|
|
601
704
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
602
705
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
603
706
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
604
707
|
|
|
605
708
|
currentInstance.currentContractClassId = contractClass.id;
|
|
606
|
-
await
|
|
709
|
+
await Promise.all([
|
|
710
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
711
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
712
|
+
]);
|
|
607
713
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
608
714
|
});
|
|
609
715
|
}
|
|
@@ -621,11 +727,12 @@ export class PXE {
|
|
|
621
727
|
* (where validators prove the public portion).
|
|
622
728
|
*
|
|
623
729
|
* @param txRequest - An authenticated tx request ready for proving
|
|
730
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
624
731
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
625
732
|
* @throws If contract code not found, or public simulation reverts.
|
|
626
733
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
627
734
|
*/
|
|
628
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
735
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
629
736
|
let privateExecutionResult: PrivateExecutionResult;
|
|
630
737
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
631
738
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -636,7 +743,7 @@ export class PXE {
|
|
|
636
743
|
await this.blockStateSynchronizer.sync();
|
|
637
744
|
const syncTime = syncTimer.ms();
|
|
638
745
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
639
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
746
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
640
747
|
|
|
641
748
|
const {
|
|
642
749
|
publicInputs,
|
|
@@ -678,17 +785,17 @@ export class PXE {
|
|
|
678
785
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
679
786
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
680
787
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
681
|
-
const
|
|
682
|
-
if (
|
|
788
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
789
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
683
790
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
684
791
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
685
792
|
|
|
686
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
687
|
-
this.log.debug(`Stored used
|
|
688
|
-
|
|
793
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
794
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
795
|
+
taggingIndexRangesUsedInTheTx,
|
|
689
796
|
});
|
|
690
797
|
} else {
|
|
691
|
-
this.log.debug(`No
|
|
798
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
692
799
|
}
|
|
693
800
|
|
|
694
801
|
return txProvingResult;
|
|
@@ -700,17 +807,13 @@ export class PXE {
|
|
|
700
807
|
|
|
701
808
|
/**
|
|
702
809
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
703
|
-
*
|
|
704
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
705
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
706
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
810
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
707
811
|
* @returns A trace of the program execution with gate counts.
|
|
708
812
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
709
813
|
*/
|
|
710
814
|
public profileTx(
|
|
711
815
|
txRequest: TxExecutionRequest,
|
|
712
|
-
profileMode
|
|
713
|
-
skipProofGeneration: boolean = true,
|
|
816
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
714
817
|
): Promise<TxProfileResult> {
|
|
715
818
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
716
819
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -733,12 +836,7 @@ export class PXE {
|
|
|
733
836
|
const syncTime = syncTimer.ms();
|
|
734
837
|
|
|
735
838
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
736
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
737
|
-
contractFunctionSimulator,
|
|
738
|
-
txRequest,
|
|
739
|
-
undefined,
|
|
740
|
-
jobId,
|
|
741
|
-
);
|
|
839
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
742
840
|
|
|
743
841
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
744
842
|
txRequest,
|
|
@@ -795,12 +893,7 @@ export class PXE {
|
|
|
795
893
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
796
894
|
*
|
|
797
895
|
*
|
|
798
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
799
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
800
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
801
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
802
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
803
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
896
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
804
897
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
805
898
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
806
899
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -809,11 +902,14 @@ export class PXE {
|
|
|
809
902
|
*/
|
|
810
903
|
public simulateTx(
|
|
811
904
|
txRequest: TxExecutionRequest,
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
905
|
+
{
|
|
906
|
+
simulatePublic,
|
|
907
|
+
skipTxValidation = false,
|
|
908
|
+
skipFeeEnforcement = false,
|
|
909
|
+
skipKernels = true,
|
|
910
|
+
overrides,
|
|
911
|
+
scopes,
|
|
912
|
+
}: SimulateTxOpts,
|
|
817
913
|
): Promise<TxSimulationResult> {
|
|
818
914
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
819
915
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -837,11 +933,21 @@ export class PXE {
|
|
|
837
933
|
await this.blockStateSynchronizer.sync();
|
|
838
934
|
const syncTime = syncTimer.ms();
|
|
839
935
|
|
|
936
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
937
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
938
|
+
|
|
939
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
942
|
+
);
|
|
943
|
+
}
|
|
840
944
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
945
|
+
|
|
946
|
+
if (hasOverriddenContracts) {
|
|
947
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
948
|
+
// We exclude them so the sync service skips them entirely.
|
|
949
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
950
|
+
}
|
|
845
951
|
|
|
846
952
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
847
953
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -852,7 +958,8 @@ export class PXE {
|
|
|
852
958
|
if (skipKernels) {
|
|
853
959
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
854
960
|
privateExecutionResult,
|
|
855
|
-
this.contractStore,
|
|
961
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
962
|
+
this.node,
|
|
856
963
|
));
|
|
857
964
|
} else {
|
|
858
965
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -871,6 +978,9 @@ export class PXE {
|
|
|
871
978
|
const publicSimulationTimer = new Timer();
|
|
872
979
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
873
980
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
981
|
+
if (publicOutput?.debugLogs?.length) {
|
|
982
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
983
|
+
}
|
|
874
984
|
}
|
|
875
985
|
|
|
876
986
|
let validationTime: number | undefined;
|
|
@@ -879,7 +989,8 @@ export class PXE {
|
|
|
879
989
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
880
990
|
validationTime = validationTimer.ms();
|
|
881
991
|
if (validationResult.result === 'invalid') {
|
|
882
|
-
|
|
992
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
993
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
883
994
|
}
|
|
884
995
|
}
|
|
885
996
|
|
|
@@ -930,29 +1041,23 @@ export class PXE {
|
|
|
930
1041
|
inspect(txRequest),
|
|
931
1042
|
`simulatePublic=${simulatePublic}`,
|
|
932
1043
|
`skipTxValidation=${skipTxValidation}`,
|
|
933
|
-
`scopes=${scopes
|
|
1044
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
934
1045
|
);
|
|
935
1046
|
}
|
|
936
1047
|
});
|
|
937
1048
|
}
|
|
938
1049
|
|
|
939
1050
|
/**
|
|
940
|
-
*
|
|
941
|
-
*
|
|
1051
|
+
* Executes a contract utility function.
|
|
942
1052
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
943
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
944
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
945
|
-
* default to all.
|
|
946
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
947
1053
|
*/
|
|
948
|
-
public
|
|
1054
|
+
public executeUtility(
|
|
949
1055
|
call: FunctionCall,
|
|
950
|
-
authwits
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1056
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1057
|
+
): Promise<UtilityExecutionResult> {
|
|
1058
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
954
1059
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
955
|
-
// delete the same read value, or reading values that another
|
|
1060
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
956
1061
|
return this.#putInJobQueue(async jobId => {
|
|
957
1062
|
try {
|
|
958
1063
|
const totalTimer = new Timer();
|
|
@@ -963,16 +1068,17 @@ export class PXE {
|
|
|
963
1068
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
964
1069
|
|
|
965
1070
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
966
|
-
await ensureContractSynced(
|
|
1071
|
+
await this.contractSyncService.ensureContractSynced(
|
|
967
1072
|
call.to,
|
|
968
1073
|
call.selector,
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
this.contractStore,
|
|
1074
|
+
(privateSyncCall, execScopes) =>
|
|
1075
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
972
1076
|
anchorBlockHeader,
|
|
1077
|
+
jobId,
|
|
1078
|
+
scopes,
|
|
973
1079
|
);
|
|
974
1080
|
|
|
975
|
-
const executionResult = await this.#
|
|
1081
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
976
1082
|
contractFunctionSimulator,
|
|
977
1083
|
call,
|
|
978
1084
|
authwits ?? [],
|
|
@@ -993,14 +1099,19 @@ export class PXE {
|
|
|
993
1099
|
};
|
|
994
1100
|
|
|
995
1101
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
996
|
-
return {
|
|
1102
|
+
return {
|
|
1103
|
+
result: executionResult,
|
|
1104
|
+
offchainEffects,
|
|
1105
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1106
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1107
|
+
};
|
|
997
1108
|
} catch (err: any) {
|
|
998
1109
|
const { to, name, args } = call;
|
|
999
1110
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1000
1111
|
throw this.#contextualizeError(
|
|
1001
1112
|
err,
|
|
1002
|
-
`
|
|
1003
|
-
`scopes=${scopes
|
|
1113
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1114
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1004
1115
|
);
|
|
1005
1116
|
}
|
|
1006
1117
|
});
|
|
@@ -1033,14 +1144,14 @@ export class PXE {
|
|
|
1033
1144
|
|
|
1034
1145
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1035
1146
|
|
|
1036
|
-
await ensureContractSynced(
|
|
1147
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1037
1148
|
filter.contractAddress,
|
|
1038
1149
|
null,
|
|
1039
|
-
async privateSyncCall =>
|
|
1040
|
-
await this.#
|
|
1041
|
-
this.node,
|
|
1042
|
-
this.contractStore,
|
|
1150
|
+
async (privateSyncCall, execScopes) =>
|
|
1151
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1043
1152
|
anchorBlockHeader,
|
|
1153
|
+
jobId,
|
|
1154
|
+
filter.scopes,
|
|
1044
1155
|
);
|
|
1045
1156
|
});
|
|
1046
1157
|
|
|
@@ -1055,9 +1166,10 @@ export class PXE {
|
|
|
1055
1166
|
}
|
|
1056
1167
|
|
|
1057
1168
|
/**
|
|
1058
|
-
* Stops the PXE's job queue.
|
|
1169
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1059
1170
|
*/
|
|
1060
|
-
public stop(): Promise<void> {
|
|
1061
|
-
|
|
1171
|
+
public async stop(): Promise<void> {
|
|
1172
|
+
await this.jobQueue.end();
|
|
1173
|
+
await this.db.close();
|
|
1062
1174
|
}
|
|
1063
1175
|
}
|