You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在ZkSyncEra调用合约时触发execution reverted错误求协助排查

问题

在ZkSync Era中调用合约方法时遇到execution reverted错误,测试对象为PancakeSwap V3池合约,但该问题可在任意合约上复现;ABI与实际合约一致,目标方法真实存在且可在区块链浏览器中查询到。

环境依赖(go.mod)

module etron

go 1.21.4

require (
    github.com/ethereum/go-ethereum v1.13.6
)

最小复现代码

package tests

import (
    "context"
    "testing"

    _pkgWeb3 "etron/pkg/web3"

    "github.com/ethereum/go-ethereum"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func TestCalling(t *testing.T) {
    client, err := ethclient.Dial("https://mainnet.era.zksync.io/")
    if err != nil {
        panic(err)
    }
    abi, err := _pkgWeb3.LoadAbi("Abi.json") 
    if err != nil {
        panic(err)
    }
    to := common.HexToAddress("0x141853f48B5Fe6cC6Cc792417dff59B9009D796d")

    callData, err := abi.Pack("slot0")

    if err != nil {
        panic(err)
    }

    msg := ethereum.CallMsg{
        To:   &to,
        Data: callData,
    }

    result, err := client.CallContract(context.TODO(), msg, nil)

    if err != nil {
        panic(err)
    }
    _ = result
}

解决思路

  • 适配ZkSync专属客户端:go-ethereum官方库未完全适配ZkSync Era的执行逻辑,直接用ethclient调用易因链上规则差异触发回滚。建议替换为ZkSync官方提供的Go SDK进行合约交互。
  • 补充调用上下文参数:ZkSync Era的合约调用可能需要额外参数:
    • 指定区块高度:将CallContract第三个参数设为最新区块标识(如big.NewInt(-1))
    • 添加From字段:即使是只读调用,部分合约会验证调用来源格式,可填入任意合法以太坊地址
      示例修改:
    import "math/big"
    
    // 指定最新区块
    result, err := client.CallContract(context.TODO(), msg, big.NewInt(-1))
    
    // 或添加From字段
    msg := ethereum.CallMsg{
        To:   &to,
        Data: callData,
        From: common.HexToAddress("0xYourValidAddress"),
    }
    
  • 校验ABI打包结果:确认LoadAbi函数完整加载了ABI文件,打印callData并与区块链浏览器中该方法的调用数据对比,确保格式一致。
  • 更换RPC端点:尝试使用ZkSync Era其他官方公共端点,避免当前节点存在同步延迟或权限限制。

内容的提问来源于stack exchange,提问作者Maksim Smolovsky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 00:33:20