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

False positive for unused-state-variables #112

Open
mrice32 opened this issue Dec 21, 2018 · 4 comments
Open

False positive for unused-state-variables #112

mrice32 opened this issue Dec 21, 2018 · 4 comments
Assignees
Labels
0.7 enhancement New feature or request
Milestone

Comments

@mrice32
Copy link
Contributor

mrice32 commented Dec 21, 2018

Not sure if this is technically something that should be raised as an issue, but we ran into this with some of our contracts. Feel free to close if this is working as intended. I simplified the false positive to this example:

/*
  Test.
*/
pragma solidity ^0.5.0;


contract Test {
    struct SwappableStruct {
        uint test;
    }

    SwappableStruct private a;
    SwappableStruct private b;

    function incrementChosenStruct(bool useA) external {
        SwappableStruct storage swappableStruct = getChosenStruct(useA);
        swappableStruct.test += 1;
    }

    function getChosenStruct(bool useA) private view returns (SwappableStruct storage swappableStruct) {
        return useA ? a : b;
    }
}

This causes slither to complain that we are not using a or b when the contract clearly makes use of both.

@dguido
Copy link
Member

dguido commented Dec 21, 2018

Not sure if this is technically something that should be raised as an issue

It is! Thanks for noting it. We'll see what we can do to refine the unused state variable check.

@montyly
Copy link
Member

montyly commented Dec 23, 2018

Hi @mrice32 , thanks for reporting these issues!

The issue is that slither does not handle currently storage reference pointers (see #70 , #82)

We are working to integrate their support (see #87).

@montyly montyly added the enhancement New feature or request label Dec 23, 2018
@montyly montyly self-assigned this Dec 23, 2018
@montyly
Copy link
Member

montyly commented Jan 9, 2019

For information, master now tracks alias for storage references but is not yet interprocedural.

It means that it will detect that

    function incrementChosenStruct(bool useA) external {
        SwappableStruct storage swappableStruct = useA ? a : b;
        swappableStruct.test += 1;
    }

Is a write to a or b, but is not yet able to do the same if the storage reference is a result of a function call (here getChosenStruct)

We are going to add the support for interprocedural alias analysis

@mrice32
Copy link
Contributor Author

mrice32 commented Jan 10, 2019

That sounds great! Thanks for taking the time to work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.7 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants