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 1 commit
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
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
Loading