Consensys/scribble

__scribble__ReentrancyUtils.sol compiler error.

elizabethdinella opened this issue · 2 comments

Hi, I am encountering a compilation error in the Scribble generated ReentrancyUtils file.

The file I am instrumenting has the following data structure: mapping(address => uint256) private _valueMap;

I ran the following command: scribble MyContract.sol --output-mode files --compiler-version "0.4.26"
Upon instrumentation, Scribble generated the following library in ReentrancyUtils.

library address_to_uint256 {
    struct S {
        mapping(address => uint256) innerM;
        address[] keys;
        mapping(address => uint256) keyIdxM;
        uint256 sum;
    }

    function addKey(S storage m, address key) private {
        uint idx = m.keyIdxM[key];
        if (idx == 0) {
            if (m.keys.length == 0) {
                m.keys.push(); //COMPILER ERROR HERE
            }
            m.keyIdxM[key] = m.keys.length;
            m.keys.push(key);
        }
    }

    function removeKey(S storage m, address key) private {
        uint256 idx = m.keyIdxM[key];
        if (idx == 0) return;
        if (idx != (m.keys.length - 1)) {
            address lastKey = m.keys[m.keys.length - 1];
            m.keys[idx] = lastKey;
            m.keyIdxM[lastKey] = idx;
        }
        m.keys.pop(); //COMPILER ERROR HERE
        delete m.keyIdxM[key];
    }

    function get(S storage m, address key) internal view returns (uint256) {
       ...
    }

    function set(S storage m, address key, uint256 val) internal returns (uint256) {
        ....
    }
}

When I attempt to compile the instrumented file I get the following errors:

__scribble_ReentrancyUtils.sol:26:17: Error: Wrong argument count for function call: 0 arguments given but expected 1.
                m.keys.push();
                ^-----------^
__scribble_ReentrancyUtils.sol:41:9: Error: Member "pop" not found or not visible after argument-dependent lookup in address[] storage ref
        m.keys.pop();

My solc version is 0.4.26

cd1m0 commented

Thank you for the report and appologies for the delay. Will look into this first thing tomrrow!

cd1m0 commented

Ok, so the two compiler errors are caused by our instrumentation not playing nice with older solidity versions. Specifically the pop() funciton on dynamic arrays was added in Solc 0.5.0, and the push() function with no arguments on dynamic arrays was added in Solc 0.6.0. I will add code to handle these older version gracefully in a bit. If you are able to use a newer compiler version (>0.6.0) that should resolve your problem in the mean time.