Consensys / surya

A set of utilities for exploring Solidity contracts
Apache License 2.0
1.07k stars 118 forks source link

Has the library issue been resolved yet? #108

Closed seongeunC closed 5 years ago

seongeunC commented 5 years ago

Has the library issue in ftrace been fixed? I have the same issue. When library safemath is present in a contract, "TypeError: Can not read property 'sub' of undefined"

GNSPS commented 5 years ago

Possibly not @seongeunC! Does that happen with any use of the SafeMath library?

Is it with the using X for Y; syntax?

seongeunC commented 5 years ago

Yes I am testing the functionality of ERC20 provided by openzeppelin. I am using SafeMath for uint256.

seongeunC commented 5 years ago

I think the information on my question was too weak. I add the contract feature that I was testing.


pragma solidity ^0.5.0;

library SafeMath {

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        assert(c / a == b);
        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // assert(b > 0); // Solidity automatically throws when dividing by 0
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
    }
}
contract Test {
    using SafeMath for uint256;

    mapping(address => uint256) internal balances;

    uint256 lockupcount = 123;

    function balanceOf(address _holder) public view returns (uint256 balance) {
        uint256 lockedBalance = 0;
        lockedBalance = lockedBalance.add(lockupcount);

        return balances[_holder] + lockedBalance;
    }
}```

$ surya ftrace Test::balanceOf all test.sol
>else throw err

TypeError: Cannot read property 'add' of undefined