@aztec/pxe 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.e2b2873ed
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/contract_function_simulator/contract_function_simulator.d.ts +48 -26
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +63 -29
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +2 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -18
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +29 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +31 -28
- package/dest/contract_sync/contract_sync_service.d.ts +3 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +32 -17
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -1
- 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 +9 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +4 -9
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +56 -22
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +37 -32
- package/dest/storage/note_store/note_store.d.ts +1 -2
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +1 -2
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +107 -72
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +2 -2
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +91 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +67 -25
- package/src/contract_sync/contract_sync_service.ts +41 -25
- package/src/debug/pxe_debug_utils.ts +3 -2
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +4 -13
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +98 -70
- package/src/storage/note_store/note_store.ts +1 -2
|
@@ -18,8 +18,9 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
18
18
|
export class ContractSyncService implements StagedStore {
|
|
19
19
|
readonly storeName = 'contract_sync';
|
|
20
20
|
|
|
21
|
-
// Tracks contracts synced since last wipe.
|
|
22
|
-
//
|
|
21
|
+
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
22
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for undefined scopes (all accounts).
|
|
23
|
+
// The value is a promise that resolves when the contract is synced.
|
|
23
24
|
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
24
25
|
|
|
25
26
|
// Per-job overridden contract addresses - these contracts should not be synced.
|
|
@@ -44,43 +45,50 @@ export class ContractSyncService implements StagedStore {
|
|
|
44
45
|
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
45
46
|
* not sync_state itself).
|
|
46
47
|
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
48
|
+
* @param scopes - Scopes to pass through to the utility executor (affects which notes are discovered).
|
|
47
49
|
*/
|
|
48
50
|
async ensureContractSynced(
|
|
49
51
|
contractAddress: AztecAddress,
|
|
50
52
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
51
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
53
|
+
utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<any>,
|
|
52
54
|
anchorBlockHeader: BlockHeader,
|
|
53
55
|
jobId: string,
|
|
56
|
+
scopes: undefined | AztecAddress[],
|
|
54
57
|
): Promise<void> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Skip sync if this contract has an override for this job
|
|
58
|
+
// Skip sync if this contract has an override for this job (overrides are keyed by contract address only)
|
|
58
59
|
const overrides = this.overriddenContracts.get(jobId);
|
|
59
|
-
if (overrides?.has(
|
|
60
|
+
if (overrides?.has(contractAddress.toString())) {
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// Skip sync if we already synced for "all scopes", or if we have an empty list of scopes
|
|
65
|
+
const allScopesKey = toKey(contractAddress, undefined);
|
|
66
|
+
const allScopesExisting = this.syncedContracts.get(allScopesKey);
|
|
67
|
+
if (allScopesExisting || (scopes && scopes.length == 0)) {
|
|
68
|
+
return;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
const unsyncedScopes = scopes?.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
72
|
+
const unsyncedScopesKeys = toKeys(contractAddress, unsyncedScopes);
|
|
73
|
+
|
|
74
|
+
if (unsyncedScopesKeys.length > 0) {
|
|
75
|
+
// Start sync and store the promise for all unsynced scopes
|
|
76
|
+
const promise = this.#doSync(
|
|
77
|
+
contractAddress,
|
|
78
|
+
functionToInvokeAfterSync,
|
|
79
|
+
call => utilityExecutor(call, unsyncedScopes),
|
|
80
|
+
anchorBlockHeader,
|
|
81
|
+
jobId,
|
|
82
|
+
).catch(err => {
|
|
83
|
+
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
84
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.delete(key));
|
|
85
|
+
throw err;
|
|
86
|
+
});
|
|
87
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.set(key, promise));
|
|
83
88
|
}
|
|
89
|
+
|
|
90
|
+
const promises = toKeys(contractAddress, scopes).map(key => this.syncedContracts.get(key)!);
|
|
91
|
+
await Promise.all(promises);
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
async #doSync(
|
|
@@ -127,3 +135,11 @@ export class ContractSyncService implements StagedStore {
|
|
|
127
135
|
return Promise.resolve();
|
|
128
136
|
}
|
|
129
137
|
}
|
|
138
|
+
|
|
139
|
+
function toKeys(contract: AztecAddress, scopes: undefined | AztecAddress[]) {
|
|
140
|
+
return scopes === undefined ? [toKey(contract, undefined)] : scopes.map(scope => toKey(contract, scope));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function toKey(contract: AztecAddress, scope: AztecAddress | undefined) {
|
|
144
|
+
return scope === undefined ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
|
|
145
|
+
}
|
|
@@ -71,10 +71,11 @@ export class PXEDebugUtils {
|
|
|
71
71
|
await this.contractSyncService.ensureContractSynced(
|
|
72
72
|
filter.contractAddress,
|
|
73
73
|
null,
|
|
74
|
-
async privateSyncCall =>
|
|
75
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
74
|
+
async (privateSyncCall, execScopes) =>
|
|
75
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
76
76
|
anchorBlockHeader,
|
|
77
77
|
jobId,
|
|
78
|
+
filter.scopes,
|
|
78
79
|
);
|
|
79
80
|
|
|
80
81
|
return this.noteStore.getNotes(filter, jobId);
|
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new LazyProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -58,14 +58,14 @@ export async function createPXE(
|
|
|
58
58
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
59
59
|
|
|
60
60
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
61
|
-
const pxe = await PXE.create(
|
|
62
|
-
aztecNode,
|
|
63
|
-
options.store,
|
|
64
|
-
prover,
|
|
61
|
+
const pxe = await PXE.create({
|
|
62
|
+
node: aztecNode,
|
|
63
|
+
store: options.store,
|
|
64
|
+
proofCreator: prover,
|
|
65
65
|
simulator,
|
|
66
66
|
protocolContractsProvider,
|
|
67
|
-
configWithContracts,
|
|
68
|
-
pxeLogger,
|
|
69
|
-
);
|
|
67
|
+
config: configWithContracts,
|
|
68
|
+
loggerOrSuffix: pxeLogger,
|
|
69
|
+
});
|
|
70
70
|
return pxe;
|
|
71
71
|
}
|
package/src/logs/log_service.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { KeyStore } from '@aztec/key-store';
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
6
5
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
7
6
|
import { DirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
8
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
@@ -159,7 +158,10 @@ export class LogService {
|
|
|
159
158
|
contractAddress: AztecAddress,
|
|
160
159
|
recipient: AztecAddress,
|
|
161
160
|
): Promise<DirectionalAppTaggingSecret[]> {
|
|
162
|
-
const recipientCompleteAddress = await this
|
|
161
|
+
const recipientCompleteAddress = await this.addressStore.getCompleteAddress(recipient);
|
|
162
|
+
if (!recipientCompleteAddress) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
163
165
|
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
164
166
|
|
|
165
167
|
// We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
|
|
@@ -206,15 +208,4 @@ export class LogService {
|
|
|
206
208
|
// TODO: This looks like it could belong more at the oracle interface level
|
|
207
209
|
return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs, this.jobId);
|
|
208
210
|
}
|
|
209
|
-
|
|
210
|
-
async #getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
|
|
211
|
-
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
212
|
-
if (!completeAddress) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`No public key registered for address ${account}.
|
|
215
|
-
Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
return completeAddress;
|
|
219
|
-
}
|
|
220
211
|
}
|
package/src/oracle_version.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
///
|
|
5
5
|
/// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 12;
|
|
8
8
|
|
|
9
9
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
10
10
|
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
11
11
|
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
12
|
-
export const ORACLE_INTERFACE_HASH = '
|
|
12
|
+
export const ORACLE_INTERFACE_HASH = '666a8a7fc697f72b29dbf0ae7464db269cf5afa019acac8861f814543147dbb4';
|
package/src/pxe.ts
CHANGED
|
@@ -86,6 +86,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
86
86
|
eventSelector: EventSelector;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
/** Options for PXE.profileTx. */
|
|
90
|
+
export type ProfileTxOpts = {
|
|
91
|
+
/** The profiling mode to use. */
|
|
92
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
93
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
|
+
skipProofGeneration?: boolean;
|
|
95
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
96
|
+
scopes?: AztecAddress[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Options for PXE.simulateTx. */
|
|
100
|
+
export type SimulateTxOpts = {
|
|
101
|
+
/** Whether to simulate the public part of the transaction. */
|
|
102
|
+
simulatePublic: boolean;
|
|
103
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
104
|
+
skipTxValidation?: boolean;
|
|
105
|
+
/** If false, fees are enforced. */
|
|
106
|
+
skipFeeEnforcement?: boolean;
|
|
107
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
108
|
+
overrides?: SimulationOverrides;
|
|
109
|
+
/** Addresses whose private state and keys are accessible during private execution. Defaults to all. */
|
|
110
|
+
scopes?: AztecAddress[];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Options for PXE.simulateUtility. */
|
|
114
|
+
export type SimulateUtilityOpts = {
|
|
115
|
+
/** The authentication witnesses required for the function call. */
|
|
116
|
+
authwits?: AuthWitness[];
|
|
117
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
118
|
+
scopes?: AztecAddress[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Args for PXE.create. */
|
|
122
|
+
export type PXECreateArgs = {
|
|
123
|
+
/** The Aztec node to connect to. */
|
|
124
|
+
node: AztecNode;
|
|
125
|
+
/** The key-value store for persisting PXE state. */
|
|
126
|
+
store: AztecAsyncKVStore;
|
|
127
|
+
/** The prover for generating private kernel proofs. */
|
|
128
|
+
proofCreator: PrivateKernelProver;
|
|
129
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
130
|
+
simulator: CircuitSimulator;
|
|
131
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
132
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
133
|
+
/** PXE configuration options. */
|
|
134
|
+
config: PXEConfig;
|
|
135
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
136
|
+
loggerOrSuffix?: string | Logger;
|
|
137
|
+
};
|
|
138
|
+
|
|
89
139
|
/**
|
|
90
140
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
91
141
|
* manage private state of users.
|
|
@@ -122,15 +172,15 @@ export class PXE {
|
|
|
122
172
|
*
|
|
123
173
|
* @returns A promise that resolves PXE is ready to be used.
|
|
124
174
|
*/
|
|
125
|
-
public static async create(
|
|
126
|
-
node
|
|
127
|
-
store
|
|
128
|
-
proofCreator
|
|
129
|
-
simulator
|
|
130
|
-
protocolContractsProvider
|
|
131
|
-
config
|
|
132
|
-
loggerOrSuffix
|
|
133
|
-
) {
|
|
175
|
+
public static async create({
|
|
176
|
+
node,
|
|
177
|
+
store,
|
|
178
|
+
proofCreator,
|
|
179
|
+
simulator,
|
|
180
|
+
protocolContractsProvider,
|
|
181
|
+
config,
|
|
182
|
+
loggerOrSuffix,
|
|
183
|
+
}: PXECreateArgs) {
|
|
134
184
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
185
|
const bindings: LoggerBindings | undefined =
|
|
136
186
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -140,7 +190,9 @@ export class PXE {
|
|
|
140
190
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
141
191
|
: loggerOrSuffix;
|
|
142
192
|
|
|
143
|
-
const
|
|
193
|
+
const info = await node.getNodeInfo();
|
|
194
|
+
|
|
195
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
144
196
|
const addressStore = new AddressStore(store);
|
|
145
197
|
const privateEventStore = new PrivateEventStore(store);
|
|
146
198
|
const contractStore = new ContractStore(store);
|
|
@@ -217,7 +269,6 @@ export class PXE {
|
|
|
217
269
|
pxe.jobQueue.start();
|
|
218
270
|
|
|
219
271
|
await pxe.#registerProtocolContracts();
|
|
220
|
-
const info = await node.getNodeInfo();
|
|
221
272
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
222
273
|
return pxe;
|
|
223
274
|
}
|
|
@@ -227,20 +278,20 @@ export class PXE {
|
|
|
227
278
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
228
279
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
229
280
|
|
|
230
|
-
return new ContractFunctionSimulator(
|
|
231
|
-
proxyContractStore,
|
|
232
|
-
this.noteStore,
|
|
233
|
-
this.keyStore,
|
|
234
|
-
this.addressStore,
|
|
235
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
236
|
-
this.senderTaggingStore,
|
|
237
|
-
this.recipientTaggingStore,
|
|
238
|
-
this.senderAddressBookStore,
|
|
239
|
-
this.capsuleStore,
|
|
240
|
-
this.privateEventStore,
|
|
241
|
-
this.simulator,
|
|
242
|
-
this.contractSyncService,
|
|
243
|
-
);
|
|
281
|
+
return new ContractFunctionSimulator({
|
|
282
|
+
contractStore: proxyContractStore,
|
|
283
|
+
noteStore: this.noteStore,
|
|
284
|
+
keyStore: this.keyStore,
|
|
285
|
+
addressStore: this.addressStore,
|
|
286
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
287
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
288
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
289
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
290
|
+
capsuleStore: this.capsuleStore,
|
|
291
|
+
privateEventStore: this.privateEventStore,
|
|
292
|
+
simulator: this.simulator,
|
|
293
|
+
contractSyncService: this.contractSyncService,
|
|
294
|
+
});
|
|
244
295
|
}
|
|
245
296
|
|
|
246
297
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -317,23 +368,20 @@ export class PXE {
|
|
|
317
368
|
await this.contractSyncService.ensureContractSynced(
|
|
318
369
|
contractAddress,
|
|
319
370
|
functionSelector,
|
|
320
|
-
|
|
371
|
+
(privateSyncCall, execScopes) =>
|
|
372
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
321
373
|
anchorBlockHeader,
|
|
322
374
|
jobId,
|
|
375
|
+
scopes,
|
|
323
376
|
);
|
|
324
377
|
|
|
325
|
-
const result = await contractFunctionSimulator.run(
|
|
326
|
-
txRequest,
|
|
378
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
327
379
|
contractAddress,
|
|
328
|
-
functionSelector,
|
|
329
|
-
undefined,
|
|
380
|
+
selector: functionSelector,
|
|
330
381
|
anchorBlockHeader,
|
|
331
|
-
// The sender for tags is set by contracts, typically by an account
|
|
332
|
-
// contract entrypoint
|
|
333
|
-
undefined, // senderForTags
|
|
334
382
|
scopes,
|
|
335
383
|
jobId,
|
|
336
|
-
);
|
|
384
|
+
});
|
|
337
385
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
338
386
|
return result;
|
|
339
387
|
} catch (err) {
|
|
@@ -657,11 +705,12 @@ export class PXE {
|
|
|
657
705
|
* (where validators prove the public portion).
|
|
658
706
|
*
|
|
659
707
|
* @param txRequest - An authenticated tx request ready for proving
|
|
708
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
660
709
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
661
710
|
* @throws If contract code not found, or public simulation reverts.
|
|
662
711
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
663
712
|
*/
|
|
664
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
713
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
665
714
|
let privateExecutionResult: PrivateExecutionResult;
|
|
666
715
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
667
716
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -672,7 +721,7 @@ export class PXE {
|
|
|
672
721
|
await this.blockStateSynchronizer.sync();
|
|
673
722
|
const syncTime = syncTimer.ms();
|
|
674
723
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
675
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
724
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
676
725
|
|
|
677
726
|
const {
|
|
678
727
|
publicInputs,
|
|
@@ -736,17 +785,13 @@ export class PXE {
|
|
|
736
785
|
|
|
737
786
|
/**
|
|
738
787
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
739
|
-
*
|
|
740
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
741
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
742
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
788
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
743
789
|
* @returns A trace of the program execution with gate counts.
|
|
744
790
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
745
791
|
*/
|
|
746
792
|
public profileTx(
|
|
747
793
|
txRequest: TxExecutionRequest,
|
|
748
|
-
profileMode
|
|
749
|
-
skipProofGeneration: boolean = true,
|
|
794
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
750
795
|
): Promise<TxProfileResult> {
|
|
751
796
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
752
797
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -769,12 +814,7 @@ export class PXE {
|
|
|
769
814
|
const syncTime = syncTimer.ms();
|
|
770
815
|
|
|
771
816
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
772
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
773
|
-
contractFunctionSimulator,
|
|
774
|
-
txRequest,
|
|
775
|
-
undefined,
|
|
776
|
-
jobId,
|
|
777
|
-
);
|
|
817
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
778
818
|
|
|
779
819
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
780
820
|
txRequest,
|
|
@@ -831,12 +871,7 @@ export class PXE {
|
|
|
831
871
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
832
872
|
*
|
|
833
873
|
*
|
|
834
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
835
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
836
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
837
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
838
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
839
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
874
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
840
875
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
841
876
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
842
877
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -845,11 +880,7 @@ export class PXE {
|
|
|
845
880
|
*/
|
|
846
881
|
public simulateTx(
|
|
847
882
|
txRequest: TxExecutionRequest,
|
|
848
|
-
simulatePublic:
|
|
849
|
-
skipTxValidation: boolean = false,
|
|
850
|
-
skipFeeEnforcement: boolean = false,
|
|
851
|
-
overrides?: SimulationOverrides,
|
|
852
|
-
scopes?: AztecAddress[],
|
|
883
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
853
884
|
): Promise<TxSimulationResult> {
|
|
854
885
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
855
886
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -980,18 +1011,12 @@ export class PXE {
|
|
|
980
1011
|
}
|
|
981
1012
|
|
|
982
1013
|
/**
|
|
983
|
-
*
|
|
984
|
-
*
|
|
1014
|
+
* Simulates the execution of a contract utility function.
|
|
985
1015
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
986
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
987
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
988
|
-
* default to all.
|
|
989
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
990
1016
|
*/
|
|
991
1017
|
public simulateUtility(
|
|
992
1018
|
call: FunctionCall,
|
|
993
|
-
authwits
|
|
994
|
-
scopes?: AztecAddress[],
|
|
1019
|
+
{ authwits, scopes }: SimulateUtilityOpts = {},
|
|
995
1020
|
): Promise<UtilitySimulationResult> {
|
|
996
1021
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
997
1022
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -1009,9 +1034,11 @@ export class PXE {
|
|
|
1009
1034
|
await this.contractSyncService.ensureContractSynced(
|
|
1010
1035
|
call.to,
|
|
1011
1036
|
call.selector,
|
|
1012
|
-
|
|
1037
|
+
(privateSyncCall, execScopes) =>
|
|
1038
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1013
1039
|
anchorBlockHeader,
|
|
1014
1040
|
jobId,
|
|
1041
|
+
scopes,
|
|
1015
1042
|
);
|
|
1016
1043
|
|
|
1017
1044
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1078,10 +1105,11 @@ export class PXE {
|
|
|
1078
1105
|
await this.contractSyncService.ensureContractSynced(
|
|
1079
1106
|
filter.contractAddress,
|
|
1080
1107
|
null,
|
|
1081
|
-
async privateSyncCall =>
|
|
1082
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
1108
|
+
async (privateSyncCall, execScopes) =>
|
|
1109
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1083
1110
|
anchorBlockHeader,
|
|
1084
1111
|
jobId,
|
|
1112
|
+
filter.scopes,
|
|
1085
1113
|
);
|
|
1086
1114
|
});
|
|
1087
1115
|
|
|
@@ -103,11 +103,10 @@ export class NoteStore implements StagedStore {
|
|
|
103
103
|
* @params jobId - the job context to read from.
|
|
104
104
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
105
105
|
* returned once if this is the case)
|
|
106
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
107
106
|
*/
|
|
108
107
|
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
|
|
109
108
|
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
110
|
-
return Promise.
|
|
109
|
+
return Promise.resolve([]);
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
return this.#store.transactionAsync(async () => {
|