Open dutterbutter opened 10 months ago
The bug is related to l2TokenAddress
method because it throws error for every token expcept for ETH
. More precise, l2TokenAddress
uses l2WethBridge.l2TokenAddress(token)
to get wETHL2
based on provided wETHL1
, which returns 0x
for every token. This means that current implementation of l2TokenAddress
on mainnet
and testnet
works only for ETH
and breaks for any other token.
{
"address": "0xf00dad97284d0c6f06dc4db3c32454d4292c6813",
"l1Address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"l2Address": "0xf00dad97284d0c6f06dc4db3c32454d4292c6813",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": 18
}
const wETHL1 = await provider.l2TokenAddress("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); // breaks
const wETHL2 = await provider.l1TokenAddress("0xf00dad97284d0c6f06dc4db3c32454d4292c6813"); // breaks
The same bug applies to testnet
and local-setup
.
Here's the PR that fixed the issue. Also the wETH
bridges does not work because they always return '0x' when it comes to l1TokenAddress
and l2TokenAddress
methods.
It looks to me that the root cause of this issue was the fact that the zks_getBridgeContracts
RPC method doesn't return the correct l1WethBridge
and l2WethBridge
addresses and instead it return the zero address.
This RPC method is used by the sdk and the call to l2TokenAddress
is sent to the incorrect weth bridge address, causing it to fail.
This is happening on both Testnet and Mainnet:
Mainnet
{"jsonrpc":"2.0","result":{"l1Erc20DefaultBridge":"0x57891966931eb4bb6fb81430e6ce0a03aabde063","l2Erc20DefaultBridge":"0x11f943b2c77b743ab90f4a0ae7d5a4e7fca3e102","l1WethBridge":"0x0000000000000000000000000000000000000000","l2WethBridge":"0x0000000000000000000000000000000000000000"},"id":1}
Testnet
{"jsonrpc":"2.0","result":{"l1Erc20DefaultBridge":"0x927ddfcc55164a59e0f33918d13a2d559bc10ce7","l2Erc20DefaultBridge":"0x00ff932a6d70e2b8f1eb4919e1e09c1923e7e57b","l1WethBridge":"0x0000000000000000000000000000000000000000","l2WethBridge":"0x0000000000000000000000000000000000000000"},"id":1}
Description:
When using the
zksync-web3
SDK to deposit or bridge funds using ERC-20 tokens, the transaction hangs and fails to execute.Steps to Reproduce:
1. Scaffold a new project
2. Include the
.env
file at the project rootCreate a .env file in the project root containing your private key and the L1 RPC endpoint.
3. Create the deposit ERC-20 tokens script
Click to expand for code snippet!
``` import { Wallet, Provider, utils } from "zksync-web3"; import * as ethers from "ethers"; // load env file import dotenv from "dotenv"; dotenv.config(); // HTTP RPC endpoints const L1_RPC_ENDPOINT = process.env.L1_RPC_ENDPOINT || ""; // or an RPC endpoint from Infura/Chainstack/QuickNode/etc. const L2_RPC_ENDPOINT = process.env.L2_RPC_ENDPOINT || "https://testnet.era.zksync.dev"; // or the zkSync Era mainnet // ERC-20 Token address in L1 const TOKEN_ADDRESS = "4. Run the script
5. Expected Output
Actual Output:
Identified Issue:
l2TokenAddress
call fails during deposit operationThe call to retrieve
l2TokenAddress
seems to be failing, and this call is made in a few places when we callwallet.deposit
.Example:
This call consistently fails with a
CALL_EXCEPTION
error.Context
When executing the deposit call from the script:
The function internally references
l2TokenAddress
in a few places:By commenting out the lines that invoke
l2TokenAddress
in the above-referenced locations, the deposit transaction executes as expected and successfully completes. This workaround suggests that the issue may be specifically related to howl2TokenAddress
is being called or handled.Deliverable
To close out this issue:
l2TokenAddress