Skip to content

Commit 4710753

Browse files
committed
Test case added, API output asserted, output format slightly changed
1 parent fcb0aed commit 4710753

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

slither/analyses/data_dependency/data_dependency.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ def get_must_depends_on(variable: SUPPORTED_TYPES) -> SUPPORTED_TYPES | None:
302302
"""
303303
must_dependencies = compute_must_dependencies(variable)
304304
if len(must_dependencies) > 1 or len(must_dependencies) == 0:
305-
return None
306-
return list(must_dependencies)[0]
307-
305+
return []
306+
return [list(must_dependencies)[0]]
308307

309308
def compute_must_dependencies(v:SUPPORTED_TYPES) -> Set[Variable]:
310309
if isinstance(v, (SolidityVariableComposed, Constant)) or (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pragma solidity ^0.8.19;
2+
3+
interface IERC20 {
4+
function transferFrom(address from, address to, uint amount) external returns (bool);
5+
}
6+
7+
/**
8+
* @title MissingReturnBug
9+
* @author IllIllI
10+
*/
11+
12+
// test case of the missing return bug described here:
13+
// https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
14+
contract Unsafe {
15+
IERC20 erc20;
16+
function good2(address to, uint256 am) public {
17+
address from_msgsender = msg.sender;
18+
int_transferFrom(from_msgsender, to, am); // from is constant
19+
}
20+
21+
// This is not detected
22+
function bad2(address from, address to, uint256 am) public {
23+
int_transferFrom(from, to, amount); // from is not a constant
24+
}
25+
26+
function int_transferFrom(address from, address to, uint256 amount) internal {
27+
erc20.transferFrom(from, to, amount); // not a constant = not a constant U constant
28+
}
29+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
from slither import Slither
3+
from slither.analyses.data_dependency.data_dependency import (
4+
get_must_depends_on
5+
)
6+
7+
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
8+
9+
def test_must_depend_on_returns(solc_binary_path):
10+
solc_path = solc_binary_path("0.8.19")
11+
file = Path(TEST_DATA_DIR, "must_depend_on.sol").as_posix()
12+
slither_obj = Slither(file, solc=solc_path)
13+
result = get_must_depends_on(slither_obj.contracts[1].functions[2].parameters[0])
14+
assert isinstance(result, list) and len(result) <= 1

0 commit comments

Comments
 (0)