Description
Right now the data dependency is context insensitive, which creates a large over approximation.
For example in
contract A{
uint a;
uint b;
function f(uint x) internal returns(uint){
return x;
}
function test1(uint paramA) public{
a = f(paramA);
}
function test2(uint paramB) public{
b = f(paramB);
}
}
Slither will merge all the deps related to the call to f(x)
when looking at the contract context. As a result, a dependency between a
and paramB
(or b
and paramA
) will be created, because the the analysis will merge all the callers of f
:
$ slither test.sol --print data-dependency
Contract A
+----------+---------------------------+
| Variable | Dependencies |
+----------+---------------------------+
| a | ['paramA', 'paramB', 'x'] |
| b | ['paramA', 'paramB', 'x'] |
+----------+---------------------------+
Having a context-sensitive analysis will lead to bette results. This is also a recurring issues with top-level functions - which tend to be called from a lot of different contexts.
Moving toward a context sensitive analysis will have an impact on the performance. We could propose the two options (sensitive/insensitive), and allow the user to enable one or the other.
Additionally we should take the opportunity to refactor the data dependency to better support the switch between the context and the different source type:
slither/slither/analyses/data_dependency/data_dependency.py
Lines 47 to 50 in 26659c4
slither/slither/analyses/data_dependency/data_dependency.py
Lines 62 to 63 in 26659c4