@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -16
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +175 -74
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +2 -2
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
- 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 +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +51 -29
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +86 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +62 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +107 -88
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +21 -7
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +4 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +5 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +6 -7
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +28 -32
- package/dest/notes/note_service.d.ts +9 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -16
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +69 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +104 -67
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -84
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +47 -49
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +278 -252
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +198 -147
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +184 -114
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +60 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- 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 +5 -8
- 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 +20 -18
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +76 -33
- package/src/config/index.ts +14 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +324 -137
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +2 -2
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
- package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
- package/src/contract_function_simulator/oracle/oracle.ts +56 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +126 -110
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +172 -95
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +3 -0
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +5 -7
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +48 -39
- package/src/notes/note_service.ts +24 -22
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +9 -9
- package/src/pxe.ts +211 -112
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -96
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +321 -318
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +250 -190
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +214 -130
- package/src/tagging/get_all_logs_by_tags.ts +92 -0
- package/src/tagging/index.ts +2 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +17 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +6 -9
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +23 -23
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.d.ts +0 -50
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -75
- package/src/tree_membership/tree_membership_service.ts +0 -97
package/src/pxe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
22
21
|
import {
|
|
23
22
|
CompleteAddress,
|
|
24
23
|
type ContractInstanceWithAddress,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -47,11 +47,12 @@ import {
|
|
|
47
47
|
TxProfileResult,
|
|
48
48
|
TxProvingResult,
|
|
49
49
|
TxSimulationResult,
|
|
50
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
51
51
|
} from '@aztec/stdlib/tx';
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
55
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
57
|
import type { PXEConfig } from './config/index.js';
|
|
57
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -59,8 +60,10 @@ import {
|
|
|
59
60
|
ContractFunctionSimulator,
|
|
60
61
|
generateSimulatedProvingResult,
|
|
61
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
|
-
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
63
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
65
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
66
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
67
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
69
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -85,6 +88,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
88
|
eventSelector: EventSelector;
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
/** Options for PXE.profileTx. */
|
|
92
|
+
export type ProfileTxOpts = {
|
|
93
|
+
/** The profiling mode to use. */
|
|
94
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
95
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
96
|
+
skipProofGeneration?: boolean;
|
|
97
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
98
|
+
scopes: AccessScopes;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Options for PXE.simulateTx. */
|
|
102
|
+
export type SimulateTxOpts = {
|
|
103
|
+
/** Whether to simulate the public part of the transaction. */
|
|
104
|
+
simulatePublic: boolean;
|
|
105
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
106
|
+
skipTxValidation?: boolean;
|
|
107
|
+
/** If false, fees are enforced. */
|
|
108
|
+
skipFeeEnforcement?: boolean;
|
|
109
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
110
|
+
overrides?: SimulationOverrides;
|
|
111
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
112
|
+
scopes: AccessScopes;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Options for PXE.executeUtility. */
|
|
116
|
+
export type ExecuteUtilityOpts = {
|
|
117
|
+
/** The authentication witnesses required for the function call. */
|
|
118
|
+
authwits?: AuthWitness[];
|
|
119
|
+
/** The accounts whose notes we can access in this call */
|
|
120
|
+
scopes: AccessScopes;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Args for PXE.create. */
|
|
124
|
+
export type PXECreateArgs = {
|
|
125
|
+
/** The Aztec node to connect to. */
|
|
126
|
+
node: AztecNode;
|
|
127
|
+
/** The key-value store for persisting PXE state. */
|
|
128
|
+
store: AztecAsyncKVStore;
|
|
129
|
+
/** The prover for generating private kernel proofs. */
|
|
130
|
+
proofCreator: PrivateKernelProver;
|
|
131
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
132
|
+
simulator: CircuitSimulator;
|
|
133
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
134
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
135
|
+
/** PXE configuration options. */
|
|
136
|
+
config: PXEConfig;
|
|
137
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
138
|
+
loggerOrSuffix?: string | Logger;
|
|
139
|
+
};
|
|
140
|
+
|
|
88
141
|
/**
|
|
89
142
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
143
|
* manage private state of users.
|
|
@@ -103,6 +156,7 @@ export class PXE {
|
|
|
103
156
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
157
|
private addressStore: AddressStore,
|
|
105
158
|
private privateEventStore: PrivateEventStore,
|
|
159
|
+
private contractSyncService: ContractSyncService,
|
|
106
160
|
private simulator: CircuitSimulator,
|
|
107
161
|
private proverEnabled: boolean,
|
|
108
162
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,25 +174,31 @@ export class PXE {
|
|
|
120
174
|
*
|
|
121
175
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
176
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
177
|
+
public static async create({
|
|
178
|
+
node,
|
|
179
|
+
store,
|
|
180
|
+
proofCreator,
|
|
181
|
+
simulator,
|
|
182
|
+
protocolContractsProvider,
|
|
183
|
+
config,
|
|
184
|
+
loggerOrSuffix,
|
|
185
|
+
}: PXECreateArgs) {
|
|
186
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
187
|
+
const bindings: LoggerBindings | undefined =
|
|
188
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
189
|
+
|
|
132
190
|
const log =
|
|
133
191
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
192
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
135
193
|
: loggerOrSuffix;
|
|
136
194
|
|
|
137
|
-
const
|
|
195
|
+
const info = await node.getNodeInfo();
|
|
196
|
+
|
|
197
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
138
198
|
const addressStore = new AddressStore(store);
|
|
139
199
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
200
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
201
|
+
const noteStore = new NoteStore(store);
|
|
142
202
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
203
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
204
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,6 +206,12 @@ export class PXE {
|
|
|
146
206
|
const capsuleStore = new CapsuleStore(store);
|
|
147
207
|
const keyStore = new KeyStore(store);
|
|
148
208
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
209
|
+
const contractSyncService = new ContractSyncService(
|
|
210
|
+
node,
|
|
211
|
+
contractStore,
|
|
212
|
+
noteStore,
|
|
213
|
+
createLogger('pxe:contract_sync', bindings),
|
|
214
|
+
);
|
|
149
215
|
const synchronizer = new BlockSynchronizer(
|
|
150
216
|
node,
|
|
151
217
|
store,
|
|
@@ -153,14 +219,22 @@ export class PXE {
|
|
|
153
219
|
noteStore,
|
|
154
220
|
privateEventStore,
|
|
155
221
|
tipsStore,
|
|
222
|
+
contractSyncService,
|
|
156
223
|
config,
|
|
157
|
-
|
|
224
|
+
bindings,
|
|
158
225
|
);
|
|
159
226
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
-
jobCoordinator.registerStores([
|
|
227
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
228
|
+
jobCoordinator.registerStores([
|
|
229
|
+
capsuleStore,
|
|
230
|
+
senderTaggingStore,
|
|
231
|
+
recipientTaggingStore,
|
|
232
|
+
privateEventStore,
|
|
233
|
+
noteStore,
|
|
234
|
+
contractSyncService,
|
|
235
|
+
]);
|
|
162
236
|
|
|
163
|
-
const debugUtils = new PXEDebugUtils(
|
|
237
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
164
238
|
|
|
165
239
|
const jobQueue = new SerialQueue();
|
|
166
240
|
|
|
@@ -177,6 +251,7 @@ export class PXE {
|
|
|
177
251
|
recipientTaggingStore,
|
|
178
252
|
addressStore,
|
|
179
253
|
privateEventStore,
|
|
254
|
+
contractSyncService,
|
|
180
255
|
simulator,
|
|
181
256
|
proverEnabled,
|
|
182
257
|
proofCreator,
|
|
@@ -187,12 +262,15 @@ export class PXE {
|
|
|
187
262
|
debugUtils,
|
|
188
263
|
);
|
|
189
264
|
|
|
190
|
-
debugUtils.
|
|
265
|
+
debugUtils.setPXEHelpers(
|
|
266
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
267
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
268
|
+
pxe.#executeUtility.bind(pxe),
|
|
269
|
+
);
|
|
191
270
|
|
|
192
271
|
pxe.jobQueue.start();
|
|
193
272
|
|
|
194
273
|
await pxe.#registerProtocolContracts();
|
|
195
|
-
const info = await node.getNodeInfo();
|
|
196
274
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
197
275
|
return pxe;
|
|
198
276
|
}
|
|
@@ -202,20 +280,20 @@ export class PXE {
|
|
|
202
280
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
203
281
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
204
282
|
|
|
205
|
-
return new ContractFunctionSimulator(
|
|
206
|
-
proxyContractStore,
|
|
207
|
-
this.noteStore,
|
|
208
|
-
this.keyStore,
|
|
209
|
-
this.addressStore,
|
|
210
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
);
|
|
283
|
+
return new ContractFunctionSimulator({
|
|
284
|
+
contractStore: proxyContractStore,
|
|
285
|
+
noteStore: this.noteStore,
|
|
286
|
+
keyStore: this.keyStore,
|
|
287
|
+
addressStore: this.addressStore,
|
|
288
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
289
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
290
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
291
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
292
|
+
capsuleStore: this.capsuleStore,
|
|
293
|
+
privateEventStore: this.privateEventStore,
|
|
294
|
+
simulator: this.simulator,
|
|
295
|
+
contractSyncService: this.contractSyncService,
|
|
296
|
+
});
|
|
219
297
|
}
|
|
220
298
|
|
|
221
299
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -267,9 +345,8 @@ export class PXE {
|
|
|
267
345
|
async #registerProtocolContracts() {
|
|
268
346
|
const registered: Record<string, string> = {};
|
|
269
347
|
for (const name of protocolContractNames) {
|
|
270
|
-
const { address,
|
|
271
|
-
|
|
272
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
348
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
349
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
273
350
|
await this.contractStore.addContractInstance(instance);
|
|
274
351
|
registered[name] = address.toString();
|
|
275
352
|
}
|
|
@@ -281,7 +358,7 @@ export class PXE {
|
|
|
281
358
|
async #executePrivate(
|
|
282
359
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
283
360
|
txRequest: TxExecutionRequest,
|
|
284
|
-
scopes:
|
|
361
|
+
scopes: AccessScopes,
|
|
285
362
|
jobId: string,
|
|
286
363
|
): Promise<PrivateExecutionResult> {
|
|
287
364
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -289,18 +366,23 @@ export class PXE {
|
|
|
289
366
|
try {
|
|
290
367
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
291
368
|
|
|
292
|
-
|
|
293
|
-
txRequest,
|
|
369
|
+
await this.contractSyncService.ensureContractSynced(
|
|
294
370
|
contractAddress,
|
|
295
371
|
functionSelector,
|
|
296
|
-
|
|
372
|
+
(privateSyncCall, execScopes) =>
|
|
373
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
297
374
|
anchorBlockHeader,
|
|
298
|
-
// The sender for tags is set by contracts, typically by an account
|
|
299
|
-
// contract entrypoint
|
|
300
|
-
undefined, // senderForTags
|
|
301
|
-
scopes,
|
|
302
375
|
jobId,
|
|
376
|
+
scopes,
|
|
303
377
|
);
|
|
378
|
+
|
|
379
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
380
|
+
contractAddress,
|
|
381
|
+
selector: functionSelector,
|
|
382
|
+
anchorBlockHeader,
|
|
383
|
+
scopes,
|
|
384
|
+
jobId,
|
|
385
|
+
});
|
|
304
386
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
305
387
|
return result;
|
|
306
388
|
} catch (err) {
|
|
@@ -312,20 +394,20 @@ export class PXE {
|
|
|
312
394
|
}
|
|
313
395
|
|
|
314
396
|
/**
|
|
315
|
-
*
|
|
397
|
+
* Execute a utility function call on the given contract.
|
|
316
398
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
317
399
|
* @param call - The function call to execute.
|
|
318
400
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
319
401
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
320
402
|
* accounts if not specified.
|
|
321
403
|
* @param jobId - The job ID for staged writes.
|
|
322
|
-
* @returns The
|
|
404
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
323
405
|
*/
|
|
324
|
-
async #
|
|
406
|
+
async #executeUtility(
|
|
325
407
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
326
408
|
call: FunctionCall,
|
|
327
409
|
authWitnesses: AuthWitness[] | undefined,
|
|
328
|
-
scopes:
|
|
410
|
+
scopes: AccessScopes,
|
|
329
411
|
jobId: string,
|
|
330
412
|
) {
|
|
331
413
|
try {
|
|
@@ -384,15 +466,33 @@ export class PXE {
|
|
|
384
466
|
config: PrivateKernelExecutionProverConfig,
|
|
385
467
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
386
468
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
-
const anchorBlockHash =
|
|
469
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
388
470
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
389
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
471
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
472
|
+
kernelOracle,
|
|
473
|
+
proofCreator,
|
|
474
|
+
!this.proverEnabled,
|
|
475
|
+
this.log.getBindings(),
|
|
476
|
+
);
|
|
390
477
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
391
478
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
392
479
|
}
|
|
393
480
|
|
|
394
481
|
// Public API
|
|
395
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Returns the block header up to which the PXE has synced.
|
|
485
|
+
* @returns The synced block header
|
|
486
|
+
*/
|
|
487
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
488
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
493
|
+
* @param address - The contract address.
|
|
494
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
495
|
+
*/
|
|
396
496
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
397
497
|
return this.contractStore.getContractInstance(address);
|
|
398
498
|
}
|
|
@@ -428,7 +528,6 @@ export class PXE {
|
|
|
428
528
|
}
|
|
429
529
|
|
|
430
530
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
431
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
432
531
|
return accountCompleteAddress;
|
|
433
532
|
}
|
|
434
533
|
|
|
@@ -502,8 +601,7 @@ export class PXE {
|
|
|
502
601
|
* @param artifact - The build artifact for the contract class.
|
|
503
602
|
*/
|
|
504
603
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
505
|
-
const
|
|
506
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
604
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
507
605
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
508
606
|
}
|
|
509
607
|
|
|
@@ -522,17 +620,17 @@ export class PXE {
|
|
|
522
620
|
if (artifact) {
|
|
523
621
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
524
622
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
525
|
-
|
|
526
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
623
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
527
624
|
throw new Error(
|
|
528
|
-
`Artifact does not match expected class id (computed ${
|
|
625
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
529
626
|
);
|
|
530
627
|
}
|
|
531
628
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
532
629
|
if (!computedAddress.equals(instance.address)) {
|
|
533
630
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
534
631
|
}
|
|
535
|
-
|
|
632
|
+
|
|
633
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
536
634
|
|
|
537
635
|
const publicFunctionSignatures = artifact.functions
|
|
538
636
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -581,15 +679,16 @@ export class PXE {
|
|
|
581
679
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
582
680
|
}
|
|
583
681
|
|
|
584
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
585
|
-
|
|
586
682
|
const publicFunctionSignatures = artifact.functions
|
|
587
683
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
588
684
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
589
685
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
590
686
|
|
|
591
687
|
currentInstance.currentContractClassId = contractClass.id;
|
|
592
|
-
await
|
|
688
|
+
await Promise.all([
|
|
689
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
690
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
691
|
+
]);
|
|
593
692
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
594
693
|
});
|
|
595
694
|
}
|
|
@@ -607,11 +706,12 @@ export class PXE {
|
|
|
607
706
|
* (where validators prove the public portion).
|
|
608
707
|
*
|
|
609
708
|
* @param txRequest - An authenticated tx request ready for proving
|
|
709
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
610
710
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
611
711
|
* @throws If contract code not found, or public simulation reverts.
|
|
612
712
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
613
713
|
*/
|
|
614
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
714
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
615
715
|
let privateExecutionResult: PrivateExecutionResult;
|
|
616
716
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
617
717
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -622,7 +722,7 @@ export class PXE {
|
|
|
622
722
|
await this.blockStateSynchronizer.sync();
|
|
623
723
|
const syncTime = syncTimer.ms();
|
|
624
724
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
625
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
725
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
626
726
|
|
|
627
727
|
const {
|
|
628
728
|
publicInputs,
|
|
@@ -686,17 +786,13 @@ export class PXE {
|
|
|
686
786
|
|
|
687
787
|
/**
|
|
688
788
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
689
|
-
*
|
|
690
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
691
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
692
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
789
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
693
790
|
* @returns A trace of the program execution with gate counts.
|
|
694
791
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
695
792
|
*/
|
|
696
793
|
public profileTx(
|
|
697
794
|
txRequest: TxExecutionRequest,
|
|
698
|
-
profileMode
|
|
699
|
-
skipProofGeneration: boolean = true,
|
|
795
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
700
796
|
): Promise<TxProfileResult> {
|
|
701
797
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
702
798
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -719,12 +815,7 @@ export class PXE {
|
|
|
719
815
|
const syncTime = syncTimer.ms();
|
|
720
816
|
|
|
721
817
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
722
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
723
|
-
contractFunctionSimulator,
|
|
724
|
-
txRequest,
|
|
725
|
-
undefined,
|
|
726
|
-
jobId,
|
|
727
|
-
);
|
|
818
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
728
819
|
|
|
729
820
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
730
821
|
txRequest,
|
|
@@ -781,12 +872,7 @@ export class PXE {
|
|
|
781
872
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
782
873
|
*
|
|
783
874
|
*
|
|
784
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
785
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
786
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
787
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
788
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
789
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
875
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
790
876
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
791
877
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
792
878
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -795,11 +881,7 @@ export class PXE {
|
|
|
795
881
|
*/
|
|
796
882
|
public simulateTx(
|
|
797
883
|
txRequest: TxExecutionRequest,
|
|
798
|
-
simulatePublic:
|
|
799
|
-
skipTxValidation: boolean = false,
|
|
800
|
-
skipFeeEnforcement: boolean = false,
|
|
801
|
-
overrides?: SimulationOverrides,
|
|
802
|
-
scopes?: AztecAddress[],
|
|
884
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
803
885
|
): Promise<TxSimulationResult> {
|
|
804
886
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
805
887
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -827,7 +909,14 @@ export class PXE {
|
|
|
827
909
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
828
910
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
829
911
|
// or not.
|
|
830
|
-
const
|
|
912
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
913
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
914
|
+
const skipKernels = hasOverriddenContracts;
|
|
915
|
+
|
|
916
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
917
|
+
if (hasOverriddenContracts) {
|
|
918
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
919
|
+
}
|
|
831
920
|
|
|
832
921
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
833
922
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -838,7 +927,8 @@ export class PXE {
|
|
|
838
927
|
if (skipKernels) {
|
|
839
928
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
840
929
|
privateExecutionResult,
|
|
841
|
-
this.contractStore,
|
|
930
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
931
|
+
this.node,
|
|
842
932
|
));
|
|
843
933
|
} else {
|
|
844
934
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -857,6 +947,9 @@ export class PXE {
|
|
|
857
947
|
const publicSimulationTimer = new Timer();
|
|
858
948
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
859
949
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
950
|
+
if (publicOutput?.debugLogs?.length) {
|
|
951
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
952
|
+
}
|
|
860
953
|
}
|
|
861
954
|
|
|
862
955
|
let validationTime: number | undefined;
|
|
@@ -865,7 +958,8 @@ export class PXE {
|
|
|
865
958
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
866
959
|
validationTime = validationTimer.ms();
|
|
867
960
|
if (validationResult.result === 'invalid') {
|
|
868
|
-
|
|
961
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
962
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
869
963
|
}
|
|
870
964
|
}
|
|
871
965
|
|
|
@@ -916,29 +1010,23 @@ export class PXE {
|
|
|
916
1010
|
inspect(txRequest),
|
|
917
1011
|
`simulatePublic=${simulatePublic}`,
|
|
918
1012
|
`skipTxValidation=${skipTxValidation}`,
|
|
919
|
-
`scopes=${scopes
|
|
1013
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
920
1014
|
);
|
|
921
1015
|
}
|
|
922
1016
|
});
|
|
923
1017
|
}
|
|
924
1018
|
|
|
925
1019
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
1020
|
+
* Executes a contract utility function.
|
|
928
1021
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
929
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
930
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
931
|
-
* default to all.
|
|
932
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
933
1022
|
*/
|
|
934
|
-
public
|
|
1023
|
+
public executeUtility(
|
|
935
1024
|
call: FunctionCall,
|
|
936
|
-
authwits
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1025
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1026
|
+
): Promise<UtilityExecutionResult> {
|
|
1027
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
940
1028
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
941
|
-
// delete the same read value, or reading values that another
|
|
1029
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
942
1030
|
return this.#putInJobQueue(async jobId => {
|
|
943
1031
|
try {
|
|
944
1032
|
const totalTimer = new Timer();
|
|
@@ -948,11 +1036,18 @@ export class PXE {
|
|
|
948
1036
|
const functionTimer = new Timer();
|
|
949
1037
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
950
1038
|
|
|
951
|
-
await this.
|
|
952
|
-
|
|
1039
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1040
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1041
|
+
call.to,
|
|
1042
|
+
call.selector,
|
|
1043
|
+
(privateSyncCall, execScopes) =>
|
|
1044
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1045
|
+
anchorBlockHeader,
|
|
1046
|
+
jobId,
|
|
1047
|
+
scopes,
|
|
953
1048
|
);
|
|
954
1049
|
|
|
955
|
-
const executionResult = await this.#
|
|
1050
|
+
const executionResult = await this.#executeUtility(
|
|
956
1051
|
contractFunctionSimulator,
|
|
957
1052
|
call,
|
|
958
1053
|
authwits ?? [],
|
|
@@ -979,8 +1074,8 @@ export class PXE {
|
|
|
979
1074
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
980
1075
|
throw this.#contextualizeError(
|
|
981
1076
|
err,
|
|
982
|
-
`
|
|
983
|
-
`scopes=${scopes
|
|
1077
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1078
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
984
1079
|
);
|
|
985
1080
|
}
|
|
986
1081
|
});
|
|
@@ -1008,15 +1103,19 @@ export class PXE {
|
|
|
1008
1103
|
await this.#putInJobQueue(async jobId => {
|
|
1009
1104
|
await this.blockStateSynchronizer.sync();
|
|
1010
1105
|
|
|
1011
|
-
|
|
1106
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1107
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1012
1108
|
|
|
1013
1109
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
1110
|
|
|
1015
|
-
await this.
|
|
1111
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1016
1112
|
filter.contractAddress,
|
|
1017
1113
|
null,
|
|
1018
|
-
async privateSyncCall =>
|
|
1019
|
-
await this.#
|
|
1114
|
+
async (privateSyncCall, execScopes) =>
|
|
1115
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1116
|
+
anchorBlockHeader,
|
|
1117
|
+
jobId,
|
|
1118
|
+
filter.scopes,
|
|
1020
1119
|
);
|
|
1021
1120
|
});
|
|
1022
1121
|
|