2

It seems like every time I try to execute a contract function through the browser compiler that requires more than around 50k gas (give or take) to execute, the browser tab's memory gets to around 1GB and the compiler crashes.

I'm using chrome and I tried executing a wide range of functions. When I run the function directly on a parity node I get the response correctly so it seems to me like it's a compiler issue.

Anyone else experienced it and know a workaround?

Note that it seems like it's reproduced more easily when using loops/arrays, maybe because of the array assignments?

Here's the example contract -

pragma solidity ^0.4.8;

contract TestContract {
    function TestContract() {
    }

    function test(uint256 iterations) constant {
        int256[] memory a = new int256[](1000);

        for (uint32 i = 0; i < iterations; ++i) {
            a[i] = i;
        }
    }
}

I pass more than 500 as an argument to the function and the compiler dies.

3
  • Not normal. Possible to post sample code so we can replicate the problem? Commented Jan 20, 2017 at 21:33
  • Added an example
    – nergall
    Commented Jan 21, 2017 at 10:08
  • Confirmed. Interesting. I don't think it's the gas per se, because I've tested factory patterns that are much larger gas cost. Played with variants of the original and noticed it always claims memory that doesn't get returned after the function is complete. So, I suspect it relates to the considerable debugging information that's available for inspection after the function is finished. Just a hunch. Hopefully someone will chime in with a better explanation. Commented Jan 22, 2017 at 0:55

1 Answer 1

1

Gas is used to limit number of computational steps a contract or a transaction can perform. Here you have a detailed answer.

pragma solidity ^0.4.19;

contract TestContract {
    function TestContract() public {}

    function test(uint256 iterations) public pure returns(uint) {
        int256[] memory a = new int256[](1000);

        for (uint32 i = 0; i < iterations; ++i) {
            a[i] = i;
        }
        return a.length;
    }
}

https://ethfiddle.com/p96qnh9DJ4

I modified your contract code a bit to explain what is happening. First we supply enough gas (9000000 default) while deploying this contract. It can iterate as long as it does not get out of gas.

Then we deploy with estimated gas 136914 and try to run iterations. Now we can get VM Exception while executing eth_call: out of gas error when trying to call test() method for larger values.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.