Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Mar 18, 2022
2 parents f11d896 + 4b74b62 commit 8344524
Show file tree
Hide file tree
Showing 20,560 changed files with 7,181 additions and 2,038 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
type: ["cli",
"data_dependency",
"embark",
# "embark",
"erc",
"etherlime",
"find_paths",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ jobs:
- name: Test with pytest
run: |
pytest tests/test_features.py
pytest tests/test_constant_folding_unary.py
4 changes: 2 additions & 2 deletions examples/scripts/convert_to_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

for node in nodes:
if node.expression:
print("Expression:\n\t{}".format(node.expression))
print(f"Expression:\n\t{node.expression}")
irs = convert_expression(node.expression, node)
print("IR expressions:")
for ir in irs:
print("\t{}".format(ir))
print(f"\t{ir}")
print()
72 changes: 18 additions & 54 deletions examples/scripts/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@
destination = contract.get_state_variable_from_name("destination")
source = contract.get_state_variable_from_name("source")

print(
"{} is dependent of {}: {}".format(
source, destination, is_dependent(source, destination, contract)
)
)
print(f"{source} is dependent of {destination}: {is_dependent(source, destination, contract)}")
assert not is_dependent(source, destination, contract)
print(
"{} is dependent of {}: {}".format(
destination, source, is_dependent(destination, source, contract)
)
)
print(f"{destination} is dependent of {source}: {is_dependent(destination, source, contract)}")
assert is_dependent(destination, source, contract)
print("{} is tainted {}".format(source, is_tainted(source, contract)))
print(f"{source} is tainted {is_tainted(source, contract)}")
assert not is_tainted(source, contract)
print("{} is tainted {}".format(destination, is_tainted(destination, contract)))
print(f"{destination} is tainted {is_tainted(destination, contract)}")
assert is_tainted(destination, contract)

contracts = slither.get_contract_from_name("Reference")
Expand All @@ -45,32 +37,20 @@
assert source

print("Reference contract")
print(
"{} is dependent of {}: {}".format(
source, destination, is_dependent(source, destination, contract)
)
)
print(f"{source} is dependent of {destination}: {is_dependent(source, destination, contract)}")
assert not is_dependent(source, destination, contract)
print(
"{} is dependent of {}: {}".format(
destination, source, is_dependent(destination, source, contract)
)
)
print(f"{destination} is dependent of {source}: {is_dependent(destination, source, contract)}")
assert is_dependent(destination, source, contract)
print("{} is tainted {}".format(source, is_tainted(source, contract)))
print(f"{source} is tainted {is_tainted(source, contract)}")
assert not is_tainted(source, contract)
print("{} is tainted {}".format(destination, is_tainted(destination, contract)))
print(f"{destination} is tainted {is_tainted(destination, contract)}")
assert is_tainted(destination, contract)

destination_indirect_1 = contract.get_state_variable_from_name("destination_indirect_1")
print(
"{} is tainted {}".format(destination_indirect_1, is_tainted(destination_indirect_1, contract))
)
print(f"{destination_indirect_1} is tainted {is_tainted(destination_indirect_1, contract)}")
assert is_tainted(destination_indirect_1, contract)
destination_indirect_2 = contract.get_state_variable_from_name("destination_indirect_2")
print(
"{} is tainted {}".format(destination_indirect_2, is_tainted(destination_indirect_2, contract))
)
print(f"{destination_indirect_2} is tainted {is_tainted(destination_indirect_2, contract)}")
assert is_tainted(destination_indirect_2, contract)

print("SolidityVar contract")
Expand All @@ -83,13 +63,9 @@
addr_2 = contract.get_state_variable_from_name("addr_2")
assert addr_2
msgsender = SolidityVariableComposed("msg.sender")
print(
"{} is dependent of {}: {}".format(addr_1, msgsender, is_dependent(addr_1, msgsender, contract))
)
print(f"{addr_1} is dependent of {msgsender}: {is_dependent(addr_1, msgsender, contract)}")
assert is_dependent(addr_1, msgsender, contract)
print(
"{} is dependent of {}: {}".format(addr_2, msgsender, is_dependent(addr_2, msgsender, contract))
)
print(f"{addr_2} is dependent of {msgsender}: {is_dependent(addr_2, msgsender, contract)}")
assert not is_dependent(addr_2, msgsender, contract)


Expand All @@ -102,11 +78,7 @@
source = contract.get_state_variable_from_name("source")
assert source

print(
"{} is dependent of {}: {}".format(
destination, source, is_dependent(destination, source, contract)
)
)
print(f"{destination} is dependent of {source}: {is_dependent(destination, source, contract)}")
assert is_dependent(destination, source, contract)

print("Base Derived contract")
Expand All @@ -117,16 +89,10 @@
destination = contract.get_state_variable_from_name("destination")
source = contract.get_state_variable_from_name("source")

print(
"{} is dependent of {}: {} (base)".format(
destination, source, is_dependent(destination, source, contract)
)
)
print(f"{destination} is dependent of {source}: {is_dependent(destination, source, contract)}")
assert not is_dependent(destination, source, contract)
print(
"{} is dependent of {}: {} (derived)".format(
destination, source, is_dependent(destination, source, contract_derived)
)
f"{destination} is dependent of {source}: {is_dependent(destination, source, contract_derived)}"
)
assert is_dependent(destination, source, contract_derived)

Expand All @@ -147,12 +113,10 @@
f2 = contract.get_function_from_signature("f2(uint256,uint256)")

print(
"{} is dependent of {}: {} (base)".format(
var_dependant, user_input, is_dependent(var_dependant, user_input, contract)
)
f"{var_dependant} is dependent of {user_input}: {is_dependent(var_dependant, user_input, contract)} (base)"
)
assert is_dependent(var_dependant, user_input, contract)
print("{} is tainted: {}".format(var_tainted, is_tainted(var_tainted, contract)))
print(f"{var_tainted} is tainted: {is_tainted(var_tainted, contract)}")
assert is_tainted(var_tainted, contract)
print("{} is tainted: {}".format(var_not_tainted, is_tainted(var_not_tainted, contract)))
print(f"{var_not_tainted} is tainted: {is_tainted(var_not_tainted, contract)}")
assert not is_tainted(var_not_tainted, contract)
4 changes: 2 additions & 2 deletions examples/scripts/export_dominator_tree_to_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

for contract in slither.contracts:
for function in list(contract.functions) + list(contract.modifiers):
filename = "{}-{}-{}_dom.dot".format(sys.argv[1], contract.name, function.full_name)
print("Export {}".format(filename))
filename = f"{sys.argv[1]}-{contract.name}-{function.full_name}_dom.dot"
print(f"Export {filename}")
function.dominator_tree_to_dot(filename)
4 changes: 2 additions & 2 deletions examples/scripts/export_to_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

for contract in slither.contracts:
for function in contract.functions + contract.modifiers:
filename = "{}-{}-{}.dot".format(sys.argv[1], contract.name, function.full_name)
print("Export {}".format(filename))
filename = f"{sys.argv[1]}-{contract.name}-{function.full_name}.dot"
print(f"Export {filename}")
function.slithir_cfg_to_dot(filename)
2 changes: 1 addition & 1 deletion examples/scripts/functions_called.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
all_calls_formated = [f.canonical_name for f in all_calls]

# Print the result
print("From entry_point the functions reached are {}".format(all_calls_formated))
print(f"From entry_point the functions reached are {all_calls_formated}")
2 changes: 1 addition & 1 deletion examples/scripts/functions_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
functions_writing_a = contract.get_functions_writing_to_variable(var_a)

# Print the result
print('The function writing "a" are {}'.format([f.name for f in functions_writing_a]))
print(f'The function writing "a" are {[f.name for f in functions_writing_a]}')
6 changes: 3 additions & 3 deletions examples/scripts/slithIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Dont explore inherited functions
if function.contract_declarer == contract:

print("Function: {}".format(function.name))
print(f"Function: {function.name}")

# Iterate over the nodes of the function
for node in function.nodes:
Expand All @@ -26,7 +26,7 @@
# And the SlithIR operations
if node.expression:

print("\tSolidity expression: {}".format(node.expression))
print(f"\tSolidity expression: {node.expression}")
print("\tSlithIR:")
for ir in node.irs:
print("\t\t\t{}".format(ir))
print(f"\t\t\t{ir}")
18 changes: 8 additions & 10 deletions examples/scripts/taint_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ def visit_node(node, visited):
else:
read = ir.read
print(ir)
print("Refs {}".format(refs))
print("Read {}".format([str(x) for x in ir.read]))
print("Before {}".format([str(x) for x in taints]))
print(f"Refs {refs}")
print(f"Read {[str(x) for x in ir.read]}")
print(f"Before {[str(x) for x in taints]}")
if any(var_read in taints for var_read in read):
taints += [ir.lvalue]
lvalue = ir.lvalue
while isinstance(lvalue, ReferenceVariable):
taints += [refs[lvalue]]
lvalue = refs[lvalue]

print("After {}".format([str(x) for x in taints]))
print(f"After {[str(x) for x in taints]}")
print()

taints = [v for v in taints if not isinstance(v, (TemporaryVariable, ReferenceVariable))]
Expand All @@ -52,7 +52,7 @@ def check_call(func, taints):
for ir in node.irs:
if isinstance(ir, HighLevelCall):
if ir.destination in taints:
print("Call to tainted address found in {}".format(function.name))
print(f"Call to tainted address found in {function.name}")


if __name__ == "__main__":
Expand All @@ -74,16 +74,14 @@ def check_call(func, taints):
prev_taints = slither.context[KEY]
for contract in slither.contracts:
for function in contract.functions:
print("Function {}".format(function.name))
print(f"Function {function.name}")
slither.context[KEY] = list(set(slither.context[KEY] + function.parameters))
visit_node(function.entry_point, [])
print("All variables tainted : {}".format([str(v) for v in slither.context[KEY]]))
print(f"All variables tainted : {[str(v) for v in slither.context[KEY]]}")

for function in contract.functions:
check_call(function, slither.context[KEY])

print(
"All state variables tainted : {}".format(
[str(v) for v in prev_taints if isinstance(v, StateVariable)]
)
f"All state variables tainted : {[str(v) for v in prev_taints if isinstance(v, StateVariable)]}"
)
6 changes: 1 addition & 5 deletions examples/scripts/variable_in_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,4 @@
]

# Print the result
print(
'The function using "a" in condition are {}'.format(
[f.name for f in function_using_a_as_condition]
)
)
print(f'The function using "a" in condition are {[f.name for f in function_using_a_as_condition]}')
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ logging-fstring-interpolation,
logging-not-lazy,
duplicate-code,
import-error,
unsubscriptable-object,
consider-using-f-string
unsubscriptable-object
"""
2 changes: 1 addition & 1 deletion slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def choose_detectors(args, all_detector_classes):
if detector in detectors:
detectors_to_run.append(detectors[detector])
else:
raise Exception("Error: {} is not a detector".format(detector))
raise Exception(f"Error: {detector} is not a detector")
detectors_to_run = sorted(detectors_to_run, key=lambda x: x.IMPACT)
return detectors_to_run

Expand Down
8 changes: 4 additions & 4 deletions slither/analyses/data_dependency/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ def pprint_dependency(caller_context: Context_types) -> None:
print("#### SSA ####")
context = caller_context.context
for k, values in context[KEY_SSA].items():
print("{} ({}):".format(k, id(k)))
print(f"{k} ({id(k)}):")
for v in values:
print("\t- {}".format(v))
print(f"\t- {v}")

print("#### NON SSA ####")
for k, values in context[KEY_NON_SSA].items():
print("{} ({}):".format(k, hex(id(k))))
print(f"{k} ({hex(id(k))}):")
for v in values:
print("\t- {} ({})".format(v, hex(id(v))))
print(f"\t- {v} ({hex(id(v))})")


# endregion
Expand Down
2 changes: 1 addition & 1 deletion slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __str__(self):
return "END_LOOP"
if self == NodeType.OTHER_ENTRYPOINT:
return "OTHER_ENTRYPOINT"
return "Unknown type {}".format(hex(self.value))
return f"Unknown type {hex(self.value)}"


# endregion
Expand Down
28 changes: 26 additions & 2 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
ERC1820_signatures,
ERC777_signatures,
ERC1155_signatures,
ERC2612_signatures,
ERC4626_signatures,
)
from slither.utils.tests_pattern import is_test_contract

Expand Down Expand Up @@ -73,7 +75,7 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit", scope: "FileScope
self._custom_errors: Dict[str, "CustomErrorContract"] = {}

# The only str is "*"
self._using_for: Dict[Union[str, Type], List[str]] = {}
self._using_for: Dict[Union[str, Type], List[Type]] = {}
self._kind: Optional[str] = None
self._is_interface: bool = False

Expand Down Expand Up @@ -243,7 +245,7 @@ def events_as_dict(self) -> Dict[str, "Event"]:
###################################################################################

@property
def using_for(self) -> Dict[Union[str, Type], List[str]]:
def using_for(self) -> Dict[Union[str, Type], List[Type]]:
return self._using_for

# endregion
Expand Down Expand Up @@ -900,6 +902,8 @@ def ercs(self) -> List[str]:
("ERC223", self.is_erc223),
("ERC721", self.is_erc721),
("ERC777", self.is_erc777),
("ERC2612", self.is_erc2612),
("ERC4626", self.is_erc4626),
]

return [erc for erc, is_erc in all_erc if is_erc()]
Expand Down Expand Up @@ -974,6 +978,26 @@ def is_erc1155(self) -> bool:
full_names = self.functions_signatures
return all(s in full_names for s in ERC1155_signatures)

def is_erc4626(self) -> bool:
"""
Check if the contract is an erc4626
Note: it does not check for correct return values
:return: Returns a true if the contract is an erc4626
"""
full_names = self.functions_signatures
return all(s in full_names for s in ERC4626_signatures)

def is_erc2612(self) -> bool:
"""
Check if the contract is an erc2612
Note: it does not check for correct return values
:return: Returns a true if the contract is an erc2612
"""
full_names = self.functions_signatures
return all(s in full_names for s in ERC2612_signatures)

@property
def is_token(self) -> bool:
"""
Expand Down
Loading

0 comments on commit 8344524

Please sign in to comment.