File tree 3 files changed +45
-3
lines changed
slither/analyses/data_dependency
3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -302,9 +302,8 @@ def get_must_depends_on(variable: SUPPORTED_TYPES) -> SUPPORTED_TYPES | None:
302
302
"""
303
303
must_dependencies = compute_must_dependencies (variable )
304
304
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 ]]
308
307
309
308
def compute_must_dependencies (v :SUPPORTED_TYPES ) -> Set [Variable ]:
310
309
if isinstance (v , (SolidityVariableComposed , Constant )) or (
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments