0

Given the following Solidity code,

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.10;

contract Contract {
    bool public immutable IS_TRUE;

    constructor() {
        IS_TRUE = true;
    }
}

My IDE (remix.ethereum.org) informs me that the gas requirement is infinite.

I am surprised because there are no loops, no imported data changes. It's just a constant that I declare, and a read access method.

Here is the complete error message:

Gas costs:

Gas requirement of function Contract.IS_TRUE is infinite: If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)

Here is a screenshot:

Code and warning from Remix IDE

Is this a bug, or should I optimize my code? Thank you.

5
  • I could deploy this code to ganache-cli / Javascript VM and Rinkeby without any issue. (No warning and all deployment are successful) Can you confirm that this is exactly the code you are trying to deploy ?
    – hroussille
    Nov 24, 2021 at 15:22
  • This code is a simplified version of my code. With the Remix IDE, it compiles correctly too. I'm just concerned about the relevance of this warning message to my code. This message seems irrelevant to me, but maybe I'm wrong and the gas requirements of my code are infinite, in which case I would like to know why.
    – T5i
    Nov 24, 2021 at 15:50
  • You have this error with the code you provided too ? I had no issue with it. If you don't have warnings / errors with the code you included in your question, could you edit it for one that does reproduce the error ?
    – hroussille
    Nov 24, 2021 at 15:53
  • I just added a picture to show the warning message on the Remix IDE.
    – T5i
    Nov 24, 2021 at 16:03
  • 1
    Your error comes from the static analysis, my bad, I was looking for it at deployment / runtime. It really feels like a bug in the static analysis plugin. Some related discussion here : ethereum.stackexchange.com/questions/34563/…, even though the argument doesn't really apply here...
    – hroussille
    Nov 24, 2021 at 18:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.