@aztec/pxe 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2b2662070
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 +15 -3
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -15
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +63 -31
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +205 -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 +61 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +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 +305 -108
- 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 +110 -87
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +126 -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 +328 -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 +116 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +19 -13
- package/dest/debug/pxe_debug_utils.d.ts +14 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +16 -15
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +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 +10 -9
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +41 -61
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +7 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -14
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +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 +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +74 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +136 -76
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +39 -36
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +84 -61
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -21
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +25 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +27 -12
- package/src/config/index.ts +3 -9
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +365 -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 +88 -60
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +385 -144
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +136 -184
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +543 -169
- 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 +176 -0
- package/src/contract_sync/{index.ts → helpers.ts} +22 -22
- package/src/debug/pxe_debug_utils.ts +48 -18
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +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 +77 -105
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +24 -15
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +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 +7 -7
- package/src/pxe.ts +252 -129
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +42 -34
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +166 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -24
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
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,6 +18,7 @@ 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 type { L2TipsProvider } from '@aztec/stdlib/block';
|
|
21
22
|
import {
|
|
22
23
|
CompleteAddress,
|
|
23
24
|
type ContractInstanceWithAddress,
|
|
@@ -33,6 +34,7 @@ import type {
|
|
|
33
34
|
PrivateKernelTailCircuitPublicInputs,
|
|
34
35
|
} from '@aztec/stdlib/kernel';
|
|
35
36
|
import {
|
|
37
|
+
BlockHeader,
|
|
36
38
|
type ContractOverrides,
|
|
37
39
|
type InTx,
|
|
38
40
|
PrivateExecutionResult,
|
|
@@ -46,7 +48,7 @@ import {
|
|
|
46
48
|
TxProfileResult,
|
|
47
49
|
TxProvingResult,
|
|
48
50
|
TxSimulationResult,
|
|
49
|
-
|
|
51
|
+
UtilityExecutionResult,
|
|
50
52
|
} from '@aztec/stdlib/tx';
|
|
51
53
|
|
|
52
54
|
import { inspect } from 'util';
|
|
@@ -59,11 +61,14 @@ import {
|
|
|
59
61
|
generateSimulatedProvingResult,
|
|
60
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
62
|
-
import {
|
|
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';
|
|
63
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
66
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
67
72
|
import {
|
|
68
73
|
PrivateKernelExecutionProver,
|
|
69
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -84,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
|
|
|
84
89
|
eventSelector: EventSelector;
|
|
85
90
|
};
|
|
86
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: AztecAddress[];
|
|
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: AztecAddress[];
|
|
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: AztecAddress[];
|
|
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
|
+
|
|
87
144
|
/**
|
|
88
145
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
89
146
|
* manage private state of users.
|
|
@@ -91,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
91
148
|
export class PXE {
|
|
92
149
|
private constructor(
|
|
93
150
|
private node: AztecNode,
|
|
151
|
+
private db: AztecAsyncKVStore,
|
|
94
152
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
95
153
|
private keyStore: KeyStore,
|
|
96
154
|
private contractStore: ContractStore,
|
|
@@ -102,6 +160,9 @@ export class PXE {
|
|
|
102
160
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
161
|
private addressStore: AddressStore,
|
|
104
162
|
private privateEventStore: PrivateEventStore,
|
|
163
|
+
private contractSyncService: ContractSyncService,
|
|
164
|
+
private messageContextService: MessageContextService,
|
|
165
|
+
private l2TipsStore: L2TipsProvider,
|
|
105
166
|
private simulator: CircuitSimulator,
|
|
106
167
|
private proverEnabled: boolean,
|
|
107
168
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,21 +180,27 @@ export class PXE {
|
|
|
119
180
|
*
|
|
120
181
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
182
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
183
|
+
public static async create({
|
|
184
|
+
node,
|
|
185
|
+
store,
|
|
186
|
+
proofCreator,
|
|
187
|
+
simulator,
|
|
188
|
+
protocolContractsProvider,
|
|
189
|
+
config,
|
|
190
|
+
loggerOrSuffix,
|
|
191
|
+
}: PXECreateArgs) {
|
|
192
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
193
|
+
const bindings: LoggerBindings | undefined =
|
|
194
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
195
|
+
|
|
131
196
|
const log =
|
|
132
197
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
133
198
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
134
199
|
: loggerOrSuffix;
|
|
135
200
|
|
|
136
|
-
const
|
|
201
|
+
const info = await node.getNodeInfo();
|
|
202
|
+
|
|
203
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
137
204
|
const addressStore = new AddressStore(store);
|
|
138
205
|
const privateEventStore = new PrivateEventStore(store);
|
|
139
206
|
const contractStore = new ContractStore(store);
|
|
@@ -145,6 +212,14 @@ export class PXE {
|
|
|
145
212
|
const capsuleStore = new CapsuleStore(store);
|
|
146
213
|
const keyStore = new KeyStore(store);
|
|
147
214
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
215
|
+
const contractSyncService = new ContractSyncService(
|
|
216
|
+
node,
|
|
217
|
+
contractStore,
|
|
218
|
+
noteStore,
|
|
219
|
+
createLogger('pxe:contract_sync', bindings),
|
|
220
|
+
);
|
|
221
|
+
const messageContextService = new MessageContextService(node);
|
|
222
|
+
|
|
148
223
|
const synchronizer = new BlockSynchronizer(
|
|
149
224
|
node,
|
|
150
225
|
store,
|
|
@@ -152,25 +227,28 @@ export class PXE {
|
|
|
152
227
|
noteStore,
|
|
153
228
|
privateEventStore,
|
|
154
229
|
tipsStore,
|
|
230
|
+
contractSyncService,
|
|
155
231
|
config,
|
|
156
|
-
|
|
232
|
+
bindings,
|
|
157
233
|
);
|
|
158
234
|
|
|
159
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
235
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
160
236
|
jobCoordinator.registerStores([
|
|
161
237
|
capsuleStore,
|
|
162
238
|
senderTaggingStore,
|
|
163
239
|
recipientTaggingStore,
|
|
164
240
|
privateEventStore,
|
|
165
241
|
noteStore,
|
|
242
|
+
contractSyncService,
|
|
166
243
|
]);
|
|
167
244
|
|
|
168
|
-
const debugUtils = new PXEDebugUtils(
|
|
245
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
169
246
|
|
|
170
247
|
const jobQueue = new SerialQueue();
|
|
171
248
|
|
|
172
249
|
const pxe = new PXE(
|
|
173
250
|
node,
|
|
251
|
+
store,
|
|
174
252
|
synchronizer,
|
|
175
253
|
keyStore,
|
|
176
254
|
contractStore,
|
|
@@ -182,6 +260,9 @@ export class PXE {
|
|
|
182
260
|
recipientTaggingStore,
|
|
183
261
|
addressStore,
|
|
184
262
|
privateEventStore,
|
|
263
|
+
contractSyncService,
|
|
264
|
+
messageContextService,
|
|
265
|
+
tipsStore,
|
|
185
266
|
simulator,
|
|
186
267
|
proverEnabled,
|
|
187
268
|
proofCreator,
|
|
@@ -192,12 +273,15 @@ export class PXE {
|
|
|
192
273
|
debugUtils,
|
|
193
274
|
);
|
|
194
275
|
|
|
195
|
-
debugUtils.
|
|
276
|
+
debugUtils.setPXEHelpers(
|
|
277
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
278
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
279
|
+
pxe.#executeUtility.bind(pxe),
|
|
280
|
+
);
|
|
196
281
|
|
|
197
282
|
pxe.jobQueue.start();
|
|
198
283
|
|
|
199
284
|
await pxe.#registerProtocolContracts();
|
|
200
|
-
const info = await node.getNodeInfo();
|
|
201
285
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
202
286
|
return pxe;
|
|
203
287
|
}
|
|
@@ -207,20 +291,22 @@ export class PXE {
|
|
|
207
291
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
208
292
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
209
293
|
|
|
210
|
-
return new ContractFunctionSimulator(
|
|
211
|
-
proxyContractStore,
|
|
212
|
-
this.noteStore,
|
|
213
|
-
this.keyStore,
|
|
214
|
-
this.addressStore,
|
|
215
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
216
|
-
this.
|
|
217
|
-
this.senderTaggingStore,
|
|
218
|
-
this.recipientTaggingStore,
|
|
219
|
-
this.senderAddressBookStore,
|
|
220
|
-
this.capsuleStore,
|
|
221
|
-
this.privateEventStore,
|
|
222
|
-
this.simulator,
|
|
223
|
-
|
|
294
|
+
return new ContractFunctionSimulator({
|
|
295
|
+
contractStore: proxyContractStore,
|
|
296
|
+
noteStore: this.noteStore,
|
|
297
|
+
keyStore: this.keyStore,
|
|
298
|
+
addressStore: this.addressStore,
|
|
299
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
300
|
+
l2TipsStore: this.l2TipsStore,
|
|
301
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
302
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
303
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
304
|
+
capsuleStore: this.capsuleStore,
|
|
305
|
+
privateEventStore: this.privateEventStore,
|
|
306
|
+
simulator: this.simulator,
|
|
307
|
+
contractSyncService: this.contractSyncService,
|
|
308
|
+
messageContextService: this.messageContextService,
|
|
309
|
+
});
|
|
224
310
|
}
|
|
225
311
|
|
|
226
312
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -272,9 +358,8 @@ export class PXE {
|
|
|
272
358
|
async #registerProtocolContracts() {
|
|
273
359
|
const registered: Record<string, string> = {};
|
|
274
360
|
for (const name of protocolContractNames) {
|
|
275
|
-
const { address,
|
|
276
|
-
|
|
277
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
361
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
362
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
278
363
|
await this.contractStore.addContractInstance(instance);
|
|
279
364
|
registered[name] = address.toString();
|
|
280
365
|
}
|
|
@@ -286,7 +371,7 @@ export class PXE {
|
|
|
286
371
|
async #executePrivate(
|
|
287
372
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
288
373
|
txRequest: TxExecutionRequest,
|
|
289
|
-
scopes: AztecAddress[]
|
|
374
|
+
scopes: AztecAddress[],
|
|
290
375
|
jobId: string,
|
|
291
376
|
): Promise<PrivateExecutionResult> {
|
|
292
377
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -294,27 +379,23 @@ export class PXE {
|
|
|
294
379
|
try {
|
|
295
380
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
296
381
|
|
|
297
|
-
await ensureContractSynced(
|
|
382
|
+
await this.contractSyncService.ensureContractSynced(
|
|
298
383
|
contractAddress,
|
|
299
384
|
functionSelector,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.contractStore,
|
|
385
|
+
(privateSyncCall, execScopes) =>
|
|
386
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
303
387
|
anchorBlockHeader,
|
|
388
|
+
jobId,
|
|
389
|
+
scopes,
|
|
304
390
|
);
|
|
305
391
|
|
|
306
|
-
const result = await contractFunctionSimulator.run(
|
|
307
|
-
txRequest,
|
|
392
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
308
393
|
contractAddress,
|
|
309
|
-
functionSelector,
|
|
310
|
-
undefined,
|
|
394
|
+
selector: functionSelector,
|
|
311
395
|
anchorBlockHeader,
|
|
312
|
-
// The sender for tags is set by contracts, typically by an account
|
|
313
|
-
// contract entrypoint
|
|
314
|
-
undefined, // senderForTags
|
|
315
396
|
scopes,
|
|
316
397
|
jobId,
|
|
317
|
-
);
|
|
398
|
+
});
|
|
318
399
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
319
400
|
return result;
|
|
320
401
|
} catch (err) {
|
|
@@ -326,25 +407,32 @@ export class PXE {
|
|
|
326
407
|
}
|
|
327
408
|
|
|
328
409
|
/**
|
|
329
|
-
*
|
|
410
|
+
* Execute a utility function call on the given contract.
|
|
330
411
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
331
412
|
* @param call - The function call to execute.
|
|
332
413
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
333
414
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
334
415
|
* accounts if not specified.
|
|
335
416
|
* @param jobId - The job ID for staged writes.
|
|
336
|
-
* @returns The
|
|
417
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
337
418
|
*/
|
|
338
|
-
async #
|
|
419
|
+
async #executeUtility(
|
|
339
420
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
340
421
|
call: FunctionCall,
|
|
341
422
|
authWitnesses: AuthWitness[] | undefined,
|
|
342
|
-
scopes: AztecAddress[]
|
|
423
|
+
scopes: AztecAddress[],
|
|
343
424
|
jobId: string,
|
|
344
425
|
) {
|
|
345
426
|
try {
|
|
346
427
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
347
|
-
|
|
428
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
429
|
+
call,
|
|
430
|
+
authWitnesses ?? [],
|
|
431
|
+
anchorBlockHeader,
|
|
432
|
+
scopes,
|
|
433
|
+
jobId,
|
|
434
|
+
);
|
|
435
|
+
return { result, offchainEffects };
|
|
348
436
|
} catch (err) {
|
|
349
437
|
if (err instanceof SimulationError) {
|
|
350
438
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -400,13 +488,33 @@ export class PXE {
|
|
|
400
488
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
401
489
|
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
402
490
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
403
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
491
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
492
|
+
kernelOracle,
|
|
493
|
+
proofCreator,
|
|
494
|
+
!this.proverEnabled,
|
|
495
|
+
this.log.getBindings(),
|
|
496
|
+
);
|
|
404
497
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
405
498
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
406
499
|
}
|
|
407
500
|
|
|
408
501
|
// Public API
|
|
409
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Returns the block header up to which the PXE has synced.
|
|
505
|
+
* @returns The synced block header
|
|
506
|
+
*/
|
|
507
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
508
|
+
return this.#putInJobQueue(() => {
|
|
509
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
515
|
+
* @param address - The contract address.
|
|
516
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
517
|
+
*/
|
|
410
518
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
411
519
|
return this.contractStore.getContractInstance(address);
|
|
412
520
|
}
|
|
@@ -456,6 +564,12 @@ export class PXE {
|
|
|
456
564
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
457
565
|
*/
|
|
458
566
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
567
|
+
if (!(await sender.isValid())) {
|
|
568
|
+
throw new Error(
|
|
569
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
459
573
|
const accounts = await this.keyStore.getAccounts();
|
|
460
574
|
if (accounts.includes(sender)) {
|
|
461
575
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -466,6 +580,9 @@ export class PXE {
|
|
|
466
580
|
|
|
467
581
|
if (wasAdded) {
|
|
468
582
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
583
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
584
|
+
// all contracts must re-sync to discover them.
|
|
585
|
+
this.contractSyncService.wipe();
|
|
469
586
|
} else {
|
|
470
587
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
471
588
|
}
|
|
@@ -515,8 +632,7 @@ export class PXE {
|
|
|
515
632
|
* @param artifact - The build artifact for the contract class.
|
|
516
633
|
*/
|
|
517
634
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
518
|
-
const
|
|
519
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
635
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
520
636
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
521
637
|
}
|
|
522
638
|
|
|
@@ -535,17 +651,17 @@ export class PXE {
|
|
|
535
651
|
if (artifact) {
|
|
536
652
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
537
653
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
538
|
-
|
|
539
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
654
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
540
655
|
throw new Error(
|
|
541
|
-
`Artifact does not match expected class id (computed ${
|
|
656
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
542
657
|
);
|
|
543
658
|
}
|
|
544
659
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
545
660
|
if (!computedAddress.equals(instance.address)) {
|
|
546
661
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
547
662
|
}
|
|
548
|
-
|
|
663
|
+
|
|
664
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
549
665
|
|
|
550
666
|
const publicFunctionSignatures = artifact.functions
|
|
551
667
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -594,15 +710,16 @@ export class PXE {
|
|
|
594
710
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
595
711
|
}
|
|
596
712
|
|
|
597
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
598
|
-
|
|
599
713
|
const publicFunctionSignatures = artifact.functions
|
|
600
714
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
601
715
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
602
716
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
603
717
|
|
|
604
718
|
currentInstance.currentContractClassId = contractClass.id;
|
|
605
|
-
await
|
|
719
|
+
await Promise.all([
|
|
720
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
721
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
722
|
+
]);
|
|
606
723
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
607
724
|
});
|
|
608
725
|
}
|
|
@@ -620,11 +737,12 @@ export class PXE {
|
|
|
620
737
|
* (where validators prove the public portion).
|
|
621
738
|
*
|
|
622
739
|
* @param txRequest - An authenticated tx request ready for proving
|
|
740
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
623
741
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
624
742
|
* @throws If contract code not found, or public simulation reverts.
|
|
625
743
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
626
744
|
*/
|
|
627
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
745
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
628
746
|
let privateExecutionResult: PrivateExecutionResult;
|
|
629
747
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
630
748
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -635,7 +753,7 @@ export class PXE {
|
|
|
635
753
|
await this.blockStateSynchronizer.sync();
|
|
636
754
|
const syncTime = syncTimer.ms();
|
|
637
755
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
638
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
756
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
639
757
|
|
|
640
758
|
const {
|
|
641
759
|
publicInputs,
|
|
@@ -677,17 +795,17 @@ export class PXE {
|
|
|
677
795
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
678
796
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
679
797
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
680
|
-
const
|
|
681
|
-
if (
|
|
798
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
799
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
682
800
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
683
801
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
684
802
|
|
|
685
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
686
|
-
this.log.debug(`Stored used
|
|
687
|
-
|
|
803
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
804
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
805
|
+
taggingIndexRangesUsedInTheTx,
|
|
688
806
|
});
|
|
689
807
|
} else {
|
|
690
|
-
this.log.debug(`No
|
|
808
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
691
809
|
}
|
|
692
810
|
|
|
693
811
|
return txProvingResult;
|
|
@@ -699,17 +817,13 @@ export class PXE {
|
|
|
699
817
|
|
|
700
818
|
/**
|
|
701
819
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
702
|
-
*
|
|
703
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
704
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
705
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
820
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
706
821
|
* @returns A trace of the program execution with gate counts.
|
|
707
822
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
708
823
|
*/
|
|
709
824
|
public profileTx(
|
|
710
825
|
txRequest: TxExecutionRequest,
|
|
711
|
-
profileMode
|
|
712
|
-
skipProofGeneration: boolean = true,
|
|
826
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
713
827
|
): Promise<TxProfileResult> {
|
|
714
828
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
715
829
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -732,12 +846,7 @@ export class PXE {
|
|
|
732
846
|
const syncTime = syncTimer.ms();
|
|
733
847
|
|
|
734
848
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
735
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
736
|
-
contractFunctionSimulator,
|
|
737
|
-
txRequest,
|
|
738
|
-
undefined,
|
|
739
|
-
jobId,
|
|
740
|
-
);
|
|
849
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
741
850
|
|
|
742
851
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
743
852
|
txRequest,
|
|
@@ -794,12 +903,7 @@ export class PXE {
|
|
|
794
903
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
795
904
|
*
|
|
796
905
|
*
|
|
797
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
798
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
799
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
800
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
801
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
802
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
906
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
803
907
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
804
908
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
805
909
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -808,11 +912,14 @@ export class PXE {
|
|
|
808
912
|
*/
|
|
809
913
|
public simulateTx(
|
|
810
914
|
txRequest: TxExecutionRequest,
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
915
|
+
{
|
|
916
|
+
simulatePublic,
|
|
917
|
+
skipTxValidation = false,
|
|
918
|
+
skipFeeEnforcement = false,
|
|
919
|
+
skipKernels = true,
|
|
920
|
+
overrides,
|
|
921
|
+
scopes,
|
|
922
|
+
}: SimulateTxOpts,
|
|
816
923
|
): Promise<TxSimulationResult> {
|
|
817
924
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
818
925
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -836,11 +943,21 @@ export class PXE {
|
|
|
836
943
|
await this.blockStateSynchronizer.sync();
|
|
837
944
|
const syncTime = syncTimer.ms();
|
|
838
945
|
|
|
946
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
947
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
948
|
+
|
|
949
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
950
|
+
throw new Error(
|
|
951
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
952
|
+
);
|
|
953
|
+
}
|
|
839
954
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
955
|
+
|
|
956
|
+
if (hasOverriddenContracts) {
|
|
957
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
958
|
+
// We exclude them so the sync service skips them entirely.
|
|
959
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
960
|
+
}
|
|
844
961
|
|
|
845
962
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
846
963
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -851,7 +968,8 @@ export class PXE {
|
|
|
851
968
|
if (skipKernels) {
|
|
852
969
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
853
970
|
privateExecutionResult,
|
|
854
|
-
this.contractStore,
|
|
971
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
972
|
+
this.node,
|
|
855
973
|
));
|
|
856
974
|
} else {
|
|
857
975
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -870,6 +988,9 @@ export class PXE {
|
|
|
870
988
|
const publicSimulationTimer = new Timer();
|
|
871
989
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
872
990
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
991
|
+
if (publicOutput?.debugLogs?.length) {
|
|
992
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
993
|
+
}
|
|
873
994
|
}
|
|
874
995
|
|
|
875
996
|
let validationTime: number | undefined;
|
|
@@ -878,7 +999,8 @@ export class PXE {
|
|
|
878
999
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
879
1000
|
validationTime = validationTimer.ms();
|
|
880
1001
|
if (validationResult.result === 'invalid') {
|
|
881
|
-
|
|
1002
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
1003
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
882
1004
|
}
|
|
883
1005
|
}
|
|
884
1006
|
|
|
@@ -929,29 +1051,23 @@ export class PXE {
|
|
|
929
1051
|
inspect(txRequest),
|
|
930
1052
|
`simulatePublic=${simulatePublic}`,
|
|
931
1053
|
`skipTxValidation=${skipTxValidation}`,
|
|
932
|
-
`scopes=${scopes
|
|
1054
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
933
1055
|
);
|
|
934
1056
|
}
|
|
935
1057
|
});
|
|
936
1058
|
}
|
|
937
1059
|
|
|
938
1060
|
/**
|
|
939
|
-
*
|
|
940
|
-
*
|
|
1061
|
+
* Executes a contract utility function.
|
|
941
1062
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
942
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
943
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
944
|
-
* default to all.
|
|
945
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
946
1063
|
*/
|
|
947
|
-
public
|
|
1064
|
+
public executeUtility(
|
|
948
1065
|
call: FunctionCall,
|
|
949
|
-
authwits
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1066
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1067
|
+
): Promise<UtilityExecutionResult> {
|
|
1068
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
953
1069
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
954
|
-
// delete the same read value, or reading values that another
|
|
1070
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
955
1071
|
return this.#putInJobQueue(async jobId => {
|
|
956
1072
|
try {
|
|
957
1073
|
const totalTimer = new Timer();
|
|
@@ -962,16 +1078,17 @@ export class PXE {
|
|
|
962
1078
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
963
1079
|
|
|
964
1080
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
965
|
-
await ensureContractSynced(
|
|
1081
|
+
await this.contractSyncService.ensureContractSynced(
|
|
966
1082
|
call.to,
|
|
967
1083
|
call.selector,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.contractStore,
|
|
1084
|
+
(privateSyncCall, execScopes) =>
|
|
1085
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
971
1086
|
anchorBlockHeader,
|
|
1087
|
+
jobId,
|
|
1088
|
+
scopes,
|
|
972
1089
|
);
|
|
973
1090
|
|
|
974
|
-
const executionResult = await this.#
|
|
1091
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
975
1092
|
contractFunctionSimulator,
|
|
976
1093
|
call,
|
|
977
1094
|
authwits ?? [],
|
|
@@ -992,14 +1109,19 @@ export class PXE {
|
|
|
992
1109
|
};
|
|
993
1110
|
|
|
994
1111
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
995
|
-
return {
|
|
1112
|
+
return {
|
|
1113
|
+
result: executionResult,
|
|
1114
|
+
offchainEffects,
|
|
1115
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1116
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1117
|
+
};
|
|
996
1118
|
} catch (err: any) {
|
|
997
1119
|
const { to, name, args } = call;
|
|
998
1120
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
999
1121
|
throw this.#contextualizeError(
|
|
1000
1122
|
err,
|
|
1001
|
-
`
|
|
1002
|
-
`scopes=${scopes
|
|
1123
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1124
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1003
1125
|
);
|
|
1004
1126
|
}
|
|
1005
1127
|
});
|
|
@@ -1032,14 +1154,14 @@ export class PXE {
|
|
|
1032
1154
|
|
|
1033
1155
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1034
1156
|
|
|
1035
|
-
await ensureContractSynced(
|
|
1157
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1036
1158
|
filter.contractAddress,
|
|
1037
1159
|
null,
|
|
1038
|
-
async privateSyncCall =>
|
|
1039
|
-
await this.#
|
|
1040
|
-
this.node,
|
|
1041
|
-
this.contractStore,
|
|
1160
|
+
async (privateSyncCall, execScopes) =>
|
|
1161
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1042
1162
|
anchorBlockHeader,
|
|
1163
|
+
jobId,
|
|
1164
|
+
filter.scopes,
|
|
1043
1165
|
);
|
|
1044
1166
|
});
|
|
1045
1167
|
|
|
@@ -1054,9 +1176,10 @@ export class PXE {
|
|
|
1054
1176
|
}
|
|
1055
1177
|
|
|
1056
1178
|
/**
|
|
1057
|
-
* Stops the PXE's job queue.
|
|
1179
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1058
1180
|
*/
|
|
1059
|
-
public stop(): Promise<void> {
|
|
1060
|
-
|
|
1181
|
+
public async stop(): Promise<void> {
|
|
1182
|
+
await this.jobQueue.end();
|
|
1183
|
+
await this.db.close();
|
|
1061
1184
|
}
|
|
1062
1185
|
}
|