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

Echidna unable to detect constants in storage Structs #1014

Closed
jat9292 opened this issue Apr 5, 2023 · 3 comments
Closed

Echidna unable to detect constants in storage Structs #1014

jat9292 opened this issue Apr 5, 2023 · 3 comments

Comments

@jat9292
Copy link

jat9292 commented Apr 5, 2023

Echidna should be able to detect constants in Structs

Hello.
I just noticed that echidna is unable to chose values which are defined as constants inside structs in the solidity code.
Actually I stumbled on this issue while trying to build my own fuzzer, using the same technique to mine constants that echidna is using. I was unsure if I had to post the issue here or in the Slither repo, as in order to solve it we must improve the _extract_constants function from the Slither package to make it able to detect such constants.

Here is a minimal example which current version of echidna fails to solve:

contract Test {
    struct Todo {
        uint x;
        bool completed;
    }
    bool flag = true;
    Todo todo = Todo(129856743768, false);

    function set(uint a) public {
        if (a == todo.x) flag = false;
    }

    function echidna_test_balance() public view returns (bool) {
        return flag;
    }
}

Maybe if I have time I will try to do a pull request on the Slither repo, unless I am missing something and this could work with a better config?

EDIT : sorry I think the issue is not what I thought : indeed , weirdly this version is easily broken by echidna :

contract Test {
    struct Todo {
        uint x;
        bool completed;
    }
    bool flag = true;

    function set(uint a) public {
        Todo memory todo = Todo(129856743768, false);
        if (a == todo.x) flag = false;
    }

    function echidna_test_balance() public view returns (bool) {
        return flag;
    }
}

So the problem does not seem to be related to the constant inside the struct, but to the fact that it is declared as a state variable instead of a local one, this behavior is still a bit weird in my opinion...

@jat9292 jat9292 changed the title Echidna unable to detect constants in Structs Echidna unable to detect constants in Structs + improve bytes constants Apr 5, 2023
@jat9292 jat9292 changed the title Echidna unable to detect constants in Structs + improve bytes constants Echidna unable to detect constants in Structs Apr 5, 2023
@jat9292 jat9292 changed the title Echidna unable to detect constants in Structs Echidna unable to detect constants in storage Structs Apr 5, 2023
@montyly
Copy link
Member

montyly commented Apr 6, 2023

Thanks @jat9292 , that's a great catch. We will investigate it (crytic/slither#1828)

@ggrieco-tob
Copy link
Member

This is still an issue, and indeed slither fails to get the constant needed

@smonicas
Copy link

This was fixed with slither 0.10.0

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

No branches or pull requests

4 participants