@aztec/pxe 0.0.1-commit.3469e52 → 0.0.1-commit.3895657bc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -16
- package/dest/config/index.d.ts +4 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +18 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +178 -77
- 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 +48 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -42
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +170 -105
- 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 +1 -38
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +61 -53
- 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 -55
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +80 -50
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +126 -113
- 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 +5 -4
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +71 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +110 -70
- 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 +15 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +327 -140
- 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 +56 -47
- package/src/contract_function_simulator/oracle/oracle.ts +176 -118
- package/src/contract_function_simulator/oracle/private_execution.ts +2 -61
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +151 -135
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +191 -127
- 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 +5 -4
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +9 -9
- package/src/pxe.ts +217 -115
- 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.
|
|
@@ -92,6 +145,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
145
|
export class PXE {
|
|
93
146
|
private constructor(
|
|
94
147
|
private node: AztecNode,
|
|
148
|
+
private db: AztecAsyncKVStore,
|
|
95
149
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
150
|
private keyStore: KeyStore,
|
|
97
151
|
private contractStore: ContractStore,
|
|
@@ -103,6 +157,7 @@ export class PXE {
|
|
|
103
157
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
158
|
private addressStore: AddressStore,
|
|
105
159
|
private privateEventStore: PrivateEventStore,
|
|
160
|
+
private contractSyncService: ContractSyncService,
|
|
106
161
|
private simulator: CircuitSimulator,
|
|
107
162
|
private proverEnabled: boolean,
|
|
108
163
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,25 +175,31 @@ export class PXE {
|
|
|
120
175
|
*
|
|
121
176
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
177
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
178
|
+
public static async create({
|
|
179
|
+
node,
|
|
180
|
+
store,
|
|
181
|
+
proofCreator,
|
|
182
|
+
simulator,
|
|
183
|
+
protocolContractsProvider,
|
|
184
|
+
config,
|
|
185
|
+
loggerOrSuffix,
|
|
186
|
+
}: PXECreateArgs) {
|
|
187
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
188
|
+
const bindings: LoggerBindings | undefined =
|
|
189
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
190
|
+
|
|
132
191
|
const log =
|
|
133
192
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
193
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
135
194
|
: loggerOrSuffix;
|
|
136
195
|
|
|
137
|
-
const
|
|
196
|
+
const info = await node.getNodeInfo();
|
|
197
|
+
|
|
198
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
138
199
|
const addressStore = new AddressStore(store);
|
|
139
200
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
201
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
202
|
+
const noteStore = new NoteStore(store);
|
|
142
203
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
204
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
205
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,6 +207,12 @@ export class PXE {
|
|
|
146
207
|
const capsuleStore = new CapsuleStore(store);
|
|
147
208
|
const keyStore = new KeyStore(store);
|
|
148
209
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
210
|
+
const contractSyncService = new ContractSyncService(
|
|
211
|
+
node,
|
|
212
|
+
contractStore,
|
|
213
|
+
noteStore,
|
|
214
|
+
createLogger('pxe:contract_sync', bindings),
|
|
215
|
+
);
|
|
149
216
|
const synchronizer = new BlockSynchronizer(
|
|
150
217
|
node,
|
|
151
218
|
store,
|
|
@@ -153,19 +220,28 @@ export class PXE {
|
|
|
153
220
|
noteStore,
|
|
154
221
|
privateEventStore,
|
|
155
222
|
tipsStore,
|
|
223
|
+
contractSyncService,
|
|
156
224
|
config,
|
|
157
|
-
|
|
225
|
+
bindings,
|
|
158
226
|
);
|
|
159
227
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
-
jobCoordinator.registerStores([
|
|
228
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
229
|
+
jobCoordinator.registerStores([
|
|
230
|
+
capsuleStore,
|
|
231
|
+
senderTaggingStore,
|
|
232
|
+
recipientTaggingStore,
|
|
233
|
+
privateEventStore,
|
|
234
|
+
noteStore,
|
|
235
|
+
contractSyncService,
|
|
236
|
+
]);
|
|
162
237
|
|
|
163
|
-
const debugUtils = new PXEDebugUtils(
|
|
238
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
164
239
|
|
|
165
240
|
const jobQueue = new SerialQueue();
|
|
166
241
|
|
|
167
242
|
const pxe = new PXE(
|
|
168
243
|
node,
|
|
244
|
+
store,
|
|
169
245
|
synchronizer,
|
|
170
246
|
keyStore,
|
|
171
247
|
contractStore,
|
|
@@ -177,6 +253,7 @@ export class PXE {
|
|
|
177
253
|
recipientTaggingStore,
|
|
178
254
|
addressStore,
|
|
179
255
|
privateEventStore,
|
|
256
|
+
contractSyncService,
|
|
180
257
|
simulator,
|
|
181
258
|
proverEnabled,
|
|
182
259
|
proofCreator,
|
|
@@ -187,12 +264,15 @@ export class PXE {
|
|
|
187
264
|
debugUtils,
|
|
188
265
|
);
|
|
189
266
|
|
|
190
|
-
debugUtils.
|
|
267
|
+
debugUtils.setPXEHelpers(
|
|
268
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
269
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
270
|
+
pxe.#executeUtility.bind(pxe),
|
|
271
|
+
);
|
|
191
272
|
|
|
192
273
|
pxe.jobQueue.start();
|
|
193
274
|
|
|
194
275
|
await pxe.#registerProtocolContracts();
|
|
195
|
-
const info = await node.getNodeInfo();
|
|
196
276
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
197
277
|
return pxe;
|
|
198
278
|
}
|
|
@@ -202,20 +282,20 @@ export class PXE {
|
|
|
202
282
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
203
283
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
204
284
|
|
|
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
|
-
);
|
|
285
|
+
return new ContractFunctionSimulator({
|
|
286
|
+
contractStore: proxyContractStore,
|
|
287
|
+
noteStore: this.noteStore,
|
|
288
|
+
keyStore: this.keyStore,
|
|
289
|
+
addressStore: this.addressStore,
|
|
290
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
291
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
292
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
293
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
294
|
+
capsuleStore: this.capsuleStore,
|
|
295
|
+
privateEventStore: this.privateEventStore,
|
|
296
|
+
simulator: this.simulator,
|
|
297
|
+
contractSyncService: this.contractSyncService,
|
|
298
|
+
});
|
|
219
299
|
}
|
|
220
300
|
|
|
221
301
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -267,9 +347,8 @@ export class PXE {
|
|
|
267
347
|
async #registerProtocolContracts() {
|
|
268
348
|
const registered: Record<string, string> = {};
|
|
269
349
|
for (const name of protocolContractNames) {
|
|
270
|
-
const { address,
|
|
271
|
-
|
|
272
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
350
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
351
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
273
352
|
await this.contractStore.addContractInstance(instance);
|
|
274
353
|
registered[name] = address.toString();
|
|
275
354
|
}
|
|
@@ -281,7 +360,7 @@ export class PXE {
|
|
|
281
360
|
async #executePrivate(
|
|
282
361
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
283
362
|
txRequest: TxExecutionRequest,
|
|
284
|
-
scopes:
|
|
363
|
+
scopes: AccessScopes,
|
|
285
364
|
jobId: string,
|
|
286
365
|
): Promise<PrivateExecutionResult> {
|
|
287
366
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -289,18 +368,23 @@ export class PXE {
|
|
|
289
368
|
try {
|
|
290
369
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
291
370
|
|
|
292
|
-
|
|
293
|
-
txRequest,
|
|
371
|
+
await this.contractSyncService.ensureContractSynced(
|
|
294
372
|
contractAddress,
|
|
295
373
|
functionSelector,
|
|
296
|
-
|
|
374
|
+
(privateSyncCall, execScopes) =>
|
|
375
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
297
376
|
anchorBlockHeader,
|
|
298
|
-
// The sender for tags is set by contracts, typically by an account
|
|
299
|
-
// contract entrypoint
|
|
300
|
-
undefined, // senderForTags
|
|
301
|
-
scopes,
|
|
302
377
|
jobId,
|
|
378
|
+
scopes,
|
|
303
379
|
);
|
|
380
|
+
|
|
381
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
382
|
+
contractAddress,
|
|
383
|
+
selector: functionSelector,
|
|
384
|
+
anchorBlockHeader,
|
|
385
|
+
scopes,
|
|
386
|
+
jobId,
|
|
387
|
+
});
|
|
304
388
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
305
389
|
return result;
|
|
306
390
|
} catch (err) {
|
|
@@ -312,20 +396,20 @@ export class PXE {
|
|
|
312
396
|
}
|
|
313
397
|
|
|
314
398
|
/**
|
|
315
|
-
*
|
|
399
|
+
* Execute a utility function call on the given contract.
|
|
316
400
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
317
401
|
* @param call - The function call to execute.
|
|
318
402
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
319
403
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
320
404
|
* accounts if not specified.
|
|
321
405
|
* @param jobId - The job ID for staged writes.
|
|
322
|
-
* @returns The
|
|
406
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
323
407
|
*/
|
|
324
|
-
async #
|
|
408
|
+
async #executeUtility(
|
|
325
409
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
326
410
|
call: FunctionCall,
|
|
327
411
|
authWitnesses: AuthWitness[] | undefined,
|
|
328
|
-
scopes:
|
|
412
|
+
scopes: AccessScopes,
|
|
329
413
|
jobId: string,
|
|
330
414
|
) {
|
|
331
415
|
try {
|
|
@@ -384,15 +468,33 @@ export class PXE {
|
|
|
384
468
|
config: PrivateKernelExecutionProverConfig,
|
|
385
469
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
386
470
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
-
const anchorBlockHash =
|
|
471
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
388
472
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
389
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
473
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
474
|
+
kernelOracle,
|
|
475
|
+
proofCreator,
|
|
476
|
+
!this.proverEnabled,
|
|
477
|
+
this.log.getBindings(),
|
|
478
|
+
);
|
|
390
479
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
391
480
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
392
481
|
}
|
|
393
482
|
|
|
394
483
|
// Public API
|
|
395
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Returns the block header up to which the PXE has synced.
|
|
487
|
+
* @returns The synced block header
|
|
488
|
+
*/
|
|
489
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
490
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
495
|
+
* @param address - The contract address.
|
|
496
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
497
|
+
*/
|
|
396
498
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
397
499
|
return this.contractStore.getContractInstance(address);
|
|
398
500
|
}
|
|
@@ -428,7 +530,6 @@ export class PXE {
|
|
|
428
530
|
}
|
|
429
531
|
|
|
430
532
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
431
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
432
533
|
return accountCompleteAddress;
|
|
433
534
|
}
|
|
434
535
|
|
|
@@ -502,8 +603,7 @@ export class PXE {
|
|
|
502
603
|
* @param artifact - The build artifact for the contract class.
|
|
503
604
|
*/
|
|
504
605
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
505
|
-
const
|
|
506
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
606
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
507
607
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
508
608
|
}
|
|
509
609
|
|
|
@@ -522,17 +622,17 @@ export class PXE {
|
|
|
522
622
|
if (artifact) {
|
|
523
623
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
524
624
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
525
|
-
|
|
526
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
625
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
527
626
|
throw new Error(
|
|
528
|
-
`Artifact does not match expected class id (computed ${
|
|
627
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
529
628
|
);
|
|
530
629
|
}
|
|
531
630
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
532
631
|
if (!computedAddress.equals(instance.address)) {
|
|
533
632
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
534
633
|
}
|
|
535
|
-
|
|
634
|
+
|
|
635
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
536
636
|
|
|
537
637
|
const publicFunctionSignatures = artifact.functions
|
|
538
638
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -581,15 +681,16 @@ export class PXE {
|
|
|
581
681
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
582
682
|
}
|
|
583
683
|
|
|
584
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
585
|
-
|
|
586
684
|
const publicFunctionSignatures = artifact.functions
|
|
587
685
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
588
686
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
589
687
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
590
688
|
|
|
591
689
|
currentInstance.currentContractClassId = contractClass.id;
|
|
592
|
-
await
|
|
690
|
+
await Promise.all([
|
|
691
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
692
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
693
|
+
]);
|
|
593
694
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
594
695
|
});
|
|
595
696
|
}
|
|
@@ -607,11 +708,12 @@ export class PXE {
|
|
|
607
708
|
* (where validators prove the public portion).
|
|
608
709
|
*
|
|
609
710
|
* @param txRequest - An authenticated tx request ready for proving
|
|
711
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
610
712
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
611
713
|
* @throws If contract code not found, or public simulation reverts.
|
|
612
714
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
613
715
|
*/
|
|
614
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
716
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
615
717
|
let privateExecutionResult: PrivateExecutionResult;
|
|
616
718
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
617
719
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -622,7 +724,7 @@ export class PXE {
|
|
|
622
724
|
await this.blockStateSynchronizer.sync();
|
|
623
725
|
const syncTime = syncTimer.ms();
|
|
624
726
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
625
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
727
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
626
728
|
|
|
627
729
|
const {
|
|
628
730
|
publicInputs,
|
|
@@ -686,17 +788,13 @@ export class PXE {
|
|
|
686
788
|
|
|
687
789
|
/**
|
|
688
790
|
* 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.
|
|
791
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
693
792
|
* @returns A trace of the program execution with gate counts.
|
|
694
793
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
695
794
|
*/
|
|
696
795
|
public profileTx(
|
|
697
796
|
txRequest: TxExecutionRequest,
|
|
698
|
-
profileMode
|
|
699
|
-
skipProofGeneration: boolean = true,
|
|
797
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
700
798
|
): Promise<TxProfileResult> {
|
|
701
799
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
702
800
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -719,12 +817,7 @@ export class PXE {
|
|
|
719
817
|
const syncTime = syncTimer.ms();
|
|
720
818
|
|
|
721
819
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
722
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
723
|
-
contractFunctionSimulator,
|
|
724
|
-
txRequest,
|
|
725
|
-
undefined,
|
|
726
|
-
jobId,
|
|
727
|
-
);
|
|
820
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
728
821
|
|
|
729
822
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
730
823
|
txRequest,
|
|
@@ -781,12 +874,7 @@ export class PXE {
|
|
|
781
874
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
782
875
|
*
|
|
783
876
|
*
|
|
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.
|
|
877
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
790
878
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
791
879
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
792
880
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -795,11 +883,7 @@ export class PXE {
|
|
|
795
883
|
*/
|
|
796
884
|
public simulateTx(
|
|
797
885
|
txRequest: TxExecutionRequest,
|
|
798
|
-
simulatePublic:
|
|
799
|
-
skipTxValidation: boolean = false,
|
|
800
|
-
skipFeeEnforcement: boolean = false,
|
|
801
|
-
overrides?: SimulationOverrides,
|
|
802
|
-
scopes?: AztecAddress[],
|
|
886
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
803
887
|
): Promise<TxSimulationResult> {
|
|
804
888
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
805
889
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -827,7 +911,14 @@ export class PXE {
|
|
|
827
911
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
828
912
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
829
913
|
// or not.
|
|
830
|
-
const
|
|
914
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
915
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
916
|
+
const skipKernels = hasOverriddenContracts;
|
|
917
|
+
|
|
918
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
919
|
+
if (hasOverriddenContracts) {
|
|
920
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
921
|
+
}
|
|
831
922
|
|
|
832
923
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
833
924
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -838,7 +929,8 @@ export class PXE {
|
|
|
838
929
|
if (skipKernels) {
|
|
839
930
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
840
931
|
privateExecutionResult,
|
|
841
|
-
this.contractStore,
|
|
932
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
933
|
+
this.node,
|
|
842
934
|
));
|
|
843
935
|
} else {
|
|
844
936
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -857,6 +949,9 @@ export class PXE {
|
|
|
857
949
|
const publicSimulationTimer = new Timer();
|
|
858
950
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
859
951
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
952
|
+
if (publicOutput?.debugLogs?.length) {
|
|
953
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
954
|
+
}
|
|
860
955
|
}
|
|
861
956
|
|
|
862
957
|
let validationTime: number | undefined;
|
|
@@ -865,7 +960,8 @@ export class PXE {
|
|
|
865
960
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
866
961
|
validationTime = validationTimer.ms();
|
|
867
962
|
if (validationResult.result === 'invalid') {
|
|
868
|
-
|
|
963
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
964
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
869
965
|
}
|
|
870
966
|
}
|
|
871
967
|
|
|
@@ -916,29 +1012,23 @@ export class PXE {
|
|
|
916
1012
|
inspect(txRequest),
|
|
917
1013
|
`simulatePublic=${simulatePublic}`,
|
|
918
1014
|
`skipTxValidation=${skipTxValidation}`,
|
|
919
|
-
`scopes=${scopes
|
|
1015
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
920
1016
|
);
|
|
921
1017
|
}
|
|
922
1018
|
});
|
|
923
1019
|
}
|
|
924
1020
|
|
|
925
1021
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
1022
|
+
* Executes a contract utility function.
|
|
928
1023
|
* @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
1024
|
*/
|
|
934
|
-
public
|
|
1025
|
+
public executeUtility(
|
|
935
1026
|
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.
|
|
1027
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
1028
|
+
): Promise<UtilityExecutionResult> {
|
|
1029
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
940
1030
|
// 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
|
|
1031
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
942
1032
|
return this.#putInJobQueue(async jobId => {
|
|
943
1033
|
try {
|
|
944
1034
|
const totalTimer = new Timer();
|
|
@@ -948,11 +1038,18 @@ export class PXE {
|
|
|
948
1038
|
const functionTimer = new Timer();
|
|
949
1039
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
950
1040
|
|
|
951
|
-
await this.
|
|
952
|
-
|
|
1041
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1042
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1043
|
+
call.to,
|
|
1044
|
+
call.selector,
|
|
1045
|
+
(privateSyncCall, execScopes) =>
|
|
1046
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1047
|
+
anchorBlockHeader,
|
|
1048
|
+
jobId,
|
|
1049
|
+
scopes,
|
|
953
1050
|
);
|
|
954
1051
|
|
|
955
|
-
const executionResult = await this.#
|
|
1052
|
+
const executionResult = await this.#executeUtility(
|
|
956
1053
|
contractFunctionSimulator,
|
|
957
1054
|
call,
|
|
958
1055
|
authwits ?? [],
|
|
@@ -979,8 +1076,8 @@ export class PXE {
|
|
|
979
1076
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
980
1077
|
throw this.#contextualizeError(
|
|
981
1078
|
err,
|
|
982
|
-
`
|
|
983
|
-
`scopes=${scopes
|
|
1079
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1080
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
984
1081
|
);
|
|
985
1082
|
}
|
|
986
1083
|
});
|
|
@@ -1008,15 +1105,19 @@ export class PXE {
|
|
|
1008
1105
|
await this.#putInJobQueue(async jobId => {
|
|
1009
1106
|
await this.blockStateSynchronizer.sync();
|
|
1010
1107
|
|
|
1011
|
-
|
|
1108
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1109
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1012
1110
|
|
|
1013
1111
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
1112
|
|
|
1015
|
-
await this.
|
|
1113
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1016
1114
|
filter.contractAddress,
|
|
1017
1115
|
null,
|
|
1018
|
-
async privateSyncCall =>
|
|
1019
|
-
await this.#
|
|
1116
|
+
async (privateSyncCall, execScopes) =>
|
|
1117
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1118
|
+
anchorBlockHeader,
|
|
1119
|
+
jobId,
|
|
1120
|
+
filter.scopes,
|
|
1020
1121
|
);
|
|
1021
1122
|
});
|
|
1022
1123
|
|
|
@@ -1031,9 +1132,10 @@ export class PXE {
|
|
|
1031
1132
|
}
|
|
1032
1133
|
|
|
1033
1134
|
/**
|
|
1034
|
-
* Stops the PXE's job queue.
|
|
1135
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1035
1136
|
*/
|
|
1036
|
-
public stop(): Promise<void> {
|
|
1037
|
-
|
|
1137
|
+
public async stop(): Promise<void> {
|
|
1138
|
+
await this.jobQueue.end();
|
|
1139
|
+
await this.db.close();
|
|
1038
1140
|
}
|
|
1039
1141
|
}
|