调用KeeperRegistry2.0合约时Gas估算错误的原因排查
Chainlink 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); } }
遇到的错误情况:
- 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}
- 改用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
相关产品推荐
相关产品推荐

