@aztec/pxe 0.0.1-commit.23b0eb0 → 0.0.1-commit.2448fdb
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 +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +17 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +63 -29
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +203 -70
- 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 +300 -103
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -78
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +111 -88
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +120 -66
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +317 -126
- 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 +20 -3
- 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} +14 -15
- 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 +11 -3
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +11 -3
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +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 +11 -3
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +7 -7
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +33 -48
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +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 +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +18 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +19 -18
- package/dest/pxe.d.ts +72 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +130 -75
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -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 +36 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +148 -70
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +6 -4
- 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 +3 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -22
- 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 +18 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +363 -131
- 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 +82 -54
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +373 -142
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +140 -181
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +532 -156
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- 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} +14 -35
- 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 +11 -4
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +11 -4
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +3 -2
- package/src/entrypoints/server/utils.ts +9 -10
- package/src/events/event_service.ts +17 -4
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +63 -91
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +19 -8
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +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 +18 -16
- package/src/private_kernel/private_kernel_oracle.ts +21 -21
- package/src/pxe.ts +234 -128
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +44 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +181 -80
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +9 -5
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +12 -25
- 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 -24
- 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
|
@@ -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.
|
|
@@ -102,6 +159,9 @@ export class PXE {
|
|
|
102
159
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
103
160
|
private addressStore: AddressStore,
|
|
104
161
|
private privateEventStore: PrivateEventStore,
|
|
162
|
+
private contractSyncService: ContractSyncService,
|
|
163
|
+
private messageContextService: MessageContextService,
|
|
164
|
+
private l2TipsStore: L2TipsProvider,
|
|
105
165
|
private simulator: CircuitSimulator,
|
|
106
166
|
private proverEnabled: boolean,
|
|
107
167
|
private proofCreator: PrivateKernelProver,
|
|
@@ -119,15 +179,15 @@ export class PXE {
|
|
|
119
179
|
*
|
|
120
180
|
* @returns A promise that resolves PXE is ready to be used.
|
|
121
181
|
*/
|
|
122
|
-
public static async create(
|
|
123
|
-
node
|
|
124
|
-
store
|
|
125
|
-
proofCreator
|
|
126
|
-
simulator
|
|
127
|
-
protocolContractsProvider
|
|
128
|
-
config
|
|
129
|
-
loggerOrSuffix
|
|
130
|
-
) {
|
|
182
|
+
public static async create({
|
|
183
|
+
node,
|
|
184
|
+
store,
|
|
185
|
+
proofCreator,
|
|
186
|
+
simulator,
|
|
187
|
+
protocolContractsProvider,
|
|
188
|
+
config,
|
|
189
|
+
loggerOrSuffix,
|
|
190
|
+
}: PXECreateArgs) {
|
|
131
191
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
132
192
|
const bindings: LoggerBindings | undefined =
|
|
133
193
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -137,7 +197,9 @@ export class PXE {
|
|
|
137
197
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
138
198
|
: loggerOrSuffix;
|
|
139
199
|
|
|
140
|
-
const
|
|
200
|
+
const info = await node.getNodeInfo();
|
|
201
|
+
|
|
202
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
141
203
|
const addressStore = new AddressStore(store);
|
|
142
204
|
const privateEventStore = new PrivateEventStore(store);
|
|
143
205
|
const contractStore = new ContractStore(store);
|
|
@@ -149,6 +211,14 @@ export class PXE {
|
|
|
149
211
|
const capsuleStore = new CapsuleStore(store);
|
|
150
212
|
const keyStore = new KeyStore(store);
|
|
151
213
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
214
|
+
const contractSyncService = new ContractSyncService(
|
|
215
|
+
node,
|
|
216
|
+
contractStore,
|
|
217
|
+
noteStore,
|
|
218
|
+
createLogger('pxe:contract_sync', bindings),
|
|
219
|
+
);
|
|
220
|
+
const messageContextService = new MessageContextService(node);
|
|
221
|
+
|
|
152
222
|
const synchronizer = new BlockSynchronizer(
|
|
153
223
|
node,
|
|
154
224
|
store,
|
|
@@ -156,6 +226,7 @@ export class PXE {
|
|
|
156
226
|
noteStore,
|
|
157
227
|
privateEventStore,
|
|
158
228
|
tipsStore,
|
|
229
|
+
contractSyncService,
|
|
159
230
|
config,
|
|
160
231
|
bindings,
|
|
161
232
|
);
|
|
@@ -167,9 +238,10 @@ export class PXE {
|
|
|
167
238
|
recipientTaggingStore,
|
|
168
239
|
privateEventStore,
|
|
169
240
|
noteStore,
|
|
241
|
+
contractSyncService,
|
|
170
242
|
]);
|
|
171
243
|
|
|
172
|
-
const debugUtils = new PXEDebugUtils(
|
|
244
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
173
245
|
|
|
174
246
|
const jobQueue = new SerialQueue();
|
|
175
247
|
|
|
@@ -186,6 +258,9 @@ export class PXE {
|
|
|
186
258
|
recipientTaggingStore,
|
|
187
259
|
addressStore,
|
|
188
260
|
privateEventStore,
|
|
261
|
+
contractSyncService,
|
|
262
|
+
messageContextService,
|
|
263
|
+
tipsStore,
|
|
189
264
|
simulator,
|
|
190
265
|
proverEnabled,
|
|
191
266
|
proofCreator,
|
|
@@ -196,12 +271,15 @@ export class PXE {
|
|
|
196
271
|
debugUtils,
|
|
197
272
|
);
|
|
198
273
|
|
|
199
|
-
debugUtils.
|
|
274
|
+
debugUtils.setPXEHelpers(
|
|
275
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
276
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
277
|
+
pxe.#executeUtility.bind(pxe),
|
|
278
|
+
);
|
|
200
279
|
|
|
201
280
|
pxe.jobQueue.start();
|
|
202
281
|
|
|
203
282
|
await pxe.#registerProtocolContracts();
|
|
204
|
-
const info = await node.getNodeInfo();
|
|
205
283
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
206
284
|
return pxe;
|
|
207
285
|
}
|
|
@@ -211,19 +289,22 @@ export class PXE {
|
|
|
211
289
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
212
290
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
213
291
|
|
|
214
|
-
return new ContractFunctionSimulator(
|
|
215
|
-
proxyContractStore,
|
|
216
|
-
this.noteStore,
|
|
217
|
-
this.keyStore,
|
|
218
|
-
this.addressStore,
|
|
219
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
222
|
-
this.
|
|
223
|
-
this.
|
|
224
|
-
this.
|
|
225
|
-
this.
|
|
226
|
-
|
|
292
|
+
return new ContractFunctionSimulator({
|
|
293
|
+
contractStore: proxyContractStore,
|
|
294
|
+
noteStore: this.noteStore,
|
|
295
|
+
keyStore: this.keyStore,
|
|
296
|
+
addressStore: this.addressStore,
|
|
297
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
298
|
+
l2TipsStore: this.l2TipsStore,
|
|
299
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
300
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
301
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
302
|
+
capsuleStore: this.capsuleStore,
|
|
303
|
+
privateEventStore: this.privateEventStore,
|
|
304
|
+
simulator: this.simulator,
|
|
305
|
+
contractSyncService: this.contractSyncService,
|
|
306
|
+
messageContextService: this.messageContextService,
|
|
307
|
+
});
|
|
227
308
|
}
|
|
228
309
|
|
|
229
310
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -275,9 +356,8 @@ export class PXE {
|
|
|
275
356
|
async #registerProtocolContracts() {
|
|
276
357
|
const registered: Record<string, string> = {};
|
|
277
358
|
for (const name of protocolContractNames) {
|
|
278
|
-
const { address,
|
|
279
|
-
|
|
280
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
359
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
360
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
281
361
|
await this.contractStore.addContractInstance(instance);
|
|
282
362
|
registered[name] = address.toString();
|
|
283
363
|
}
|
|
@@ -289,7 +369,7 @@ export class PXE {
|
|
|
289
369
|
async #executePrivate(
|
|
290
370
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
291
371
|
txRequest: TxExecutionRequest,
|
|
292
|
-
scopes: AztecAddress[]
|
|
372
|
+
scopes: AztecAddress[],
|
|
293
373
|
jobId: string,
|
|
294
374
|
): Promise<PrivateExecutionResult> {
|
|
295
375
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -297,29 +377,23 @@ export class PXE {
|
|
|
297
377
|
try {
|
|
298
378
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
299
379
|
|
|
300
|
-
await ensureContractSynced(
|
|
380
|
+
await this.contractSyncService.ensureContractSynced(
|
|
301
381
|
contractAddress,
|
|
302
382
|
functionSelector,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.contractStore,
|
|
306
|
-
this.noteStore,
|
|
383
|
+
(privateSyncCall, execScopes) =>
|
|
384
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
307
385
|
anchorBlockHeader,
|
|
308
386
|
jobId,
|
|
387
|
+
scopes,
|
|
309
388
|
);
|
|
310
389
|
|
|
311
|
-
const result = await contractFunctionSimulator.run(
|
|
312
|
-
txRequest,
|
|
390
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
313
391
|
contractAddress,
|
|
314
|
-
functionSelector,
|
|
315
|
-
undefined,
|
|
392
|
+
selector: functionSelector,
|
|
316
393
|
anchorBlockHeader,
|
|
317
|
-
// The sender for tags is set by contracts, typically by an account
|
|
318
|
-
// contract entrypoint
|
|
319
|
-
undefined, // senderForTags
|
|
320
394
|
scopes,
|
|
321
395
|
jobId,
|
|
322
|
-
);
|
|
396
|
+
});
|
|
323
397
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
324
398
|
return result;
|
|
325
399
|
} catch (err) {
|
|
@@ -331,25 +405,32 @@ export class PXE {
|
|
|
331
405
|
}
|
|
332
406
|
|
|
333
407
|
/**
|
|
334
|
-
*
|
|
408
|
+
* Execute a utility function call on the given contract.
|
|
335
409
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
336
410
|
* @param call - The function call to execute.
|
|
337
411
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
338
412
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
339
413
|
* accounts if not specified.
|
|
340
414
|
* @param jobId - The job ID for staged writes.
|
|
341
|
-
* @returns The
|
|
415
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
342
416
|
*/
|
|
343
|
-
async #
|
|
417
|
+
async #executeUtility(
|
|
344
418
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
345
419
|
call: FunctionCall,
|
|
346
420
|
authWitnesses: AuthWitness[] | undefined,
|
|
347
|
-
scopes: AztecAddress[]
|
|
421
|
+
scopes: AztecAddress[],
|
|
348
422
|
jobId: string,
|
|
349
423
|
) {
|
|
350
424
|
try {
|
|
351
425
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
352
|
-
|
|
426
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
427
|
+
call,
|
|
428
|
+
authWitnesses ?? [],
|
|
429
|
+
anchorBlockHeader,
|
|
430
|
+
scopes,
|
|
431
|
+
jobId,
|
|
432
|
+
);
|
|
433
|
+
return { result, offchainEffects };
|
|
353
434
|
} catch (err) {
|
|
354
435
|
if (err instanceof SimulationError) {
|
|
355
436
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -403,8 +484,7 @@ export class PXE {
|
|
|
403
484
|
config: PrivateKernelExecutionProverConfig,
|
|
404
485
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
405
486
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
406
|
-
const
|
|
407
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
487
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
408
488
|
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
409
489
|
kernelOracle,
|
|
410
490
|
proofCreator,
|
|
@@ -417,6 +497,21 @@ export class PXE {
|
|
|
417
497
|
|
|
418
498
|
// Public API
|
|
419
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Returns the block header up to which the PXE has synced.
|
|
502
|
+
* @returns The synced block header
|
|
503
|
+
*/
|
|
504
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
505
|
+
return this.#putInJobQueue(() => {
|
|
506
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
512
|
+
* @param address - The contract address.
|
|
513
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
514
|
+
*/
|
|
420
515
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
421
516
|
return this.contractStore.getContractInstance(address);
|
|
422
517
|
}
|
|
@@ -466,6 +561,12 @@ export class PXE {
|
|
|
466
561
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
467
562
|
*/
|
|
468
563
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
564
|
+
if (!(await sender.isValid())) {
|
|
565
|
+
throw new Error(
|
|
566
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
469
570
|
const accounts = await this.keyStore.getAccounts();
|
|
470
571
|
if (accounts.includes(sender)) {
|
|
471
572
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -476,6 +577,9 @@ export class PXE {
|
|
|
476
577
|
|
|
477
578
|
if (wasAdded) {
|
|
478
579
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
580
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
581
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
582
|
+
await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
|
|
479
583
|
} else {
|
|
480
584
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
481
585
|
}
|
|
@@ -525,8 +629,7 @@ export class PXE {
|
|
|
525
629
|
* @param artifact - The build artifact for the contract class.
|
|
526
630
|
*/
|
|
527
631
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
528
|
-
const
|
|
529
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
632
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
530
633
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
531
634
|
}
|
|
532
635
|
|
|
@@ -545,17 +648,17 @@ export class PXE {
|
|
|
545
648
|
if (artifact) {
|
|
546
649
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
547
650
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
548
|
-
|
|
549
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
651
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
550
652
|
throw new Error(
|
|
551
|
-
`Artifact does not match expected class id (computed ${
|
|
653
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
552
654
|
);
|
|
553
655
|
}
|
|
554
656
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
555
657
|
if (!computedAddress.equals(instance.address)) {
|
|
556
658
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
557
659
|
}
|
|
558
|
-
|
|
660
|
+
|
|
661
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
559
662
|
|
|
560
663
|
const publicFunctionSignatures = artifact.functions
|
|
561
664
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -604,15 +707,16 @@ export class PXE {
|
|
|
604
707
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
605
708
|
}
|
|
606
709
|
|
|
607
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
608
|
-
|
|
609
710
|
const publicFunctionSignatures = artifact.functions
|
|
610
711
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
611
712
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
612
713
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
613
714
|
|
|
614
715
|
currentInstance.currentContractClassId = contractClass.id;
|
|
615
|
-
await
|
|
716
|
+
await Promise.all([
|
|
717
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
718
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
719
|
+
]);
|
|
616
720
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
617
721
|
});
|
|
618
722
|
}
|
|
@@ -630,11 +734,12 @@ export class PXE {
|
|
|
630
734
|
* (where validators prove the public portion).
|
|
631
735
|
*
|
|
632
736
|
* @param txRequest - An authenticated tx request ready for proving
|
|
737
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
633
738
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
634
739
|
* @throws If contract code not found, or public simulation reverts.
|
|
635
740
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
636
741
|
*/
|
|
637
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
742
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
638
743
|
let privateExecutionResult: PrivateExecutionResult;
|
|
639
744
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
640
745
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -645,7 +750,7 @@ export class PXE {
|
|
|
645
750
|
await this.blockStateSynchronizer.sync();
|
|
646
751
|
const syncTime = syncTimer.ms();
|
|
647
752
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
648
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
753
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
649
754
|
|
|
650
755
|
const {
|
|
651
756
|
publicInputs,
|
|
@@ -687,17 +792,17 @@ export class PXE {
|
|
|
687
792
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
688
793
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
689
794
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
690
|
-
const
|
|
691
|
-
if (
|
|
795
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
796
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
692
797
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
693
798
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
694
799
|
|
|
695
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
696
|
-
this.log.debug(`Stored used
|
|
697
|
-
|
|
800
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
801
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
802
|
+
taggingIndexRangesUsedInTheTx,
|
|
698
803
|
});
|
|
699
804
|
} else {
|
|
700
|
-
this.log.debug(`No
|
|
805
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
701
806
|
}
|
|
702
807
|
|
|
703
808
|
return txProvingResult;
|
|
@@ -709,17 +814,13 @@ export class PXE {
|
|
|
709
814
|
|
|
710
815
|
/**
|
|
711
816
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
712
|
-
*
|
|
713
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
714
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
715
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
817
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
716
818
|
* @returns A trace of the program execution with gate counts.
|
|
717
819
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
718
820
|
*/
|
|
719
821
|
public profileTx(
|
|
720
822
|
txRequest: TxExecutionRequest,
|
|
721
|
-
profileMode
|
|
722
|
-
skipProofGeneration: boolean = true,
|
|
823
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
723
824
|
): Promise<TxProfileResult> {
|
|
724
825
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
725
826
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -742,12 +843,7 @@ export class PXE {
|
|
|
742
843
|
const syncTime = syncTimer.ms();
|
|
743
844
|
|
|
744
845
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
745
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
746
|
-
contractFunctionSimulator,
|
|
747
|
-
txRequest,
|
|
748
|
-
undefined,
|
|
749
|
-
jobId,
|
|
750
|
-
);
|
|
846
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
751
847
|
|
|
752
848
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
753
849
|
txRequest,
|
|
@@ -804,12 +900,7 @@ export class PXE {
|
|
|
804
900
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
805
901
|
*
|
|
806
902
|
*
|
|
807
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
808
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
809
|
-
* @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 skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
811
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
812
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
903
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
813
904
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
814
905
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
815
906
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -818,11 +909,14 @@ export class PXE {
|
|
|
818
909
|
*/
|
|
819
910
|
public simulateTx(
|
|
820
911
|
txRequest: TxExecutionRequest,
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
912
|
+
{
|
|
913
|
+
simulatePublic,
|
|
914
|
+
skipTxValidation = false,
|
|
915
|
+
skipFeeEnforcement = false,
|
|
916
|
+
skipKernels = true,
|
|
917
|
+
overrides,
|
|
918
|
+
scopes,
|
|
919
|
+
}: SimulateTxOpts,
|
|
826
920
|
): Promise<TxSimulationResult> {
|
|
827
921
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
828
922
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -846,11 +940,21 @@ export class PXE {
|
|
|
846
940
|
await this.blockStateSynchronizer.sync();
|
|
847
941
|
const syncTime = syncTimer.ms();
|
|
848
942
|
|
|
943
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
944
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
945
|
+
|
|
946
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
947
|
+
throw new Error(
|
|
948
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
949
|
+
);
|
|
950
|
+
}
|
|
849
951
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
952
|
+
|
|
953
|
+
if (hasOverriddenContracts) {
|
|
954
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
955
|
+
// We exclude them so the sync service skips them entirely.
|
|
956
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
957
|
+
}
|
|
854
958
|
|
|
855
959
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
856
960
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -861,7 +965,8 @@ export class PXE {
|
|
|
861
965
|
if (skipKernels) {
|
|
862
966
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
863
967
|
privateExecutionResult,
|
|
864
|
-
this.contractStore,
|
|
968
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
969
|
+
this.node,
|
|
865
970
|
));
|
|
866
971
|
} else {
|
|
867
972
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -880,6 +985,9 @@ export class PXE {
|
|
|
880
985
|
const publicSimulationTimer = new Timer();
|
|
881
986
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
882
987
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
988
|
+
if (publicOutput?.debugLogs?.length) {
|
|
989
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
990
|
+
}
|
|
883
991
|
}
|
|
884
992
|
|
|
885
993
|
let validationTime: number | undefined;
|
|
@@ -888,7 +996,8 @@ export class PXE {
|
|
|
888
996
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
889
997
|
validationTime = validationTimer.ms();
|
|
890
998
|
if (validationResult.result === 'invalid') {
|
|
891
|
-
|
|
999
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
1000
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
892
1001
|
}
|
|
893
1002
|
}
|
|
894
1003
|
|
|
@@ -939,29 +1048,23 @@ export class PXE {
|
|
|
939
1048
|
inspect(txRequest),
|
|
940
1049
|
`simulatePublic=${simulatePublic}`,
|
|
941
1050
|
`skipTxValidation=${skipTxValidation}`,
|
|
942
|
-
`scopes=${scopes
|
|
1051
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
943
1052
|
);
|
|
944
1053
|
}
|
|
945
1054
|
});
|
|
946
1055
|
}
|
|
947
1056
|
|
|
948
1057
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
1058
|
+
* Executes a contract utility function.
|
|
951
1059
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
952
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
953
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
954
|
-
* default to all.
|
|
955
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
956
1060
|
*/
|
|
957
|
-
public
|
|
1061
|
+
public executeUtility(
|
|
958
1062
|
call: FunctionCall,
|
|
959
|
-
authwits
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1063
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1064
|
+
): Promise<UtilityExecutionResult> {
|
|
1065
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
963
1066
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
964
|
-
// delete the same read value, or reading values that another
|
|
1067
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
965
1068
|
return this.#putInJobQueue(async jobId => {
|
|
966
1069
|
try {
|
|
967
1070
|
const totalTimer = new Timer();
|
|
@@ -972,18 +1075,17 @@ export class PXE {
|
|
|
972
1075
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
973
1076
|
|
|
974
1077
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
975
|
-
await ensureContractSynced(
|
|
1078
|
+
await this.contractSyncService.ensureContractSynced(
|
|
976
1079
|
call.to,
|
|
977
1080
|
call.selector,
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
this.contractStore,
|
|
981
|
-
this.noteStore,
|
|
1081
|
+
(privateSyncCall, execScopes) =>
|
|
1082
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
982
1083
|
anchorBlockHeader,
|
|
983
1084
|
jobId,
|
|
1085
|
+
scopes,
|
|
984
1086
|
);
|
|
985
1087
|
|
|
986
|
-
const executionResult = await this.#
|
|
1088
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
987
1089
|
contractFunctionSimulator,
|
|
988
1090
|
call,
|
|
989
1091
|
authwits ?? [],
|
|
@@ -1004,14 +1106,19 @@ export class PXE {
|
|
|
1004
1106
|
};
|
|
1005
1107
|
|
|
1006
1108
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1007
|
-
return {
|
|
1109
|
+
return {
|
|
1110
|
+
result: executionResult,
|
|
1111
|
+
offchainEffects,
|
|
1112
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1113
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1114
|
+
};
|
|
1008
1115
|
} catch (err: any) {
|
|
1009
1116
|
const { to, name, args } = call;
|
|
1010
1117
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1011
1118
|
throw this.#contextualizeError(
|
|
1012
1119
|
err,
|
|
1013
|
-
`
|
|
1014
|
-
`scopes=${scopes
|
|
1120
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1121
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1015
1122
|
);
|
|
1016
1123
|
}
|
|
1017
1124
|
});
|
|
@@ -1044,16 +1151,14 @@ export class PXE {
|
|
|
1044
1151
|
|
|
1045
1152
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1046
1153
|
|
|
1047
|
-
await ensureContractSynced(
|
|
1154
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1048
1155
|
filter.contractAddress,
|
|
1049
1156
|
null,
|
|
1050
|
-
async privateSyncCall =>
|
|
1051
|
-
await this.#
|
|
1052
|
-
this.node,
|
|
1053
|
-
this.contractStore,
|
|
1054
|
-
this.noteStore,
|
|
1157
|
+
async (privateSyncCall, execScopes) =>
|
|
1158
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1055
1159
|
anchorBlockHeader,
|
|
1056
1160
|
jobId,
|
|
1161
|
+
filter.scopes,
|
|
1057
1162
|
);
|
|
1058
1163
|
});
|
|
1059
1164
|
|
|
@@ -1070,7 +1175,8 @@ export class PXE {
|
|
|
1070
1175
|
/**
|
|
1071
1176
|
* Stops the PXE's job queue.
|
|
1072
1177
|
*/
|
|
1073
|
-
public stop(): Promise<void> {
|
|
1074
|
-
|
|
1178
|
+
public async stop(): Promise<void> {
|
|
1179
|
+
await this.jobQueue.end();
|
|
1180
|
+
await this.blockStateSynchronizer.stop();
|
|
1075
1181
|
}
|
|
1076
1182
|
}
|