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

scribble produces invalid code given a constant let-binding used in a new context #149

Closed
cd1m0 opened this issue Feb 15, 2022 · 0 comments · Fixed by #151
Closed

scribble produces invalid code given a constant let-binding used in a new context #149

cd1m0 opened this issue Feb 15, 2022 · 0 comments · Fixed by #151
Assignees
Labels
bug Something isn't working

Comments

@cd1m0
Copy link
Collaborator

cd1m0 commented Feb 15, 2022

Given the following sample:

pragma solidity 0.8.10;

contract Foo {
    /// #if_succeeds let t:= Foo(0x0) in old(t.balanceOf())>0;
    function balanceOf() public view returns (uint) {}
}

Scribble will produce the following invalid code:

contract Foo is __scribble_ReentrancyUtils {
...
    function balanceOf() public returns (uint RET_0) {
        vars0 memory _v;
        unchecked {
            _v.old_0 = _v.t.balanceOf();
        }
        RET_0 = _original_Foo_balanceOf();
        unchecked {
            _v.t = Foo(0x0);
            _v.let_0 = _v.old_0 > 0;
            if (!(_v.let_0)) {
                emit AssertionFailed("0: ");
                assert(false);
            }
        }
    }

    function _original_Foo_balanceOf() private view returns (uint) {}
}

The issue is that _v.t is used before its defined.

The problem is that t was defined in the postcondition context (let t:= Foo(0x0)) but was used in the precondition context (old(t.balanceOf())). Scribble usually rejects such code as invalid, but we added an exception for the case where the let-binding is set to a constant expression. However when I added that exception I forgot to fix the transpiling code to move the definition of the let-binding to the precondition context.

@cd1m0 cd1m0 self-assigned this Feb 15, 2022
@cd1m0 cd1m0 added the bug Something isn't working label Feb 15, 2022
cd1m0 added a commit that referenced this issue Feb 15, 2022
@cd1m0 cd1m0 mentioned this issue Feb 15, 2022
cd1m0 added a commit that referenced this issue Feb 15, 2022
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.

1 participant