solidity-coverage: Internal calls from constructor fail to compile

We’ve been running into a compilation issue related to calling internal functions from a constructor (I think this used to be an issue in solc). The following contract fails to compile after being instrumented:

pragma solidity ^0.5.0;

pragma experimental ABIEncoderV2;

library TestLib {
    struct State {
        uint integer;
    }

    function internalFunction(State storage state) internal {
        state.integer = 5;
    }
}


contract Test {
    using TestLib for TestLib.State;
    TestLib.State state;

    constructor() public {
        state.internalFunction();
    }

    function getInteger() public returns (uint) {
        return state.integer;
    }
}

The error that the compiler gives is:

InternalCompilerError: Assembly exception for bytecode

We’ve noticed that moving the internal call to a public method seems to avoid the issue. The following contract compiles fine after being instrumented:

pragma solidity ^0.5.0;

pragma experimental ABIEncoderV2;

library TestLib {
    struct State {
        uint integer;
    }

    function internalFunction(State storage state) internal {
        state.integer = 5;
    }
}


contract Test {
    using TestLib for TestLib.State;
    TestLib.State state;

    constructor() public {
        callInternalFunction();
    }

    function getInteger() public returns (uint) {
        return state.integer;
    }

    function callInternalFunction() public {
        state.internalFunction();
    }
}

Two other things to note:

  • We have noticed that this only happens when ABIEncoderV2 is enabled.
  • These contracts all compile (without instrumentation) with the most recent version of solc.

cc @ptare

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

To run coverage you’ll need to run the following commands from the top level directory:

npm install
./ci/coverage.sh core

Thanks for the tip - I’l make sure I run with >= 5.0.31. I locally upgraded to the newest truffle release 5.1.0, and got the same error:

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server
Error: Error: Error
    at Object.run (/Users/matt/git/protocol/node_modules/truffle/build/webpack:/packages/migrate/index.js?abc3:92:1)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)
Truffle v5.1.0 (core: 5.1.0)
Node v11.15.0

It’s not super complicated, it’s just these files:

https://github.com/UMAprotocol/protocol/blob/master/ci/coverage.sh https://github.com/UMAprotocol/protocol/blob/master/common/globalSolcoverConfig.js

I’ll need to work through the beta instructions, which will almost certainly get rid of or simplify most of this code.

I’ll move to the beta and let you know what I find! Thanks!