Skip to content

Commit

Permalink
fixed data dependencies for ReferenceVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
YanhuiJessica committed Feb 4, 2024
1 parent e3dcf1e commit ea3df51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/scripts/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,19 @@
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)

Check warning on line 144 in examples/scripts/data_dependency.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

C0304: Final newline missing (missing-final-newline)
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: 2 additions & 0 deletions slither/analyses/data_dependency/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ def add_dependency(lvalue: Variable, function: Function, ir: Operation, is_prote
read: Union[List[Union[LVALUE, SolidityVariableComposed]], List[SlithIRVariable]]
if isinstance(ir, Index):
read = [ir.variable_left]
if isinstance(lvalue, ReferenceVariable):
read.append(ir.variable_right)
elif isinstance(ir, InternalCall) and ir.function:
read = ir.function.return_values_ssa
else:
Expand Down

0 comments on commit ea3df51

Please sign in to comment.