-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
must depend on analysis with relevant test cases
- Loading branch information
1 parent
84e8633
commit 52416ba
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pragma solidity ^0.8.19; | ||
|
||
interface IERC20 { | ||
function transferFrom(address from, address to, uint amount) external returns (bool); | ||
} | ||
|
||
/** | ||
* @title MissingReturnBug | ||
* @author IllIllI | ||
*/ | ||
|
||
// test case of the missing return bug described here: | ||
// https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca | ||
contract Unsafe { | ||
IERC20 erc20; | ||
function good2(address to, uint256 am) public { | ||
address from_msgsender = msg.sender; | ||
int_transferFrom(from_msgsender, to, am); // from is constant | ||
} | ||
|
||
// This is not detected | ||
function bad2(address from, address to, uint256 am) public { | ||
address from_msgsender = msg.sender; | ||
int_transferFrom(from_msgsender, to, amount); // from is not a constant | ||
} | ||
|
||
function int_transferFrom(address from, address to, uint256 amount) internal { | ||
erc20.transferFrom(from, to, amount); // not a constant = not a constant U constant | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pathlib import Path | ||
from slither import Slither | ||
from slither.analyses.data_dependency.data_dependency import get_must_depends_on | ||
from slither.core.variables.variable import Variable | ||
from slither.core.declarations import SolidityVariable, SolidityVariableComposed | ||
from typing import Union | ||
from slither.slithir.variables import ( | ||
Constant, | ||
) | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
SUPPORTED_TYPES = Union[Variable, SolidityVariable, Constant] | ||
|
||
|
||
def test_must_depend_on_returns(solc_binary_path): | ||
solc_path = solc_binary_path("0.8.19") | ||
file = Path(TEST_DATA_DIR, "must_depend_on.sol").as_posix() | ||
slither_obj = Slither(file, solc=solc_path) | ||
|
||
for contract in slither_obj.contracts: | ||
for function in contract.functions: | ||
if contract == "Unsafe" and function == "int_transferFrom": | ||
result = get_must_depends_on(function.parameters[0]) | ||
break | ||
assert isinstance(result, list) | ||
assert result[0] == SolidityVariableComposed("msg.sender"), "Output should be msg.sender" | ||
|
||
result = get_must_depends_on(slither_obj.contracts[1].functions[2].parameters[1]) | ||
assert isinstance(result, list) | ||
assert len(result) == 0, "Output should be empty" |