skalenetwork / skaled

Running more than 20 production blockchains, SKALED is Ethereum-compatible, high performance C++ Proof-of-Stake client, tools and libraries. Uses SKALE consensus as a blockchain consensus core. Includes dynamic Oracle. Implements file storage and retrieval as an EVM extension.
https://skale.network
GNU General Public License v3.0
85 stars 39 forks source link

Incorrect Gas Estimation #1966

Closed nftpixels closed 4 days ago

nftpixels commented 3 weeks ago

Describe the bug As of using the Calypso Mainnet I found that all writes on my contracts run out of gas due to it estimating the incorrect amount of gas. The testnet estimates just fine and so does hard coding the gas limit on mainnet.

Example transaction: https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com/tx/0x45f7df11b45abee5fa7f07af10e8d3303aae8a3a19b093500e2c49912cf53e77

To Reproduce Steps to reproduce the behavior:

  1. Go to https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com/address/0x7AeDdf3adf87FCE483739E8B6fa9221f20d7d856?tab=contract
  2. Click on writes
  3. Try and execute the mint function. It should work with any wallet that is connected with sFuel
  4. It should run out of gas because MM fails to get the correct gas estimates.

Expected behavior The amount of gas estimated should be enough to cover the transaction cost.

Screenshots N/A

Desktop (please complete the following information):

Additional Context:

I'm using the solidity function in Unity through the Nethereum Csharp library. This is my code for calling the function:

    // Mint function to allow users to mint their first shape
    public static async Task<string> MintShape()
    {
        return await contract.SendTransaction("mint", parameters: new object[] { });
    }

The contract class level code then does this:

        /// <summary>
        /// Sends a transaction to the smart contract.
        /// </summary>
        /// <param name="methodName">The name of the method to call.</param>
        /// <param name="gas">The gas limit.</param>
        /// <param name="gasPrice">The gas price.</param>
        /// <param name="value">The value to send.</param>
        /// <param name="parameters">The method parameters.</param>
        /// <returns>The transaction hash.</returns>
        public async Task<string> SendTransaction(string methodName, string gas = null, string gasPrice = null, string value = null, params object[] parameters)
        {
            if (wallet == null)
            {
                throw new Exception("No wallet was found assigned to this smart contract. Please make sure you set one at the time of instantiating this contract!");
            }

            return await wallet.SendTransaction(Address(), gas, gasPrice, value, data: EncodeFunctionData(methodName, parameters));
}

By leaving the gas and gasLimit as null, nethereum uses the RPC to estimate the gas for the transaction which in the case of the Mainnet, fails to estimate the correct amount.

Hardcoding the gas limit like so:

    public static async Task<string> MintShape()
    {
        return await contract.SendTransaction("mint", gas: "300000", parameters: new object[] { });
    }

Works just fine as we're increasing the gas limit.

DmytroNazarenko commented 3 weeks ago

Hey @nftpixels ! Could you provide more details about the steps to reproduce the bug? I've just tried the same steps that you've provided and successfully executed mint transaction via blockscout and MM:

https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com/tx/0x06ee16344af4723b2ed8b68e49a79508997bd79b13a2515e385e607f67b37865

image
nftpixels commented 3 weeks ago

Hi Team,

Thank you for taking the time to look into this issue.

I can only assume it was something to do with Metamask or the JSON-RPC API or something if it's working properly now. 🤔

We can close this issue seeing as it's no longer happening, but I'll keep you posted if I experience any other issues in future.

Thank you!

On Sat, 24 Aug 2024, 07:02 Dmytro Nazarenko, @.***> wrote:

Hey @nftpixels https://github.com/nftpixels ! Could you provide more details about the steps to reproduce the bug? I've just tried the same steps that you've provided and successfully executed mint transaction via blockscout and MM:

https://honorable-steel-rasalhague.explorer.mainnet.skalenodes.com/tx/0x06ee16344af4723b2ed8b68e49a79508997bd79b13a2515e385e607f67b37865 image.png (view on web) https://github.com/user-attachments/assets/710bfc9a-2b63-4cfa-ae2f-b055f27e29f3

— Reply to this email directly, view it on GitHub https://github.com/skalenetwork/skaled/issues/1966#issuecomment-2307651256, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXG3FMPWU6DIITDYJWPBWGTZS6BK7AVCNFSM6AAAAABM25AYJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGY2TCMRVGY . You are receiving this because you were mentioned.Message ID: @.***>

TheGreatAxios commented 4 days ago

Closed as no longer an issue and cannot duplicate.