I have deployed Uniswap V2 factory and router contracts on zklink nova mainnet Factory - https://etherscan.deth.net/address/0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f Router - https://etherscan.deth.net/address/0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

zklink nova is built on top of zksync tech. https://docs.zklink.io/developer/evm-compatibility

When I try to call addLiquidity it gives this error

  action: 'sendTransaction',
  data: null,
  reason: null,
  invocation: null,
  revert: null,
  transaction: {
    to: '0x343944e27688296D83532379398E401359a13693',
    from: '0x1aBeA91c444E43cBf645dB61F4DC09200F0E25b0',
    data: ''
  receipt: TransactionReceipt {
    provider: Provider { _contractAddresses: {} },
    to: '0x343944e27688296D83532379398E401359a13693',
    from: '0x1aBeA91c444E43cBf645dB61F4DC09200F0E25b0',
    contractAddress: null,
    hash: '0x59b8abeac4c5a8736672234411ec327e68b3201340a2e249a7bb3ddf3de7444f',
    index: 0,
    blockHash: '0xdd128a142b1fbe08f621f427824133da999a38c94f5b1073d7e476419210d93c',
    blockNumber: 24584,
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    gasUsed: 170597n,
    blobGasUsed: undefined,
    cumulativeGasUsed: 0n,
    gasPrice: 10000000n,
    blobGasPrice: undefined,
    type: 2,
    status: 0,
    root: '0xdd128a142b1fbe08f621f427824133da999a38c94f5b1073d7e476419210d93c',
    l1BatchNumber: undefined,
    l1BatchTxIndex: undefined,
    l2ToL1Logs: [],
    _logs: [ [Log], [Log], [Log] ]
  shortMessage: 'transaction execution reverted'

When I try to add initial liquidity to a token pair that I created it by calling router contract addLiquidity throws this error

I don't understand the exact error here I narrowed it down to either the safeTransferFrom is causing issue or the

liquidity = IUniswapV2Pair(pair).mint(to);

because I ran the createPair and I was able to create pair for the two tokens

1 Answer 1


I haven't looked too much into it, but it's definitely possible this error is caused by a subtle different behavior of zksync-era with respect with ethereum.

When Uniswap's factory creates a new pool, it uses the CREATE2 opcode so the pool address can be calculated deterministically:

    // https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol
    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(uint(keccak256(abi.encodePacked(
                keccak256(abi.encodePacked(token0, token1)),
                hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash

The problem is that on zksync-era the rule for address derivation is different: https://docs.zksync.io/build/developer-reference/differences-with-ethereum.html#create-create2 . Uniswap's router uses the pairFor function to get the pool address. Since this value is wrong, the transaction fails.

If you want to solve the issue, then you need to modify the function above to make it compatible with zksync rules. Googling around, I found someone already worked on it (I haven't tested it though):

    // https://github.com/uniswap-zksync/era-uniswap-swap-router-contracts/blob/v1.1.0-zksync-era/contracts/libraries/UniswapV2Library.sol
    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(
        address factory,
        address tokenA,
        address tokenB
    ) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(
                        bytes32(0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494), // keccak256("zksyncCreate2")
                        bytes32(uint256(uint160(factory))), // sender
                        keccak256(abi.encodePacked(token0, token1)), // salt
                        hex'0100065f2f2a556816a482652f101ddda2947216a5720dd91a79c61709cbf2b8', // init code hash
                        bytes32(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) // constructor input hash: keccak256("")
  • Tried this still gives the same error Mar 18 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.