@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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 (156) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +60 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +69 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +315 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +99 -0
  13. package/dest/bench/utils.d.ts +10 -27
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +27 -43
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +66 -38
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +34 -53
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +9 -6
  25. package/dest/e2e_epochs/epochs_test.d.ts +56 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +222 -42
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +60 -0
  31. package/dest/e2e_fees/fees_test.d.ts +16 -5
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +87 -88
  34. package/dest/e2e_l1_publisher/write_json.d.ts +8 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +57 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +5 -5
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +132 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +56 -21
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +154 -125
  49. package/dest/e2e_p2p/shared.d.ts +41 -3
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +146 -6
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +10 -5
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +51 -24
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
  58. package/dest/fixtures/fixtures.d.ts +5 -6
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  62. package/dest/fixtures/get_acvm_config.js +2 -14
  63. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  64. package/dest/fixtures/get_bb_config.js +8 -15
  65. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  66. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  67. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  68. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  69. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  70. package/dest/fixtures/setup_l1_contracts.js +3 -3
  71. package/dest/fixtures/setup_p2p_test.d.ts +14 -6
  72. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  73. package/dest/fixtures/setup_p2p_test.js +73 -21
  74. package/dest/fixtures/snapshot_manager.d.ts +8 -3
  75. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  76. package/dest/fixtures/snapshot_manager.js +120 -104
  77. package/dest/fixtures/token_utils.d.ts +4 -3
  78. package/dest/fixtures/token_utils.d.ts.map +1 -1
  79. package/dest/fixtures/token_utils.js +24 -7
  80. package/dest/fixtures/utils.d.ts +65 -22
  81. package/dest/fixtures/utils.d.ts.map +1 -1
  82. package/dest/fixtures/utils.js +439 -318
  83. package/dest/fixtures/web3signer.d.ts +5 -0
  84. package/dest/fixtures/web3signer.d.ts.map +1 -0
  85. package/dest/fixtures/web3signer.js +42 -0
  86. package/dest/shared/cross_chain_test_harness.d.ts +28 -18
  87. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  88. package/dest/shared/cross_chain_test_harness.js +97 -41
  89. package/dest/shared/gas_portal_test_harness.d.ts +23 -18
  90. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  91. package/dest/shared/gas_portal_test_harness.js +43 -25
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/uniswap_l1_l2.d.ts +5 -6
  94. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  95. package/dest/shared/uniswap_l1_l2.js +136 -90
  96. package/dest/simulators/lending_simulator.d.ts +5 -6
  97. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  98. package/dest/simulators/lending_simulator.js +11 -15
  99. package/dest/simulators/token_simulator.d.ts +2 -1
  100. package/dest/simulators/token_simulator.d.ts.map +1 -1
  101. package/dest/simulators/token_simulator.js +16 -13
  102. package/dest/spartan/setup_test_wallets.d.ts +8 -1
  103. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  104. package/dest/spartan/setup_test_wallets.js +108 -22
  105. package/dest/spartan/utils.d.ts +60 -307
  106. package/dest/spartan/utils.d.ts.map +1 -1
  107. package/dest/spartan/utils.js +200 -115
  108. package/package.json +60 -56
  109. package/src/bench/client_flows/benchmark.ts +341 -0
  110. package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
  111. package/src/bench/client_flows/config.ts +61 -0
  112. package/src/bench/client_flows/data_extractor.ts +111 -0
  113. package/src/bench/utils.ts +26 -52
  114. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
  115. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
  116. package/src/e2e_deploy_contract/deploy_test.ts +11 -8
  117. package/src/e2e_epochs/epochs_test.ts +276 -54
  118. package/src/e2e_fees/bridging_race.notest.ts +75 -0
  119. package/src/e2e_fees/fees_test.ts +121 -108
  120. package/src/e2e_l1_publisher/write_json.ts +74 -0
  121. package/src/e2e_multi_validator/utils.ts +258 -0
  122. package/src/e2e_nested_contract/nested_contract_test.ts +22 -14
  123. package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
  124. package/src/e2e_p2p/p2p_network.ts +212 -144
  125. package/src/e2e_p2p/shared.ts +234 -14
  126. package/src/e2e_token_contract/token_contract_test.ts +42 -38
  127. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  128. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
  129. package/src/fixtures/fixtures.ts +4 -3
  130. package/src/fixtures/get_acvm_config.ts +2 -10
  131. package/src/fixtures/get_bb_config.ts +15 -11
  132. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  133. package/src/fixtures/setup_l1_contracts.ts +5 -6
  134. package/src/fixtures/setup_p2p_test.ts +112 -30
  135. package/src/fixtures/snapshot_manager.ts +150 -102
  136. package/src/fixtures/token_utils.ts +33 -8
  137. package/src/fixtures/utils.ts +530 -352
  138. package/src/fixtures/web3signer.ts +46 -0
  139. package/src/guides/up_quick_start.sh +4 -4
  140. package/src/shared/cross_chain_test_harness.ts +92 -52
  141. package/src/shared/gas_portal_test_harness.ts +47 -31
  142. package/src/shared/uniswap_l1_l2.ts +127 -124
  143. package/src/simulators/lending_simulator.ts +11 -15
  144. package/src/simulators/token_simulator.ts +17 -12
  145. package/src/spartan/DEVELOP.md +116 -0
  146. package/src/spartan/setup_test_wallets.ts +144 -29
  147. package/src/spartan/utils.ts +194 -116
  148. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  149. package/dest/sample-dapp/connect.js +0 -12
  150. package/dest/sample-dapp/contracts.js +0 -10
  151. package/dest/sample-dapp/deploy.js +0 -35
  152. package/dest/sample-dapp/index.js +0 -98
  153. package/src/sample-dapp/connect.mjs +0 -16
  154. package/src/sample-dapp/contracts.mjs +0 -14
  155. package/src/sample-dapp/deploy.mjs +0 -40
  156. package/src/sample-dapp/index.mjs +0 -128
@@ -2,7 +2,6 @@ import {
2
2
  type AccountWallet,
3
3
  AztecAddress,
4
4
  type AztecNode,
5
- type CheatCodes,
6
5
  EthAddress,
7
6
  Fr,
8
7
  type Logger,
@@ -10,21 +9,24 @@ import {
10
9
  computeAuthWitMessageHash,
11
10
  generateClaimSecret,
12
11
  } from '@aztec/aztec.js';
12
+ import { CheatCodes } from '@aztec/aztec/testing';
13
13
  import {
14
14
  type DeployL1ContractsReturnType,
15
- type ViemPublicClient,
16
- type ViemWalletClient,
15
+ type ExtendedViemWalletClient,
16
+ RollupContract,
17
17
  deployL1Contract,
18
18
  extractEvent,
19
19
  } from '@aztec/ethereum';
20
20
  import { sha256ToField } from '@aztec/foundation/crypto';
21
- import { InboxAbi, RollupAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
21
+ import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
22
22
  import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
23
+ import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
24
+ import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
23
25
 
24
26
  import { jest } from '@jest/globals';
25
27
  import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
26
28
 
27
- import { ensureAccountsPubliclyDeployed } from '../fixtures/utils.js';
29
+ import { ensureAccountContractsPublished } from '../fixtures/utils.js';
28
30
  import { CrossChainTestHarness } from './cross_chain_test_harness.js';
29
31
 
30
32
  // PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
@@ -45,10 +47,8 @@ export type UniswapSetupContext = {
45
47
  pxe: PXE;
46
48
  /** Logger instance named as the current test. */
47
49
  logger: Logger;
48
- /** Viem Public client instance. */
49
- publicClient: ViemPublicClient;
50
- /** Viem Wallet Client instance. */
51
- walletClient: ViemWalletClient;
50
+ /** The L1 wallet client, extended with public actions. */
51
+ l1Client: ExtendedViemWalletClient;
52
52
  /** The owner wallet. */
53
53
  ownerWallet: AccountWallet;
54
54
  /** The sponsor wallet. */
@@ -76,22 +76,21 @@ export const uniswapL1L2TestSuite = (
76
76
  let pxe: PXE;
77
77
  let logger: Logger;
78
78
 
79
- let walletClient: ViemWalletClient;
80
- let publicClient: ViemPublicClient;
79
+ let l1Client: ExtendedViemWalletClient;
81
80
 
82
81
  let ownerWallet: AccountWallet;
83
82
  let ownerAddress: AztecAddress;
84
83
  let ownerEthAddress: EthAddress;
85
84
  // does transactions on behalf of owner on Aztec:
86
85
  let sponsorWallet: AccountWallet;
87
- // let sponsorAddress: AztecAddress;
86
+ let sponsorAddress: AztecAddress;
88
87
 
89
88
  let daiCrossChainHarness: CrossChainTestHarness;
90
89
  let wethCrossChainHarness: CrossChainTestHarness;
91
90
 
92
91
  let deployL1ContractsValues: DeployL1ContractsReturnType;
93
- let rollup: GetContractReturnType<typeof RollupAbi, ViemWalletClient>;
94
- let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ViemWalletClient>;
92
+ let rollup: RollupContract;
93
+ let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ExtendedViemWalletClient>;
95
94
  let uniswapPortalAddress: EthAddress;
96
95
  let uniswapL2Contract: UniswapContract;
97
96
 
@@ -100,43 +99,33 @@ export const uniswapL1L2TestSuite = (
100
99
  const minimumOutputAmount = 0n;
101
100
 
102
101
  let cheatCodes: CheatCodes;
103
-
102
+ let version: number;
104
103
  beforeAll(async () => {
105
- ({
106
- aztecNode,
107
- pxe,
108
- logger,
109
- publicClient,
110
- walletClient,
111
- ownerWallet,
112
- sponsorWallet,
113
- deployL1ContractsValues,
114
- cheatCodes,
115
- } = await setup());
104
+ ({ aztecNode, pxe, logger, l1Client, ownerWallet, sponsorWallet, deployL1ContractsValues, cheatCodes } =
105
+ await setup());
116
106
 
117
- if (Number(await publicClient.getBlockNumber()) < expectedForkBlockNumber) {
107
+ if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
118
108
  throw new Error('This test must be run on a fork of mainnet with the expected fork block');
119
109
  }
120
110
 
121
- rollup = getContract({
122
- address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
123
- abi: RollupAbi,
124
- client: deployL1ContractsValues.walletClient,
125
- });
126
-
111
+ rollup = new RollupContract(
112
+ deployL1ContractsValues.l1Client,
113
+ deployL1ContractsValues.l1ContractAddresses.rollupAddress,
114
+ );
115
+ version = Number(await rollup.getVersion());
127
116
  ownerAddress = ownerWallet.getAddress();
128
- // sponsorAddress = sponsorWallet.getAddress();
129
- ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
117
+ sponsorAddress = sponsorWallet.getAddress();
118
+ ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
130
119
 
131
- await ensureAccountsPubliclyDeployed(ownerWallet, [ownerWallet, sponsorWallet]);
120
+ await ensureAccountContractsPublished(ownerWallet, [ownerWallet, sponsorWallet]);
132
121
 
133
122
  logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
134
123
  daiCrossChainHarness = await CrossChainTestHarness.new(
135
124
  aztecNode,
136
125
  pxe,
137
- publicClient,
138
- walletClient,
126
+ deployL1ContractsValues.l1Client,
139
127
  ownerWallet,
128
+ ownerAddress,
140
129
  logger,
141
130
  DAI_ADDRESS,
142
131
  );
@@ -145,28 +134,27 @@ export const uniswapL1L2TestSuite = (
145
134
  wethCrossChainHarness = await CrossChainTestHarness.new(
146
135
  aztecNode,
147
136
  pxe,
148
- publicClient,
149
- walletClient,
137
+ l1Client,
150
138
  ownerWallet,
139
+ ownerAddress,
151
140
  logger,
152
141
  WETH9_ADDRESS,
153
142
  );
154
143
 
155
144
  logger.info('Deploy Uniswap portal on L1 and L2...');
156
- uniswapPortalAddress = await deployL1Contract(
157
- walletClient,
158
- publicClient,
159
- UniswapPortalAbi,
160
- UniswapPortalBytecode,
161
- ).then(({ address }) => address);
145
+ uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(
146
+ ({ address }) => address,
147
+ );
162
148
 
163
149
  uniswapPortal = getContract({
164
150
  address: uniswapPortalAddress.toString(),
165
151
  abi: UniswapPortalAbi,
166
- client: walletClient,
152
+ client: l1Client,
167
153
  });
168
154
  // deploy l2 uniswap contract and attach to portal
169
- uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress).send().deployed();
155
+ uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress)
156
+ .send({ from: ownerAddress })
157
+ .deployed();
170
158
 
171
159
  const registryAddress = (await pxe.getNodeInfo()).l1ContractAddresses.registryAddress;
172
160
 
@@ -177,8 +165,8 @@ export const uniswapL1L2TestSuite = (
177
165
 
178
166
  // Give me some WETH so I can deposit to L2 and do the swap...
179
167
  logger.info('Getting some weth');
180
- const hash = await walletClient.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
181
- await publicClient.waitForTransactionReceipt({ hash });
168
+ const hash = await l1Client.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
169
+ await l1Client.waitForTransactionReceipt({ hash });
182
170
 
183
171
  const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
184
172
  expect(wethBalance).toBe(parseEther('1000'));
@@ -218,7 +206,7 @@ export const uniswapL1L2TestSuite = (
218
206
  // 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
219
207
  logger.info('Approving uniswap to transfer funds to public to self on my behalf');
220
208
  const nonceForWETHTransferToPublicApproval = new Fr(1n);
221
- await ownerWallet.createAuthWit({
209
+ const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
222
210
  caller: uniswapL2Contract.address,
223
211
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
224
212
  ownerAddress,
@@ -244,7 +232,7 @@ export const uniswapL1L2TestSuite = (
244
232
  secretHashForDepositingSwappedDai,
245
233
  ownerEthAddress,
246
234
  )
247
- .send()
235
+ .send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
248
236
  .wait();
249
237
 
250
238
  const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
@@ -259,13 +247,13 @@ export const uniswapL1L2TestSuite = (
259
247
  ownerEthAddress.toBuffer32(),
260
248
  ]);
261
249
 
262
- const swapPrivateLeaf = sha256ToField([
263
- uniswapL2Contract.address,
264
- new Fr(1), // aztec version
265
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
266
- new Fr(publicClient.chain.id), // chain id
267
- swapPrivateContent,
268
- ]);
250
+ const swapPrivateLeaf = computeL2ToL1MessageHash({
251
+ l2Sender: uniswapL2Contract.address,
252
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
253
+ content: swapPrivateContent,
254
+ rollupVersion: new Fr(version),
255
+ chainId: new Fr(l1Client.chain.id),
256
+ });
269
257
 
270
258
  const withdrawContent = sha256ToField([
271
259
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
@@ -274,13 +262,13 @@ export const uniswapL1L2TestSuite = (
274
262
  uniswapPortalAddress.toBuffer32(),
275
263
  ]);
276
264
 
277
- const withdrawLeaf = sha256ToField([
278
- wethCrossChainHarness.l2Bridge.address,
279
- new Fr(1), // aztec version
280
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
281
- new Fr(publicClient.chain.id), // chain id
282
- withdrawContent,
283
- ]);
265
+ const withdrawLeaf = computeL2ToL1MessageHash({
266
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
267
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
268
+ content: withdrawContent,
269
+ rollupVersion: new Fr(version),
270
+ chainId: new Fr(l1Client.chain.id),
271
+ });
284
272
 
285
273
  // ensure that user's funds were burnt
286
274
  await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
@@ -288,23 +276,30 @@ export const uniswapL1L2TestSuite = (
288
276
  await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
289
277
 
290
278
  // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
291
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
279
+ await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
292
280
 
293
281
  // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
294
282
  logger.info('Execute withdraw and swap on the uniswapPortal!');
295
283
  const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
296
284
  daiCrossChainHarness.tokenPortalAddress,
297
285
  );
298
-
299
- const [swapPrivateL2MessageIndex, swapPrivateSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
286
+ const swapResult = await computeL2ToL1MembershipWitness(
287
+ aztecNode,
300
288
  l2UniswapInteractionReceipt.blockNumber!,
301
289
  swapPrivateLeaf,
302
290
  );
303
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
291
+ const withdrawResult = await computeL2ToL1MembershipWitness(
292
+ aztecNode,
304
293
  l2UniswapInteractionReceipt.blockNumber!,
305
294
  withdrawLeaf,
306
295
  );
307
296
 
297
+ const swapPrivateL2MessageIndex = swapResult!.leafIndex;
298
+ const swapPrivateSiblingPath = swapResult!.siblingPath;
299
+
300
+ const withdrawL2MessageIndex = withdrawResult!.leafIndex;
301
+ const withdrawSiblingPath = withdrawResult!.siblingPath;
302
+
308
303
  const withdrawMessageMetadata = {
309
304
  _l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber!),
310
305
  _leafIndex: BigInt(withdrawL2MessageIndex),
@@ -333,7 +328,7 @@ export const uniswapL1L2TestSuite = (
333
328
  ] as const;
334
329
 
335
330
  // this should also insert a message into the inbox.
336
- const txReceipt = await daiCrossChainHarness.publicClient.waitForTransactionReceipt({
331
+ const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
337
332
  hash: await uniswapPortal.write.swapPrivate(swapArgs),
338
333
  });
339
334
 
@@ -643,7 +638,7 @@ export const uniswapL1L2TestSuite = (
643
638
  Fr.random(),
644
639
  ownerEthAddress,
645
640
  )
646
- .prove(),
641
+ .simulate({ from: ownerAddress }),
647
642
  ).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
648
643
  });
649
644
 
@@ -655,7 +650,7 @@ export const uniswapL1L2TestSuite = (
655
650
  // 2. owner gives uniswap approval to transfer the funds to public:
656
651
  logger.info('Approving uniswap to transfer funds to public to self on my behalf');
657
652
  const nonceForWETHTransferToPublicApproval = new Fr(3n);
658
- await ownerWallet.createAuthWit({
653
+ const transferToPublicAuthwith = await ownerWallet.createAuthWit({
659
654
  caller: uniswapL2Contract.address,
660
655
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
661
656
  ownerAddress,
@@ -680,7 +675,7 @@ export const uniswapL1L2TestSuite = (
680
675
  Fr.random(),
681
676
  ownerEthAddress,
682
677
  )
683
- .prove(),
678
+ .prove({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] }),
684
679
  ).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
685
680
  });
686
681
 
@@ -704,7 +699,7 @@ export const uniswapL1L2TestSuite = (
704
699
  },
705
700
  true,
706
701
  );
707
- await validateActionInteraction.send().wait();
702
+ await validateActionInteraction.send({ from: ownerAddress }).wait();
708
703
 
709
704
  // No approval to call `swap` but should work even without it:
710
705
  const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
@@ -723,7 +718,7 @@ export const uniswapL1L2TestSuite = (
723
718
  ownerEthAddress,
724
719
  Fr.ZERO, // nonce for swap -> doesn't matter
725
720
  )
726
- .send()
721
+ .send({ from: ownerAddress })
727
722
  .wait();
728
723
  // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
729
724
  await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
@@ -752,9 +747,9 @@ export const uniswapL1L2TestSuite = (
752
747
  nonceForSwap,
753
748
  );
754
749
  const validateActionInteraction = await ownerWallet.setPublicAuthWit({ caller: approvedUser, action }, true);
755
- await validateActionInteraction.send().wait();
750
+ await validateActionInteraction.send({ from: ownerAddress }).wait();
756
751
 
757
- await expect(action.simulate()).rejects.toThrow(/unauthorized/);
752
+ await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
758
753
  });
759
754
 
760
755
  it("uniswap can't pull funds without transfer approval", async () => {
@@ -773,7 +768,7 @@ export const uniswapL1L2TestSuite = (
773
768
  },
774
769
  true,
775
770
  );
776
- await validateActionInteraction.send().wait();
771
+ await validateActionInteraction.send({ from: ownerAddress }).wait();
777
772
 
778
773
  await expect(
779
774
  uniswapL2Contract.methods
@@ -790,7 +785,7 @@ export const uniswapL1L2TestSuite = (
790
785
  ownerEthAddress,
791
786
  Fr.ZERO,
792
787
  )
793
- .simulate(),
788
+ .simulate({ from: ownerAddress }),
794
789
  ).rejects.toThrow(/unauthorized/);
795
790
  });
796
791
 
@@ -803,7 +798,7 @@ export const uniswapL1L2TestSuite = (
803
798
  // Owner gives uniswap approval to transfer the funds to public to self on its behalf
804
799
  logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
805
800
  const nonceForWETHTransferToPublicApproval = new Fr(4n);
806
- await ownerWallet.createAuthWit({
801
+ const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
807
802
  caller: uniswapL2Contract.address,
808
803
  action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
809
804
  ownerAddress,
@@ -830,7 +825,7 @@ export const uniswapL1L2TestSuite = (
830
825
  secretHashForDepositingSwappedDai,
831
826
  ownerEthAddress,
832
827
  )
833
- .send()
828
+ .send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
834
829
  .wait();
835
830
 
836
831
  const swapPrivateContent = sha256ToField([
@@ -847,13 +842,13 @@ export const uniswapL1L2TestSuite = (
847
842
  ownerEthAddress.toBuffer32(),
848
843
  ]);
849
844
 
850
- const swapPrivateLeaf = sha256ToField([
851
- uniswapL2Contract.address,
852
- new Fr(1), // aztec version
853
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
854
- new Fr(publicClient.chain.id), // chain id
855
- swapPrivateContent,
856
- ]);
845
+ const swapPrivateLeaf = computeL2ToL1MessageHash({
846
+ l2Sender: uniswapL2Contract.address,
847
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
848
+ content: swapPrivateContent,
849
+ rollupVersion: new Fr(version),
850
+ chainId: new Fr(l1Client.chain.id),
851
+ });
857
852
 
858
853
  const withdrawContent = sha256ToField([
859
854
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
@@ -862,23 +857,27 @@ export const uniswapL1L2TestSuite = (
862
857
  uniswapPortalAddress.toBuffer32(),
863
858
  ]);
864
859
 
865
- const withdrawLeaf = sha256ToField([
866
- wethCrossChainHarness.l2Bridge.address,
867
- new Fr(1), // aztec version
868
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
869
- new Fr(publicClient.chain.id), // chain id
870
- withdrawContent,
871
- ]);
860
+ const withdrawLeaf = computeL2ToL1MessageHash({
861
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
862
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
863
+ content: withdrawContent,
864
+ rollupVersion: new Fr(version),
865
+ chainId: new Fr(l1Client.chain.id),
866
+ });
872
867
 
873
- const [swapPrivateL2MessageIndex, swapPrivateSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
874
- withdrawReceipt.blockNumber!,
875
- swapPrivateLeaf,
876
- );
877
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
868
+ const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber!, swapPrivateLeaf);
869
+ const withdrawResult = await computeL2ToL1MembershipWitness(
870
+ aztecNode,
878
871
  withdrawReceipt.blockNumber!,
879
872
  withdrawLeaf,
880
873
  );
881
874
 
875
+ const swapPrivateL2MessageIndex = swapResult!.leafIndex;
876
+ const swapPrivateSiblingPath = swapResult!.siblingPath;
877
+
878
+ const withdrawL2MessageIndex = withdrawResult!.leafIndex;
879
+ const withdrawSiblingPath = withdrawResult!.siblingPath;
880
+
882
881
  const withdrawMessageMetadata = {
883
882
  _l2BlockNumber: BigInt(withdrawReceipt.blockNumber!),
884
883
  _leafIndex: BigInt(withdrawL2MessageIndex),
@@ -899,7 +898,7 @@ export const uniswapL1L2TestSuite = (
899
898
  await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
900
899
 
901
900
  // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
902
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
901
+ await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
903
902
 
904
903
  // On L1 call swap_public!
905
904
  logger.info('call swap_public on L1');
@@ -939,7 +938,7 @@ export const uniswapL1L2TestSuite = (
939
938
  },
940
939
  true,
941
940
  );
942
- await validateActionInteraction.send().wait();
941
+ await validateActionInteraction.send({ from: ownerAddress }).wait();
943
942
 
944
943
  // Call swap_public on L2
945
944
  const secretHashForDepositingSwappedDai = Fr.random();
@@ -957,7 +956,7 @@ export const uniswapL1L2TestSuite = (
957
956
  ownerEthAddress,
958
957
  Fr.ZERO,
959
958
  )
960
- .send()
959
+ .send({ from: ownerAddress })
961
960
  .wait();
962
961
 
963
962
  const swapPublicContent = sha256ToField([
@@ -977,13 +976,13 @@ export const uniswapL1L2TestSuite = (
977
976
  ownerEthAddress.toBuffer32(),
978
977
  ]);
979
978
 
980
- const swapPublicLeaf = sha256ToField([
981
- uniswapL2Contract.address,
982
- new Fr(1), // aztec version
983
- EthAddress.fromString(uniswapPortal.address).toBuffer32(),
984
- new Fr(publicClient.chain.id), // chain id
985
- swapPublicContent,
986
- ]);
979
+ const swapPublicLeaf = computeL2ToL1MessageHash({
980
+ l2Sender: uniswapL2Contract.address,
981
+ l1Recipient: EthAddress.fromString(uniswapPortal.address),
982
+ content: swapPublicContent,
983
+ rollupVersion: new Fr(version),
984
+ chainId: new Fr(l1Client.chain.id),
985
+ });
987
986
 
988
987
  const withdrawContent = sha256ToField([
989
988
  Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
@@ -992,23 +991,27 @@ export const uniswapL1L2TestSuite = (
992
991
  uniswapPortalAddress.toBuffer32(),
993
992
  ]);
994
993
 
995
- const withdrawLeaf = sha256ToField([
996
- wethCrossChainHarness.l2Bridge.address,
997
- new Fr(1), // aztec version
998
- wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
999
- new Fr(publicClient.chain.id), // chain id
1000
- withdrawContent,
1001
- ]);
994
+ const withdrawLeaf = computeL2ToL1MessageHash({
995
+ l2Sender: wethCrossChainHarness.l2Bridge.address,
996
+ l1Recipient: wethCrossChainHarness.tokenPortalAddress,
997
+ content: withdrawContent,
998
+ rollupVersion: new Fr(version),
999
+ chainId: new Fr(l1Client.chain.id),
1000
+ });
1002
1001
 
1003
- const [swapPublicL2MessageIndex, swapPublicSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
1004
- withdrawReceipt.blockNumber!,
1005
- swapPublicLeaf,
1006
- );
1007
- const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
1002
+ const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber!, swapPublicLeaf);
1003
+ const withdrawResult = await computeL2ToL1MembershipWitness(
1004
+ aztecNode,
1008
1005
  withdrawReceipt.blockNumber!,
1009
1006
  withdrawLeaf,
1010
1007
  );
1011
1008
 
1009
+ const swapPublicL2MessageIndex = swapResult!.leafIndex;
1010
+ const swapPublicSiblingPath = swapResult!.siblingPath;
1011
+
1012
+ const withdrawL2MessageIndex = withdrawResult!.leafIndex;
1013
+ const withdrawSiblingPath = withdrawResult!.siblingPath;
1014
+
1012
1015
  const withdrawMessageMetadata = {
1013
1016
  _l2BlockNumber: BigInt(withdrawReceipt.blockNumber!),
1014
1017
  _leafIndex: BigInt(withdrawL2MessageIndex),
@@ -1029,7 +1032,7 @@ export const uniswapL1L2TestSuite = (
1029
1032
  await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
1030
1033
 
1031
1034
  // Since the outbox is only consumable when the block is proven, we need to set the block to be proven
1032
- await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
1035
+ await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
1033
1036
 
1034
1037
  // Call swap_private on L1
1035
1038
  logger.info('Execute withdraw and swap on the uniswapPortal!');
@@ -1,13 +1,11 @@
1
1
  // Convenience struct to hold an account's address and secret that can easily be passed around.
2
- import { AztecAddress, type CheatCodes, Fr } from '@aztec/aztec.js';
2
+ import { AztecAddress, Fr } from '@aztec/aztec.js';
3
+ import { CheatCodes } from '@aztec/aztec/testing';
4
+ import type { RollupContract } from '@aztec/ethereum';
3
5
  import { pedersenHash } from '@aztec/foundation/crypto';
4
6
  import type { TestDateProvider } from '@aztec/foundation/timer';
5
- import type { RollupAbi } from '@aztec/l1-artifacts';
6
7
  import type { LendingContract } from '@aztec/noir-contracts.js/Lending';
7
8
 
8
- import type { Account, GetContractReturnType, HttpTransport, WalletClient } from 'viem';
9
- import type * as chains from 'viem/chains';
10
-
11
9
  import type { TokenSimulator } from './token_simulator.js';
12
10
 
13
11
  /**
@@ -83,7 +81,7 @@ export class LendingSimulator {
83
81
  private rate: bigint,
84
82
  private ethereumSlotDuration: number,
85
83
  /** the rollup contract */
86
- public rollup: GetContractReturnType<typeof RollupAbi, WalletClient<HttpTransport, chains.Chain, Account>>,
84
+ public rollup: RollupContract,
87
85
  /** the lending contract */
88
86
  public lendingContract: LendingContract,
89
87
  /** the collateral asset used in the lending contract */
@@ -94,10 +92,8 @@ export class LendingSimulator {
94
92
 
95
93
  async prepare() {
96
94
  this.accumulator = BASE;
97
- const slot = await this.rollup.read.getSlotAt([
98
- BigInt(await this.cc.eth.timestamp()) + BigInt(this.ethereumSlotDuration),
99
- ]);
100
- this.time = Number(await this.rollup.read.getTimestampForSlot([slot]));
95
+ const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()) + BigInt(this.ethereumSlotDuration));
96
+ this.time = Number(await this.rollup.getTimestampForSlot(slot));
101
97
  }
102
98
 
103
99
  async progressSlots(diff: number, dateProvider?: TestDateProvider) {
@@ -105,8 +101,8 @@ export class LendingSimulator {
105
101
  return;
106
102
  }
107
103
 
108
- const slot = await this.rollup.read.getSlotAt([BigInt(await this.cc.eth.timestamp())]);
109
- const ts = Number(await this.rollup.read.getTimestampForSlot([slot + BigInt(diff)]));
104
+ const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()));
105
+ const ts = Number(await this.rollup.getTimestampForSlot(slot + BigInt(diff)));
110
106
  const timeDiff = ts - this.time;
111
107
  this.time = ts;
112
108
 
@@ -115,7 +111,7 @@ export class LendingSimulator {
115
111
  if (dateProvider) {
116
112
  dateProvider.setTime(this.time * 1000);
117
113
  }
118
- await this.cc.rollup.markAsProven(await this.rollup.read.getPendingBlockNumber());
114
+ await this.cc.rollup.markAsProven(await this.rollup.getBlockNumber());
119
115
  this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(timeDiff)), BASE);
120
116
  }
121
117
 
@@ -187,14 +183,14 @@ export class LendingSimulator {
187
183
 
188
184
  expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
189
185
 
190
- const asset = await this.lendingContract.methods.get_asset(0).simulate();
186
+ const asset = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
191
187
 
192
188
  const interestAccumulator = asset['interest_accumulator'];
193
189
  expect(interestAccumulator).toEqual(this.accumulator);
194
190
  expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
195
191
 
196
192
  for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
197
- const privatePos = await this.lendingContract.methods.get_position(key).simulate();
193
+ const privatePos = await this.lendingContract.methods.get_position(key).simulate({ from: key });
198
194
  expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
199
195
  expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
200
196
  expect(privatePos['debt']).toEqual(
@@ -1,4 +1,3 @@
1
- /* eslint-disable jsdoc/require-jsdoc */
2
1
  import { type AztecAddress, BatchCall, type Logger, type Wallet } from '@aztec/aztec.js';
3
2
  import type { TokenContract } from '@aztec/noir-contracts.js/Token';
4
3
 
@@ -14,6 +13,7 @@ export class TokenSimulator {
14
13
  constructor(
15
14
  protected token: TokenContract,
16
15
  protected defaultWallet: Wallet,
16
+ protected defaultAddress: AztecAddress,
17
17
  protected logger: Logger,
18
18
  protected accounts: AztecAddress[],
19
19
  ) {}
@@ -97,13 +97,15 @@ export class TokenSimulator {
97
97
 
98
98
  async checkPublic() {
99
99
  // public calls
100
- const calls = [await this.token.methods.total_supply().request()];
101
- for (const address of this.accounts) {
102
- calls.push(await this.token.methods.balance_of_public(address).request());
103
- }
100
+ const calls = [
101
+ this.token.methods.total_supply(),
102
+ ...this.accounts.map(address => this.token.methods.balance_of_public(address)),
103
+ ];
104
104
 
105
105
  const results = (
106
- await Promise.all(chunk(calls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate()))
106
+ await Promise.all(
107
+ chunk(calls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress })),
108
+ )
107
109
  ).flat();
108
110
  expect(results[0]).toEqual(this.totalSupply);
109
111
 
@@ -126,12 +128,13 @@ export class TokenSimulator {
126
128
  }
127
129
  }
128
130
 
129
- const defaultCalls = [];
130
- for (const address of defaultLookups) {
131
- defaultCalls.push(await this.token.methods.balance_of_private(address).request());
132
- }
131
+ const defaultCalls = defaultLookups.map(address => this.token.methods.balance_of_private(address));
133
132
  const results = (
134
- await Promise.all(chunk(defaultCalls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate()))
133
+ await Promise.all(
134
+ chunk(defaultCalls, 4).map(batch =>
135
+ new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress }),
136
+ ),
137
+ )
135
138
  ).flat();
136
139
  for (let i = 0; i < defaultLookups.length; i++) {
137
140
  expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i]));
@@ -143,7 +146,9 @@ export class TokenSimulator {
143
146
  const wallet = this.lookupProvider.get(address.toString());
144
147
  const asset = wallet ? this.token.withWallet(wallet) : this.token;
145
148
 
146
- const actualPrivateBalance = await asset.methods.balance_of_private({ address }).simulate();
149
+ const actualPrivateBalance = await asset.methods
150
+ .balance_of_private({ address })
151
+ .simulate({ from: this.defaultAddress });
147
152
  expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
148
153
  }
149
154
  }