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

调用KeeperRegistry2.0合约时Gas估算错误的原因排查

问题描述

我使用KeeperManager合约调用Chainlink KeeperRegistry2.0来管理Upkeep状态,示例合约代码如下:

interface IKeeperRegistry {
  function pauseUpkeep(uint256 id) external;
}

contract KeeperManager{
    IKeeperRegistry immutable public i_registry;
    //_registry地址为0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2
    constructor(IKeeperRegistry _registry) {
      i_registry = _registry;
    }

    function pause(uint256 _upkeepID) external {
            i_registry.pauseUpkeep(_upkeepID);     
    }
}

遇到的错误情况:

  1. Remix部署时出现Gas估算错误:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Returned error: {"jsonrpc":"2.0","error":"invalid opcode: opcode 0x5f not defined","id":2219264146385420}

  1. 改用Hardhat部署成功后,在Mumbai Polygonscan中调用合约仍报错:

We were not able to estimate gas. There might be an error in the contract and this transaction may fail.

使用v2.0的registry和registrar接口时也存在同样问题。

错误原因

  • PUSH0指令兼容性问题:错误中的opcode 0x5f是以太坊上海升级引入的PUSH0指令,Mumbai测试网的EVM环境可能未启用该升级特性,导致合约执行时触发未定义指令报错。
  • 接口与权限问题:
    • 你定义的IKeeperRegistry接口仅包含pauseUpkeep方法,但Chainlink KeeperRegistry2.0的实际合约有更复杂的内部逻辑,且pauseUpkeep要求调用者必须是对应Upkeep的管理员或授权地址,权限校验失败会导致Gas估算时模拟执行中断,返回错误。
    • 若传入的registry地址(0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2)并非Mumbai网络上合法的Chainlink KeeperRegistry2.0合约地址,调用时会触发未知执行逻辑,引发Gas估算失败。
  • Gas估算机制限制:当外部合约调用会触发revert(如权限不足、地址无效)时,Remix和Polygonscan的Gas估算工具无法完成完整的执行模拟,因此返回无法估算Gas的提示,本质是实际调用会执行失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 19:17:25