@aztec/wallet-sdk 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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 +125 -0
- 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 +113 -59
- 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 +114 -63
- package/src/base-wallet/get_gas_limits.ts +88 -0
- package/src/base-wallet/index.ts +1 -0
package/README.md
CHANGED
|
@@ -319,3 +319,128 @@ function useWalletDiscovery(chainInfo: ChainInfo, appId: string) {
|
|
|
319
319
|
return { providers, isDiscovering, cancel: () => discoveryRef.current?.cancel() };
|
|
320
320
|
}
|
|
321
321
|
```
|
|
322
|
+
|
|
323
|
+
## Storage backends
|
|
324
|
+
|
|
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
|
+
|
|
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
|
+
- **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
|
+
|
|
330
|
+
The backend is chosen by *which store you construct and hand to the wallet* there is no runtime flag or environment variable.
|
|
331
|
+
|
|
332
|
+
> **Data migration is not supported between backends, by design.** The v4→v5 protocol upgrade discards all local state regardless, so switching to SQLite-OPFS simply means starting from a fresh store.
|
|
333
|
+
|
|
334
|
+
### Quick start: embedded wallet with an encrypted SQLite store
|
|
335
|
+
|
|
336
|
+
If you build on `@aztec/wallets`' `EmbeddedWallet`, open its two stores (PXE state + the wallet DB) with `openEncryptedEmbeddedStores`, then pass them in:
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
340
|
+
import { openEncryptedEmbeddedStores } from '@aztec/wallets/embedded/store-encryption';
|
|
341
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
342
|
+
|
|
343
|
+
const log = createLogger('wallet:storage');
|
|
344
|
+
|
|
345
|
+
// Your wallet derives a 32-byte key (see "Key management" below).
|
|
346
|
+
// IMPORTANT: return a *fresh* Uint8Array each call. Opening a store consumes (empties)
|
|
347
|
+
// the key, so a reused array would be empty on the second open (see "important" below).
|
|
348
|
+
const getEncryptionKey = async () => new Uint8Array(myDerivedKey);
|
|
349
|
+
|
|
350
|
+
const { pxeStore, walletStore } = await openEncryptedEmbeddedStores(
|
|
351
|
+
{
|
|
352
|
+
pxe: { name: `pxe-${rollupAddress}`, poolDirectory: '/pxe' },
|
|
353
|
+
wallet: { name: `wallet-${rollupAddress}`, poolDirectory: '/wallet' },
|
|
354
|
+
},
|
|
355
|
+
getEncryptionKey,
|
|
356
|
+
log,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
const wallet = await EmbeddedWallet.create(nodeUrl, {
|
|
360
|
+
pxe: { store: pxeStore },
|
|
361
|
+
walletDb: { store: walletStore },
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
If the supplied key cannot decrypt an existing store, `openEncryptedEmbeddedStores` throws `EmbeddedWalletEncryptionError` with `storeName: 'pxe' | 'wallet'`, which you can then surface as a "wrong password" error in your UI:
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { EmbeddedWalletEncryptionError } from '@aztec/wallets/embedded/store-encryption';
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
await openEncryptedEmbeddedStores(/* ... */);
|
|
372
|
+
} catch (err) {
|
|
373
|
+
if (err instanceof EmbeddedWalletEncryptionError) {
|
|
374
|
+
showWrongPasswordError(); // err.storeName tells you which store failed
|
|
375
|
+
} else {
|
|
376
|
+
throw err;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Important
|
|
382
|
+
|
|
383
|
+
1. **Opening a store consumes the key, it does not copy it.** So that raw key material does not linger in page memory, the SDK moves your key into the storage worker and detaches the buffer on your side. The `Uint8Array` you passed comes back empty, so the same array cannot be reused to open a second store. To open more than one store with the same key, hand each open a fresh copy (`new Uint8Array(key)`). `openEncryptedEmbeddedStores` does this for you by invoking your `getEncryptionKey` callback once per store.
|
|
384
|
+
2. **Each coexisting store needs its own `poolDirectory`.** The OPFS SAH Pool holds an *exclusive* lock on its directory, so two stores sharing the default pool fail with "Access Handles cannot be created if there is another open Access Handle…". Give every store a distinct, stable `poolDirectory` (stable so the same files re-open next session).
|
|
385
|
+
|
|
386
|
+
### No multi-tab access: assume one tab at a time
|
|
387
|
+
|
|
388
|
+
A store can be opened by **one browser tab at a time per origin**. If the user opens your wallet in a second tab of the same origin pointing at the same store, the second open contends for that lock.
|
|
389
|
+
|
|
390
|
+
Thanks to the lock, the data is never corrupted, but the second open fails or hangs rather than succeeding, and there is no graceful "already open elsewhere" signal yet.
|
|
391
|
+
|
|
392
|
+
Until it does, design for a single active tab: detect a second instance (e.g. with the [Web Locks API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API) or a `BroadcastChannel`) and steer the user back to the existing tab, or open the store read-only there.
|
|
393
|
+
|
|
394
|
+
If you need genuine concurrent multi-tab access, route all storage access through a single `SharedWorker` that you own and that holds the one connection.
|
|
395
|
+
|
|
396
|
+
### Opting out of encryption
|
|
397
|
+
|
|
398
|
+
If you do not need at-rest encryption (you rely on full-disk encryption, or the device is trusted), an *unencrypted* SQLite-OPFS store is still a better default than IndexedDB.
|
|
399
|
+
|
|
400
|
+
The `createStore` convenience helper always uses the default OPFS pool directory and does not currently let you change it, so it only works for a single store per tab. The embedded wallet runs two stores (PXE + walletDB), so open them directly from `AztecSQLiteOPFSStore` with a distinct `poolDirectory` each:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
404
|
+
import { AztecSQLiteOPFSStore } from '@aztec/kv-store/sqlite-opfs';
|
|
405
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
406
|
+
|
|
407
|
+
const log = createLogger('wallet:storage');
|
|
408
|
+
|
|
409
|
+
// No key; just name, ephemeral=false, and a distinct poolDirectory per store.
|
|
410
|
+
const pxeStore = await AztecSQLiteOPFSStore.open(log, `pxe-${rollupAddress}`, false, '/pxe');
|
|
411
|
+
const walletStore = await AztecSQLiteOPFSStore.open(log, `wallet-${rollupAddress}`, false, '/wallet');
|
|
412
|
+
|
|
413
|
+
const wallet = await EmbeddedWallet.create(nodeUrl, {
|
|
414
|
+
pxe: { store: pxeStore },
|
|
415
|
+
walletDb: { store: walletStore },
|
|
416
|
+
});
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Building your own wallet (lower-level API)
|
|
420
|
+
|
|
421
|
+
If you are not using `EmbeddedWallet`, construct stores directly from `@aztec/kv-store/sqlite-opfs` and pass them wherever a store is accepted (e.g. `PXECreationOptions.store`):
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
import { openEncryptedStore, createStore, SqliteEncryptionError } from '@aztec/kv-store/sqlite-opfs';
|
|
425
|
+
|
|
426
|
+
// Encrypted, persistent:
|
|
427
|
+
const store = await openEncryptedStore(new Uint8Array(myDerivedKey), 'my-store', '/my-pool');
|
|
428
|
+
|
|
429
|
+
// Or unencrypted:
|
|
430
|
+
const plain = await createStore('my-store', { dataStoreMapSizeKb: 2e10 });
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Note: `dataStoreMapSizeKb` is an LMDB-specific ceiling (the maximum memory-map size). SQLite-OPFS grows its file dynamically and ignores the value, but it is a required field of the shared `DataStoreConfig` type, so you must still pass something (any number is fine). We will fix this implementation leak in coming versions.
|
|
434
|
+
|
|
435
|
+
Note: `openEncryptedStore` throws `SqliteEncryptionError` (with a typed `code`, e.g. `'decrypt_failed'`) on a bad key.
|
|
436
|
+
|
|
437
|
+
### Using SQLite-OPFS in a browser extension (MV3)
|
|
438
|
+
|
|
439
|
+
SQLite-OPFS needs OPFS, a Web Worker, and cross-origin isolation (SharedArrayBuffer). In a Chrome MV3 extension:
|
|
440
|
+
|
|
441
|
+
- **Run it in an offscreen document, not the background service worker.** The service worker is ephemeral and does not reliably provide OPFS/SharedArrayBuffer; an offscreen document does, and it is where your PXE and stores should live.
|
|
442
|
+
- **No COOP/COEP header setup is needed inside the extension.** Extension pages are cross-origin-isolated by default. (A plain web page hosting the wallet *does* need those headers.)
|
|
443
|
+
|
|
444
|
+
### Key management is your responsibility
|
|
445
|
+
|
|
446
|
+
The store encrypts data at rest given a 32-byte key, but deriving and safeguarding that key is the wallet's job. A common pattern is to derive the key from a user password with a memory-hard KDF (e.g. Argon2id) and hold it only in memory while the wallet is unlocked. Adapt this to your own security model.
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFL0QsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLGVBQWUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQ2pGLE9BQU8sRUFFTCxLQUFLLHNCQUFzQixFQUUzQixLQUFLLFVBQVUsRUFHaEIsTUFBTSwyQkFBMkIsQ0FBQztBQUNuQyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRTVELE9BQU8sRUFDTCxLQUFLLE9BQU8sRUFDWixLQUFLLGVBQWUsRUFDcEIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssYUFBYSxFQUNsQiw0QkFBNEIsRUFDNUIsS0FBSyxxQkFBcUIsRUFDMUIsS0FBSyxZQUFZLEVBQ2pCLEtBQUssa0JBQWtCLEVBQ3ZCLEtBQUssY0FBYyxFQUNuQixLQUFLLFdBQVcsRUFDaEIsS0FBSyxlQUFlLEVBQ3BCLCtCQUErQixFQUMvQixLQUFLLE1BQU0sRUFDWCxLQUFLLGtCQUFrQixFQUN4QixNQUFNLHdCQUF3QixDQUFDO0FBQ2hDLE9BQU8sRUFBRSw4QkFBOEIsRUFBd0MsTUFBTSw0QkFBNEIsQ0FBQztBQUVsSCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ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FLFlBQVksRUFBRSxJQUFJLEVBQUUscUJBQXFCLEdBQUcsT0FBTyxDQUFDLHNCQUFzQixDQUFDLENBRS9GO0lBRUssZ0JBQWdCLENBQUMsQ0FBQyxFQUN0QixRQUFRLEVBQUUsdUJBQXVCLEVBQ2pDLFdBQVcsRUFBRSxrQkFBa0IsR0FDOUIsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBZTVCO0lBRUQ7OztPQUdHO0lBQ0csbUJBQW1CLENBQUMsT0FBTyxFQUFFLFlBQVk7Ozs7OztPQWlDOUM7SUFFSyx3QkFBd0IsQ0FBQyxFQUFFLEVBQUUsRUFBRTs7O09BTXBDO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,
|
|
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,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAEL,KAAK,sBAAsB,EAE3B,KAAK,UAAU,EAGhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,4BAA4B,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK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BAAgB,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
-
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { DefaultWaitOpts, NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
3
3
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
4
4
|
import { ContractInitializationStatus, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
5
5
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
@@ -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,15 +374,12 @@ 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);
|
|
335
381
|
const tx = await provenTx.toTx();
|
|
336
382
|
const txHash = tx.getTxHash();
|
|
337
|
-
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
338
|
-
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
339
|
-
}
|
|
340
383
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
341
384
|
await this.aztecNode.sendTx(tx).catch((err)=>{
|
|
342
385
|
throw this.contextualizeError(err, inspect(tx));
|
|
@@ -350,10 +393,19 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
350
393
|
};
|
|
351
394
|
}
|
|
352
395
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
353
|
-
const
|
|
354
|
-
const
|
|
396
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
397
|
+
const waitOpts = this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined ? {
|
|
398
|
+
...callerWaitOpts,
|
|
399
|
+
interval: this.defaultWaitInterval
|
|
400
|
+
} : callerWaitOpts;
|
|
401
|
+
// The tx was just sent, so an immediate first poll cannot find it mined; skip one poll interval up front.
|
|
402
|
+
const initialDelay = waitOpts?.initialDelay ?? waitOpts?.interval ?? DefaultWaitOpts.interval;
|
|
403
|
+
const receipt = await waitForTx(this.aztecNode, txHash, {
|
|
404
|
+
...waitOpts,
|
|
405
|
+
initialDelay
|
|
406
|
+
});
|
|
355
407
|
// Display debug logs from public execution if present (served in test mode only)
|
|
356
|
-
if (receipt.debugLogs?.length) {
|
|
408
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
357
409
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
358
410
|
}
|
|
359
411
|
return {
|
|
@@ -369,7 +421,11 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
369
421
|
if (!instance) {
|
|
370
422
|
return undefined;
|
|
371
423
|
}
|
|
372
|
-
|
|
424
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
425
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
426
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
427
|
+
// want to fallback to the current class.
|
|
428
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
373
429
|
return artifact?.name;
|
|
374
430
|
}
|
|
375
431
|
contextualizeError(err, ...context) {
|
|
@@ -395,9 +451,7 @@ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simul
|
|
|
395
451
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
396
452
|
const decodedEvents = pxeEvents.map((pxeEvent)=>{
|
|
397
453
|
return {
|
|
398
|
-
event: decodeFromAbi(
|
|
399
|
-
eventDef.abiType
|
|
400
|
-
], pxeEvent.packedEvent),
|
|
454
|
+
event: decodeFromAbi(eventDef.abiType, pxeEvent.packedEvent),
|
|
401
455
|
metadata: {
|
|
402
456
|
l2BlockNumber: pxeEvent.l2BlockNumber,
|
|
403
457
|
l2BlockHash: pxeEvent.l2BlockHash,
|
|
@@ -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.9a89641",
|
|
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.9a89641",
|
|
79
|
+
"@aztec/constants": "0.0.1-commit.9a89641",
|
|
80
|
+
"@aztec/entrypoints": "0.0.1-commit.9a89641",
|
|
81
|
+
"@aztec/foundation": "0.0.1-commit.9a89641",
|
|
82
|
+
"@aztec/pxe": "0.0.1-commit.9a89641",
|
|
83
|
+
"@aztec/stdlib": "0.0.1-commit.9a89641"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.9a89641",
|
|
87
87
|
"@jest/globals": "^30.0.0",
|
|
88
88
|
"@types/jest": "^30.0.0",
|
|
89
89
|
"@types/node": "^22.15.17",
|
|
@@ -2,9 +2,11 @@ import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
|
2
2
|
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
3
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
4
4
|
import {
|
|
5
|
+
DefaultWaitOpts,
|
|
5
6
|
type InteractionWaitOptions,
|
|
6
7
|
NO_WAIT,
|
|
7
8
|
type SendReturn,
|
|
9
|
+
type WaitOpts,
|
|
8
10
|
extractOffchainOutput,
|
|
9
11
|
} from '@aztec/aztec.js/contracts';
|
|
10
12
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
@@ -41,12 +43,7 @@ import {
|
|
|
41
43
|
} from '@aztec/stdlib/abi';
|
|
42
44
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
43
45
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
-
import {
|
|
45
|
-
type ContractInstanceWithAddress,
|
|
46
|
-
type NodeInfo,
|
|
47
|
-
computePartialAddress,
|
|
48
|
-
getContractClassFromArtifact,
|
|
49
|
-
} from '@aztec/stdlib/contract';
|
|
46
|
+
import { type ContractInstancePreimage, type NodeInfo, computePartialAddress } from '@aztec/stdlib/contract';
|
|
50
47
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
51
48
|
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
52
49
|
import {
|
|
@@ -54,6 +51,7 @@ import {
|
|
|
54
51
|
computeSiloedPublicInitializationNullifier,
|
|
55
52
|
} from '@aztec/stdlib/hash';
|
|
56
53
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
54
|
+
import { type MasterSecretKeys, deriveKeys, deriveKeysFromMasterSecretKeys } from '@aztec/stdlib/keys';
|
|
57
55
|
import {
|
|
58
56
|
BlockHeader,
|
|
59
57
|
ExecutionPayload,
|
|
@@ -65,6 +63,7 @@ import {
|
|
|
65
63
|
|
|
66
64
|
import { inspect } from 'util';
|
|
67
65
|
|
|
66
|
+
import { assertGasLimitsWithinNetworkLimits } from './get_gas_limits.js';
|
|
68
67
|
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
69
68
|
|
|
70
69
|
/**
|
|
@@ -114,6 +113,9 @@ export type CompleteFeeOptionsConfig = {
|
|
|
114
113
|
export abstract class BaseWallet implements Wallet {
|
|
115
114
|
protected minFeePadding = 0.5;
|
|
116
115
|
protected cancellableTransactions = false;
|
|
116
|
+
// Poll interval (in seconds) injected into sendTx waits when the caller does not specify one. Left undefined on
|
|
117
|
+
// production wallets so the DefaultWaitOpts 1s cadence stands; test wallets talking to in-process nodes lower it.
|
|
118
|
+
protected defaultWaitInterval?: number;
|
|
117
119
|
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
118
120
|
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
119
121
|
private nodeInfoPromise: Promise<NodeInfo> | undefined;
|
|
@@ -125,10 +127,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
125
127
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
126
128
|
) {}
|
|
127
129
|
|
|
128
|
-
protected scopesFrom(
|
|
129
|
-
|
|
130
|
+
protected scopesFrom(
|
|
131
|
+
from: AztecAddress | NoFrom,
|
|
132
|
+
additionalScopes: AztecAddress[],
|
|
133
|
+
sendMessagesAs: AztecAddress | undefined,
|
|
134
|
+
): AztecAddress[] {
|
|
135
|
+
// The sendMessagesAs account must be in scope so that its tagging secrets can be accessed.
|
|
136
|
+
const tagSenderScopes = sendMessagesAs ? [sendMessagesAs] : [];
|
|
137
|
+
const baseScopes = from === NO_FROM ? [] : [from];
|
|
138
|
+
const allScopes = [...baseScopes, ...additionalScopes, ...tagSenderScopes];
|
|
130
139
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
131
|
-
return [...scopeSet].map(AztecAddress.
|
|
140
|
+
return [...scopeSet].map(AztecAddress.fromStringUnsafe);
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
/**
|
|
@@ -154,18 +163,42 @@ export abstract class BaseWallet implements Wallet {
|
|
|
154
163
|
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
155
164
|
*/
|
|
156
165
|
async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
157
|
-
const
|
|
158
|
-
return
|
|
166
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
167
|
+
return sources.map(source => ({ item: source.sender, alias: '' }));
|
|
159
168
|
}
|
|
160
169
|
|
|
161
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Fetches and caches the node info for the wallet's lifetime, since a wallet talks to a single network and
|
|
172
|
+
* node info never changes. A rejected fetch clears the cache so the next call retries instead of replaying
|
|
173
|
+
* the cached rejection forever — important because the gas-limit fill-in and validation (run on every send)
|
|
174
|
+
* depend on it.
|
|
175
|
+
*/
|
|
176
|
+
private getNodeInfo(): Promise<NodeInfo> {
|
|
162
177
|
if (!this.nodeInfoPromise) {
|
|
163
|
-
this.nodeInfoPromise = this.aztecNode.getNodeInfo()
|
|
178
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo().catch(err => {
|
|
179
|
+
this.nodeInfoPromise = undefined;
|
|
180
|
+
throw err;
|
|
181
|
+
});
|
|
164
182
|
}
|
|
165
|
-
|
|
183
|
+
return this.nodeInfoPromise;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async getChainInfo(): Promise<ChainInfo> {
|
|
187
|
+
const { l1ChainId, rollupVersion } = await this.getNodeInfo();
|
|
166
188
|
return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
|
|
167
189
|
}
|
|
168
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Returns the maximum gas limits a single transaction may declare on this wallet's network (the
|
|
193
|
+
* node-advertised `txsLimits.gas`). Internal helper used to fill in default gas limits when sending a
|
|
194
|
+
* transaction without explicit limits, and to validate caller-provided limits before sending. Backed by
|
|
195
|
+
* the cached node info, since a wallet talks to a single network.
|
|
196
|
+
*/
|
|
197
|
+
protected async getMaxTxGasLimits(): Promise<Gas> {
|
|
198
|
+
const { txsLimits } = await this.getNodeInfo();
|
|
199
|
+
return new Gas(txsLimits.gas.daGas, txsLimits.gas.l2Gas);
|
|
200
|
+
}
|
|
201
|
+
|
|
169
202
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
170
203
|
executionPayload: ExecutionPayload,
|
|
171
204
|
from: AztecAddress | NoFrom,
|
|
@@ -272,10 +305,25 @@ export abstract class BaseWallet implements Wallet {
|
|
|
272
305
|
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
273
306
|
};
|
|
274
307
|
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
275
|
-
// When sending for real
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
308
|
+
// When sending for real without explicit limits, declare the most a single tx may use on this network
|
|
309
|
+
// (the node's per-tx admission limit), so the proposer does not skip the tx for over-declaring gas.
|
|
310
|
+
let fullGasSettings;
|
|
311
|
+
if (forEstimation) {
|
|
312
|
+
// Estimation deliberately uses very high internal limits and skips tx validation, so we do not
|
|
313
|
+
// validate against the network admission limit here.
|
|
314
|
+
fullGasSettings = GasSettings.forEstimation(gasSettingsOverrides);
|
|
315
|
+
} else {
|
|
316
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
317
|
+
// If the caller declared explicit gas limits, reject them up front when they exceed the network's
|
|
318
|
+
// per-tx admission limit (mirroring the node's GasLimitsValidator). Otherwise fill in the limit.
|
|
319
|
+
if (gasSettingsOverrides.gasLimits) {
|
|
320
|
+
assertGasLimitsWithinNetworkLimits(gasSettingsOverrides.gasLimits, maxTxGasLimits);
|
|
321
|
+
}
|
|
322
|
+
fullGasSettings = GasSettings.fallback({
|
|
323
|
+
...gasSettingsOverrides,
|
|
324
|
+
gasLimits: gasSettingsOverrides.gasLimits ?? maxTxGasLimits,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
279
327
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
280
328
|
return {
|
|
281
329
|
gasSettings: fullGasSettings,
|
|
@@ -306,46 +354,42 @@ export abstract class BaseWallet implements Wallet {
|
|
|
306
354
|
}
|
|
307
355
|
}
|
|
308
356
|
|
|
309
|
-
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
310
|
-
|
|
357
|
+
async registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
358
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
359
|
+
return address;
|
|
311
360
|
}
|
|
312
361
|
|
|
313
362
|
async registerContract(
|
|
314
|
-
instance:
|
|
363
|
+
instance: ContractInstancePreimage,
|
|
315
364
|
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 });
|
|
365
|
+
secretKeyOrKeys?: Fr | MasterSecretKeys,
|
|
366
|
+
): Promise<void> {
|
|
367
|
+
// Classes and instances are registered independently: register the artifact (if provided) then the instance.
|
|
368
|
+
// Neither call validates that the artifact matches the class the instance runs, a missing artifact only surfaces
|
|
369
|
+
// when the contract is later simulated.
|
|
370
|
+
if (artifact) {
|
|
371
|
+
await this.pxe.registerContractClass(artifact);
|
|
343
372
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
373
|
+
const contractAddress = await this.pxe.registerContract(instance);
|
|
374
|
+
|
|
375
|
+
if (secretKeyOrKeys) {
|
|
376
|
+
// PXE never receives the account seed (from which the message-signing/fallback secret keys could be re-derived):
|
|
377
|
+
// the wallet derives the keys here. Of these, PXE only reads and stores the four privacy secret keys and the
|
|
378
|
+
// message-signing and fallback *public* keys — it never touches the message-signing or fallback secret keys.
|
|
379
|
+
//
|
|
380
|
+
// Since PXE recomputes the address from those keys, we assert it matches the instance's address: a mismatch means
|
|
381
|
+
// the provided keys don't correspond to this account.
|
|
382
|
+
const derivedKeys =
|
|
383
|
+
secretKeyOrKeys instanceof Fr
|
|
384
|
+
? await deriveKeys(secretKeyOrKeys)
|
|
385
|
+
: await deriveKeysFromMasterSecretKeys(secretKeyOrKeys);
|
|
386
|
+
const { address } = await this.pxe.registerAccount(derivedKeys, await computePartialAddress(instance));
|
|
387
|
+
if (!address.equals(contractAddress)) {
|
|
388
|
+
throw new Error(
|
|
389
|
+
`Registered account address ${address.toString()} does not match contract instance address ${contractAddress.toString()}: the provided keys do not correspond to this account.`,
|
|
390
|
+
);
|
|
391
|
+
}
|
|
347
392
|
}
|
|
348
|
-
return instance;
|
|
349
393
|
}
|
|
350
394
|
|
|
351
395
|
registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
@@ -367,7 +411,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
367
411
|
simulatePublic: true,
|
|
368
412
|
skipTxValidation: opts.skipTxValidation,
|
|
369
413
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
370
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
414
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
371
415
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
372
416
|
overrides: opts.overrides,
|
|
373
417
|
});
|
|
@@ -463,7 +507,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
463
507
|
return this.pxe.profileTx(txRequest, {
|
|
464
508
|
profileMode: opts.profileMode,
|
|
465
509
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
466
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
510
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
467
511
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
468
512
|
});
|
|
469
513
|
}
|
|
@@ -480,7 +524,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
480
524
|
});
|
|
481
525
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
482
526
|
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
483
|
-
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
527
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes ?? [], opts.sendMessagesAs),
|
|
484
528
|
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
485
529
|
});
|
|
486
530
|
const offchainOutput = extractOffchainOutput(
|
|
@@ -489,9 +533,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
489
533
|
);
|
|
490
534
|
const tx = await provenTx.toTx();
|
|
491
535
|
const txHash = tx.getTxHash();
|
|
492
|
-
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
493
|
-
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
494
|
-
}
|
|
495
536
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
496
537
|
await this.aztecNode.sendTx(tx).catch(err => {
|
|
497
538
|
throw this.contextualizeError(err, inspect(tx));
|
|
@@ -504,11 +545,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
504
545
|
}
|
|
505
546
|
|
|
506
547
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
507
|
-
const
|
|
508
|
-
const
|
|
548
|
+
const callerWaitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
549
|
+
const waitOpts: WaitOpts | undefined =
|
|
550
|
+
this.defaultWaitInterval !== undefined && callerWaitOpts?.interval === undefined
|
|
551
|
+
? { ...callerWaitOpts, interval: this.defaultWaitInterval }
|
|
552
|
+
: callerWaitOpts;
|
|
553
|
+
// The tx was just sent, so an immediate first poll cannot find it mined; skip one poll interval up front.
|
|
554
|
+
const initialDelay = waitOpts?.initialDelay ?? waitOpts?.interval ?? DefaultWaitOpts.interval;
|
|
555
|
+
const receipt = await waitForTx(this.aztecNode, txHash, { ...waitOpts, initialDelay });
|
|
509
556
|
|
|
510
557
|
// Display debug logs from public execution if present (served in test mode only)
|
|
511
|
-
if (receipt.debugLogs?.length) {
|
|
558
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
512
559
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
513
560
|
}
|
|
514
561
|
|
|
@@ -524,7 +571,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
524
571
|
if (!instance) {
|
|
525
572
|
return undefined;
|
|
526
573
|
}
|
|
527
|
-
|
|
574
|
+
// Contract names are class-stable (an upgrade preserves the contract name), so the original class artifact is a
|
|
575
|
+
// sufficient source for the display name without resolving the current class against the node.
|
|
576
|
+
// TODO: if a contract were to be upgraded and its original artifact never registered, then this would fail and we'd
|
|
577
|
+
// want to fallback to the current class.
|
|
578
|
+
const artifact = await this.pxe.getContractArtifact(instance.originalContractClassId);
|
|
528
579
|
return artifact?.name;
|
|
529
580
|
}
|
|
530
581
|
|
|
@@ -554,7 +605,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
554
605
|
|
|
555
606
|
const decodedEvents = pxeEvents.map((pxeEvent: PackedPrivateEvent): PrivateEvent<T> => {
|
|
556
607
|
return {
|
|
557
|
-
event: decodeFromAbi(
|
|
608
|
+
event: decodeFromAbi(eventDef.abiType, pxeEvent.packedEvent) as T,
|
|
558
609
|
metadata: {
|
|
559
610
|
l2BlockNumber: pxeEvent.l2BlockNumber,
|
|
560
611
|
l2BlockHash: pxeEvent.l2BlockHash,
|
|
@@ -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';
|