@aztec/wallet-sdk 0.0.1-commit.0b941701 → 0.0.1-commit.0c875d939
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 +39 -6
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +83 -14
- 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 +111 -26
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +230 -0
|
@@ -2,11 +2,12 @@ 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, SimulateUtilityOptions, 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';
|
|
9
9
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
10
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
10
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
11
12
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
12
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
@@ -14,7 +15,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
14
15
|
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
15
16
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
16
17
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
17
|
-
import type
|
|
18
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilitySimulationResult } from '@aztec/stdlib/tx';
|
|
18
19
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
19
20
|
/**
|
|
20
21
|
* Options to configure fee payment for a transaction
|
|
@@ -39,7 +40,8 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
39
40
|
protected log: import("@aztec/foundation/log").Logger;
|
|
40
41
|
protected minFeePadding: number;
|
|
41
42
|
protected cancellableTransactions: boolean;
|
|
42
|
-
protected constructor(pxe: PXE, aztecNode: AztecNode);
|
|
43
|
+
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
44
|
+
protected scopesFor(from: AztecAddress): AztecAddress[];
|
|
43
45
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
44
46
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
45
47
|
/**
|
|
@@ -53,6 +55,20 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
53
55
|
getChainInfo(): Promise<ChainInfo>;
|
|
54
56
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
55
57
|
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
58
|
+
/**
|
|
59
|
+
* Request capabilities from the wallet.
|
|
60
|
+
*
|
|
61
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
62
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
63
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
64
|
+
* friction by allowing apps to request permissions upfront.
|
|
65
|
+
*
|
|
66
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
67
|
+
* while the feature stabilizes.
|
|
68
|
+
*
|
|
69
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
70
|
+
*/
|
|
71
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
56
72
|
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
57
73
|
/**
|
|
58
74
|
* Completes partial user-provided fee options with wallet defaults.
|
|
@@ -82,17 +98,34 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
82
98
|
}>;
|
|
83
99
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
84
100
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
101
|
+
/**
|
|
102
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
103
|
+
* @param executionPayload - The execution payload to simulate.
|
|
104
|
+
* @param from - The sender address.
|
|
105
|
+
* @param feeOptions - Fee options for the transaction.
|
|
106
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
107
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
108
|
+
* @param scopes - The scopes to use for the simulation.
|
|
109
|
+
*/
|
|
110
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions, scopes: AccessScopes, skipTxValidation?: boolean, skipFeeEnforcement?: boolean): Promise<TxSimulationResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
113
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
114
|
+
* Return values from both paths are merged back in original call order.
|
|
115
|
+
* @param executionPayload - The execution payload to simulate.
|
|
116
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
117
|
+
* @returns The merged simulation result.
|
|
118
|
+
*/
|
|
85
119
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
86
120
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
87
121
|
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
88
122
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
89
|
-
simulateUtility(call: FunctionCall,
|
|
123
|
+
simulateUtility(call: FunctionCall, opts: SimulateUtilityOptions): Promise<UtilitySimulationResult>;
|
|
90
124
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
91
125
|
getContractMetadata(address: AztecAddress): Promise<{
|
|
92
126
|
instance: ContractInstanceWithAddress | undefined;
|
|
93
127
|
isContractInitialized: boolean;
|
|
94
128
|
isContractPublished: boolean;
|
|
95
|
-
isContractClassPubliclyRegistered: boolean;
|
|
96
129
|
isContractUpdated: boolean;
|
|
97
130
|
updatedContractClassId: Fr | undefined;
|
|
98
131
|
}>;
|
|
@@ -101,4 +134,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
101
134
|
isContractClassPubliclyRegistered: boolean;
|
|
102
135
|
}>;
|
|
103
136
|
}
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
137
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL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oot":"","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,sBAAsB,EACtB,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,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,M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Y;;;;;;OAe9C;IAEK,wBAAwB,CAAC,EAAE,EAAE,EAAE;;;OAMpC;CACF"}
|
|
@@ -11,6 +11,7 @@ import { Gas, GasSettings } 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 {
|
|
@@ -20,13 +21,20 @@ import { inspect } from 'util';
|
|
|
20
21
|
minFeePadding;
|
|
21
22
|
cancellableTransactions;
|
|
22
23
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
23
|
-
constructor(pxe, aztecNode){
|
|
24
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
24
25
|
this.pxe = pxe;
|
|
25
26
|
this.aztecNode = aztecNode;
|
|
26
|
-
this.log =
|
|
27
|
+
this.log = log;
|
|
27
28
|
this.minFeePadding = 0.5;
|
|
28
29
|
this.cancellableTransactions = false;
|
|
29
30
|
}
|
|
31
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
32
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
33
|
+
scopesFor(from) {
|
|
34
|
+
return from.isZero() ? [] : [
|
|
35
|
+
from
|
|
36
|
+
];
|
|
37
|
+
}
|
|
30
38
|
/**
|
|
31
39
|
* Returns the list of aliased contacts associated with the wallet.
|
|
32
40
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -67,6 +75,21 @@ import { inspect } from 'util';
|
|
|
67
75
|
const chainInfo = await this.getChainInfo();
|
|
68
76
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
69
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Request capabilities from the wallet.
|
|
80
|
+
*
|
|
81
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
82
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
83
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
84
|
+
* friction by allowing apps to request permissions upfront.
|
|
85
|
+
*
|
|
86
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
87
|
+
* while the feature stabilizes.
|
|
88
|
+
*
|
|
89
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
90
|
+
*/ requestCapabilities(_manifest) {
|
|
91
|
+
throw new Error('Not implemented');
|
|
92
|
+
}
|
|
70
93
|
async batch(methods) {
|
|
71
94
|
const results = [];
|
|
72
95
|
for (const method of methods){
|
|
@@ -168,20 +191,65 @@ import { inspect } from 'util';
|
|
|
168
191
|
}
|
|
169
192
|
return instance;
|
|
170
193
|
}
|
|
171
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
196
|
+
* @param executionPayload - The execution payload to simulate.
|
|
197
|
+
* @param from - The sender address.
|
|
198
|
+
* @param feeOptions - Fee options for the transaction.
|
|
199
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
200
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
201
|
+
* @param scopes - The scopes to use for the simulation.
|
|
202
|
+
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement) {
|
|
203
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
204
|
+
return this.pxe.simulateTx(txRequest, {
|
|
205
|
+
simulatePublic: true,
|
|
206
|
+
skipTxValidation,
|
|
207
|
+
skipFeeEnforcement,
|
|
208
|
+
scopes
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
213
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
214
|
+
* Return values from both paths are merged back in original call order.
|
|
215
|
+
* @param executionPayload - The execution payload to simulate.
|
|
216
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
217
|
+
* @returns The merged simulation result.
|
|
218
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
172
219
|
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
|
-
|
|
220
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
221
|
+
const remainingPayload = {
|
|
222
|
+
...executionPayload,
|
|
223
|
+
calls: remainingCalls
|
|
224
|
+
};
|
|
225
|
+
const chainInfo = await this.getChainInfo();
|
|
226
|
+
let blockHeader;
|
|
227
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
228
|
+
// To keep things consistent, we'll always try with PXE first
|
|
229
|
+
try {
|
|
230
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
231
|
+
} catch {
|
|
232
|
+
blockHeader = await this.aztecNode.getBlockHeader();
|
|
233
|
+
}
|
|
234
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
235
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true) : Promise.resolve([]),
|
|
236
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, opts.from, feeOptions, this.scopesFor(opts.from), opts.skipTxValidation, opts.skipFeeEnforcement ?? true) : Promise.resolve(null)
|
|
237
|
+
]);
|
|
238
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
175
239
|
}
|
|
176
240
|
async profileTx(executionPayload, opts) {
|
|
177
241
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
178
242
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
179
|
-
return this.pxe.profileTx(txRequest,
|
|
243
|
+
return this.pxe.profileTx(txRequest, {
|
|
244
|
+
profileMode: opts.profileMode,
|
|
245
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
246
|
+
scopes: this.scopesFor(opts.from)
|
|
247
|
+
});
|
|
180
248
|
}
|
|
181
249
|
async sendTx(executionPayload, opts) {
|
|
182
250
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
183
251
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
184
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
252
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFor(opts.from));
|
|
185
253
|
const tx = await provenTx.toTx();
|
|
186
254
|
const txHash = tx.getTxHash();
|
|
187
255
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -213,8 +281,13 @@ import { inspect } from 'util';
|
|
|
213
281
|
}
|
|
214
282
|
return err;
|
|
215
283
|
}
|
|
216
|
-
simulateUtility(call,
|
|
217
|
-
return this.pxe.simulateUtility(call,
|
|
284
|
+
simulateUtility(call, opts) {
|
|
285
|
+
return this.pxe.simulateUtility(call, {
|
|
286
|
+
authwits: opts.authWitnesses,
|
|
287
|
+
scopes: [
|
|
288
|
+
opts.scope
|
|
289
|
+
]
|
|
290
|
+
});
|
|
218
291
|
}
|
|
219
292
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
220
293
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
@@ -236,16 +309,12 @@ import { inspect } from 'util';
|
|
|
236
309
|
const instance = await this.pxe.getContractInstance(address);
|
|
237
310
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
238
311
|
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
|
-
]);
|
|
312
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
243
313
|
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
244
314
|
return {
|
|
245
315
|
instance: instance ?? undefined,
|
|
246
316
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
247
317
|
isContractPublished: !!publiclyRegisteredContract,
|
|
248
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
249
318
|
isContractUpdated: !!isContractUpdated,
|
|
250
319
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
251
320
|
};
|
|
@@ -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[], normalResult: TxSimulationResult | null): TxSimulationResult;
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUF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ALL } 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(''), node, 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.0c875d939",
|
|
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.0c875d939",
|
|
75
|
+
"@aztec/constants": "0.0.1-commit.0c875d939",
|
|
76
|
+
"@aztec/entrypoints": "0.0.1-commit.0c875d939",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.0c875d939",
|
|
78
|
+
"@aztec/pxe": "0.0.1-commit.0c875d939",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.0c875d939"
|
|
74
80
|
},
|
|
75
81
|
"devDependencies": {
|
|
76
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
82
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.0c875d939",
|
|
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,
|
|
@@ -12,7 +13,9 @@ import type {
|
|
|
12
13
|
ProfileOptions,
|
|
13
14
|
SendOptions,
|
|
14
15
|
SimulateOptions,
|
|
16
|
+
SimulateUtilityOptions,
|
|
15
17
|
Wallet,
|
|
18
|
+
WalletCapabilities,
|
|
16
19
|
} from '@aztec/aztec.js/wallet';
|
|
17
20
|
import {
|
|
18
21
|
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
@@ -25,6 +28,7 @@ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
|
25
28
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
26
29
|
import { createLogger } from '@aztec/foundation/log';
|
|
27
30
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
31
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
28
32
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
29
33
|
import {
|
|
30
34
|
type ContractArtifact,
|
|
@@ -43,16 +47,19 @@ import { SimulationError } from '@aztec/stdlib/errors';
|
|
|
43
47
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
44
48
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
45
49
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
46
|
-
import
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
import {
|
|
51
|
+
BlockHeader,
|
|
52
|
+
type TxExecutionRequest,
|
|
53
|
+
type TxProfileResult,
|
|
49
54
|
TxSimulationResult,
|
|
50
|
-
UtilitySimulationResult,
|
|
55
|
+
type UtilitySimulationResult,
|
|
51
56
|
} from '@aztec/stdlib/tx';
|
|
52
57
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
58
|
|
|
54
59
|
import { inspect } from 'util';
|
|
55
60
|
|
|
61
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
62
|
+
|
|
56
63
|
/**
|
|
57
64
|
* Options to configure fee payment for a transaction
|
|
58
65
|
*/
|
|
@@ -72,8 +79,6 @@ export type FeeOptions = {
|
|
|
72
79
|
* A base class for Wallet implementations
|
|
73
80
|
*/
|
|
74
81
|
export abstract class BaseWallet implements Wallet {
|
|
75
|
-
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
|
-
|
|
77
82
|
protected minFeePadding = 0.5;
|
|
78
83
|
protected cancellableTransactions = false;
|
|
79
84
|
|
|
@@ -81,8 +86,15 @@ export abstract class BaseWallet implements Wallet {
|
|
|
81
86
|
protected constructor(
|
|
82
87
|
protected readonly pxe: PXE,
|
|
83
88
|
protected readonly aztecNode: AztecNode,
|
|
89
|
+
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
84
90
|
) {}
|
|
85
91
|
|
|
92
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
93
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
94
|
+
protected scopesFor(from: AztecAddress): AztecAddress[] {
|
|
95
|
+
return from.isZero() ? [] : [from];
|
|
96
|
+
}
|
|
97
|
+
|
|
86
98
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
87
99
|
|
|
88
100
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -137,6 +149,23 @@ export abstract class BaseWallet implements Wallet {
|
|
|
137
149
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
138
150
|
}
|
|
139
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Request capabilities from the wallet.
|
|
154
|
+
*
|
|
155
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
156
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
157
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
158
|
+
* friction by allowing apps to request permissions upfront.
|
|
159
|
+
*
|
|
160
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
161
|
+
* while the feature stabilizes.
|
|
162
|
+
*
|
|
163
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
164
|
+
*/
|
|
165
|
+
public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
166
|
+
throw new Error('Not implemented');
|
|
167
|
+
}
|
|
168
|
+
|
|
140
169
|
public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
141
170
|
const results: any[] = [];
|
|
142
171
|
for (const method of methods) {
|
|
@@ -263,23 +292,87 @@ export abstract class BaseWallet implements Wallet {
|
|
|
263
292
|
return instance;
|
|
264
293
|
}
|
|
265
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
297
|
+
* @param executionPayload - The execution payload to simulate.
|
|
298
|
+
* @param from - The sender address.
|
|
299
|
+
* @param feeOptions - Fee options for the transaction.
|
|
300
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
301
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
302
|
+
* @param scopes - The scopes to use for the simulation.
|
|
303
|
+
*/
|
|
304
|
+
protected async simulateViaEntrypoint(
|
|
305
|
+
executionPayload: ExecutionPayload,
|
|
306
|
+
from: AztecAddress,
|
|
307
|
+
feeOptions: FeeOptions,
|
|
308
|
+
scopes: AccessScopes,
|
|
309
|
+
skipTxValidation?: boolean,
|
|
310
|
+
skipFeeEnforcement?: boolean,
|
|
311
|
+
) {
|
|
312
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
313
|
+
return this.pxe.simulateTx(txRequest, { simulatePublic: true, skipTxValidation, skipFeeEnforcement, scopes });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
318
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
319
|
+
* Return values from both paths are merged back in original call order.
|
|
320
|
+
* @param executionPayload - The execution payload to simulate.
|
|
321
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
322
|
+
* @returns The merged simulation result.
|
|
323
|
+
*/
|
|
266
324
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
267
325
|
const feeOptions = opts.fee?.estimateGas
|
|
268
326
|
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
269
327
|
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
328
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
329
|
+
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
330
|
+
|
|
331
|
+
const chainInfo = await this.getChainInfo();
|
|
332
|
+
let blockHeader: BlockHeader;
|
|
333
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
334
|
+
// To keep things consistent, we'll always try with PXE first
|
|
335
|
+
try {
|
|
336
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
337
|
+
} catch {
|
|
338
|
+
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
342
|
+
optimizableCalls.length > 0
|
|
343
|
+
? simulateViaNode(
|
|
344
|
+
this.aztecNode,
|
|
345
|
+
optimizableCalls,
|
|
346
|
+
opts.from,
|
|
347
|
+
chainInfo,
|
|
348
|
+
feeOptions.gasSettings,
|
|
349
|
+
blockHeader,
|
|
350
|
+
opts.skipFeeEnforcement ?? true,
|
|
351
|
+
)
|
|
352
|
+
: Promise.resolve([]),
|
|
353
|
+
remainingCalls.length > 0
|
|
354
|
+
? this.simulateViaEntrypoint(
|
|
355
|
+
remainingPayload,
|
|
356
|
+
opts.from,
|
|
357
|
+
feeOptions,
|
|
358
|
+
this.scopesFor(opts.from),
|
|
359
|
+
opts.skipTxValidation,
|
|
360
|
+
opts.skipFeeEnforcement ?? true,
|
|
361
|
+
)
|
|
362
|
+
: Promise.resolve(null),
|
|
363
|
+
]);
|
|
364
|
+
|
|
365
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
277
366
|
}
|
|
278
367
|
|
|
279
368
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
280
369
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
281
370
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
282
|
-
return this.pxe.profileTx(txRequest,
|
|
371
|
+
return this.pxe.profileTx(txRequest, {
|
|
372
|
+
profileMode: opts.profileMode,
|
|
373
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
374
|
+
scopes: this.scopesFor(opts.from),
|
|
375
|
+
});
|
|
283
376
|
}
|
|
284
377
|
|
|
285
378
|
public async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
@@ -288,7 +381,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
288
381
|
): Promise<SendReturn<W>> {
|
|
289
382
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
290
383
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
291
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
384
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFor(opts.from));
|
|
292
385
|
const tx = await provenTx.toTx();
|
|
293
386
|
const txHash = tx.getTxHash();
|
|
294
387
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -324,8 +417,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
324
417
|
return err;
|
|
325
418
|
}
|
|
326
419
|
|
|
327
|
-
simulateUtility(call: FunctionCall,
|
|
328
|
-
return this.pxe.simulateUtility(call, authwits);
|
|
420
|
+
simulateUtility(call: FunctionCall, opts: SimulateUtilityOptions): Promise<UtilitySimulationResult> {
|
|
421
|
+
return this.pxe.simulateUtility(call, { authwits: opts.authWitnesses, scopes: [opts.scope] });
|
|
329
422
|
}
|
|
330
423
|
|
|
331
424
|
async getPrivateEvents<T>(
|
|
@@ -352,14 +445,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
352
445
|
const instance = await this.pxe.getContractInstance(address);
|
|
353
446
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
354
447
|
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
|
-
]);
|
|
448
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
363
449
|
const isContractUpdated =
|
|
364
450
|
publiclyRegisteredContract &&
|
|
365
451
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
@@ -367,7 +453,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
367
453
|
instance: instance ?? undefined,
|
|
368
454
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
369
455
|
isContractPublished: !!publiclyRegisteredContract,
|
|
370
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
371
456
|
isContractUpdated: !!isContractUpdated,
|
|
372
457
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
|
373
458
|
};
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
node,
|
|
130
|
+
1, // minRevertibleSideEffectCounter
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
provingResult.publicInputs.feePayer = from;
|
|
134
|
+
|
|
135
|
+
const tx = await Tx.create({
|
|
136
|
+
data: provingResult.publicInputs,
|
|
137
|
+
chonkProof: ChonkProof.empty(),
|
|
138
|
+
contractClassLogFields: [],
|
|
139
|
+
publicFunctionCalldata: publicFunctionCalldata,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
143
|
+
|
|
144
|
+
if (publicOutput.revertReason) {
|
|
145
|
+
throw publicOutput.revertReason;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
153
|
+
* and sending each batch directly to the node.
|
|
154
|
+
*
|
|
155
|
+
* @param node - The Aztec node to simulate on.
|
|
156
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
157
|
+
* @param from - The account address making the calls.
|
|
158
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
159
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
160
|
+
* @param blockHeader - Block header to use as anchor.
|
|
161
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
162
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
163
|
+
*/
|
|
164
|
+
export async function simulateViaNode(
|
|
165
|
+
node: AztecNode,
|
|
166
|
+
publicStaticCalls: FunctionCall[],
|
|
167
|
+
from: AztecAddress,
|
|
168
|
+
chainInfo: ChainInfo,
|
|
169
|
+
gasSettings: GasSettings,
|
|
170
|
+
blockHeader: BlockHeader,
|
|
171
|
+
skipFeeEnforcement: boolean = true,
|
|
172
|
+
): Promise<TxSimulationResult[]> {
|
|
173
|
+
const batches: FunctionCall[][] = [];
|
|
174
|
+
|
|
175
|
+
for (let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL) {
|
|
176
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const results: TxSimulationResult[] = [];
|
|
180
|
+
|
|
181
|
+
for (const batch of batches) {
|
|
182
|
+
const result = await simulateBatchViaNode(
|
|
183
|
+
node,
|
|
184
|
+
batch,
|
|
185
|
+
from,
|
|
186
|
+
chainInfo,
|
|
187
|
+
gasSettings,
|
|
188
|
+
blockHeader,
|
|
189
|
+
skipFeeEnforcement,
|
|
190
|
+
);
|
|
191
|
+
results.push(result);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return results;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
199
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
200
|
+
* concatenated: optimized first, then normal.
|
|
201
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
202
|
+
*
|
|
203
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
204
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
205
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
206
|
+
*/
|
|
207
|
+
export function buildMergedSimulationResult(
|
|
208
|
+
optimizedResults: TxSimulationResult[],
|
|
209
|
+
normalResult: TxSimulationResult | null,
|
|
210
|
+
): TxSimulationResult {
|
|
211
|
+
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
212
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
213
|
+
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
214
|
+
|
|
215
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
216
|
+
|
|
217
|
+
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
218
|
+
? {
|
|
219
|
+
...baseResult.publicOutput,
|
|
220
|
+
publicReturnValues: allReturnValues,
|
|
221
|
+
}
|
|
222
|
+
: undefined;
|
|
223
|
+
|
|
224
|
+
return new TxSimulationResult(
|
|
225
|
+
baseResult.privateExecutionResult,
|
|
226
|
+
baseResult.publicInputs,
|
|
227
|
+
mergedPublicOutput,
|
|
228
|
+
normalResult?.stats,
|
|
229
|
+
);
|
|
230
|
+
}
|