@aztec/wallet-sdk 0.0.1-commit.b9865e97 → 0.0.1-commit.be03c316
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/README.md +1 -1
- package/dest/base-wallet/base_wallet.d.ts +22 -6
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +104 -50
- package/dest/base-wallet/get_gas_limits.d.ts +36 -0
- package/dest/base-wallet/get_gas_limits.d.ts.map +1 -0
- package/dest/base-wallet/get_gas_limits.js +55 -0
- 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/package.json +8 -8
- package/src/base-wallet/base_wallet.ts +107 -57
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +1 -0
package/README.md
CHANGED
|
@@ -324,7 +324,7 @@ function useWalletDiscovery(chainInfo: ChainInfo, appId: string) {
|
|
|
324
324
|
|
|
325
325
|
Your wallet and the PXE it embeds persist state through a pluggable key-value store (`@aztec/kv-store`). In the browser there are two backends:
|
|
326
326
|
|
|
327
|
-
- **IndexedDB** (`@aztec/kv-store/indexeddb`): the default in browser environments up to Aztec Alpha v4
|
|
327
|
+
- **IndexedDB** (`@aztec/kv-store/deprecated/indexeddb`): the default in browser environments up to Aztec Alpha v4, now moved to a deprecated subpath. We plan to remove this backend, so new browser code should use the SQLite backend below.
|
|
328
328
|
- **SQLite-OPFS** (`@aztec/kv-store/sqlite-opfs`): the default KV store backend from Aztec Alpha v5 on. It's backed by the durable Origin Private File System web standard, and it offers a number of advantages over IndexedDB: a sane transaction model (IDB transactions auto-close the moment the event loop yields, which constrains the store layer), support for encryption at rest, and better performance in the access patterns we exercise the most from both wallet and PXE.
|
|
329
329
|
|
|
330
330
|
The backend is chosen by *which store you construct and hand to the wallet* there is no runtime flag or environment variable.
|
|
@@ -11,9 +11,10 @@ import type { PXE } from '@aztec/pxe/server';
|
|
|
11
11
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
12
12
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
13
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
-
import { type
|
|
15
|
-
import { GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
14
|
+
import { type ContractInstancePreimage } from '@aztec/stdlib/contract';
|
|
15
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
16
16
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
17
|
+
import { type MasterSecretKeys } from '@aztec/stdlib/keys';
|
|
17
18
|
import { ExecutionPayload, type TxExecutionRequest, type TxProfileResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
18
19
|
/**
|
|
19
20
|
* Options to configure fee payment for a transaction
|
|
@@ -59,9 +60,10 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
59
60
|
protected log: import("@aztec/foundation/log").Logger;
|
|
60
61
|
protected minFeePadding: number;
|
|
61
62
|
protected cancellableTransactions: boolean;
|
|
63
|
+
protected defaultWaitInterval?: number;
|
|
62
64
|
private nodeInfoPromise;
|
|
63
65
|
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
64
|
-
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes
|
|
66
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[], sendMessagesAs: AztecAddress | undefined): AztecAddress[];
|
|
65
67
|
/**
|
|
66
68
|
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
67
69
|
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
@@ -80,7 +82,21 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
80
82
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
81
83
|
*/
|
|
82
84
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
87
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
88
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
89
|
+
* depend on it.
|
|
90
|
+
*/
|
|
91
|
+
private getNodeInfo;
|
|
83
92
|
getChainInfo(): Promise<ChainInfo>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
95
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
96
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
97
|
+
* the cached node info, since a wallet talks to a single network.
|
|
98
|
+
*/
|
|
99
|
+
protected getMaxTxGasLimits(): Promise<Gas>;
|
|
84
100
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress | NoFrom, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
85
101
|
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
86
102
|
/**
|
|
@@ -110,7 +126,7 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
110
126
|
*/
|
|
111
127
|
protected getMinFees(estimate?: ManaUsageEstimate): Promise<GasFees>;
|
|
112
128
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
113
|
-
registerContract(instance:
|
|
129
|
+
registerContract(instance: ContractInstancePreimage, artifact?: ContractArtifact, secretKeyOrKeys?: Fr | MasterSecretKeys): Promise<void>;
|
|
114
130
|
registerContractClass(artifact: ContractArtifact): Promise<void>;
|
|
115
131
|
/**
|
|
116
132
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
@@ -149,7 +165,7 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
149
165
|
* @param address - The contract address to query.
|
|
150
166
|
*/
|
|
151
167
|
getContractMetadata(address: AztecAddress): Promise<{
|
|
152
|
-
instance:
|
|
168
|
+
instance: import("@aztec/stdlib/contract").ContractInstancePreimageWithAddress | undefined;
|
|
153
169
|
initializationStatus: ContractInitializationStatus;
|
|
154
170
|
isContractPublished: boolean;
|
|
155
171
|
isContractUpdated: boolean;
|
|
@@ -160,4 +176,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
160
176
|
isContractClassPubliclyRegistered: boolean;
|
|
161
177
|
}>;
|
|
162
178
|
}
|
|
163
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
179
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFL0QsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLGVBQWUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQ2pGLE9BQU8sRUFDTCxLQUFLLHNCQUFzQixFQUUzQixLQUFLLFVBQVUsRUFFaEIsTUFBTSwyQkFBMkIsQ0FBQztBQUNuQyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRTVELE9BQU8sRUFDTCxLQUFLLE9BQU8sRUFDWixLQUFLLGVBQWUsRUFDcEIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssYUFBYSxFQUNsQiw0QkFBNEIsRUFDNUIsS0FBSyxxQkFBcUIsRUFDMUIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssa0JBQWtCLEVBQ3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gBAAgB,CAAC,CAAC,EACtB,QAAQ,EAAE,uBAAuB,EACjC,WAAW,EAAE,kBAAkB,GAC9B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAe5B;IAED;;;OAGG;IACG,mBAAmB,CAAC,OAAO,EAAE,YAAY;;;;;;OAiC9C;IAEK,wBAAwB,CAAC,EAAE,EAAE,EAAE;;;OAMpC;CACF"}
|
|
@@ -9,12 +9,14 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
9
9
|
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
10
10
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
11
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
-
import { computePartialAddress
|
|
12
|
+
import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
13
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
14
14
|
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
15
15
|
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
16
|
+
import { deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
16
17
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
17
18
|
import { inspect } from 'util';
|
|
19
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
18
20
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
19
21
|
/**
|
|
20
22
|
* A base class for Wallet implementations
|
|
@@ -24,6 +26,9 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
24
26
|
log;
|
|
25
27
|
minFeePadding;
|
|
26
28
|
cancellableTransactions;
|
|
29
|
+
// Poll interval (in seconds) injected into sendTx waits when the caller does not specify one. Left undefined on
|
|
30
|
+
// production wallets so the DefaultWaitOpts 1s cadence stands; test wallets talking to in-process nodes lower it.
|
|
31
|
+
defaultWaitInterval;
|
|
27
32
|
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
28
33
|
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
29
34
|
nodeInfoPromise;
|
|
@@ -35,15 +40,23 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
35
40
|
this.minFeePadding = 0.5;
|
|
36
41
|
this.cancellableTransactions = false;
|
|
37
42
|
}
|
|
38
|
-
scopesFrom(from, additionalScopes
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
scopesFrom(from, additionalScopes, sendMessagesAs) {
|
|
44
|
+
// The sendMessagesAs account must be in scope so that its tagging secrets can be accessed.
|
|
45
|
+
const tagSenderScopes = sendMessagesAs ? [
|
|
46
|
+
sendMessagesAs
|
|
47
|
+
] : [];
|
|
48
|
+
const baseScopes = from === NO_FROM ? [] : [
|
|
49
|
+
from
|
|
50
|
+
];
|
|
51
|
+
const allScopes = [
|
|
52
|
+
...baseScopes,
|
|
53
|
+
...additionalScopes,
|
|
54
|
+
...tagSenderScopes
|
|
42
55
|
];
|
|
43
56
|
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
44
57
|
return [
|
|
45
58
|
...scopeSet
|
|
46
|
-
].map(AztecAddress.
|
|
59
|
+
].map(AztecAddress.fromStringUnsafe);
|
|
47
60
|
}
|
|
48
61
|
/**
|
|
49
62
|
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
@@ -61,22 +74,44 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
61
74
|
* - Contacts: more general concept akin to a phone's contact list.
|
|
62
75
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
63
76
|
*/ async getAddressBook() {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
const sources = await this.pxe.getTaggingSecretSources({
|
|
78
|
+
kind: 'address-derived'
|
|
79
|
+
});
|
|
80
|
+
return sources.map((source)=>({
|
|
81
|
+
item: source.sender,
|
|
67
82
|
alias: ''
|
|
68
83
|
}));
|
|
69
84
|
}
|
|
70
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
87
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
88
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
89
|
+
* depend on it.
|
|
90
|
+
*/ getNodeInfo() {
|
|
71
91
|
if (!this.nodeInfoPromise) {
|
|
72
|
-
this.nodeInfoPromise = this.aztecNode.getNodeInfo()
|
|
92
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch((err)=>{
|
|
93
|
+
this.nodeInfoPromise = undefined;
|
|
94
|
+
throw err;
|
|
95
|
+
});
|
|
73
96
|
}
|
|
74
|
-
|
|
97
|
+
return this.nodeInfoPromise;
|
|
98
|
+
}
|
|
99
|
+
async getChainInfo() {
|
|
100
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
75
101
|
return {
|
|
76
102
|
chainId: new Fr(l1ChainId),
|
|
77
103
|
version: new Fr(rollupVersion)
|
|
78
104
|
};
|
|
79
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
108
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
109
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
110
|
+
* the cached node info, since a wallet talks to a single network.
|
|
111
|
+
*/ async getMaxTxGasLimits() {
|
|
112
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
113
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
114
|
+
}
|
|
80
115
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
81
116
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
82
117
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
@@ -164,8 +199,25 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
164
199
|
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
165
200
|
};
|
|
166
201
|
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
167
|
-
// When sending for real
|
|
168
|
-
|
|
202
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
203
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
204
|
+
let fullGasSettings;
|
|
205
|
+
if (forEstimation) {
|
|
206
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
207
|
+
// validate against the network admission limit here.
|
|
208
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
209
|
+
} else {
|
|
210
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
211
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
212
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
213
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
214
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
215
|
+
}
|
|
216
|
+
fullGasSettings = GasSettings.fallback({
|
|
217
|
+
...gasSettingsOverrides,
|
|
218
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits
|
|
219
|
+
});
|
|
220
|
+
}
|
|
169
221
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
170
222
|
return {
|
|
171
223
|
gasSettings: fullGasSettings,
|
|
@@ -193,40 +245,34 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
193
245
|
throw err;
|
|
194
246
|
}
|
|
195
247
|
}
|
|
196
|
-
registerSender(address, _alias = '') {
|
|
197
|
-
|
|
248
|
+
async registerSender(address, _alias = '') {
|
|
249
|
+
await this.pxe.registerTaggingSecretSource({
|
|
250
|
+
kind: 'address-derived',
|
|
251
|
+
sender: address
|
|
252
|
+
});
|
|
253
|
+
return address;
|
|
198
254
|
}
|
|
199
|
-
async registerContract(instance, artifact,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
|
|
206
|
-
// wallet holds an outdated version of this contract
|
|
207
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
208
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// If no artifact provided, we just use the existing registration
|
|
212
|
-
} else {
|
|
213
|
-
// Instance not registered yet
|
|
214
|
-
if (!artifact) {
|
|
215
|
-
// Try to get the artifact from the wallet's contract class storage
|
|
216
|
-
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
217
|
-
if (!artifact) {
|
|
218
|
-
throw new Error(`Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
await this.pxe.registerContract({
|
|
222
|
-
artifact,
|
|
223
|
-
instance
|
|
224
|
-
});
|
|
255
|
+
async registerContract(instance, artifact, secretKeyOrKeys) {
|
|
256
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
257
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
258
|
+
// when the contract is later simulated.
|
|
259
|
+
if (artifact) {
|
|
260
|
+
await this.pxe.registerContractClass(artifact);
|
|
225
261
|
}
|
|
226
|
-
|
|
227
|
-
|
|
262
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
263
|
+
if (secretKeyOrKeys) {
|
|
264
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
265
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
266
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
267
|
+
//
|
|
268
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
269
|
+
// the provided keys don't correspond to this account.
|
|
270
|
+
const derivedKeys = secretKeyOrKeys instanceof Fr ? await deriveKeys(secretKeyOrKeys) : await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
271
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
272
|
+
if (!address.equals(contractAddress)) {
|
|
273
|
+
throw new Error(`Registered account address ${address.toString()} does not match contract instance address ${contractAddress.toString()}: the provided keys do not correspond to this account.`);
|
|
274
|
+
}
|
|
228
275
|
}
|
|
229
|
-
return instance;
|
|
230
276
|
}
|
|
231
277
|
registerContractClass(artifact) {
|
|
232
278
|
return this.pxe.registerContractClass(artifact);
|
|
@@ -241,7 +287,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
241
287
|
simulatePublic: true,
|
|
242
288
|
skipTxValidation: opts.skipTxValidation,
|
|
243
289
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
244
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
290
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
245
291
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
246
292
|
overrides: opts.overrides
|
|
247
293
|
});
|
|
@@ -315,7 +361,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
315
361
|
return this.pxe.profileTx(txRequest, {
|
|
316
362
|
profileMode: opts.profileMode,
|
|
317
363
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
318
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
364
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
319
365
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
320
366
|
});
|
|
321
367
|
}
|
|
@@ -328,7 +374,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
328
374
|
});
|
|
329
375
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
330
376
|
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
331
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
377
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
332
378
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
333
379
|
});
|
|
334
380
|
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
@@ -350,7 +396,11 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
350
396
|
};
|
|
351
397
|
}
|
|
352
398
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
353
|
-
const
|
|
399
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
400
|
+
const waitOpts = this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined ? {
|
|
401
|
+
...callerWaitOpts,
|
|
402
|
+
interval: this.defaultWaitInterval
|
|
403
|
+
} : callerWaitOpts;
|
|
354
404
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
355
405
|
// Display debug logs from public execution if present (served in test mode only)
|
|
356
406
|
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
@@ -369,7 +419,11 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
369
419
|
if (!instance) {
|
|
370
420
|
return undefined;
|
|
371
421
|
}
|
|
372
|
-
|
|
422
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
423
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
424
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
425
|
+
// want to fallback to the current class.
|
|
426
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
373
427
|
return artifact?.name;
|
|
374
428
|
}
|
|
375
429
|
contextualizeError(err, ...context) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Gas, type GasUsed } from '@aztec/stdlib/gas';
|
|
2
|
+
/**
|
|
3
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
4
|
+
* admission limits.
|
|
5
|
+
*
|
|
6
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
7
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
8
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
9
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
10
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
11
|
+
* usage and clamps each dimension to the admission limit.
|
|
12
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
13
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
14
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
15
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
16
|
+
* declared limit regardless of the buffer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getGasLimits(gasUsed: GasUsed, maxTxGasLimits: Gas, pad?: number): {
|
|
19
|
+
/**
|
|
20
|
+
* Gas limit for the tx, excluding teardown gas
|
|
21
|
+
*/
|
|
22
|
+
gasLimits: Gas;
|
|
23
|
+
/**
|
|
24
|
+
* Gas limit for the teardown phase
|
|
25
|
+
*/
|
|
26
|
+
teardownGasLimits: Gas;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
30
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
31
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
32
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
33
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function assertGasLimitsWithinNetworkLimits(gasLimits: Gas, maxTxGasLimits: Gas): void;
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2dhc19saW1pdHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9nZXRfZ2FzX2xpbWl0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsR0FBRyxFQUFFLEtBQUssT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFFdEQ7Ozs7Ozs7Ozs7Ozs7OztHQWVHO0FBQ0gsd0JBQWdCLFlBQVksQ0FDMUIsT0FBTyxFQUFFLE9BQU8sRUFDaEIsY0FBYyxFQUFFLEdBQUcsRUFDbkIsR0FBRyxTQUFNLEdBQ1I7SUFDRDs7T0FFRztJQUNILFNBQVMsRUFBRSxHQUFHLENBQUM7SUFDZjs7T0FFRztJQUNILGlCQUFpQixFQUFFLEdBQUcsQ0FBQztDQUN4QixDQTZCQTtBQVFEOzs7Ozs7R0FNRztBQUNILHdCQUFnQixrQ0FBa0MsQ0FBQyxTQUFTLEVBQUUsR0FBRyxFQUFFLGNBQWMsRUFBRSxHQUFHLEdBQUcsSUFBSSxDQVc1RiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_gas_limits.d.ts","sourceRoot":"","sources":["../../src/base-wallet/get_gas_limits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,GAAG,EACnB,GAAG,SAAM,GACR;IACD;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC;IACf;;OAEG;IACH,iBAAiB,EAAE,GAAG,CAAC;CACxB,CA6BA;AAQD;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,GAAG,IAAI,CAW5F"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS, MAX_TX_DA_GAS } from '@aztec/constants';
|
|
2
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
/**
|
|
4
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
5
|
+
* admission limits.
|
|
6
|
+
*
|
|
7
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
8
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
9
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
10
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
11
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
12
|
+
* usage and clamps each dimension to the admission limit.
|
|
13
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
14
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
15
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
16
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
17
|
+
* declared limit regardless of the buffer.
|
|
18
|
+
*/ export function getGasLimits(gasUsed, maxTxGasLimits, pad = 0.1) {
|
|
19
|
+
const { totalGas, teardownGas } = gasUsed;
|
|
20
|
+
// `maxTxGasLimits` is the node-advertised admission limit. Node info is remote input, so we defensively
|
|
21
|
+
// clamp to the per-tx protocol maxima so a value above them can never be honored.
|
|
22
|
+
const maxLimits = new Gas(Math.min(maxTxGasLimits.daGas, MAX_TX_DA_GAS), Math.min(maxTxGasLimits.l2Gas, MAX_PROCESSABLE_L2_GAS));
|
|
23
|
+
// The simulated usage must fit within the admission limits, otherwise the tx can never be included.
|
|
24
|
+
if (totalGas.daGas > maxLimits.daGas) {
|
|
25
|
+
throw new Error(`Transaction consumes ${totalGas.daGas} DA gas but the network only admits transactions declaring up to ${maxLimits.daGas} DA gas`);
|
|
26
|
+
}
|
|
27
|
+
if (totalGas.l2Gas > maxLimits.l2Gas) {
|
|
28
|
+
throw new Error(`Transaction consumes ${totalGas.l2Gas} L2 gas but the network only admits transactions declaring up to ${maxLimits.l2Gas} L2 gas`);
|
|
29
|
+
}
|
|
30
|
+
// Pad the limits by the buffer, then cap each dimension at the admission limit so the buffer cannot push a
|
|
31
|
+
// declared limit past what inbound validation accepts. Teardown is part of the total, so clamping it to the
|
|
32
|
+
// admission limit is safe.
|
|
33
|
+
return {
|
|
34
|
+
gasLimits: padGas(totalGas, pad, maxLimits),
|
|
35
|
+
teardownGasLimits: padGas(teardownGas, pad, maxLimits)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Pads each gas dimension, capping it at the network admission limit. */ function padGas(gas, pad, cap) {
|
|
39
|
+
const padded = gas.mul(1 + pad);
|
|
40
|
+
return new Gas(Math.min(padded.daGas, cap.daGas), Math.min(padded.l2Gas, cap.l2Gas));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
44
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
45
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
46
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
47
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
48
|
+
*/ export function assertGasLimitsWithinNetworkLimits(gasLimits, maxTxGasLimits) {
|
|
49
|
+
if (gasLimits.daGas > maxTxGasLimits.daGas) {
|
|
50
|
+
throw new Error(`Declared DA gas limit (${gasLimits.daGas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.daGas})`);
|
|
51
|
+
}
|
|
52
|
+
if (gasLimits.l2Gas > maxTxGasLimits.l2Gas) {
|
|
53
|
+
throw new Error(`Declared L2 gas limit (${gasLimits.l2Gas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.l2Gas})`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { BaseWallet, type CompleteFeeOptionsConfig, type FeeOptions, type SimulateViaEntrypointOptions, } from './base_wallet.js';
|
|
2
2
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
-
|
|
3
|
+
export { getGasLimits, assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLEtBQUssd0JBQXdCLEVBQzdCLEtBQUssVUFBVSxFQUNmLEtBQUssNEJBQTRCLEdBQ2xDLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUMvRyxPQUFPLEVBQUUsWUFBWSxFQUFFLGtDQUFrQyxFQUFFLE1BQU0scUJBQXFCLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,qBAAqB,CAAC"}
|
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.be03c316",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
79
|
-
"@aztec/constants": "0.0.1-commit.
|
|
80
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
81
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
82
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
83
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
78
|
+
"@aztec/aztec.js": "0.0.1-commit.be03c316",
|
|
79
|
+
"@aztec/constants": "0.0.1-commit.be03c316",
|
|
80
|
+
"@aztec/entrypoints": "0.0.1-commit.be03c316",
|
|
81
|
+
"@aztec/foundation": "0.0.1-commit.be03c316",
|
|
82
|
+
"@aztec/pxe": "0.0.1-commit.be03c316",
|
|
83
|
+
"@aztec/stdlib": "0.0.1-commit.be03c316"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.be03c316",
|
|
87
87
|
"@jest/globals": "^30.0.0",
|
|
88
88
|
"@types/jest": "^30.0.0",
|
|
89
89
|
"@types/node": "^22.15.17",
|
|
@@ -41,12 +41,7 @@ import {
|
|
|
41
41
|
} from '@aztec/stdlib/abi';
|
|
42
42
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
43
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
-
import {
|
|
45
|
-
type ContractInstanceWithAddress,
|
|
46
|
-
type NodeInfo,
|
|
47
|
-
computePartialAddress,
|
|
48
|
-
getContractClassFromArtifact,
|
|
49
|
-
} from '@aztec/stdlib/contract';
|
|
44
|
+
import { type ContractInstancePreimage, type NodeInfo, computePartialAddress } from '@aztec/stdlib/contract';
|
|
50
45
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
51
46
|
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
52
47
|
import {
|
|
@@ -54,6 +49,7 @@ import {
|
|
|
54
49
|
computeSiloedPublicInitializationNullifier,
|
|
55
50
|
} from '@aztec/stdlib/hash';
|
|
56
51
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
52
|
+
import { type MasterSecretKeys, deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
57
53
|
import {
|
|
58
54
|
BlockHeader,
|
|
59
55
|
ExecutionPayload,
|
|
@@ -65,6 +61,7 @@ import {
|
|
|
65
61
|
|
|
66
62
|
import { inspect } from 'util';
|
|
67
63
|
|
|
64
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
68
65
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
69
66
|
|
|
70
67
|
/**
|
|
@@ -114,6 +111,9 @@ export type CompleteFeeOptionsConfig = {
|
|
|
114
111
|
export abstract class BaseWallet implements Wallet {
|
|
115
112
|
protected minFeePadding = 0.5;
|
|
116
113
|
protected cancellableTransactions = false;
|
|
114
|
+
// Poll interval (in seconds) injected into sendTx waits when the caller does not specify one. Left undefined on
|
|
115
|
+
// production wallets so the DefaultWaitOpts 1s cadence stands; test wallets talking to in-process nodes lower it.
|
|
116
|
+
protected defaultWaitInterval?: number;
|
|
117
117
|
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
118
118
|
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
119
119
|
private nodeInfoPromise: Promise<NodeInfo> | undefined;
|
|
@@ -125,10 +125,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
125
125
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
126
126
|
) {}
|
|
127
127
|
|
|
128
|
-
protected scopesFrom(
|
|
129
|
-
|
|
128
|
+
protected scopesFrom(
|
|
129
|
+
from: AztecAddress | NoFrom,
|
|
130
|
+
additionalScopes: AztecAddress[],
|
|
131
|
+
sendMessagesAs: AztecAddress | undefined,
|
|
132
|
+
): AztecAddress[] {
|
|
133
|
+
// The sendMessagesAs account must be in scope so that its tagging secrets can be accessed.
|
|
134
|
+
const tagSenderScopes = sendMessagesAs ? [sendMessagesAs] : [];
|
|
135
|
+
const baseScopes = from === NO_FROM ? [] : [from];
|
|
136
|
+
const allScopes = [...baseScopes, ...additionalScopes, ...tagSenderScopes];
|
|
130
137
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
131
|
-
return [...scopeSet].map(AztecAddress.
|
|
138
|
+
return [...scopeSet].map(AztecAddress.fromStringUnsafe);
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
/**
|
|
@@ -154,18 +161,42 @@ export abstract class BaseWallet implements Wallet {
|
|
|
154
161
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
155
162
|
*/
|
|
156
163
|
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
157
|
-
const
|
|
158
|
-
return
|
|
164
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
165
|
+
return sources.map(source => ({ item: source.sender, alias: '' }));
|
|
159
166
|
}
|
|
160
167
|
|
|
161
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
170
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
171
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
172
|
+
* depend on it.
|
|
173
|
+
*/
|
|
174
|
+
private getNodeInfo(): Promise<NodeInfo> {
|
|
162
175
|
if (!this.nodeInfoPromise) {
|
|
163
|
-
this.nodeInfoPromise = this.aztecNode.getNodeInfo()
|
|
176
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch(err => {
|
|
177
|
+
this.nodeInfoPromise = undefined;
|
|
178
|
+
throw err;
|
|
179
|
+
});
|
|
164
180
|
}
|
|
165
|
-
|
|
181
|
+
return this.nodeInfoPromise;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async getChainInfo(): Promise<ChainInfo> {
|
|
185
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
166
186
|
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
167
187
|
}
|
|
168
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
191
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
192
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
193
|
+
* the cached node info, since a wallet talks to a single network.
|
|
194
|
+
*/
|
|
195
|
+
protected async getMaxTxGasLimits(): Promise<Gas> {
|
|
196
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
197
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
198
|
+
}
|
|
199
|
+
|
|
169
200
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
170
201
|
executionPayload: ExecutionPayload,
|
|
171
202
|
from: AztecAddress | NoFrom,
|
|
@@ -272,10 +303,25 @@ export abstract class BaseWallet implements Wallet {
|
|
|
272
303
|
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
273
304
|
};
|
|
274
305
|
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
275
|
-
// When sending for real
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
306
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
307
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
308
|
+
let fullGasSettings;
|
|
309
|
+
if (forEstimation) {
|
|
310
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
311
|
+
// validate against the network admission limit here.
|
|
312
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
313
|
+
} else {
|
|
314
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
315
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
316
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
317
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
318
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
319
|
+
}
|
|
320
|
+
fullGasSettings = GasSettings.fallback({
|
|
321
|
+
...gasSettingsOverrides,
|
|
322
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
279
325
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
280
326
|
return {
|
|
281
327
|
gasSettings: fullGasSettings,
|
|
@@ -306,46 +352,42 @@ export abstract class BaseWallet implements Wallet {
|
|
|
306
352
|
}
|
|
307
353
|
}
|
|
308
354
|
|
|
309
|
-
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
310
|
-
|
|
355
|
+
async registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
356
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
357
|
+
return address;
|
|
311
358
|
}
|
|
312
359
|
|
|
313
360
|
async registerContract(
|
|
314
|
-
instance:
|
|
361
|
+
instance: ContractInstancePreimage,
|
|
315
362
|
artifact?: ContractArtifact,
|
|
316
|
-
|
|
317
|
-
): Promise<
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
324
|
-
if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
|
|
325
|
-
// wallet holds an outdated version of this contract
|
|
326
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
327
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
// If no artifact provided, we just use the existing registration
|
|
331
|
-
} else {
|
|
332
|
-
// Instance not registered yet
|
|
333
|
-
if (!artifact) {
|
|
334
|
-
// Try to get the artifact from the wallet's contract class storage
|
|
335
|
-
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
336
|
-
if (!artifact) {
|
|
337
|
-
throw new Error(
|
|
338
|
-
`Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`,
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
await this.pxe.registerContract({ artifact, instance });
|
|
363
|
+
secretKeyOrKeys?: Fr | MasterSecretKeys,
|
|
364
|
+
): Promise<void> {
|
|
365
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
366
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
367
|
+
// when the contract is later simulated.
|
|
368
|
+
if (artifact) {
|
|
369
|
+
await this.pxe.registerContractClass(artifact);
|
|
343
370
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
371
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
372
|
+
|
|
373
|
+
if (secretKeyOrKeys) {
|
|
374
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
375
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
376
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
377
|
+
//
|
|
378
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
379
|
+
// the provided keys don't correspond to this account.
|
|
380
|
+
const derivedKeys =
|
|
381
|
+
secretKeyOrKeys instanceof Fr
|
|
382
|
+
? await deriveKeys(secretKeyOrKeys)
|
|
383
|
+
: await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
384
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
385
|
+
if (!address.equals(contractAddress)) {
|
|
386
|
+
throw new Error(
|
|
387
|
+
`Registered account address ${address.toString()} does not match contract instance address ${contractAddress.toString()}: the provided keys do not correspond to this account.`,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
347
390
|
}
|
|
348
|
-
return instance;
|
|
349
391
|
}
|
|
350
392
|
|
|
351
393
|
registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
@@ -367,7 +409,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
367
409
|
simulatePublic: true,
|
|
368
410
|
skipTxValidation: opts.skipTxValidation,
|
|
369
411
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
370
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
412
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
371
413
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
372
414
|
overrides: opts.overrides,
|
|
373
415
|
});
|
|
@@ -463,7 +505,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
463
505
|
return this.pxe.profileTx(txRequest, {
|
|
464
506
|
profileMode: opts.profileMode,
|
|
465
507
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
466
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
508
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
467
509
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
468
510
|
});
|
|
469
511
|
}
|
|
@@ -480,7 +522,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
480
522
|
});
|
|
481
523
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
482
524
|
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
483
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
525
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
484
526
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
485
527
|
});
|
|
486
528
|
const offchainOutput = extractOffchainOutput(
|
|
@@ -504,7 +546,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
504
546
|
}
|
|
505
547
|
|
|
506
548
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
507
|
-
const
|
|
549
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
550
|
+
const waitOpts =
|
|
551
|
+
this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined
|
|
552
|
+
? { ...callerWaitOpts, interval: this.defaultWaitInterval }
|
|
553
|
+
: callerWaitOpts;
|
|
508
554
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
509
555
|
|
|
510
556
|
// Display debug logs from public execution if present (served in test mode only)
|
|
@@ -524,7 +570,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
524
570
|
if (!instance) {
|
|
525
571
|
return undefined;
|
|
526
572
|
}
|
|
527
|
-
|
|
573
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
574
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
575
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
576
|
+
// want to fallback to the current class.
|
|
577
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
528
578
|
return artifact?.name;
|
|
529
579
|
}
|
|
530
580
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS, MAX_TX_DA_GAS } from '@aztec/constants';
|
|
2
|
+
import { Gas, type GasUsed } from '@aztec/stdlib/gas';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns suggested total and teardown gas limits for a simulated tx, clamped to the network's per-tx
|
|
6
|
+
* admission limits.
|
|
7
|
+
*
|
|
8
|
+
* The network only admits transactions that declare up to `maxTxGasLimits` per dimension (the
|
|
9
|
+
* node-advertised `txsLimits.gas`). Wallets pass the value read from their own node info, but since node info
|
|
10
|
+
* is remote input it is defensively clamped here to the per-tx protocol maxima so a value above them is never
|
|
11
|
+
* honored. If the simulated usage already exceeds the resulting admission limits the tx can never be included,
|
|
12
|
+
* so this throws a descriptive error instead of returning a limit the node would reject. Otherwise it pads the
|
|
13
|
+
* usage and clamps each dimension to the admission limit.
|
|
14
|
+
* @param gasUsed - The gas actually consumed during simulation.
|
|
15
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
16
|
+
* @param pad - Fraction to pad the suggested gas limits by (as a decimal, e.g. 0.1 for 10%). The effective
|
|
17
|
+
* padding shrinks to zero as usage approaches the network limit, since the network will not admit a higher
|
|
18
|
+
* declared limit regardless of the buffer.
|
|
19
|
+
*/
|
|
20
|
+
export function getGasLimits(
|
|
21
|
+
gasUsed: GasUsed,
|
|
22
|
+
maxTxGasLimits: Gas,
|
|
23
|
+
pad = 0.1,
|
|
24
|
+
): {
|
|
25
|
+
/**
|
|
26
|
+
* Gas limit for the tx, excluding teardown gas
|
|
27
|
+
*/
|
|
28
|
+
gasLimits: Gas;
|
|
29
|
+
/**
|
|
30
|
+
* Gas limit for the teardown phase
|
|
31
|
+
*/
|
|
32
|
+
teardownGasLimits: Gas;
|
|
33
|
+
} {
|
|
34
|
+
const { totalGas, teardownGas } = gasUsed;
|
|
35
|
+
|
|
36
|
+
// `maxTxGasLimits` is the node-advertised admission limit. Node info is remote input, so we defensively
|
|
37
|
+
// clamp to the per-tx protocol maxima so a value above them can never be honored.
|
|
38
|
+
const maxLimits = new Gas(
|
|
39
|
+
Math.min(maxTxGasLimits.daGas, MAX_TX_DA_GAS),
|
|
40
|
+
Math.min(maxTxGasLimits.l2Gas, MAX_PROCESSABLE_L2_GAS),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// The simulated usage must fit within the admission limits, otherwise the tx can never be included.
|
|
44
|
+
if (totalGas.daGas > maxLimits.daGas) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Transaction consumes ${totalGas.daGas} DA gas but the network only admits transactions declaring up to ${maxLimits.daGas} DA gas`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (totalGas.l2Gas > maxLimits.l2Gas) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Transaction consumes ${totalGas.l2Gas} L2 gas but the network only admits transactions declaring up to ${maxLimits.l2Gas} L2 gas`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Pad the limits by the buffer, then cap each dimension at the admission limit so the buffer cannot push a
|
|
56
|
+
// declared limit past what inbound validation accepts. Teardown is part of the total, so clamping it to the
|
|
57
|
+
// admission limit is safe.
|
|
58
|
+
return {
|
|
59
|
+
gasLimits: padGas(totalGas, pad, maxLimits),
|
|
60
|
+
teardownGasLimits: padGas(teardownGas, pad, maxLimits),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Pads each gas dimension, capping it at the network admission limit. */
|
|
65
|
+
function padGas(gas: Gas, pad: number, cap: Gas): Gas {
|
|
66
|
+
const padded = gas.mul(1 + pad);
|
|
67
|
+
return new Gas(Math.min(padded.daGas, cap.daGas), Math.min(padded.l2Gas, cap.l2Gas));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Validates that caller-declared gas limits do not exceed the network's per-tx admission limits, throwing a
|
|
72
|
+
* descriptive error per dimension when they do. The node's inbound validation checks declared
|
|
73
|
+
* `gasSettings.gasLimits`, so we mirror that here to surface the rejection locally before the tx is sent.
|
|
74
|
+
* @param gasLimits - The gas limits the transaction will declare.
|
|
75
|
+
* @param maxTxGasLimits - The maximum gas a single tx may declare on this network (the node-advertised `txsLimits.gas`).
|
|
76
|
+
*/
|
|
77
|
+
export function assertGasLimitsWithinNetworkLimits(gasLimits: Gas, maxTxGasLimits: Gas): void {
|
|
78
|
+
if (gasLimits.daGas > maxTxGasLimits.daGas) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Declared DA gas limit (${gasLimits.daGas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.daGas})`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (gasLimits.l2Gas > maxTxGasLimits.l2Gas) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Declared L2 gas limit (${gasLimits.l2Gas}) exceeds the maximum this network allows per tx (${maxTxGasLimits.l2Gas})`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -5,3 +5,4 @@ export {
|
|
|
5
5
|
type SimulateViaEntrypointOptions,
|
|
6
6
|
} from './base_wallet.js';
|
|
7
7
|
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
8
|
+
export { getGasLimits, assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|