Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:crytic/slither into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Jan 7, 2021
2 parents 7751cba + 960fc1c commit 119a024
Show file tree
Hide file tree
Showing 8 changed files with 5,042 additions and 6 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ To run the unit tests, you need

Several linters and security checkers are run on the PRs.

To run them locally:
To run them locally in the root dir of the repository:

- `pylint slither --rcfile pyproject.toml`
- `black slither --config pyproject.toml`
- `pylint slither tests --rcfile pyproject.toml`
- `black . --config pyproject.toml`

We use black `19.10b0`.
### Detectors tests
Expand Down
6 changes: 3 additions & 3 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from slither.core.expressions.expression import Expression
from slither.slithir.operations import Operation
from slither.slither import Slither
from slither.core.cfg.node import NodeType
from slither.core.slither_core import SlitherCore

LOGGER = logging.getLogger("Function")
Expand Down Expand Up @@ -299,17 +298,18 @@ def can_reenter(self, callstack=None) -> bool:

def can_send_eth(self) -> bool:
"""
Check if the function can send eth
Check if the function or any internal (not external) functions called by it can send eth
:return bool:
"""
from slither.slithir.operations import Call

if self._can_send_eth is None:
self._can_send_eth = False
for ir in self.all_slithir_operations():
if isinstance(ir, Call) and ir.can_send_eth():
self._can_send_eth = True
return True
return self._can_reenter
return self._can_send_eth

@property
def slither(self) -> "SlitherCore":
Expand Down
Empty file added tests/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions tests/detectors/reentrancy-benign/reentrancy-benign.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pragma solidity ^0.4.0;

contract ReentrancyBenign {
uint8 anotherVariableToChange;
uint8 counter = 0;

function bad0() public {
if (!(msg.sender.call())) {
revert();
}
counter += 1;
}

function bad1(address target) public {
(bool success) = target.call();
require(success);
counter += 1;
}

function bad2(address target) public {
(bool success) = target.call();
if (success) {
address(target).call.value(1000)();
counter += 1;
}
else {
revert();
}
}

function bad3(address target) public {
externalCaller(target);
varChanger();
ethSender(target);
}

function bad4(address target) public {
externalCaller(target);
ethSender(address(0));
varChanger();
address(target).call.value(2)();
}

function bad5(address target) public {
ethSender(address(0));
varChanger();
ethSender(address(0));
}

function externalCaller(address target) private {
address(target).call();
}

function ethSender(address target) private {
address(target).call.value(1)();
}

function varChanger() private {
anotherVariableToChange++;
}
}
Loading

0 comments on commit 119a024

Please sign in to comment.