Skip to content

eth_estimateGas fails when contract contains try/catch #9801

@tsudmi

Description

@tsudmi

Client / Network

  • Nethermind v1.35.2
  • Network: Gnosis
  • Node flags:
--config=gnosis_archive
--Pruning.Mode=None
--JsonRpc.Enabled=true
--JsonRpc.Host=0.0.0.0
--JsonRpc.Port=6020
--Init.WebSocketsEnabled=true
--JsonRpc.WebSocketsPort=6033
--JsonRpc.JwtSecretFile=/data/jwtsecret
--JsonRpc.EngineHost=127.0.0.1
--JsonRpc.EnginePort=8551
--Network.ExternalIp=x.x.x.x
--Network.P2PPort=30300
--Network.DiscoveryPort=30300
--HealthChecks.Enabled=true
--Metrics.Enabled=true
--Metrics.ExposePort=9565

❗ Bug Description

eth_estimateGas returns:

Error response handling JsonRpc Id:3 Method:eth_estimateGas 
Code: -32000 
Message: Gas estimation failed due to out of gas

This happens only when the contract function contains a Solidity try/catch that catches a failure in a callee.
The actual transaction executes successfully on-chain if a manual gas limit is provided.

Without the try/catch, gas estimation works normally.


🔁 Steps to Reproduce

Solidity contract with try/catch: https://gnosisscan.io/address/0x1358898C25046386e1fd538AA2025890D182Ef01

from web3 import Web3

RPC_URL = "https://nethermind"
CONTRACT_ADDRESS = "0x1358898C25046386e1fd538AA2025890D182Ef01"
SENDER_ADDRESS = "0x47A5D720D7f352daAa1C3313F6a7661793e0D47a"

ABI = [
    {
        "inputs": [],
        "name": "increment",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    }
]

w3 = Web3(Web3.HTTPProvider(RPC_URL))
contract = w3.eth.contract(Web3.to_checksum_address(CONTRACT_ADDRESS), abi=ABI)

tx = contract.functions.increment().build_transaction({
    "from": Web3.to_checksum_address(SENDER_ADDRESS),
    "nonce": w3.eth.get_transaction_count(SENDER_ADDRESS),
    "chainId": w3.eth.chain_id,
})

w3.eth.estimate_gas(tx)   # <-- fails

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions