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

Invariant can cause infinite recursion stack overflow #201

Open
NeverFearTomorrow opened this issue Nov 7, 2022 · 3 comments
Open

Invariant can cause infinite recursion stack overflow #201

NeverFearTomorrow opened this issue Nov 7, 2022 · 3 comments
Assignees

Comments

@NeverFearTomorrow
Copy link

If an invariant calls a function that makes an external call, then the invariant winds up triggering itself, which leads to infinite recursion.
This could be considered user error, but it's very hard to detect the source of the problem, because stack overflow leads to an unhelpful error message on revert. I think it would be good if scribble would explicitly detect and disallow the use of a function that makes external calls in an invariant. Or maybe there's some other way to warn the user against doing this, or preventing this from happening. The user may not realize right away that a simple view function is technically crossing a contract boundary when they use that function to acquire some basic info for use in their invariant, so anything to help ward the user off of this is helpful.

@cd1m0
Copy link
Collaborator

cd1m0 commented Nov 9, 2022

Thank you for reporting this! Will try to reproduce and get back to you.

@cd1m0 cd1m0 self-assigned this Nov 9, 2022
@blitz-1306
Copy link
Contributor

@NeverFearTomorrow Hello there and sorry for the late response.

I did a few attempt to try to reproduce mentioned behavior, however I did not hit the issue. An example that I used is following:

contract Sample {
    function foo(uint256 i) external pure returns (bool) {
        return i == 1;
    }

    /// #if_succeeds this.foo(i) ? $result == (i + 2) : $result == (i + 5);
    function bar(uint256 i) external view returns (uint256) {
        return this.foo(i) ? i + 2 : i + 5;
    }
}

Maybe I'm digging in the wrong direction.

Is there a possibility that you still have a minimalistic example that would allow us to reproduce the problem? Or maybe you could hint us additional details? Let us know if you have a bit more clues on this.

Thank you.

@blitz-1306
Copy link
Contributor

Maybe it also is a duplicate for #38. Seem to be related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants