@aztec/pxe 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/check_oracle_version.js +4 -4
- package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
- package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
- package/dest/block_synchronizer/block_stream_source.js +37 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +30 -10
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -15
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +62 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +206 -76
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +63 -45
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +76 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +289 -97
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +58 -86
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +121 -95
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +124 -64
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +356 -126
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +7 -4
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +69 -35
- package/dest/contract_sync/helpers.d.ts +2 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +9 -4
- package/dest/debug/pxe_debug_utils.d.ts +5 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +4 -7
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +11 -3
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +11 -3
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +3 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -1
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +11 -3
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +26 -5
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +7 -7
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +33 -48
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -7
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +18 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +19 -18
- package/dest/pxe.d.ts +84 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +153 -83
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +36 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +148 -70
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +3 -0
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -5
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -22
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +6 -7
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_stream_source.ts +52 -0
- package/src/block_synchronizer/block_synchronizer.ts +33 -11
- package/src/config/index.ts +3 -9
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +366 -138
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
- package/src/contract_function_simulator/oracle/interfaces.ts +91 -53
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +378 -140
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +151 -183
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +598 -156
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +102 -55
- package/src/contract_sync/helpers.ts +8 -3
- package/src/debug/pxe_debug_utils.ts +11 -14
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +11 -4
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +11 -4
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +2 -1
- package/src/entrypoints/server/utils.ts +9 -10
- package/src/events/event_service.ts +30 -5
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +63 -91
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +19 -8
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +18 -16
- package/src/private_kernel/private_kernel_oracle.ts +21 -21
- package/src/pxe.ts +278 -131
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +44 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +181 -80
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +5 -5
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/storage/tagging_store/recipient_tagging_store.ts +9 -5
- package/src/storage/tagging_store/sender_tagging_store.ts +185 -138
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +12 -25
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +10 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +23 -10
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +27 -26
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
package/src/pxe.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
+
import type { L2TipsProvider } from '@aztec/stdlib/block';
|
|
21
22
|
import {
|
|
22
23
|
CompleteAddress,
|
|
23
24
|
type ContractInstanceWithAddress,
|
|
@@ -33,6 +34,7 @@ import type {
|
|
|
33
34
|
PrivateKernelTailCircuitPublicInputs,
|
|
34
35
|
} from '@aztec/stdlib/kernel';
|
|
35
36
|
import {
|
|
37
|
+
BlockHeader,
|
|
36
38
|
type ContractOverrides,
|
|
37
39
|
type InTx,
|
|
38
40
|
PrivateExecutionResult,
|
|
@@ -46,7 +48,7 @@ import {
|
|
|
46
48
|
TxProfileResult,
|
|
47
49
|
TxProvingResult,
|
|
48
50
|
TxSimulationResult,
|
|
49
|
-
|
|
51
|
+
UtilityExecutionResult,
|
|
50
52
|
} from '@aztec/stdlib/tx';
|
|
51
53
|
|
|
52
54
|
import { inspect } from 'util';
|
|
@@ -59,12 +61,14 @@ import {
|
|
|
59
61
|
generateSimulatedProvingResult,
|
|
60
62
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
63
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
62
65
|
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
63
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';
|
|
67
70
|
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
68
72
|
import {
|
|
69
73
|
PrivateKernelExecutionProver,
|
|
70
74
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -85,6 +89,70 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
89
|
eventSelector: EventSelector;
|
|
86
90
|
};
|
|
87
91
|
|
|
92
|
+
/** Options for PXE.proveTx. */
|
|
93
|
+
export type ProveTxOpts = {
|
|
94
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
95
|
+
scopes: AztecAddress[];
|
|
96
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
97
|
+
senderForTags?: AztecAddress;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Options for PXE.profileTx. */
|
|
101
|
+
export type ProfileTxOpts = {
|
|
102
|
+
/** The profiling mode to use. */
|
|
103
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
104
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
105
|
+
skipProofGeneration?: boolean;
|
|
106
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
107
|
+
scopes: AztecAddress[];
|
|
108
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
109
|
+
senderForTags?: AztecAddress;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Options for PXE.simulateTx. */
|
|
113
|
+
export type SimulateTxOpts = {
|
|
114
|
+
/** Whether to simulate the public part of the transaction. */
|
|
115
|
+
simulatePublic: boolean;
|
|
116
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
117
|
+
skipTxValidation?: boolean;
|
|
118
|
+
/** If false, fees are enforced. */
|
|
119
|
+
skipFeeEnforcement?: boolean;
|
|
120
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
121
|
+
skipKernels?: boolean;
|
|
122
|
+
/** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
|
|
123
|
+
overrides?: SimulationOverrides;
|
|
124
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
125
|
+
scopes: AztecAddress[];
|
|
126
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
127
|
+
senderForTags?: AztecAddress;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** Options for PXE.executeUtility. */
|
|
131
|
+
export type ExecuteUtilityOpts = {
|
|
132
|
+
/** The authentication witnesses required for the function call. */
|
|
133
|
+
authwits?: AuthWitness[];
|
|
134
|
+
/** The accounts whose notes we can access in this call */
|
|
135
|
+
scopes: AztecAddress[];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Args for PXE.create. */
|
|
139
|
+
export type PXECreateArgs = {
|
|
140
|
+
/** The Aztec node to connect to. */
|
|
141
|
+
node: AztecNode;
|
|
142
|
+
/** The key-value store for persisting PXE state. */
|
|
143
|
+
store: AztecAsyncKVStore;
|
|
144
|
+
/** The prover for generating private kernel proofs. */
|
|
145
|
+
proofCreator: PrivateKernelProver;
|
|
146
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
147
|
+
simulator: CircuitSimulator;
|
|
148
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
149
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
150
|
+
/** PXE configuration options. */
|
|
151
|
+
config: PXEConfig;
|
|
152
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
153
|
+
loggerOrSuffix?: string | Logger;
|
|
154
|
+
};
|
|
155
|
+
|
|
88
156
|
/**
|
|
89
157
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
158
|
* manage private state of users.
|
|
@@ -92,6 +160,7 @@ export type PackedPrivateEvent = InTx & {
|
|
|
92
160
|
export class PXE {
|
|
93
161
|
private constructor(
|
|
94
162
|
private node: AztecNode,
|
|
163
|
+
private db: AztecAsyncKVStore,
|
|
95
164
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
96
165
|
private keyStore: KeyStore,
|
|
97
166
|
private contractStore: ContractStore,
|
|
@@ -104,6 +173,8 @@ export class PXE {
|
|
|
104
173
|
private addressStore: AddressStore,
|
|
105
174
|
private privateEventStore: PrivateEventStore,
|
|
106
175
|
private contractSyncService: ContractSyncService,
|
|
176
|
+
private messageContextService: MessageContextService,
|
|
177
|
+
private l2TipsStore: L2TipsProvider,
|
|
107
178
|
private simulator: CircuitSimulator,
|
|
108
179
|
private proverEnabled: boolean,
|
|
109
180
|
private proofCreator: PrivateKernelProver,
|
|
@@ -121,15 +192,15 @@ export class PXE {
|
|
|
121
192
|
*
|
|
122
193
|
* @returns A promise that resolves PXE is ready to be used.
|
|
123
194
|
*/
|
|
124
|
-
public static async create(
|
|
125
|
-
node
|
|
126
|
-
store
|
|
127
|
-
proofCreator
|
|
128
|
-
simulator
|
|
129
|
-
protocolContractsProvider
|
|
130
|
-
config
|
|
131
|
-
loggerOrSuffix
|
|
132
|
-
) {
|
|
195
|
+
public static async create({
|
|
196
|
+
node,
|
|
197
|
+
store,
|
|
198
|
+
proofCreator,
|
|
199
|
+
simulator,
|
|
200
|
+
protocolContractsProvider,
|
|
201
|
+
config,
|
|
202
|
+
loggerOrSuffix,
|
|
203
|
+
}: PXECreateArgs) {
|
|
133
204
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
134
205
|
const bindings: LoggerBindings | undefined =
|
|
135
206
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -139,7 +210,9 @@ export class PXE {
|
|
|
139
210
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
140
211
|
: loggerOrSuffix;
|
|
141
212
|
|
|
142
|
-
const
|
|
213
|
+
const info = await node.getNodeInfo();
|
|
214
|
+
|
|
215
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
143
216
|
const addressStore = new AddressStore(store);
|
|
144
217
|
const privateEventStore = new PrivateEventStore(store);
|
|
145
218
|
const contractStore = new ContractStore(store);
|
|
@@ -157,6 +230,8 @@ export class PXE {
|
|
|
157
230
|
noteStore,
|
|
158
231
|
createLogger('pxe:contract_sync', bindings),
|
|
159
232
|
);
|
|
233
|
+
const messageContextService = new MessageContextService(node);
|
|
234
|
+
|
|
160
235
|
const synchronizer = new BlockSynchronizer(
|
|
161
236
|
node,
|
|
162
237
|
store,
|
|
@@ -185,6 +260,7 @@ export class PXE {
|
|
|
185
260
|
|
|
186
261
|
const pxe = new PXE(
|
|
187
262
|
node,
|
|
263
|
+
store,
|
|
188
264
|
synchronizer,
|
|
189
265
|
keyStore,
|
|
190
266
|
contractStore,
|
|
@@ -197,6 +273,8 @@ export class PXE {
|
|
|
197
273
|
addressStore,
|
|
198
274
|
privateEventStore,
|
|
199
275
|
contractSyncService,
|
|
276
|
+
messageContextService,
|
|
277
|
+
tipsStore,
|
|
200
278
|
simulator,
|
|
201
279
|
proverEnabled,
|
|
202
280
|
proofCreator,
|
|
@@ -210,13 +288,12 @@ export class PXE {
|
|
|
210
288
|
debugUtils.setPXEHelpers(
|
|
211
289
|
pxe.#putInJobQueue.bind(pxe),
|
|
212
290
|
pxe.#getSimulatorForTx.bind(pxe),
|
|
213
|
-
pxe.#
|
|
291
|
+
pxe.#executeUtility.bind(pxe),
|
|
214
292
|
);
|
|
215
293
|
|
|
216
294
|
pxe.jobQueue.start();
|
|
217
295
|
|
|
218
296
|
await pxe.#registerProtocolContracts();
|
|
219
|
-
const info = await node.getNodeInfo();
|
|
220
297
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
221
298
|
return pxe;
|
|
222
299
|
}
|
|
@@ -226,20 +303,22 @@ export class PXE {
|
|
|
226
303
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
227
304
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
228
305
|
|
|
229
|
-
return new ContractFunctionSimulator(
|
|
230
|
-
proxyContractStore,
|
|
231
|
-
this.noteStore,
|
|
232
|
-
this.keyStore,
|
|
233
|
-
this.addressStore,
|
|
234
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
235
|
-
this.
|
|
236
|
-
this.
|
|
237
|
-
this.
|
|
238
|
-
this.
|
|
239
|
-
this.
|
|
240
|
-
this.
|
|
241
|
-
this.
|
|
242
|
-
|
|
306
|
+
return new ContractFunctionSimulator({
|
|
307
|
+
contractStore: proxyContractStore,
|
|
308
|
+
noteStore: this.noteStore,
|
|
309
|
+
keyStore: this.keyStore,
|
|
310
|
+
addressStore: this.addressStore,
|
|
311
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
312
|
+
l2TipsStore: this.l2TipsStore,
|
|
313
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
314
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
315
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
316
|
+
capsuleStore: this.capsuleStore,
|
|
317
|
+
privateEventStore: this.privateEventStore,
|
|
318
|
+
simulator: this.simulator,
|
|
319
|
+
contractSyncService: this.contractSyncService,
|
|
320
|
+
messageContextService: this.messageContextService,
|
|
321
|
+
});
|
|
243
322
|
}
|
|
244
323
|
|
|
245
324
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -291,9 +370,8 @@ export class PXE {
|
|
|
291
370
|
async #registerProtocolContracts() {
|
|
292
371
|
const registered: Record<string, string> = {};
|
|
293
372
|
for (const name of protocolContractNames) {
|
|
294
|
-
const { address,
|
|
295
|
-
|
|
296
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
373
|
+
const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
374
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
297
375
|
await this.contractStore.addContractInstance(instance);
|
|
298
376
|
registered[name] = address.toString();
|
|
299
377
|
}
|
|
@@ -302,37 +380,42 @@ export class PXE {
|
|
|
302
380
|
|
|
303
381
|
// Executes the entrypoint private function, as well as all nested private
|
|
304
382
|
// functions that might arise.
|
|
305
|
-
async #executePrivate(
|
|
306
|
-
contractFunctionSimulator
|
|
307
|
-
txRequest
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
383
|
+
async #executePrivate({
|
|
384
|
+
contractFunctionSimulator,
|
|
385
|
+
txRequest,
|
|
386
|
+
anchorBlockHeader,
|
|
387
|
+
scopes,
|
|
388
|
+
jobId,
|
|
389
|
+
senderForTags,
|
|
390
|
+
}: {
|
|
391
|
+
contractFunctionSimulator: ContractFunctionSimulator;
|
|
392
|
+
txRequest: TxExecutionRequest;
|
|
393
|
+
anchorBlockHeader: BlockHeader;
|
|
394
|
+
scopes: AztecAddress[];
|
|
395
|
+
jobId: string;
|
|
396
|
+
senderForTags?: AztecAddress;
|
|
397
|
+
}): Promise<PrivateExecutionResult> {
|
|
311
398
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
312
399
|
|
|
313
400
|
try {
|
|
314
|
-
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
315
|
-
|
|
316
401
|
await this.contractSyncService.ensureContractSynced(
|
|
317
402
|
contractAddress,
|
|
318
403
|
functionSelector,
|
|
319
|
-
|
|
404
|
+
(privateSyncCall, execScopes) =>
|
|
405
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
320
406
|
anchorBlockHeader,
|
|
321
407
|
jobId,
|
|
408
|
+
scopes,
|
|
322
409
|
);
|
|
323
410
|
|
|
324
|
-
const result = await contractFunctionSimulator.run(
|
|
325
|
-
txRequest,
|
|
411
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
326
412
|
contractAddress,
|
|
327
|
-
functionSelector,
|
|
328
|
-
undefined,
|
|
413
|
+
selector: functionSelector,
|
|
329
414
|
anchorBlockHeader,
|
|
330
|
-
// The sender for tags is set by contracts, typically by an account
|
|
331
|
-
// contract entrypoint
|
|
332
|
-
undefined, // senderForTags
|
|
333
415
|
scopes,
|
|
334
416
|
jobId,
|
|
335
|
-
|
|
417
|
+
senderForTags,
|
|
418
|
+
});
|
|
336
419
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
337
420
|
return result;
|
|
338
421
|
} catch (err) {
|
|
@@ -344,25 +427,32 @@ export class PXE {
|
|
|
344
427
|
}
|
|
345
428
|
|
|
346
429
|
/**
|
|
347
|
-
*
|
|
430
|
+
* Execute a utility function call on the given contract.
|
|
348
431
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
349
432
|
* @param call - The function call to execute.
|
|
350
433
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
351
434
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
352
435
|
* accounts if not specified.
|
|
353
436
|
* @param jobId - The job ID for staged writes.
|
|
354
|
-
* @returns The
|
|
437
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
355
438
|
*/
|
|
356
|
-
async #
|
|
439
|
+
async #executeUtility(
|
|
357
440
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
358
441
|
call: FunctionCall,
|
|
359
442
|
authWitnesses: AuthWitness[] | undefined,
|
|
360
|
-
scopes: AztecAddress[]
|
|
443
|
+
scopes: AztecAddress[],
|
|
361
444
|
jobId: string,
|
|
362
445
|
) {
|
|
363
446
|
try {
|
|
364
447
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
365
|
-
|
|
448
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
449
|
+
call,
|
|
450
|
+
authWitnesses ?? [],
|
|
451
|
+
anchorBlockHeader,
|
|
452
|
+
scopes,
|
|
453
|
+
jobId,
|
|
454
|
+
);
|
|
455
|
+
return { result, offchainEffects };
|
|
366
456
|
} catch (err) {
|
|
367
457
|
if (err instanceof SimulationError) {
|
|
368
458
|
await enrichSimulationError(err, this.contractStore, this.log);
|
|
@@ -413,11 +503,10 @@ export class PXE {
|
|
|
413
503
|
txExecutionRequest: TxExecutionRequest,
|
|
414
504
|
proofCreator: PrivateKernelProver,
|
|
415
505
|
privateExecutionResult: PrivateExecutionResult,
|
|
506
|
+
anchorBlockHeader: BlockHeader,
|
|
416
507
|
config: PrivateKernelExecutionProverConfig,
|
|
417
508
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
418
|
-
const
|
|
419
|
-
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
420
|
-
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
509
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
421
510
|
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
422
511
|
kernelOracle,
|
|
423
512
|
proofCreator,
|
|
@@ -430,6 +519,21 @@ export class PXE {
|
|
|
430
519
|
|
|
431
520
|
// Public API
|
|
432
521
|
|
|
522
|
+
/**
|
|
523
|
+
* Returns the block header up to which the PXE has synced.
|
|
524
|
+
* @returns The synced block header
|
|
525
|
+
*/
|
|
526
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
527
|
+
return this.#putInJobQueue(() => {
|
|
528
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
534
|
+
* @param address - The contract address.
|
|
535
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
536
|
+
*/
|
|
433
537
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
434
538
|
return this.contractStore.getContractInstance(address);
|
|
435
539
|
}
|
|
@@ -479,6 +583,12 @@ export class PXE {
|
|
|
479
583
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
480
584
|
*/
|
|
481
585
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
586
|
+
if (!(await sender.isValid())) {
|
|
587
|
+
throw new Error(
|
|
588
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
482
592
|
const accounts = await this.keyStore.getAccounts();
|
|
483
593
|
if (accounts.includes(sender)) {
|
|
484
594
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
@@ -489,6 +599,9 @@ export class PXE {
|
|
|
489
599
|
|
|
490
600
|
if (wasAdded) {
|
|
491
601
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
602
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
603
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
604
|
+
await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
|
|
492
605
|
} else {
|
|
493
606
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
494
607
|
}
|
|
@@ -538,8 +651,7 @@ export class PXE {
|
|
|
538
651
|
* @param artifact - The build artifact for the contract class.
|
|
539
652
|
*/
|
|
540
653
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
541
|
-
const
|
|
542
|
-
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
654
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
543
655
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
544
656
|
}
|
|
545
657
|
|
|
@@ -558,17 +670,17 @@ export class PXE {
|
|
|
558
670
|
if (artifact) {
|
|
559
671
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
560
672
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
561
|
-
|
|
562
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
673
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
563
674
|
throw new Error(
|
|
564
|
-
`Artifact does not match expected class id (computed ${
|
|
675
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
565
676
|
);
|
|
566
677
|
}
|
|
567
678
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
568
679
|
if (!computedAddress.equals(instance.address)) {
|
|
569
680
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
570
681
|
}
|
|
571
|
-
|
|
682
|
+
|
|
683
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
572
684
|
|
|
573
685
|
const publicFunctionSignatures = artifact.functions
|
|
574
686
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -617,15 +729,16 @@ export class PXE {
|
|
|
617
729
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
618
730
|
}
|
|
619
731
|
|
|
620
|
-
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
621
|
-
|
|
622
732
|
const publicFunctionSignatures = artifact.functions
|
|
623
733
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
624
734
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
625
735
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
626
736
|
|
|
627
737
|
currentInstance.currentContractClassId = contractClass.id;
|
|
628
|
-
await
|
|
738
|
+
await Promise.all([
|
|
739
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
740
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
741
|
+
]);
|
|
629
742
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
630
743
|
});
|
|
631
744
|
}
|
|
@@ -643,11 +756,12 @@ export class PXE {
|
|
|
643
756
|
* (where validators prove the public portion).
|
|
644
757
|
*
|
|
645
758
|
* @param txRequest - An authenticated tx request ready for proving
|
|
759
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
646
760
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
647
761
|
* @throws If contract code not found, or public simulation reverts.
|
|
648
762
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
649
763
|
*/
|
|
650
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
764
|
+
public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
|
|
651
765
|
let privateExecutionResult: PrivateExecutionResult;
|
|
652
766
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
653
767
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -656,16 +770,24 @@ export class PXE {
|
|
|
656
770
|
try {
|
|
657
771
|
const syncTimer = new Timer();
|
|
658
772
|
await this.blockStateSynchronizer.sync();
|
|
773
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
659
774
|
const syncTime = syncTimer.ms();
|
|
660
775
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
661
|
-
privateExecutionResult = await this.#executePrivate(
|
|
776
|
+
privateExecutionResult = await this.#executePrivate({
|
|
777
|
+
contractFunctionSimulator,
|
|
778
|
+
txRequest,
|
|
779
|
+
anchorBlockHeader,
|
|
780
|
+
scopes,
|
|
781
|
+
jobId,
|
|
782
|
+
senderForTags,
|
|
783
|
+
});
|
|
662
784
|
|
|
663
785
|
const {
|
|
664
786
|
publicInputs,
|
|
665
787
|
chonkProof,
|
|
666
788
|
executionSteps,
|
|
667
789
|
timings: { proving } = {},
|
|
668
|
-
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
790
|
+
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
|
|
669
791
|
simulate: false,
|
|
670
792
|
skipFeeEnforcement: false,
|
|
671
793
|
profileMode: 'none',
|
|
@@ -700,17 +822,17 @@ export class PXE {
|
|
|
700
822
|
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
701
823
|
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
702
824
|
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
825
|
+
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
|
|
826
|
+
if (taggingIndexRangesUsedInTheTx.length > 0) {
|
|
705
827
|
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
706
828
|
const txHash = (await txProvingResult.toTx()).txHash;
|
|
707
829
|
|
|
708
|
-
await this.senderTaggingStore.storePendingIndexes(
|
|
709
|
-
this.log.debug(`Stored used
|
|
710
|
-
|
|
830
|
+
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
|
|
831
|
+
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
|
|
832
|
+
taggingIndexRangesUsedInTheTx,
|
|
711
833
|
});
|
|
712
834
|
} else {
|
|
713
|
-
this.log.debug(`No
|
|
835
|
+
this.log.debug(`No tagging index ranges used in the tx`);
|
|
714
836
|
}
|
|
715
837
|
|
|
716
838
|
return txProvingResult;
|
|
@@ -722,17 +844,13 @@ export class PXE {
|
|
|
722
844
|
|
|
723
845
|
/**
|
|
724
846
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
725
|
-
*
|
|
726
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
727
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
728
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
847
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
729
848
|
* @returns A trace of the program execution with gate counts.
|
|
730
849
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
731
850
|
*/
|
|
732
851
|
public profileTx(
|
|
733
852
|
txRequest: TxExecutionRequest,
|
|
734
|
-
profileMode
|
|
735
|
-
skipProofGeneration: boolean = true,
|
|
853
|
+
{ profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
|
|
736
854
|
): Promise<TxProfileResult> {
|
|
737
855
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
738
856
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -752,20 +870,24 @@ export class PXE {
|
|
|
752
870
|
);
|
|
753
871
|
const syncTimer = new Timer();
|
|
754
872
|
await this.blockStateSynchronizer.sync();
|
|
873
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
755
874
|
const syncTime = syncTimer.ms();
|
|
756
875
|
|
|
757
876
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
758
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
877
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
759
878
|
contractFunctionSimulator,
|
|
760
879
|
txRequest,
|
|
761
|
-
|
|
880
|
+
anchorBlockHeader,
|
|
881
|
+
scopes,
|
|
762
882
|
jobId,
|
|
763
|
-
|
|
883
|
+
senderForTags,
|
|
884
|
+
});
|
|
764
885
|
|
|
765
886
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
766
887
|
txRequest,
|
|
767
888
|
this.proofCreator,
|
|
768
889
|
privateExecutionResult,
|
|
890
|
+
anchorBlockHeader,
|
|
769
891
|
{
|
|
770
892
|
simulate: skipProofGeneration,
|
|
771
893
|
skipFeeEnforcement: false,
|
|
@@ -817,12 +939,7 @@ export class PXE {
|
|
|
817
939
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
818
940
|
*
|
|
819
941
|
*
|
|
820
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
821
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
822
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
823
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
824
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
825
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
942
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
826
943
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
827
944
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
828
945
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -831,11 +948,15 @@ export class PXE {
|
|
|
831
948
|
*/
|
|
832
949
|
public simulateTx(
|
|
833
950
|
txRequest: TxExecutionRequest,
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
951
|
+
{
|
|
952
|
+
simulatePublic,
|
|
953
|
+
skipTxValidation = false,
|
|
954
|
+
skipFeeEnforcement = false,
|
|
955
|
+
skipKernels = true,
|
|
956
|
+
overrides,
|
|
957
|
+
scopes,
|
|
958
|
+
senderForTags,
|
|
959
|
+
}: SimulateTxOpts,
|
|
839
960
|
): Promise<TxSimulationResult> {
|
|
840
961
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
841
962
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -857,23 +978,34 @@ export class PXE {
|
|
|
857
978
|
);
|
|
858
979
|
const syncTimer = new Timer();
|
|
859
980
|
await this.blockStateSynchronizer.sync();
|
|
981
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
860
982
|
const syncTime = syncTimer.ms();
|
|
861
983
|
|
|
862
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
863
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
864
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
865
|
-
// or not.
|
|
866
984
|
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
867
985
|
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
868
|
-
const skipKernels = hasOverriddenContracts;
|
|
869
986
|
|
|
870
|
-
|
|
987
|
+
if (hasOverriddenContracts && !skipKernels) {
|
|
988
|
+
throw new Error(
|
|
989
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
993
|
+
|
|
871
994
|
if (hasOverriddenContracts) {
|
|
872
|
-
|
|
995
|
+
// Overridden contracts don't have a sync function, so calling sync on them would fail.
|
|
996
|
+
// We exclude them so the sync service skips them entirely.
|
|
997
|
+
this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
|
|
873
998
|
}
|
|
874
999
|
|
|
875
1000
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
876
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
1001
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
1002
|
+
contractFunctionSimulator,
|
|
1003
|
+
txRequest,
|
|
1004
|
+
anchorBlockHeader,
|
|
1005
|
+
scopes,
|
|
1006
|
+
jobId,
|
|
1007
|
+
senderForTags,
|
|
1008
|
+
});
|
|
877
1009
|
|
|
878
1010
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
879
1011
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
@@ -881,15 +1013,22 @@ export class PXE {
|
|
|
881
1013
|
if (skipKernels) {
|
|
882
1014
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
883
1015
|
privateExecutionResult,
|
|
884
|
-
this.contractStore,
|
|
1016
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
1017
|
+
this.node,
|
|
885
1018
|
));
|
|
886
1019
|
} else {
|
|
887
1020
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
888
|
-
({ publicInputs, executionSteps } = await this.#prove(
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1021
|
+
({ publicInputs, executionSteps } = await this.#prove(
|
|
1022
|
+
txRequest,
|
|
1023
|
+
this.proofCreator,
|
|
1024
|
+
privateExecutionResult,
|
|
1025
|
+
anchorBlockHeader,
|
|
1026
|
+
{
|
|
1027
|
+
simulate: true,
|
|
1028
|
+
skipFeeEnforcement,
|
|
1029
|
+
profileMode: 'none',
|
|
1030
|
+
},
|
|
1031
|
+
));
|
|
893
1032
|
}
|
|
894
1033
|
|
|
895
1034
|
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
@@ -900,6 +1039,9 @@ export class PXE {
|
|
|
900
1039
|
const publicSimulationTimer = new Timer();
|
|
901
1040
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
902
1041
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
1042
|
+
if (publicOutput?.debugLogs?.length) {
|
|
1043
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
1044
|
+
}
|
|
903
1045
|
}
|
|
904
1046
|
|
|
905
1047
|
let validationTime: number | undefined;
|
|
@@ -908,7 +1050,8 @@ export class PXE {
|
|
|
908
1050
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
909
1051
|
validationTime = validationTimer.ms();
|
|
910
1052
|
if (validationResult.result === 'invalid') {
|
|
911
|
-
|
|
1053
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
1054
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
912
1055
|
}
|
|
913
1056
|
}
|
|
914
1057
|
|
|
@@ -959,29 +1102,23 @@ export class PXE {
|
|
|
959
1102
|
inspect(txRequest),
|
|
960
1103
|
`simulatePublic=${simulatePublic}`,
|
|
961
1104
|
`skipTxValidation=${skipTxValidation}`,
|
|
962
|
-
`scopes=${scopes
|
|
1105
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
963
1106
|
);
|
|
964
1107
|
}
|
|
965
1108
|
});
|
|
966
1109
|
}
|
|
967
1110
|
|
|
968
1111
|
/**
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1112
|
+
* Executes a contract utility function.
|
|
971
1113
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
972
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
973
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
974
|
-
* default to all.
|
|
975
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
976
1114
|
*/
|
|
977
|
-
public
|
|
1115
|
+
public executeUtility(
|
|
978
1116
|
call: FunctionCall,
|
|
979
|
-
authwits
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1117
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1118
|
+
): Promise<UtilityExecutionResult> {
|
|
1119
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
983
1120
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
984
|
-
// delete the same read value, or reading values that another
|
|
1121
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
985
1122
|
return this.#putInJobQueue(async jobId => {
|
|
986
1123
|
try {
|
|
987
1124
|
const totalTimer = new Timer();
|
|
@@ -995,12 +1132,14 @@ export class PXE {
|
|
|
995
1132
|
await this.contractSyncService.ensureContractSynced(
|
|
996
1133
|
call.to,
|
|
997
1134
|
call.selector,
|
|
998
|
-
|
|
1135
|
+
(privateSyncCall, execScopes) =>
|
|
1136
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
999
1137
|
anchorBlockHeader,
|
|
1000
1138
|
jobId,
|
|
1139
|
+
scopes,
|
|
1001
1140
|
);
|
|
1002
1141
|
|
|
1003
|
-
const executionResult = await this.#
|
|
1142
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1004
1143
|
contractFunctionSimulator,
|
|
1005
1144
|
call,
|
|
1006
1145
|
authwits ?? [],
|
|
@@ -1021,14 +1160,19 @@ export class PXE {
|
|
|
1021
1160
|
};
|
|
1022
1161
|
|
|
1023
1162
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1024
|
-
return {
|
|
1163
|
+
return {
|
|
1164
|
+
result: executionResult,
|
|
1165
|
+
offchainEffects,
|
|
1166
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1167
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1168
|
+
};
|
|
1025
1169
|
} catch (err: any) {
|
|
1026
1170
|
const { to, name, args } = call;
|
|
1027
1171
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1028
1172
|
throw this.#contextualizeError(
|
|
1029
1173
|
err,
|
|
1030
|
-
`
|
|
1031
|
-
`scopes=${scopes
|
|
1174
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1175
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1032
1176
|
);
|
|
1033
1177
|
}
|
|
1034
1178
|
});
|
|
@@ -1064,10 +1208,11 @@ export class PXE {
|
|
|
1064
1208
|
await this.contractSyncService.ensureContractSynced(
|
|
1065
1209
|
filter.contractAddress,
|
|
1066
1210
|
null,
|
|
1067
|
-
async privateSyncCall =>
|
|
1068
|
-
await this.#
|
|
1211
|
+
async (privateSyncCall, execScopes) =>
|
|
1212
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1069
1213
|
anchorBlockHeader,
|
|
1070
1214
|
jobId,
|
|
1215
|
+
filter.scopes,
|
|
1071
1216
|
);
|
|
1072
1217
|
});
|
|
1073
1218
|
|
|
@@ -1082,9 +1227,11 @@ export class PXE {
|
|
|
1082
1227
|
}
|
|
1083
1228
|
|
|
1084
1229
|
/**
|
|
1085
|
-
* Stops the PXE's job queue.
|
|
1230
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1086
1231
|
*/
|
|
1087
|
-
public stop(): Promise<void> {
|
|
1088
|
-
|
|
1232
|
+
public async stop(): Promise<void> {
|
|
1233
|
+
await this.jobQueue.end();
|
|
1234
|
+
await this.blockStateSynchronizer.stop();
|
|
1235
|
+
await this.db.close();
|
|
1089
1236
|
}
|
|
1090
1237
|
}
|