Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Using For #33

Closed
newcodepusher opened this issue Apr 20, 2021 · 4 comments · Fixed by #42
Closed

Support Using For #33

newcodepusher opened this issue Apr 20, 2021 · 4 comments · Fixed by #42
Labels
bug Something isn't working

Comments

@newcodepusher
Copy link

Сan you add support for similar solidity instructions?
solidity using-for

@cd1m0
Copy link
Collaborator

cd1m0 commented Apr 22, 2021

Can you clarify what you mean for support for using-for or add a sample that you wish to be supported? When I try to instrument the following sample:

library L {
        function plusOne(uint x) internal pure returns (uint) {
                return x + 1;
        }
}

contract Foo {
        using L for uint;

        /// if_succeeds old(x).plusOne() == x;
        function inc(uint x) public returns (uint) {
                return x + 1;
        }
}

I get the following instrumented code, which seems correct:

pragma solidity 0.8.3;

library L {
    function plusOne(uint x) internal pure returns (uint) {
        return x + 1;
    }
}

contract Foo {
    using L for uint;

    event AssertionFailed(string message);

    struct vars0 {
        uint256 old_0;
    }

    function inc(uint x) public returns (uint RET_0) {
        vars0 memory _v;
        unchecked {
            _v.old_0 = x;
        }
        RET_0 = _original_Foo_inc(x);
        unchecked {
            if (!(_v.old_0.plusOne() == x)) {
                emit AssertionFailed("0: ");
                assert(false);
            }
        }
    }

    function _original_Foo_inc(uint x) private returns (uint) {
        return x + 1;
    }
}
/// Utility contract holding a stack counter
contract __scribble_ReentrancyUtils {
    bool __scribble_out_of_contract = true;
}

@newcodepusher
Copy link
Author

newcodepusher commented Apr 23, 2021

Your example works, but this one does not

pragma solidity >=0.6.0 <0.8.0;

library Token {
    function balanceOf(address x) internal pure returns (uint) {
        return 123;
    }
}

contract Foo {
    using Token for address;

    /// if_succeeds x.balanceOf() == 123;
    function balanceOf(address x) public returns (uint) {
        return x.balanceOf();
    }
}

Test.sol:12:36 TypeError: Address type expression x doesn't have a builtin member balanceOf

@cd1m0
Copy link
Collaborator

cd1m0 commented Apr 23, 2021

Got it! Thank you for the sample. Will try to fix this promptly

@cd1m0
Copy link
Collaborator

cd1m0 commented May 5, 2021

The issue is that the typechecking logic below is too aggressive. The same problem would happen if the argument was Foo x instead of address x and we had this.balanceOf() in the expression. Fix coming in shortly, and will be merged in the next release.

https://github.com/ConsenSys/scribble/blob/6e737c9ff7db2e0466825411b86a810a6079f988/src/spec-lang/tc/typecheck.ts#L1559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants