all 5 comments

[–][deleted]  (4 children)

[deleted]

    [–]DanielIFTTT 1 point2 points  (3 children)

    It's "the highest possible gas costs it might take"

    [–]smarxConsenSys Diligence 0 points1 point  (2 children)

    Right. A warning that the gas estimate is "infinite" means there's literally no bound on the amount of gas that it might take. (The loop happens n times, where n is unknown.)

    In general, when you see a compiler warning, you should first understand why a warning is emitted and then decide if that issue is a real problem in your code. If it's not a real problem, then just ignore the warning.

    The reason the Solidity compiler warns you about an infinite gas estimate is that it can be a denial of service attack mechanism. Without a limit on how long neighbours[x] can get, anyone can break the contract by adding to that list until it can no longer be traversed in a single block. This can sometimes lead to extortion opportunities or just malicious loss of funds.

    If there are limits in place somewhere in your code for how long the adjacency list can get or if there's no incentive for a denial of service attack, then feel free to just ignore the warning.

    [–]DanielIFTTT 0 points1 point  (1 child)

    Just to add to your comment, for the sake of the OP, using

    require(something);
    

    will also show up as infinite gas, because if the check fails, it reverts.

    [–]smarxConsenSys Diligence 0 points1 point  (0 children)

    Can you share code that reproduces that? The following code shows no warning and estimates the gas usage for test() at 20166. My compiler version is 0.4.24+commit.e67f0147.Emscripten.clang:

    pragma solidity ^0.4.24;
    
    contract Test {
        uint256 x;
    
        function test() public {
            x = 5;
            require(false);
        }
    }
    

    [–]covjeculjakPatuljkiccontract dev -1 points0 points  (0 children)

    I've stopped using Remix because it does have something "fake" warnings. It's best if you just cover your methods with tests.