@aztec/end-to-end 0.0.1-commit.ef17749e1 → 0.0.1-commit.f103f88

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.
Files changed (92) hide show
  1. package/README.md +27 -0
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  4. package/dest/bench/client_flows/client_flows_benchmark.js +13 -28
  5. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +3 -2
  6. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  7. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +1 -1
  8. package/dest/e2e_epochs/epochs_test.d.ts +3 -1
  9. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  10. package/dest/e2e_epochs/epochs_test.js +8 -5
  11. package/dest/e2e_fees/fees_test.js +1 -1
  12. package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
  13. package/dest/e2e_p2p/p2p_network.d.ts +5 -7
  14. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  15. package/dest/e2e_p2p/p2p_network.js +14 -13
  16. package/dest/e2e_p2p/reqresp/utils.d.ts +1 -1
  17. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -1
  18. package/dest/e2e_p2p/reqresp/utils.js +16 -3
  19. package/dest/e2e_p2p/shared.d.ts +16 -12
  20. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  21. package/dest/e2e_p2p/shared.js +33 -51
  22. package/dest/fixtures/authwit_proxy.d.ts +1 -1
  23. package/dest/fixtures/authwit_proxy.d.ts.map +1 -1
  24. package/dest/fixtures/authwit_proxy.js +4 -0
  25. package/dest/fixtures/e2e_prover_test.d.ts +4 -3
  26. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  27. package/dest/fixtures/e2e_prover_test.js +7 -12
  28. package/dest/fixtures/get_bb_config.d.ts +1 -1
  29. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  30. package/dest/fixtures/get_bb_config.js +5 -5
  31. package/dest/fixtures/setup.d.ts +16 -8
  32. package/dest/fixtures/setup.d.ts.map +1 -1
  33. package/dest/fixtures/setup.js +24 -18
  34. package/dest/fixtures/setup_p2p_test.d.ts +6 -6
  35. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  36. package/dest/fixtures/setup_p2p_test.js +8 -8
  37. package/dest/fixtures/token_utils.d.ts +1 -1
  38. package/dest/fixtures/token_utils.d.ts.map +1 -1
  39. package/dest/fixtures/token_utils.js +2 -5
  40. package/dest/legacy-jest-resolver.d.cts +3 -0
  41. package/dest/legacy-jest-resolver.d.cts.map +1 -0
  42. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  43. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  44. package/dest/shared/uniswap_l1_l2.js +9 -12
  45. package/dest/simulators/lending_simulator.d.ts +1 -1
  46. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  47. package/dest/simulators/lending_simulator.js +2 -2
  48. package/dest/simulators/token_simulator.js +1 -1
  49. package/dest/spartan/setup_test_wallets.d.ts +4 -2
  50. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  51. package/dest/spartan/setup_test_wallets.js +69 -39
  52. package/dest/spartan/utils/config.d.ts +4 -1
  53. package/dest/spartan/utils/config.d.ts.map +1 -1
  54. package/dest/spartan/utils/config.js +1 -0
  55. package/dest/spartan/utils/index.d.ts +2 -1
  56. package/dest/spartan/utils/index.d.ts.map +1 -1
  57. package/dest/spartan/utils/index.js +2 -0
  58. package/dest/spartan/utils/pod_logs.d.ts +25 -0
  59. package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
  60. package/dest/spartan/utils/pod_logs.js +74 -0
  61. package/dest/test-wallet/test_wallet.d.ts +24 -23
  62. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  63. package/dest/test-wallet/test_wallet.js +115 -80
  64. package/dest/test-wallet/worker_wallet.d.ts +4 -4
  65. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  66. package/dest/test-wallet/worker_wallet_schema.d.ts +9 -4
  67. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -1
  68. package/package.json +40 -40
  69. package/src/bench/client_flows/client_flows_benchmark.ts +31 -22
  70. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +3 -6
  71. package/src/e2e_epochs/epochs_test.ts +17 -5
  72. package/src/e2e_fees/fees_test.ts +1 -1
  73. package/src/e2e_p2p/inactivity_slash_test.ts +3 -3
  74. package/src/e2e_p2p/p2p_network.ts +22 -27
  75. package/src/e2e_p2p/reqresp/utils.ts +24 -3
  76. package/src/e2e_p2p/shared.ts +36 -67
  77. package/src/fixtures/authwit_proxy.ts +4 -0
  78. package/src/fixtures/e2e_prover_test.ts +12 -17
  79. package/src/fixtures/get_bb_config.ts +7 -6
  80. package/src/fixtures/setup.ts +38 -25
  81. package/src/fixtures/setup_p2p_test.ts +9 -9
  82. package/src/fixtures/token_utils.ts +1 -4
  83. package/src/legacy-jest-resolver.cjs +135 -0
  84. package/src/shared/uniswap_l1_l2.ts +29 -24
  85. package/src/simulators/lending_simulator.ts +4 -2
  86. package/src/simulators/token_simulator.ts +1 -1
  87. package/src/spartan/setup_test_wallets.ts +96 -34
  88. package/src/spartan/utils/config.ts +1 -0
  89. package/src/spartan/utils/index.ts +3 -0
  90. package/src/spartan/utils/pod_logs.ts +99 -0
  91. package/src/test-wallet/test_wallet.ts +144 -99
  92. package/src/test-wallet/worker_wallet.ts +3 -2
@@ -1,4 +1,5 @@
1
1
  import { generateSchnorrAccounts } from '@aztec/accounts/testing';
2
+ import { NO_FROM } from '@aztec/aztec.js/account';
2
3
  import { AztecAddress } from '@aztec/aztec.js/addresses';
3
4
  import { NO_WAIT } from '@aztec/aztec.js/contracts';
4
5
  import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
@@ -10,7 +11,7 @@ import type { Wallet } from '@aztec/aztec.js/wallet';
10
11
  import { createEthereumChain } from '@aztec/ethereum/chain';
11
12
  import { createExtendedL1Client } from '@aztec/ethereum/client';
12
13
  import type { Logger } from '@aztec/foundation/log';
13
- import { retryUntil } from '@aztec/foundation/retry';
14
+ import { makeBackoff, retry, retryUntil } from '@aztec/foundation/retry';
14
15
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
15
16
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
16
17
  import { registerInitialLocalNetworkAccountsInWallet } from '@aztec/wallets/testing';
@@ -89,7 +90,7 @@ export async function deploySponsoredTestAccountsWithTokens(
89
90
  const paymentMethod = new SponsoredFeePaymentMethod(await getSponsoredFPCAddress());
90
91
  const recipientDeployMethod = await recipientAccount.getDeployMethod();
91
92
  await recipientDeployMethod.send({
92
- from: AztecAddress.ZERO,
93
+ from: NO_FROM,
93
94
  fee: { paymentMethod },
94
95
  wait: { timeout: 2400 },
95
96
  });
@@ -97,7 +98,7 @@ export async function deploySponsoredTestAccountsWithTokens(
97
98
  fundedAccounts.map(async a => {
98
99
  const deployMethod = await a.getDeployMethod();
99
100
  await deployMethod.send({
100
- from: AztecAddress.ZERO,
101
+ from: NO_FROM,
101
102
  fee: { paymentMethod },
102
103
  wait: { timeout: 2400 },
103
104
  }); // increase timeout on purpose in order to account for two empty epochs
@@ -129,50 +130,91 @@ export async function deploySponsoredTestAccountsWithTokens(
129
130
  }
130
131
 
131
132
  async function deployAccountWithDiagnostics(
132
- account: { getDeployMethod: () => Promise<{ send: (opts: any) => any }>; address: any },
133
+ account: { getDeployMethod: () => Promise<{ simulate: (opts: any) => any; send: (opts: any) => any }>; address: any },
133
134
  paymentMethod: SponsoredFeePaymentMethod,
134
135
  aztecNode: AztecNode,
135
136
  logger: Logger,
136
137
  accountLabel: string,
138
+ estimateGas?: boolean,
137
139
  ): Promise<void> {
138
140
  const deployMethod = await account.getDeployMethod();
139
- let txHash;
140
- try {
141
- const deployResult = await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod }, wait: NO_WAIT });
142
- txHash = deployResult.txHash;
143
- await waitForTx(aztecNode, txHash, { timeout: 2400 });
144
- logger.info(`${accountLabel} deployed at ${account.address}`);
145
- } catch (error) {
146
- const blockNumber = await aztecNode.getBlockNumber();
147
- let receipt;
148
- try {
149
- receipt = await aztecNode.getTxReceipt(txHash);
150
- } catch {
151
- receipt = 'unavailable';
152
- }
153
- logger.error(`${accountLabel} deployment failed`, {
154
- txHash: txHash.toString(),
155
- receipt: JSON.stringify(receipt),
156
- currentBlockNumber: blockNumber,
157
- error: String(error),
158
- });
159
- throw error;
141
+ let gasSettings: any;
142
+ if (estimateGas) {
143
+ const sim = await deployMethod.simulate({ from: NO_FROM, fee: { paymentMethod } });
144
+ gasSettings = sim.estimatedGas;
145
+ logger.info(`${accountLabel} estimated gas: DA=${gasSettings.gasLimits.daGas} L2=${gasSettings.gasLimits.l2Gas}`);
160
146
  }
147
+
148
+ // Track the tx hash across retries so we don't re-send when the previous tx is still pending.
149
+ let sentTxHash: { txHash: any } | undefined;
150
+
151
+ await retry(
152
+ async () => {
153
+ // Check if already deployed (handles case where previous attempt succeeded but waitForTx timed out)
154
+ const existing = await aztecNode.getContract(account.address);
155
+ if (existing) {
156
+ logger.info(`${accountLabel} already deployed at ${account.address}, skipping`);
157
+ return;
158
+ }
159
+
160
+ // If we already sent a tx, check if it was dropped before deciding to re-send.
161
+ if (sentTxHash) {
162
+ const prevReceipt = await aztecNode.getTxReceipt(sentTxHash.txHash);
163
+ if (prevReceipt.isDropped()) {
164
+ logger.info(`${accountLabel} previous tx ${sentTxHash.txHash} was dropped, re-sending`);
165
+ sentTxHash = undefined;
166
+ } else {
167
+ logger.info(`${accountLabel} previous tx ${sentTxHash.txHash} still pending, waiting again...`);
168
+ }
169
+ }
170
+
171
+ if (!sentTxHash) {
172
+ const deployResult = await deployMethod.send({
173
+ from: NO_FROM,
174
+ fee: { paymentMethod, gasSettings },
175
+ wait: NO_WAIT,
176
+ });
177
+ sentTxHash = { txHash: deployResult.txHash };
178
+ logger.info(`${accountLabel} tx sent`, { txHash: sentTxHash.txHash.toString() });
179
+ }
180
+
181
+ const receipt = await waitForTx(aztecNode, sentTxHash.txHash, { timeout: 600 });
182
+ if (receipt.isDropped()) {
183
+ sentTxHash = undefined;
184
+ throw new Error(`${accountLabel} tx was dropped, retrying...`);
185
+ }
186
+ logger.info(`${accountLabel} deployed at ${account.address}`);
187
+ },
188
+ `deploy ${accountLabel}`,
189
+ makeBackoff([1, 2, 4, 8, 16]),
190
+ logger,
191
+ );
161
192
  }
162
193
 
163
194
  async function deployAccountsInBatches(
164
- accounts: { getDeployMethod: () => Promise<{ send: (opts: any) => any }>; address: any }[],
195
+ accounts: {
196
+ getDeployMethod: () => Promise<{ simulate: (opts: any) => any; send: (opts: any) => any }>;
197
+ address: any;
198
+ }[],
165
199
  paymentMethod: SponsoredFeePaymentMethod,
166
200
  aztecNode: AztecNode,
167
201
  logger: Logger,
168
202
  labelPrefix: string,
169
203
  batchSize = 2,
204
+ estimateGas?: boolean,
170
205
  ): Promise<void> {
171
206
  for (let i = 0; i < accounts.length; i += batchSize) {
172
207
  const batch = accounts.slice(i, i + batchSize);
173
208
  await Promise.all(
174
209
  batch.map((account, idx) =>
175
- deployAccountWithDiagnostics(account, paymentMethod, aztecNode, logger, `${labelPrefix}${i + idx + 1}`),
210
+ deployAccountWithDiagnostics(
211
+ account,
212
+ paymentMethod,
213
+ aztecNode,
214
+ logger,
215
+ `${labelPrefix}${i + idx + 1}`,
216
+ estimateGas,
217
+ ),
176
218
  ),
177
219
  );
178
220
  }
@@ -183,6 +225,7 @@ export async function deploySponsoredTestAccounts(
183
225
  aztecNode: AztecNode,
184
226
  logger: Logger,
185
227
  numberOfFundedWallets = 1,
228
+ opts?: { estimateGas?: boolean },
186
229
  ): Promise<TestAccountsWithoutTokens> {
187
230
  const [recipient, ...funded] = await generateSchnorrAccounts(numberOfFundedWallets + 1);
188
231
  const recipientAccount = await wallet.createSchnorrAccount(recipient.secret, recipient.salt);
@@ -192,8 +235,23 @@ export async function deploySponsoredTestAccounts(
192
235
 
193
236
  const paymentMethod = new SponsoredFeePaymentMethod(await getSponsoredFPCAddress());
194
237
 
195
- await deployAccountWithDiagnostics(recipientAccount, paymentMethod, aztecNode, logger, 'Recipient account');
196
- await deployAccountsInBatches(fundedAccounts, paymentMethod, aztecNode, logger, 'Funded account ', 2);
238
+ await deployAccountWithDiagnostics(
239
+ recipientAccount,
240
+ paymentMethod,
241
+ aztecNode,
242
+ logger,
243
+ 'Recipient account',
244
+ opts?.estimateGas,
245
+ );
246
+ await deployAccountsInBatches(
247
+ fundedAccounts,
248
+ paymentMethod,
249
+ aztecNode,
250
+ logger,
251
+ 'Funded account ',
252
+ 2,
253
+ opts?.estimateGas,
254
+ );
197
255
 
198
256
  return {
199
257
  aztecNode,
@@ -231,7 +289,7 @@ export async function deployTestAccountsWithTokens(
231
289
  fundedAccounts.map(async (a, i) => {
232
290
  const paymentMethod = new FeeJuicePaymentMethodWithClaim(a.address, claims[i]);
233
291
  const deployMethod = await a.getDeployMethod();
234
- await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod } });
292
+ await deployMethod.send({ from: NO_FROM, fee: { paymentMethod } });
235
293
  logger.info(`Account deployed at ${a.address}`);
236
294
  }),
237
295
  );
@@ -307,14 +365,18 @@ async function deployTokenAndMint(
307
365
  logger: Logger,
308
366
  ) {
309
367
  logger.verbose(`Deploying TokenContract...`);
310
- const {
311
- receipt: { contract: tokenContract },
312
- } = await TokenContract.deploy(wallet, admin, TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS).send({
368
+ const { contract: tokenContract } = await TokenContract.deploy(
369
+ wallet,
370
+ admin,
371
+ TOKEN_NAME,
372
+ TOKEN_SYMBOL,
373
+ TOKEN_DECIMALS,
374
+ ).send({
313
375
  from: admin,
314
376
  fee: {
315
377
  paymentMethod,
316
378
  },
317
- wait: { timeout: 600, returnReceipt: true },
379
+ wait: { timeout: 600 },
318
380
  });
319
381
 
320
382
  const tokenAddress = tokenContract.address;
@@ -8,6 +8,7 @@ const logger = createLogger('e2e:k8s-utils');
8
8
  const testConfigSchema = z.object({
9
9
  NAMESPACE: z.string().default('scenario'),
10
10
  REAL_VERIFIER: schemas.Boolean.optional().default(true),
11
+ DEBUG_FORCE_TX_PROOF_VERIFICATION: schemas.Boolean.optional().default(true),
11
12
  CREATE_ETH_DEVNET: schemas.Boolean.optional().default(false),
12
13
  L1_RPC_URLS_JSON: z.string().optional(),
13
14
  L1_ACCOUNT_MNEMONIC: z.string().optional(),
@@ -66,3 +66,6 @@ export { getPublicViemClient, getL1DeploymentAddresses, getNodeClient } from './
66
66
 
67
67
  // Health checks
68
68
  export { ChainHealth, type ChainHealthSnapshot } from './health.js';
69
+
70
+ // Pod log extraction
71
+ export { type BlockBuiltLogEntry, fetchBlockBuiltLogs } from './pod_logs.js';
@@ -0,0 +1,99 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
3
+ import { exec } from 'child_process';
4
+ import { promisify } from 'util';
5
+
6
+ import { getSequencers } from './nodes.js';
7
+
8
+ const execAsync = promisify(exec);
9
+
10
+ /** Parsed l2-block-built stats from a sequencer pod log line. */
11
+ export type BlockBuiltLogEntry = {
12
+ blockNumber: number;
13
+ txCount: number;
14
+ duration: number;
15
+ publicProcessDuration: number;
16
+ manaPerSec: number;
17
+ privateLogCount: number;
18
+ publicLogCount: number;
19
+ contractClassLogCount: number;
20
+ contractClassLogSize: number;
21
+ };
22
+
23
+ const FIELDS: (keyof BlockBuiltLogEntry)[] = [
24
+ 'blockNumber',
25
+ 'txCount',
26
+ 'duration',
27
+ 'publicProcessDuration',
28
+ 'manaPerSec',
29
+ 'privateLogCount',
30
+ 'publicLogCount',
31
+ 'contractClassLogCount',
32
+ 'contractClassLogSize',
33
+ ];
34
+
35
+ /**
36
+ * Fetches l2-block-built log entries from sequencer pods for given block numbers.
37
+ * Queries all validator pods (only the proposer will have the log for a given block).
38
+ *
39
+ * @param namespace - Kubernetes namespace
40
+ * @param sinceTime - ISO 8601 timestamp to limit log search (e.g., from before block building was re-enabled)
41
+ * @param blockNumbers - Set of block numbers to filter for
42
+ * @param logger - Logger instance
43
+ * @returns Array of parsed BlockBuiltLogEntry, de-duplicated by blockNumber, sorted ascending
44
+ */
45
+ export async function fetchBlockBuiltLogs(
46
+ namespace: string,
47
+ sinceTime: string,
48
+ blockNumbers: Set<number>,
49
+ logger: Logger,
50
+ ): Promise<BlockBuiltLogEntry[]> {
51
+ const pods = await getSequencers(namespace);
52
+ const entriesByBlock = new Map<number, BlockBuiltLogEntry>();
53
+
54
+ // Subtract 60s from sinceTime to account for clock skew between test runner and k8s pods.
55
+ // Block number filtering ensures we only match the right blocks, so extra lines are harmless.
56
+ const sinceDate = new Date(new Date(sinceTime).getTime() - 60_000);
57
+ const sinceFlag = sinceDate.toISOString();
58
+
59
+ for (const pod of pods) {
60
+ try {
61
+ const cmd = `kubectl logs ${pod} -n ${namespace} -c aztec --since-time=${sinceFlag}`;
62
+ logger.info(`Fetching logs: ${cmd}`);
63
+ const { stdout } = await execAsync(cmd, { maxBuffer: 10 * 1024 * 1024 });
64
+
65
+ const lines = stdout.split('\n');
66
+ const matchingLines = lines.filter(l => l.includes('l2-block-built'));
67
+ logger.info(`Pod ${pod}: ${lines.length} log lines, ${matchingLines.length} contain l2-block-built`);
68
+
69
+ for (const line of matchingLines) {
70
+ try {
71
+ const parsed = JSON.parse(line);
72
+ if (parsed.eventName !== 'l2-block-built' || !blockNumbers.has(parsed.blockNumber)) {
73
+ continue;
74
+ }
75
+ if (entriesByBlock.has(parsed.blockNumber)) {
76
+ continue;
77
+ }
78
+ const entry: BlockBuiltLogEntry = {} as BlockBuiltLogEntry;
79
+ for (const field of FIELDS) {
80
+ entry[field] = parsed[field] ?? 0;
81
+ }
82
+ entriesByBlock.set(entry.blockNumber, entry);
83
+ logger.verbose(`Parsed l2-block-built log for block ${entry.blockNumber}`, entry);
84
+ } catch {
85
+ // Not valid JSON, skip
86
+ }
87
+ }
88
+ } catch (err) {
89
+ logger.warn(`Failed to fetch logs from pod ${pod}: ${err}`);
90
+ }
91
+ }
92
+
93
+ if (entriesByBlock.size < blockNumbers.size) {
94
+ const missing = [...blockNumbers].filter(bn => !entriesByBlock.has(bn));
95
+ logger.warn(`Missing l2-block-built logs for block(s): ${missing.join(', ')}`);
96
+ }
97
+
98
+ return [...entriesByBlock.values()].sort((a, b) => a.blockNumber - b.blockNumber);
99
+ }
@@ -1,7 +1,9 @@
1
1
  import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
2
2
  import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
- import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
4
- import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
3
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
5
+ import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
6
+ import type { CompleteAddress } from '@aztec/aztec.js/addresses';
5
7
  import {
6
8
  type CallIntent,
7
9
  type ContractFunctionInteractionCallIntent,
@@ -13,10 +15,12 @@ import {
13
15
  } from '@aztec/aztec.js/authorization';
14
16
  import type { AztecNode } from '@aztec/aztec.js/node';
15
17
  import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
18
+ import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
16
19
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
20
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
17
21
  import { Fq, Fr } from '@aztec/foundation/curves/bn254';
18
22
  import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
19
- import type { AccessScopes, NotesFilter } from '@aztec/pxe/client/lazy';
23
+ import type { NotesFilter } from '@aztec/pxe/client/lazy';
20
24
  import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
21
25
  import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
22
26
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
@@ -24,9 +28,17 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
24
28
  import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
25
29
  import { deriveSigningKey } from '@aztec/stdlib/keys';
26
30
  import type { NoteDao } from '@aztec/stdlib/note';
27
- import type { BlockHeader, TxHash, TxReceipt, TxSimulationResult } from '@aztec/stdlib/tx';
31
+ import {
32
+ type BlockHeader,
33
+ type ContractOverrides,
34
+ SimulationOverrides,
35
+ type TxExecutionRequest,
36
+ type TxHash,
37
+ type TxReceipt,
38
+ } from '@aztec/stdlib/tx';
28
39
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
29
- import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
40
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
41
+ import type { AccountType } from '@aztec/wallets/embedded';
30
42
 
31
43
  import { AztecNodeProxy, ProvenTx } from './utils.js';
32
44
 
@@ -36,6 +48,7 @@ import { AztecNodeProxy, ProvenTx } from './utils.js';
36
48
  export interface AccountData {
37
49
  secret: Fr;
38
50
  salt: Fr;
51
+ type?: AccountType;
39
52
  contract: AccountContract;
40
53
  }
41
54
 
@@ -76,70 +89,92 @@ export class TestWallet extends BaseWallet {
76
89
 
77
90
  createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
78
91
  signingKey = signingKey ?? deriveSigningKey(secret);
79
- const accountData = {
80
- secret,
81
- salt,
82
- contract: new SchnorrAccountContract(signingKey),
83
- };
84
- return this.createAccount(accountData);
92
+ return this.createAccount({ secret, salt, type: 'schnorr', contract: new SchnorrAccountContract(signingKey) });
85
93
  }
86
94
 
87
95
  createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
88
- const accountData = {
96
+ return this.createAccount({
89
97
  secret,
90
98
  salt,
99
+ type: 'ecdsasecp256r1',
91
100
  contract: new EcdsaRAccountContract(signingKey),
92
- };
93
- return this.createAccount(accountData);
101
+ });
94
102
  }
95
103
 
96
104
  createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
97
- const accountData = {
105
+ return this.createAccount({
98
106
  secret,
99
107
  salt,
108
+ type: 'ecdsasecp256k1',
100
109
  contract: new EcdsaKAccountContract(signingKey),
101
- };
102
- return this.createAccount(accountData);
103
- }
104
-
105
- async getFakeAccountDataFor(address: AztecAddress) {
106
- const originalAccount = await this.getAccountFromAddress(address);
107
- if (originalAccount instanceof SignerlessAccount) {
108
- throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
109
- }
110
- const originalAddress = (originalAccount as Account).getCompleteAddress();
111
- const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
112
- if (!contractInstance) {
113
- throw new Error(`No contract instance found for address: ${originalAddress.address}`);
114
- }
115
- const stubAccount = createStubAccount(originalAddress);
116
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
117
- salt: Fr.random(),
118
110
  });
119
- return {
120
- account: stubAccount,
121
- instance,
122
- artifact: StubAccountContractArtifact,
123
- };
124
111
  }
125
- protected accounts: Map<string, Account> = new Map();
126
112
 
127
113
  /**
128
- * Toggle for running "simulated simulations" when calling simulateTx.
129
- *
130
- * When this flag is true, simulateViaEntrypoint constructs a request using a fake account
131
- * (and accepts contract overrides on the input) and the PXE emulates kernel effects without
132
- * generating kernel witnesses. When false, simulateViaEntrypoint defers to the standard
133
- * simulation path via the real account entrypoint.
114
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
134
115
  */
135
- private simulatedSimulations = false;
116
+ protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
117
+ const accounts = await this.getAccounts();
118
+ const contracts: ContractOverrides = {};
119
+
120
+ const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
121
+
122
+ for (const account of filtered) {
123
+ const address = account.item;
124
+ const originalAccount = await this.getAccountFromAddress(address);
125
+ const completeAddress = originalAccount.getCompleteAddress();
126
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
127
+ if (!contractInstance) {
128
+ throw new Error(
129
+ `No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
130
+ );
131
+ }
132
+
133
+ const stubArtifact = this.getStubArtifactFor(address);
134
+ const stubConstructorArgs =
135
+ this.getTypeFor(address) === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
136
+ const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
137
+ salt: Fr.random(),
138
+ constructorArgs: stubConstructorArgs,
139
+ });
140
+
141
+ contracts[address.toString()] = {
142
+ instance: stubInstance,
143
+ artifact: stubArtifact,
144
+ };
145
+ }
136
146
 
137
- enableSimulatedSimulations() {
138
- this.simulatedSimulations = true;
147
+ return contracts;
139
148
  }
140
149
 
141
- disableSimulatedSimulations() {
142
- this.simulatedSimulations = false;
150
+ protected accounts: Map<string, { account: Account; type: AccountType }> = new Map();
151
+
152
+ private getTypeFor(address: AztecAddress): AccountType {
153
+ return this.accounts.get(address.toString())?.type ?? 'schnorr';
154
+ }
155
+
156
+ private getStubArtifactFor(address: AztecAddress) {
157
+ return this.getTypeFor(address) === 'schnorr'
158
+ ? StubSchnorrAccountContractArtifact
159
+ : StubEcdsaAccountContractArtifact;
160
+ }
161
+
162
+ private getStubAccountFor(address: AztecAddress, completeAddress: CompleteAddress) {
163
+ return this.getTypeFor(address) === 'schnorr'
164
+ ? createStubSchnorrAccount(completeAddress)
165
+ : createStubEcdsaAccount(completeAddress);
166
+ }
167
+
168
+ /**
169
+ * Controls how the test wallet simulates transactions:
170
+ * - `kernelless`: Skips kernel circuits but uses the real account contract. Default.
171
+ * - `kernelless-override`: Skips kernels and replaces the account with a stub that doesn't do authwit validation.
172
+ * - `full`: Uses real kernel circuits and real account contracts. Slow!
173
+ */
174
+ private simulationMode: 'kernelless' | 'kernelless-override' | 'full' = 'kernelless';
175
+
176
+ setSimulationMode(mode: 'kernelless' | 'kernelless-override' | 'full') {
177
+ this.simulationMode = mode;
143
178
  }
144
179
 
145
180
  setMinFeePadding(value?: number) {
@@ -147,27 +182,25 @@ export class TestWallet extends BaseWallet {
147
182
  }
148
183
 
149
184
  protected getAccountFromAddress(address: AztecAddress): Promise<Account> {
150
- let account: Account | undefined;
151
- if (address.equals(AztecAddress.ZERO)) {
152
- account = new SignerlessAccount();
153
- } else {
154
- account = this.accounts.get(address?.toString() ?? '');
155
- }
185
+ const entry = this.accounts.get(address?.toString() ?? '');
156
186
 
157
- if (!account) {
187
+ if (!entry) {
158
188
  throw new Error(`Account not found in wallet for address: ${address}`);
159
189
  }
160
190
 
161
- return Promise.resolve(account);
191
+ return Promise.resolve(entry.account);
162
192
  }
163
193
 
164
194
  getAccounts() {
165
- return Promise.resolve(Array.from(this.accounts.values()).map(acc => ({ alias: '', item: acc.getAddress() })));
195
+ return Promise.resolve(
196
+ Array.from(this.accounts.values()).map(entry => ({ alias: '', item: entry.account.getAddress() })),
197
+ );
166
198
  }
167
199
 
168
200
  async createAccount(accountData?: AccountData): Promise<AccountManager> {
169
201
  const secret = accountData?.secret ?? Fr.random();
170
202
  const salt = accountData?.salt ?? Fr.random();
203
+ const type = accountData?.type ?? 'schnorr';
171
204
  const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
172
205
 
173
206
  const accountManager = await AccountManager.create(this, secret, contract, salt);
@@ -177,7 +210,8 @@ export class TestWallet extends BaseWallet {
177
210
 
178
211
  await this.registerContract(instance, artifact, secret);
179
212
 
180
- this.accounts.set(accountManager.address.toString(), await accountManager.getAccount());
213
+ const address = accountManager.address.toString();
214
+ this.accounts.set(address, { account: await accountManager.getAccount(), type });
181
215
 
182
216
  return accountManager;
183
217
  }
@@ -220,60 +254,71 @@ export class TestWallet extends BaseWallet {
220
254
  return account.createAuthWit(intentInnerHash, chainInfo);
221
255
  }
222
256
 
223
- /**
224
- * Override simulateViaEntrypoint to use fake accounts for kernelless simulation
225
- * when simulatedSimulations is enabled. Otherwise falls through to the real entrypoint path.
226
- */
227
257
  protected override async simulateViaEntrypoint(
228
258
  executionPayload: ExecutionPayload,
229
- from: AztecAddress,
230
- feeOptions: FeeOptions,
231
- scopes: AccessScopes,
232
- skipTxValidation?: boolean,
233
- skipFeeEnforcement?: boolean,
234
- ): Promise<TxSimulationResult> {
235
- if (!this.simulatedSimulations) {
236
- return super.simulateViaEntrypoint(
237
- executionPayload,
238
- from,
239
- feeOptions,
240
- scopes,
241
- skipTxValidation,
242
- skipFeeEnforcement,
243
- );
244
- }
259
+ opts: SimulateViaEntrypointOptions,
260
+ ): Promise<TxSimulationResultWithAppOffset> {
261
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
262
+ const scopes = this.scopesFrom(from, additionalScopes);
263
+ const skipKernels = this.simulationMode !== 'full';
264
+ const useOverride = this.simulationMode === 'kernelless-override';
245
265
 
246
266
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
247
- const executionOptions: DefaultAccountEntrypointOptions = {
248
- txNonce: Fr.random(),
249
- cancellable: this.cancellableTransactions,
250
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
251
- };
252
267
  const finalExecutionPayload = feeExecutionPayload
253
268
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
254
269
  : executionPayload;
255
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
256
270
  const chainInfo = await this.getChainInfo();
257
- const txRequest = await fromAccount.createTxExecutionRequest(
258
- finalExecutionPayload,
259
- feeOptions.gasSettings,
260
- chainInfo,
261
- executionOptions,
262
- );
263
- const contractOverrides = {
264
- [from.toString()]: { instance, artifact },
265
- };
266
- return this.pxe.simulateTx(txRequest, {
271
+
272
+ let overrides: SimulationOverrides | undefined;
273
+ let txRequest: TxExecutionRequest;
274
+ if (useOverride) {
275
+ const accountOverrides = await this.buildAccountOverrides(scopes);
276
+ overrides = new SimulationOverrides(accountOverrides);
277
+ }
278
+
279
+ if (from === NO_FROM) {
280
+ const entrypoint = new DefaultEntrypoint();
281
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
282
+ } else {
283
+ let fromAccount: Account;
284
+ if (useOverride) {
285
+ const originalAccount = await this.getAccountFromAddress(from);
286
+ fromAccount = this.getStubAccountFor(from, originalAccount.getCompleteAddress());
287
+ } else {
288
+ fromAccount = await this.getAccountFromAddress(from);
289
+ }
290
+ const executionOptions: DefaultAccountEntrypointOptions = {
291
+ txNonce: Fr.random(),
292
+ cancellable: this.cancellableTransactions,
293
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
294
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
295
+ };
296
+ txRequest = await fromAccount.createTxExecutionRequest(
297
+ finalExecutionPayload,
298
+ feeOptions.gasSettings,
299
+ chainInfo,
300
+ executionOptions,
301
+ );
302
+ }
303
+
304
+ const result = await this.pxe.simulateTx(txRequest, {
267
305
  simulatePublic: true,
268
- skipFeeEnforcement: true,
269
- skipTxValidation: true,
270
- overrides: { contracts: contractOverrides },
306
+ skipKernels,
307
+ skipFeeEnforcement,
308
+ skipTxValidation,
309
+ overrides,
271
310
  scopes,
272
311
  });
312
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
313
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
273
314
  }
274
315
 
275
316
  async proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx> {
276
- const fee = await this.completeFeeOptions(opts.from, exec.feePayer, opts.fee?.gasSettings);
317
+ const fee = await this.completeFeeOptions({
318
+ from: opts.from,
319
+ feePayer: exec.feePayer,
320
+ gasSettings: opts.fee?.gasSettings,
321
+ });
277
322
  const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
278
323
  const txProvingResult = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
279
324
  return new ProvenTx(