Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas estimations on Gnosis Chain too low #5637

Closed
iamacook opened this issue May 2, 2023 · 3 comments
Closed

Gas estimations on Gnosis Chain too low #5637

iamacook opened this issue May 2, 2023 · 3 comments
Assignees
Labels

Comments

@iamacook
Copy link

iamacook commented May 2, 2023

Description

eth_estimateGas estimations on Gnosis Chain are too low (specifically for Safe transactions requiring safeTxGas).

Steps to Reproduce

Make eth_estimateGas calls to either of the official Gnosis Chain RPCs: https://rpc.gnosischain.com / https://rpc.gnosis.gateway.fm and observe the low gas which inevitably reverts (simulation):

{
    "method": "eth_estimateGas",
    "params": [
        {
            "type": "0x0",
            "from": "0xbbeedb6d8e56e23f5812e59d1b6602f15957271f",
            "to": "0x828cf988de33bf93527533852e95e2da449ec171",
            "data": "0x6a761202000000000000000000000000828cf988de33bf93527533852e95e2da449ec171000000000000000000000000000000000000000000000000000000e8d4a51000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014bb80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041e0a9f565f27a4fd5743e5b7ad92f4217467bc5a7a419c7e159a5950de845ad9b0e88bf1c5549d5335ca087c010a7560a5caf991ba88850d10cb1e2d6196b4a151b00000000000000000000000000000000000000000000000000000000000000"
        }
    ],
    "id": 63,
    "jsonrpc": "2.0"
}

Actual behavior

Estimation is too low and transaction reverts.

Expected behavior

Estimation returns sufficient gas for the transaction to succeed, ~30-60% higher than what it currently is.

@emlautarom1
Copy link
Contributor

emlautarom1 commented Jul 12, 2023

I'm able to reproduce the issue using the following JS script that leverages ethers:

const ethers = require("ethers");

(async () => {
    [
        { client: "Localhost", url: "http://127.0.0.1:8545/" },
        { client: "Official", url: "https://rpc.gnosischain.com/" },
        { client: "Gateway", url: "https://rpc.gnosis.gateway.fm" },
        { client: "BlockPi", url: "https://gnosis.blockpi.network/v1/rpc/public" },
        { client: "Blast", url: "https://gnosis-mainnet.public.blastapi.io" },
        { client: "Pokt", url: "https://gnosischain-rpc.gateway.pokt.network" },
        { client: "Ankr", url: "https://rpc.ankr.com/gnosis" }
    ].forEach(async ({ client, url }) => await estimateGas(client, url));
})();

async function estimateGas(client, url) {
    let body = {
        "from": "0xbbeedb6d8e56e23f5812e59d1b6602f15957271f",
        "to": "0x828cf988de33bf93527533852e95e2da449ec171",
        "data": "0x6a761202000000000000000000000000828cf988de33bf93527533852e95e2da449ec171000000000000000000000000000000000000000000000000000000e8d4a51000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014bb80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041e0a9f565f27a4fd5743e5b7ad92f4217467bc5a7a419c7e159a5950de845ad9b0e88bf1c5549d5335ca087c010a7560a5caf991ba88850d10cb1e2d6196b4a151b00000000000000000000000000000000000000000000000000000000000000"
    }

    let response = await ethers.utils.fetchJson(url, `{ "id": 42, "jsonrpc": "2.0", "method": "eth_estimateGas", "params": [${JSON.stringify(body)} ] }`);
    let estimation = parseInt(response.result, 16);
    console.log(`Client '${client}' estimated '${estimation}'`);
}

The interesting part is that all RPC providers return 59074, while on localhost I tried:

In this case, both clients return 29400. It would be really useful to know what client are those RPC providers using to be able to debug where is that estimation coming from.

Update: RPC providers are all using Nethermind:

Official: Nethermind/v1.19.3+e8ac1da4
Gateway: Nethermind/v1.19.3+e8ac1da4
BlockPi: Nethermind/v1.19.3+e8ac1da4
Ankr: Nethermind/v1.19.3+e8ac1da4
Blast: Nethermind/v1.19.3+e8ac1da4
Pokt: Nethermind/v1.14.7+4fe81c6b

@emlautarom1
Copy link
Contributor

After verifying with a simulator, the actual gas used to execute this transaction is 56285 (see https://dashboard.tenderly.co/shared/simulation/df8e2e37-9336-447b-9d13-bd5359bd3129). Still, the transaction requires a higher gas limit due to the existence of safeTxGas (documented here: https://help.safe.global/en/articles/40837-advanced-transaction-parameters). The contract involved in the transaction will check that the remaining gas is at least the value of safeTxGas, which, in this case, is 84920 since that is the value that the user has provided..

If we run the transaction again with the estimation provided by the RPCs + the value of safeTxGas (59074 + 84920 = 143994), then the transaction actually goes through.

How should then Nethermind deal with this kind of transactions that can perform arbitrary checks on the gas? For this specific kind of "safe" transactions, a possibility would for Nethermind to have a special condition (a plugin?) to add the value of safeTxGas to the original estimation. What do you think @deffrian?

This was referenced Jul 26, 2023
@emlautarom1
Copy link
Contributor

emlautarom1 commented Aug 3, 2023

I will close the ticket with a wontfix label. An detailed explanation about this issue is available here: #5973 (comment).

For users of "safe transaction", our suggestion is to add this value to the gas estimation provided by the node you're using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants