@aztec/wallet-sdk 0.0.1-commit.2ed92850 → 0.0.1-commit.43597cc1
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/base-wallet/base_wallet.d.ts +34 -4
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +48 -8
- package/dest/base-wallet/index.d.ts +2 -1
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +1 -0
- package/dest/base-wallet/utils.d.ts +48 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +128 -0
- package/package.json +15 -9
- package/src/base-wallet/base_wallet.ts +83 -20
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +229 -0
|
@@ -2,7 +2,7 @@ import type { Account } from '@aztec/aztec.js/account';
|
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
3
|
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
|
-
import type { Aliased, BatchResults, BatchedMethod, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet, WalletCapabilities } from '@aztec/aztec.js/wallet';
|
|
6
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
7
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
8
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -14,7 +14,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
14
14
|
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
15
15
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
16
16
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
17
|
-
import type
|
|
17
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilitySimulationResult } from '@aztec/stdlib/tx';
|
|
18
18
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
19
19
|
/**
|
|
20
20
|
* Options to configure fee payment for a transaction
|
|
@@ -53,6 +53,20 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
53
53
|
getChainInfo(): Promise<ChainInfo>;
|
|
54
54
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
55
55
|
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
56
|
+
/**
|
|
57
|
+
* Request capabilities from the wallet.
|
|
58
|
+
*
|
|
59
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
60
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
61
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
62
|
+
* friction by allowing apps to request permissions upfront.
|
|
63
|
+
*
|
|
64
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
65
|
+
* while the feature stabilizes.
|
|
66
|
+
*
|
|
67
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
68
|
+
*/
|
|
69
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
56
70
|
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
57
71
|
/**
|
|
58
72
|
* Completes partial user-provided fee options with wallet defaults.
|
|
@@ -82,6 +96,23 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
82
96
|
}>;
|
|
83
97
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
84
98
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
99
|
+
/**
|
|
100
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
101
|
+
* @param executionPayload - The execution payload to simulate.
|
|
102
|
+
* @param from - The sender address.
|
|
103
|
+
* @param feeOptions - Fee options for the transaction.
|
|
104
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
105
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
106
|
+
*/
|
|
107
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions, skipTxValidation?: boolean, skipFeeEnforcement?: boolean): Promise<TxSimulationResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
110
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
111
|
+
* Return values from both paths are merged back in original call order.
|
|
112
|
+
* @param executionPayload - The execution payload to simulate.
|
|
113
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
114
|
+
* @returns The merged simulation result.
|
|
115
|
+
*/
|
|
85
116
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
86
117
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
87
118
|
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
@@ -92,7 +123,6 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
92
123
|
instance: ContractInstanceWithAddress | undefined;
|
|
93
124
|
isContractInitialized: boolean;
|
|
94
125
|
isContractPublished: boolean;
|
|
95
|
-
isContractClassPubliclyRegistered: boolean;
|
|
96
126
|
isContractUpdated: boolean;
|
|
97
127
|
updatedContractClassId: Fr | undefined;
|
|
98
128
|
}>;
|
|
@@ -101,4 +131,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
101
131
|
isContractClassPubliclyRegistered: boolean;
|
|
102
132
|
}>;
|
|
103
133
|
}
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
134
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDakYsT0FBTyxFQUFFLEtBQUssc0JBQXNCLEVBQVcsS0FBSyxVQUFVLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUNsRyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRTVELE9BQU8sS0FBSyxFQUNWLE9BQU8sRUFDUCxlQUFlLEVBQ2YsWUFBWSxFQUNaLGFBQWEsRUFDYixZQUFZLEVBQ1osa0JBQWtCLEVBQ2xCLGNBQWMsRUFDZCxXQUFXLEVBQ1gsZUFBZSxFQUNmLE1BQU0sRUFDTixrQkFBa0IsRUFDbkIsTUFBTSx3QkFBd0IsQ0FBQztBQU9oQyxPQUFPLEVBQUUsOEJBQThCLEVBQXdDLE1BQU0sNEJBQTRCLENBQUM7QUFDbEgsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDL0QsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFFBQVEsRUFBRS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|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,KAAK,sBAAsB,EAAW,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,eAAe,EACf,MAAM,
|
|
1
|
+
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,KAAK,sBAAsB,EAAW,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EACf,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,eAAe,EACf,MAAM,EACN,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EAAE,8BAA8B,EAAwC,MAAM,4BAA4B,CAAC;AAClH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAA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} from '@aztec/stdlib/gas';
|
|
|
11
11
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
12
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
13
13
|
import { inspect } from 'util';
|
|
14
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
14
15
|
/**
|
|
15
16
|
* A base class for Wallet implementations
|
|
16
17
|
*/ export class BaseWallet {
|
|
@@ -67,6 +68,21 @@ import { inspect } from 'util';
|
|
|
67
68
|
const chainInfo = await this.getChainInfo();
|
|
68
69
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
69
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Request capabilities from the wallet.
|
|
73
|
+
*
|
|
74
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
75
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
76
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
77
|
+
* friction by allowing apps to request permissions upfront.
|
|
78
|
+
*
|
|
79
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
80
|
+
* while the feature stabilizes.
|
|
81
|
+
*
|
|
82
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
83
|
+
*/ requestCapabilities(_manifest) {
|
|
84
|
+
throw new Error('Not implemented');
|
|
85
|
+
}
|
|
70
86
|
async batch(methods) {
|
|
71
87
|
const results = [];
|
|
72
88
|
for (const method of methods){
|
|
@@ -168,10 +184,38 @@ import { inspect } from 'util';
|
|
|
168
184
|
}
|
|
169
185
|
return instance;
|
|
170
186
|
}
|
|
171
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
189
|
+
* @param executionPayload - The execution payload to simulate.
|
|
190
|
+
* @param from - The sender address.
|
|
191
|
+
* @param feeOptions - Fee options for the transaction.
|
|
192
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
193
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
194
|
+
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement) {
|
|
195
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
196
|
+
return this.pxe.simulateTx(txRequest, true, skipTxValidation, skipFeeEnforcement);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
200
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
201
|
+
* Return values from both paths are merged back in original call order.
|
|
202
|
+
* @param executionPayload - The execution payload to simulate.
|
|
203
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
204
|
+
* @returns The merged simulation result.
|
|
205
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
172
206
|
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
173
|
-
const
|
|
174
|
-
|
|
207
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
208
|
+
const remainingPayload = {
|
|
209
|
+
...executionPayload,
|
|
210
|
+
calls: remainingCalls
|
|
211
|
+
};
|
|
212
|
+
const chainInfo = await this.getChainInfo();
|
|
213
|
+
const blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
214
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
215
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true) : Promise.resolve([]),
|
|
216
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, opts.from, feeOptions, opts.skipTxValidation, opts.skipFeeEnforcement ?? true) : Promise.resolve(null)
|
|
217
|
+
]);
|
|
218
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
175
219
|
}
|
|
176
220
|
async profileTx(executionPayload, opts) {
|
|
177
221
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
@@ -236,16 +280,12 @@ import { inspect } from 'util';
|
|
|
236
280
|
const instance = await this.pxe.getContractInstance(address);
|
|
237
281
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
238
282
|
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
239
|
-
const
|
|
240
|
-
this.aztecNode.getNullifierMembershipWitness('latest', initNullifier),
|
|
241
|
-
publiclyRegisteredContract ? this.aztecNode.getContractClass(publiclyRegisteredContract.currentContractClassId || instance?.currentContractClassId) : undefined
|
|
242
|
-
]);
|
|
283
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
243
284
|
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
244
285
|
return {
|
|
245
286
|
instance: instance ?? undefined,
|
|
246
287
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
247
288
|
isContractPublished: !!publiclyRegisteredContract,
|
|
248
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
249
289
|
isContractUpdated: !!isContractUpdated,
|
|
250
290
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
251
291
|
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
2
|
-
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLEtBQUssVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDL0QsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
6
|
+
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
7
|
+
/**
|
|
8
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
9
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
10
|
+
*
|
|
11
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
12
|
+
* Any non-public-static call may enqueue public state mutations
|
|
13
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
14
|
+
* must go through the normal simulation path to see the correct state.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
18
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
19
|
+
optimizableCalls: FunctionCall[];
|
|
20
|
+
/** All remaining calls. */
|
|
21
|
+
remainingCalls: FunctionCall[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
25
|
+
* and sending each batch directly to the node.
|
|
26
|
+
*
|
|
27
|
+
* @param node - The Aztec node to simulate on.
|
|
28
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
29
|
+
* @param from - The account address making the calls.
|
|
30
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
31
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
32
|
+
* @param blockHeader - Block header to use as anchor.
|
|
33
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
34
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
35
|
+
*/
|
|
36
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement?: boolean): Promise<TxSimulationResult[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
39
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
40
|
+
* concatenated: optimized first, then normal.
|
|
41
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
42
|
+
*
|
|
43
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
44
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
45
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult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WAAW,EACxB,kBAAkB,GAAE,OAAc,GACjC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAuB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,GACtC,kBAAkB,CAoBpB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
5
|
+
import { ClaimedLengthArray, CountedPublicCallRequest, PrivateCircuitPublicInputs, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
6
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
7
|
+
import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, TxContext, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
/**
|
|
9
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
10
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
11
|
+
*
|
|
12
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
13
|
+
* Any non-public-static call may enqueue public state mutations
|
|
14
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
15
|
+
* must go through the normal simulation path to see the correct state.
|
|
16
|
+
*
|
|
17
|
+
*/ export function extractOptimizablePublicStaticCalls(payload) {
|
|
18
|
+
const splitIndex = payload.calls.findIndex((call)=>!call.isPublicStatic());
|
|
19
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
20
|
+
return {
|
|
21
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
22
|
+
remainingCalls: payload.calls.slice(boundary)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
27
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
28
|
+
*
|
|
29
|
+
* @param node - The Aztec node to simulate on.
|
|
30
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
31
|
+
* @param from - The account address making the calls.
|
|
32
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
33
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
34
|
+
* @param blockHeader - Block header to use as anchor.
|
|
35
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
36
|
+
* @returns TxSimulationResult with public return values.
|
|
37
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement) {
|
|
38
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
39
|
+
const publicFunctionCalldata = [];
|
|
40
|
+
for (const call of publicStaticCalls){
|
|
41
|
+
const calldata = await HashedValues.fromCalldata([
|
|
42
|
+
call.selector.toField(),
|
|
43
|
+
...call.args
|
|
44
|
+
]);
|
|
45
|
+
publicFunctionCalldata.push(calldata);
|
|
46
|
+
}
|
|
47
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, (i)=>{
|
|
48
|
+
const call = publicStaticCalls[i];
|
|
49
|
+
if (!call) {
|
|
50
|
+
return CountedPublicCallRequest.empty();
|
|
51
|
+
}
|
|
52
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i].hash);
|
|
53
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
54
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
55
|
+
});
|
|
56
|
+
const publicCallRequestsArray = new ClaimedLengthArray(publicCallRequests, publicStaticCalls.length);
|
|
57
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
58
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
59
|
+
anchorBlockHeader: blockHeader,
|
|
60
|
+
txContext: txContext,
|
|
61
|
+
publicCallRequests: publicCallRequestsArray,
|
|
62
|
+
startSideEffectCounter: new Fr(0),
|
|
63
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1)
|
|
64
|
+
});
|
|
65
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
66
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(Buffer.alloc(0), Buffer.alloc(0), new Map(), publicInputs, [], new Map(), [], [], [], [], []);
|
|
67
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
68
|
+
const provingResult = await generateSimulatedProvingResult(privateResult, (_contractAddress, _functionSelector)=>Promise.resolve(''), 1);
|
|
69
|
+
provingResult.publicInputs.feePayer = from;
|
|
70
|
+
const tx = await Tx.create({
|
|
71
|
+
data: provingResult.publicInputs,
|
|
72
|
+
chonkProof: ChonkProof.empty(),
|
|
73
|
+
contractClassLogFields: [],
|
|
74
|
+
publicFunctionCalldata: publicFunctionCalldata
|
|
75
|
+
});
|
|
76
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
77
|
+
if (publicOutput.revertReason) {
|
|
78
|
+
throw publicOutput.revertReason;
|
|
79
|
+
}
|
|
80
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
84
|
+
* and sending each batch directly to the node.
|
|
85
|
+
*
|
|
86
|
+
* @param node - The Aztec node to simulate on.
|
|
87
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
88
|
+
* @param from - The account address making the calls.
|
|
89
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
90
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
91
|
+
* @param blockHeader - Block header to use as anchor.
|
|
92
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
93
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
94
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true) {
|
|
95
|
+
const batches = [];
|
|
96
|
+
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
97
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
98
|
+
}
|
|
99
|
+
const results = [];
|
|
100
|
+
for (const batch of batches){
|
|
101
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement);
|
|
102
|
+
results.push(result);
|
|
103
|
+
}
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
108
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
109
|
+
* concatenated: optimized first, then normal.
|
|
110
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
111
|
+
*
|
|
112
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
113
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
114
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
115
|
+
*/ export function buildMergedSimulationResult(optimizedResults, normalResult) {
|
|
116
|
+
const optimizedReturnValues = optimizedResults.flatMap((r)=>r.publicOutput?.publicReturnValues ?? []);
|
|
117
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
118
|
+
const allReturnValues = [
|
|
119
|
+
...optimizedReturnValues,
|
|
120
|
+
...normalReturnValues
|
|
121
|
+
];
|
|
122
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
123
|
+
const mergedPublicOutput = baseResult.publicOutput ? {
|
|
124
|
+
...baseResult.publicOutput,
|
|
125
|
+
publicReturnValues: allReturnValues
|
|
126
|
+
} : undefined;
|
|
127
|
+
return new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallet-sdk",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.43597cc1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
@@ -13,8 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"typedocOptions": {
|
|
15
15
|
"entryPoints": [
|
|
16
|
-
"./src/index.ts"
|
|
16
|
+
"./src/base-wallet/index.ts",
|
|
17
|
+
"./src/extension/handlers/index.ts",
|
|
18
|
+
"./src/extension/provider/index.ts",
|
|
19
|
+
"./src/crypto.ts",
|
|
20
|
+
"./src/types.ts",
|
|
21
|
+
"./src/manager/index.ts"
|
|
17
22
|
],
|
|
23
|
+
"name": "Wallet SDK",
|
|
18
24
|
"tsconfig": "./tsconfig.json"
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
@@ -65,15 +71,15 @@
|
|
|
65
71
|
]
|
|
66
72
|
},
|
|
67
73
|
"dependencies": {
|
|
68
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
71
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
72
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
73
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
74
|
+
"@aztec/aztec.js": "0.0.1-commit.43597cc1",
|
|
75
|
+
"@aztec/constants": "0.0.1-commit.43597cc1",
|
|
76
|
+
"@aztec/entrypoints": "0.0.1-commit.43597cc1",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.43597cc1",
|
|
78
|
+
"@aztec/pxe": "0.0.1-commit.43597cc1",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.43597cc1"
|
|
74
80
|
},
|
|
75
81
|
"devDependencies": {
|
|
76
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
82
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.43597cc1",
|
|
77
83
|
"@jest/globals": "^30.0.0",
|
|
78
84
|
"@types/jest": "^30.0.0",
|
|
79
85
|
"@types/node": "^22.15.17",
|
|
@@ -5,6 +5,7 @@ import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
|
5
5
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
6
6
|
import type {
|
|
7
7
|
Aliased,
|
|
8
|
+
AppCapabilities,
|
|
8
9
|
BatchResults,
|
|
9
10
|
BatchedMethod,
|
|
10
11
|
PrivateEvent,
|
|
@@ -13,6 +14,7 @@ import type {
|
|
|
13
14
|
SendOptions,
|
|
14
15
|
SimulateOptions,
|
|
15
16
|
Wallet,
|
|
17
|
+
WalletCapabilities,
|
|
16
18
|
} from '@aztec/aztec.js/wallet';
|
|
17
19
|
import {
|
|
18
20
|
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
@@ -43,16 +45,18 @@ import { SimulationError } from '@aztec/stdlib/errors';
|
|
|
43
45
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
44
46
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
45
47
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
46
|
-
import
|
|
47
|
-
TxExecutionRequest,
|
|
48
|
-
TxProfileResult,
|
|
48
|
+
import {
|
|
49
|
+
type TxExecutionRequest,
|
|
50
|
+
type TxProfileResult,
|
|
49
51
|
TxSimulationResult,
|
|
50
|
-
UtilitySimulationResult,
|
|
52
|
+
type UtilitySimulationResult,
|
|
51
53
|
} from '@aztec/stdlib/tx';
|
|
52
54
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
55
|
|
|
54
56
|
import { inspect } from 'util';
|
|
55
57
|
|
|
58
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
59
|
+
|
|
56
60
|
/**
|
|
57
61
|
* Options to configure fee payment for a transaction
|
|
58
62
|
*/
|
|
@@ -137,6 +141,23 @@ export abstract class BaseWallet implements Wallet {
|
|
|
137
141
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
138
142
|
}
|
|
139
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Request capabilities from the wallet.
|
|
146
|
+
*
|
|
147
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
148
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
149
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
150
|
+
* friction by allowing apps to request permissions upfront.
|
|
151
|
+
*
|
|
152
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
153
|
+
* while the feature stabilizes.
|
|
154
|
+
*
|
|
155
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
156
|
+
*/
|
|
157
|
+
public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
158
|
+
throw new Error('Not implemented');
|
|
159
|
+
}
|
|
160
|
+
|
|
140
161
|
public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
141
162
|
const results: any[] = [];
|
|
142
163
|
for (const method of methods) {
|
|
@@ -263,17 +284,67 @@ export abstract class BaseWallet implements Wallet {
|
|
|
263
284
|
return instance;
|
|
264
285
|
}
|
|
265
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
289
|
+
* @param executionPayload - The execution payload to simulate.
|
|
290
|
+
* @param from - The sender address.
|
|
291
|
+
* @param feeOptions - Fee options for the transaction.
|
|
292
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
293
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
294
|
+
*/
|
|
295
|
+
protected async simulateViaEntrypoint(
|
|
296
|
+
executionPayload: ExecutionPayload,
|
|
297
|
+
from: AztecAddress,
|
|
298
|
+
feeOptions: FeeOptions,
|
|
299
|
+
skipTxValidation?: boolean,
|
|
300
|
+
skipFeeEnforcement?: boolean,
|
|
301
|
+
) {
|
|
302
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
303
|
+
return this.pxe.simulateTx(txRequest, true /* simulatePublic */, skipTxValidation, skipFeeEnforcement);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
308
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
309
|
+
* Return values from both paths are merged back in original call order.
|
|
310
|
+
* @param executionPayload - The execution payload to simulate.
|
|
311
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
312
|
+
* @returns The merged simulation result.
|
|
313
|
+
*/
|
|
266
314
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
267
315
|
const feeOptions = opts.fee?.estimateGas
|
|
268
316
|
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
269
317
|
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
318
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
319
|
+
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
320
|
+
|
|
321
|
+
const chainInfo = await this.getChainInfo();
|
|
322
|
+
const blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
323
|
+
|
|
324
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
325
|
+
optimizableCalls.length > 0
|
|
326
|
+
? simulateViaNode(
|
|
327
|
+
this.aztecNode,
|
|
328
|
+
optimizableCalls,
|
|
329
|
+
opts.from,
|
|
330
|
+
chainInfo,
|
|
331
|
+
feeOptions.gasSettings,
|
|
332
|
+
blockHeader,
|
|
333
|
+
opts.skipFeeEnforcement ?? true,
|
|
334
|
+
)
|
|
335
|
+
: Promise.resolve([]),
|
|
336
|
+
remainingCalls.length > 0
|
|
337
|
+
? this.simulateViaEntrypoint(
|
|
338
|
+
remainingPayload,
|
|
339
|
+
opts.from,
|
|
340
|
+
feeOptions,
|
|
341
|
+
opts.skipTxValidation,
|
|
342
|
+
opts.skipFeeEnforcement ?? true,
|
|
343
|
+
)
|
|
344
|
+
: Promise.resolve(null),
|
|
345
|
+
]);
|
|
346
|
+
|
|
347
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
277
348
|
}
|
|
278
349
|
|
|
279
350
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
@@ -352,14 +423,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
352
423
|
const instance = await this.pxe.getContractInstance(address);
|
|
353
424
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
354
425
|
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
355
|
-
const
|
|
356
|
-
this.aztecNode.getNullifierMembershipWitness('latest', initNullifier),
|
|
357
|
-
publiclyRegisteredContract
|
|
358
|
-
? this.aztecNode.getContractClass(
|
|
359
|
-
publiclyRegisteredContract.currentContractClassId || instance?.currentContractClassId,
|
|
360
|
-
)
|
|
361
|
-
: undefined,
|
|
362
|
-
]);
|
|
426
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
363
427
|
const isContractUpdated =
|
|
364
428
|
publiclyRegisteredContract &&
|
|
365
429
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
@@ -367,7 +431,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
367
431
|
instance: instance ?? undefined,
|
|
368
432
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
369
433
|
isContractPublished: !!publiclyRegisteredContract,
|
|
370
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
371
434
|
isContractUpdated: !!isContractUpdated,
|
|
372
435
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
|
373
436
|
};
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
3
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
4
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
7
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
8
|
+
import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
11
|
+
import {
|
|
12
|
+
ClaimedLengthArray,
|
|
13
|
+
CountedPublicCallRequest,
|
|
14
|
+
PrivateCircuitPublicInputs,
|
|
15
|
+
PublicCallRequest,
|
|
16
|
+
} from '@aztec/stdlib/kernel';
|
|
17
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
18
|
+
import {
|
|
19
|
+
type BlockHeader,
|
|
20
|
+
type ExecutionPayload,
|
|
21
|
+
HashedValues,
|
|
22
|
+
PrivateCallExecutionResult,
|
|
23
|
+
PrivateExecutionResult,
|
|
24
|
+
PublicSimulationOutput,
|
|
25
|
+
Tx,
|
|
26
|
+
TxContext,
|
|
27
|
+
TxSimulationResult,
|
|
28
|
+
} from '@aztec/stdlib/tx';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
32
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
33
|
+
*
|
|
34
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
35
|
+
* Any non-public-static call may enqueue public state mutations
|
|
36
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
37
|
+
* must go through the normal simulation path to see the correct state.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
41
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
42
|
+
optimizableCalls: FunctionCall[];
|
|
43
|
+
/** All remaining calls. */
|
|
44
|
+
remainingCalls: FunctionCall[];
|
|
45
|
+
} {
|
|
46
|
+
const splitIndex = payload.calls.findIndex(call => !call.isPublicStatic());
|
|
47
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
48
|
+
return {
|
|
49
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
50
|
+
remainingCalls: payload.calls.slice(boundary),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
56
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
57
|
+
*
|
|
58
|
+
* @param node - The Aztec node to simulate on.
|
|
59
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
60
|
+
* @param from - The account address making the calls.
|
|
61
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
62
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
63
|
+
* @param blockHeader - Block header to use as anchor.
|
|
64
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
65
|
+
* @returns TxSimulationResult with public return values.
|
|
66
|
+
*/
|
|
67
|
+
async function simulateBatchViaNode(
|
|
68
|
+
node: AztecNode,
|
|
69
|
+
publicStaticCalls: FunctionCall[],
|
|
70
|
+
from: AztecAddress,
|
|
71
|
+
chainInfo: ChainInfo,
|
|
72
|
+
gasSettings: GasSettings,
|
|
73
|
+
blockHeader: BlockHeader,
|
|
74
|
+
skipFeeEnforcement: boolean,
|
|
75
|
+
): Promise<TxSimulationResult> {
|
|
76
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
77
|
+
|
|
78
|
+
const publicFunctionCalldata: HashedValues[] = [];
|
|
79
|
+
for (const call of publicStaticCalls) {
|
|
80
|
+
const calldata = await HashedValues.fromCalldata([call.selector.toField(), ...call.args]);
|
|
81
|
+
publicFunctionCalldata.push(calldata);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, i => {
|
|
85
|
+
const call = publicStaticCalls[i];
|
|
86
|
+
if (!call) {
|
|
87
|
+
return CountedPublicCallRequest.empty();
|
|
88
|
+
}
|
|
89
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i]!.hash);
|
|
90
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
91
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const publicCallRequestsArray: ClaimedLengthArray<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL> =
|
|
95
|
+
new ClaimedLengthArray(
|
|
96
|
+
publicCallRequests as Tuple<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL>,
|
|
97
|
+
publicStaticCalls.length,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
101
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
102
|
+
anchorBlockHeader: blockHeader,
|
|
103
|
+
txContext: txContext,
|
|
104
|
+
publicCallRequests: publicCallRequestsArray,
|
|
105
|
+
startSideEffectCounter: new Fr(0),
|
|
106
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
110
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(
|
|
111
|
+
Buffer.alloc(0),
|
|
112
|
+
Buffer.alloc(0),
|
|
113
|
+
new Map(),
|
|
114
|
+
publicInputs,
|
|
115
|
+
[],
|
|
116
|
+
new Map(),
|
|
117
|
+
[],
|
|
118
|
+
[],
|
|
119
|
+
[],
|
|
120
|
+
[],
|
|
121
|
+
[],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
125
|
+
|
|
126
|
+
const provingResult = await generateSimulatedProvingResult(
|
|
127
|
+
privateResult,
|
|
128
|
+
(_contractAddress: AztecAddress, _functionSelector: FunctionSelector) => Promise.resolve(''),
|
|
129
|
+
1, // minRevertibleSideEffectCounter
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
provingResult.publicInputs.feePayer = from;
|
|
133
|
+
|
|
134
|
+
const tx = await Tx.create({
|
|
135
|
+
data: provingResult.publicInputs,
|
|
136
|
+
chonkProof: ChonkProof.empty(),
|
|
137
|
+
contractClassLogFields: [],
|
|
138
|
+
publicFunctionCalldata: publicFunctionCalldata,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
142
|
+
|
|
143
|
+
if (publicOutput.revertReason) {
|
|
144
|
+
throw publicOutput.revertReason;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
152
|
+
* and sending each batch directly to the node.
|
|
153
|
+
*
|
|
154
|
+
* @param node - The Aztec node to simulate on.
|
|
155
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
156
|
+
* @param from - The account address making the calls.
|
|
157
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
158
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
159
|
+
* @param blockHeader - Block header to use as anchor.
|
|
160
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
161
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
162
|
+
*/
|
|
163
|
+
export async function simulateViaNode(
|
|
164
|
+
node: AztecNode,
|
|
165
|
+
publicStaticCalls: FunctionCall[],
|
|
166
|
+
from: AztecAddress,
|
|
167
|
+
chainInfo: ChainInfo,
|
|
168
|
+
gasSettings: GasSettings,
|
|
169
|
+
blockHeader: BlockHeader,
|
|
170
|
+
skipFeeEnforcement: boolean = true,
|
|
171
|
+
): Promise<TxSimulationResult[]> {
|
|
172
|
+
const batches: FunctionCall[][] = [];
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL) {
|
|
175
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const results: TxSimulationResult[] = [];
|
|
179
|
+
|
|
180
|
+
for (const batch of batches) {
|
|
181
|
+
const result = await simulateBatchViaNode(
|
|
182
|
+
node,
|
|
183
|
+
batch,
|
|
184
|
+
from,
|
|
185
|
+
chainInfo,
|
|
186
|
+
gasSettings,
|
|
187
|
+
blockHeader,
|
|
188
|
+
skipFeeEnforcement,
|
|
189
|
+
);
|
|
190
|
+
results.push(result);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return results;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
198
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
199
|
+
* concatenated: optimized first, then normal.
|
|
200
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
201
|
+
*
|
|
202
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
203
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
204
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
205
|
+
*/
|
|
206
|
+
export function buildMergedSimulationResult(
|
|
207
|
+
optimizedResults: TxSimulationResult[],
|
|
208
|
+
normalResult: TxSimulationResult | null,
|
|
209
|
+
): TxSimulationResult {
|
|
210
|
+
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
211
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
212
|
+
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
213
|
+
|
|
214
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
215
|
+
|
|
216
|
+
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
217
|
+
? {
|
|
218
|
+
...baseResult.publicOutput,
|
|
219
|
+
publicReturnValues: allReturnValues,
|
|
220
|
+
}
|
|
221
|
+
: undefined;
|
|
222
|
+
|
|
223
|
+
return new TxSimulationResult(
|
|
224
|
+
baseResult.privateExecutionResult,
|
|
225
|
+
baseResult.publicInputs,
|
|
226
|
+
mergedPublicOutput,
|
|
227
|
+
normalResult?.stats,
|
|
228
|
+
);
|
|
229
|
+
}
|