@aztec/cli-wallet 0.0.1-commit.f295ac2 → 0.0.1-commit.f8ca9b2f3

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.
@@ -22,7 +22,7 @@ import { NoteDao } from '@aztec/stdlib/note';
22
22
  import type { NotesFilter } from '@aztec/stdlib/note';
23
23
  import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
24
24
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
- import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
25
+ import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
26
26
 
27
27
  import type { WalletDB } from '../storage/wallet_db.js';
28
28
  import type { AccountType } from './constants.js';
@@ -67,6 +67,7 @@ export class CLIWallet extends BaseWallet {
67
67
  const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
68
68
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
69
69
  const fromAccount = await this.getAccountFromAddress(from);
70
+ const chainInfo = await this.getChainInfo();
70
71
  const executionOptions: DefaultAccountEntrypointOptions = {
71
72
  txNonce,
72
73
  cancellable: this.cancellableTransactions,
@@ -75,6 +76,7 @@ export class CLIWallet extends BaseWallet {
75
76
  return await fromAccount.createTxExecutionRequest(
76
77
  feeExecutionPayload ?? executionPayload,
77
78
  feeOptions.gasSettings,
79
+ chainInfo,
78
80
  executionOptions,
79
81
  );
80
82
  }
@@ -91,8 +93,7 @@ export class CLIWallet extends BaseWallet {
91
93
  override async getAccountFromAddress(address: AztecAddress) {
92
94
  let account: Account | undefined;
93
95
  if (address.equals(AztecAddress.ZERO)) {
94
- const chainInfo = await this.getChainInfo();
95
- account = new SignerlessAccount(chainInfo);
96
+ account = new SignerlessAccount();
96
97
  } else if (this.accountCache.has(address.toString())) {
97
98
  return this.accountCache.get(address.toString())!;
98
99
  } else {
@@ -176,15 +177,26 @@ export class CLIWallet extends BaseWallet {
176
177
  return account;
177
178
  }
178
179
 
180
+ /**
181
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
182
+ * to bypass the account's authorization mechanisms via contract overrides.
183
+ * @param address - The address of the account to impersonate
184
+ * @returns The stub account, contract instance, and artifact for simulation
185
+ */
179
186
  private async getFakeAccountDataFor(address: AztecAddress) {
180
- const chainInfo = await this.getChainInfo();
181
187
  const originalAccount = await this.getAccountFromAddress(address);
182
- const originalAddress = originalAccount.getCompleteAddress();
188
+ // Account contracts can only be overridden if they have an associated address
189
+ // Overwriting SignerlessAccount is not supported, and does not really make sense
190
+ // since it has no authorization mechanism.
191
+ if (originalAccount instanceof SignerlessAccount) {
192
+ throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
193
+ }
194
+ const originalAddress = (originalAccount as Account).getCompleteAddress();
183
195
  const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
184
196
  if (!contractInstance) {
185
197
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
186
198
  }
187
- const stubAccount = createStubAccount(originalAddress, chainInfo);
199
+ const stubAccount = createStubAccount(originalAddress);
188
200
  const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
189
201
  salt: Fr.random(),
190
202
  });
@@ -196,10 +208,31 @@ export class CLIWallet extends BaseWallet {
196
208
  }
197
209
 
198
210
  override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
199
- let simulationResults;
200
- const feeOptions = opts.fee?.estimateGas
201
- ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
202
- : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
211
+ const simulationResults = await super.simulateTx(executionPayload, opts);
212
+
213
+ if (opts.fee?.estimateGas) {
214
+ const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
215
+ const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
216
+ printGasEstimates(feeOptions, limits, this.userLog);
217
+ }
218
+ return simulationResults;
219
+ }
220
+
221
+ /**
222
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
223
+ * Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
224
+ */
225
+ protected override async simulateViaEntrypoint(
226
+ executionPayload: ExecutionPayload,
227
+ from: AztecAddress,
228
+ feeOptions: FeeOptions,
229
+ skipTxValidation?: boolean,
230
+ skipFeeEnforcement?: boolean,
231
+ ): Promise<TxSimulationResult> {
232
+ if (from.equals(AztecAddress.ZERO)) {
233
+ return super.simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement);
234
+ }
235
+
203
236
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
204
237
  const executionOptions: DefaultAccountEntrypointOptions = {
205
238
  txNonce: Fr.random(),
@@ -210,42 +243,22 @@ export class CLIWallet extends BaseWallet {
210
243
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
211
244
  : executionPayload;
212
245
 
213
- // Kernelless simulations using the multicall entrypoints are not currently supported,
214
- // since we only override proper account contracts.
215
- // TODO: allow disabling kernels even when no overrides are necessary
216
- if (opts.from.equals(AztecAddress.ZERO)) {
217
- const fromAccount = await this.getAccountFromAddress(opts.from);
218
- const txRequest = await fromAccount.createTxExecutionRequest(
219
- finalExecutionPayload,
220
- feeOptions.gasSettings,
221
- executionOptions,
222
- );
223
- simulationResults = await this.pxe.simulateTx(
224
- txRequest,
225
- true /* simulatePublic */,
226
- opts?.skipTxValidation,
227
- opts?.skipFeeEnforcement ?? true,
228
- );
229
- } else {
230
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
231
- const txRequest = await fromAccount.createTxExecutionRequest(
232
- finalExecutionPayload,
233
- feeOptions.gasSettings,
234
- executionOptions,
235
- );
236
- const contractOverrides = {
237
- [opts.from.toString()]: { instance, artifact },
238
- };
239
- simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
240
- contracts: contractOverrides,
241
- });
242
- }
243
-
244
- if (opts.fee?.estimateGas) {
245
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
246
- printGasEstimates(feeOptions, limits, this.userLog);
247
- }
248
- return simulationResults;
246
+ const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
247
+ const chainInfo = await this.getChainInfo();
248
+ const txRequest = await fromAccount.createTxExecutionRequest(
249
+ finalExecutionPayload,
250
+ feeOptions.gasSettings,
251
+ chainInfo,
252
+ executionOptions,
253
+ );
254
+ return this.pxe.simulateTx(txRequest, {
255
+ simulatePublic: true,
256
+ skipFeeEnforcement: true,
257
+ skipTxValidation: true,
258
+ overrides: {
259
+ contracts: { [from.toString()]: { instance, artifact } },
260
+ },
261
+ });
249
262
  }
250
263
 
251
264
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because