Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed data dependencies for ReferenceVariable #2288

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/scripts/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@
assert is_tainted(var_tainted, contract)
print(f"{var_not_tainted} is tainted: {is_tainted(var_not_tainted, contract)}")
assert not is_tainted(var_not_tainted, contract)

print("Index contract")
contracts = slither.get_contract_from_name("Index")
assert len(contracts) == 1
contract = contracts[0]
ref = contract.get_state_variable_from_name("ref")
assert ref
mapping_var = contract.get_state_variable_from_name("mapping_var")
assert mapping_var

print(f"{ref} is dependent of {mapping_var}: {is_dependent(ref, mapping_var, contract)}")
assert is_dependent(ref, mapping_var, contract)
print(f"{ref} is dependent of {msgsender}: {is_dependent(ref, msgsender, contract)}")
assert is_dependent(ref, msgsender, contract)
print(
f"{mapping_var} is dependent of {msgsender}: {is_dependent(mapping_var, msgsender, contract)}"
)
assert not is_dependent(mapping_var, msgsender, contract)
10 changes: 10 additions & 0 deletions examples/scripts/data_dependency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,13 @@ contract PropagateThroughReturnValue {
return (var_state);
}
}

contract Index {
mapping(address => uint) public mapping_var;
uint public ref;

function set() external {
ref = mapping_var[msg.sender];
}

}
2 changes: 1 addition & 1 deletion slither/analyses/data_dependency/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def add_dependency(lvalue: Variable, function: Function, ir: Operation, is_prote
if not is_protected:
function.context[KEY_SSA_UNPROTECTED][lvalue] = set()
read: Union[List[Union[LVALUE, SolidityVariableComposed]], List[SlithIRVariable]]
if isinstance(ir, Index):
if isinstance(ir, Index) and not isinstance(lvalue, ReferenceVariable):
read = [ir.variable_left]
elif isinstance(ir, InternalCall) and ir.function:
read = ir.function.return_values_ssa
Expand Down
Loading