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 on reentrancy detector when calling a view function #126

Closed
ptare opened this issue Jan 10, 2019 · 1 comment
Closed

False positive on reentrancy detector when calling a view function #126

ptare opened this issue Jan 10, 2019 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@ptare
Copy link

ptare commented Jan 10, 2019

When a method calls a view function on an external contract and then modifies state, one of Slither's reentrancy detectors trigger. See this minimal example [1] and the error Slither produces [2].

A call to a view function should be safe against reentrancy bugs (as long as the Solidity version is ^0.5.0) because any calls back into the calling code will also be prevented from changing state, so this might be a false positive.

/*
  A self-contained example of false positive on calling view functions.
*/
pragma solidity ^0.5.0;

contract ViewOnly {
    uint public myVar = 0;
    function safeFunction() external view returns (uint) {
        return myVar;
    }

    function notCalled() external {
        myVar = 5;
    }
}

contract Main {
    uint public stateVariable;
    ViewOnly public viewOnly;

    function mainFunction() external {
        viewOnly.safeFunction();
        stateVariable = 0;
    }
}
Reentrancy in Main.mainFunction (MinimalViewExample.sol#21-24):
	External calls:
	- viewOnly.safeFunction() (MinimalViewExample.sol#22)
	External calls sending eth:
	State variables written after the call(s):
	- stateVariable (MinimalViewExample.sol#23)
@montyly
Copy link
Member

montyly commented Jan 10, 2019

Hi @ptare,

Thank you for your feedback, that's an interesting corner case!
We are going to update the reentrancy heuristic to take it into account

@montyly montyly added the enhancement New feature or request label Jan 10, 2019
@montyly montyly added this to the 0.6.0 milestone Jan 28, 2019
@montyly montyly closed this as completed in 77cd643 Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants