mirror of https://github.com/crytic/slither
parent
88954ac6d9
commit
3f706061e4
@ -1,95 +1,139 @@ |
||||
import sys |
||||
from slither import Slither |
||||
from slither.analyses.data_dependency.data_dependency import is_dependent, is_tainted, pprint_dependency |
||||
from slither.analyses.data_dependency.data_dependency import ( |
||||
is_dependent, |
||||
is_tainted, |
||||
pprint_dependency, |
||||
) |
||||
from slither.core.declarations.solidity_variables import SolidityVariableComposed |
||||
|
||||
if len(sys.argv) != 2: |
||||
print('Usage: python data_dependency.py file.sol') |
||||
print("Usage: python data_dependency.py file.sol") |
||||
exit(-1) |
||||
|
||||
slither = Slither(sys.argv[1]) |
||||
|
||||
contract = slither.get_contract_from_name('Simple') |
||||
contract = slither.get_contract_from_name("Simple") |
||||
|
||||
destination = contract.get_state_variable_from_name('destination') |
||||
source = contract.get_state_variable_from_name('source') |
||||
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( |
||||
"{} is dependent of {}: {}".format( |
||||
source, 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( |
||||
"{} is dependent of {}: {}".format( |
||||
destination, source, is_dependent(destination, source, contract) |
||||
) |
||||
) |
||||
assert is_dependent(destination, source, contract) |
||||
print('{} is tainted {}'.format(source, is_tainted(source, contract))) |
||||
print("{} is tainted {}".format(source, is_tainted(source, contract))) |
||||
assert not is_tainted(source, contract) |
||||
print('{} is tainted {}'.format(destination, is_tainted(destination, contract))) |
||||
print("{} is tainted {}".format(destination, is_tainted(destination, contract))) |
||||
assert is_tainted(destination, contract) |
||||
|
||||
contract = slither.get_contract_from_name('Reference') |
||||
contract = slither.get_contract_from_name("Reference") |
||||
|
||||
destination = contract.get_state_variable_from_name('destination') |
||||
source = contract.get_state_variable_from_name('source') |
||||
destination = contract.get_state_variable_from_name("destination") |
||||
source = contract.get_state_variable_from_name("source") |
||||
|
||||
print('Reference contract') |
||||
print('{} is dependent of {}: {}'.format(source, destination, is_dependent(source, destination, contract))) |
||||
print("Reference contract") |
||||
print( |
||||
"{} is dependent of {}: {}".format( |
||||
source, 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( |
||||
"{} is dependent of {}: {}".format( |
||||
destination, source, is_dependent(destination, source, contract) |
||||
) |
||||
) |
||||
assert is_dependent(destination, source, contract) |
||||
print('{} is tainted {}'.format(source, is_tainted(source, contract))) |
||||
print("{} is tainted {}".format(source, is_tainted(source, contract))) |
||||
assert not is_tainted(source, contract) |
||||
print('{} is tainted {}'.format(destination, is_tainted(destination, contract))) |
||||
print("{} is tainted {}".format(destination, 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))) |
||||
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)) |
||||
) |
||||
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))) |
||||
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)) |
||||
) |
||||
assert is_tainted(destination_indirect_2, contract) |
||||
|
||||
print('SolidityVar contract') |
||||
print("SolidityVar contract") |
||||
|
||||
contract = slither.get_contract_from_name('SolidityVar') |
||||
contract = slither.get_contract_from_name("SolidityVar") |
||||
|
||||
addr_1 = contract.get_state_variable_from_name('addr_1') |
||||
addr_2 = contract.get_state_variable_from_name('addr_2') |
||||
msgsender = SolidityVariableComposed('msg.sender') |
||||
print('{} is dependent of {}: {}'.format(addr_1, msgsender, is_dependent(addr_1, msgsender, contract))) |
||||
addr_1 = contract.get_state_variable_from_name("addr_1") |
||||
addr_2 = contract.get_state_variable_from_name("addr_2") |
||||
msgsender = SolidityVariableComposed("msg.sender") |
||||
print( |
||||
"{} is dependent of {}: {}".format(addr_1, 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( |
||||
"{} is dependent of {}: {}".format(addr_2, msgsender, is_dependent(addr_2, msgsender, contract)) |
||||
) |
||||
assert not is_dependent(addr_2, msgsender, contract) |
||||
|
||||
|
||||
print('Intermediate contract') |
||||
contract = slither.get_contract_from_name('Intermediate') |
||||
destination = contract.get_state_variable_from_name('destination') |
||||
source = contract.get_state_variable_from_name('source') |
||||
print("Intermediate contract") |
||||
contract = slither.get_contract_from_name("Intermediate") |
||||
destination = contract.get_state_variable_from_name("destination") |
||||
source = contract.get_state_variable_from_name("source") |
||||
|
||||
print('{} is dependent of {}: {}'.format(destination, source, is_dependent(destination, source, contract))) |
||||
print( |
||||
"{} is dependent of {}: {}".format( |
||||
destination, source, is_dependent(destination, source, contract) |
||||
) |
||||
) |
||||
assert is_dependent(destination, source, contract) |
||||
|
||||
print('Base Derived contract') |
||||
contract = slither.get_contract_from_name('Base') |
||||
contract_derived = slither.get_contract_from_name('Derived') |
||||
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("Base Derived contract") |
||||
contract = slither.get_contract_from_name("Base") |
||||
contract_derived = slither.get_contract_from_name("Derived") |
||||
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) |
||||
) |
||||
) |
||||
assert not is_dependent(destination, source, contract) |
||||
print('{} is dependent of {}: {} (derived)'.format(destination, source, is_dependent(destination, source, contract_derived))) |
||||
print( |
||||
"{} is dependent of {}: {} (derived)".format( |
||||
destination, source, is_dependent(destination, source, contract_derived) |
||||
) |
||||
) |
||||
assert is_dependent(destination, source, contract_derived) |
||||
|
||||
print('PropagateThroughArguments contract') |
||||
contract = slither.get_contract_from_name('PropagateThroughArguments') |
||||
var_tainted = contract.get_state_variable_from_name('var_tainted') |
||||
var_not_tainted = contract.get_state_variable_from_name('var_not_tainted') |
||||
var_dependant = contract.get_state_variable_from_name('var_dependant') |
||||
print("PropagateThroughArguments contract") |
||||
contract = slither.get_contract_from_name("PropagateThroughArguments") |
||||
var_tainted = contract.get_state_variable_from_name("var_tainted") |
||||
var_not_tainted = contract.get_state_variable_from_name("var_not_tainted") |
||||
var_dependant = contract.get_state_variable_from_name("var_dependant") |
||||
|
||||
f = contract.get_function_from_signature('f(uint256)') |
||||
f = contract.get_function_from_signature("f(uint256)") |
||||
user_input = f.parameters[0] |
||||
f2 = contract.get_function_from_signature('f2(uint256,uint256)') |
||||
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))) |
||||
print( |
||||
"{} is dependent of {}: {} (base)".format( |
||||
var_dependant, user_input, is_dependent(var_dependant, user_input, contract) |
||||
) |
||||
) |
||||
assert is_dependent(var_dependant, user_input, contract) |
||||
print('{} is tainted: {}'.format(var_tainted, is_tainted(var_tainted, contract))) |
||||
print("{} is tainted: {}".format(var_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("{} is tainted: {}".format(var_not_tainted, is_tainted(var_not_tainted, contract))) |
||||
assert not is_tainted(var_not_tainted, contract) |
||||
|
@ -1,17 +1,13 @@ |
||||
from setuptools import setup, find_packages |
||||
|
||||
setup( |
||||
name='slither-my-plugins', |
||||
description='This is an example of detectors and printers to Slither.', |
||||
url='https://github.com/trailofbits/slither-plugins', |
||||
author='Trail of Bits', |
||||
version='0.0', |
||||
name="slither-my-plugins", |
||||
description="This is an example of detectors and printers to Slither.", |
||||
url="https://github.com/trailofbits/slither-plugins", |
||||
author="Trail of Bits", |
||||
version="0.0", |
||||
packages=find_packages(), |
||||
python_requires='>=3.6', |
||||
install_requires=[ |
||||
'slither-analyzer==0.1' |
||||
], |
||||
entry_points={ |
||||
'slither_analyzer.plugin': 'slither my-plugin=slither_my_plugin:make_plugin', |
||||
} |
||||
python_requires=">=3.6", |
||||
install_requires=["slither-analyzer==0.1"], |
||||
entry_points={"slither_analyzer.plugin": "slither my-plugin=slither_my_plugin:make_plugin",}, |
||||
) |
||||
|
@ -1,27 +1,26 @@ |
||||
import sys |
||||
import json |
||||
from deepdiff import DeepDiff # pip install deepdiff |
||||
from deepdiff import DeepDiff # pip install deepdiff |
||||
from pprint import pprint |
||||
|
||||
if len(sys.argv) !=3: |
||||
print('Usage: python json_diff.py 1.json 2.json') |
||||
if len(sys.argv) != 3: |
||||
print("Usage: python json_diff.py 1.json 2.json") |
||||
exit(-1) |
||||
|
||||
with open(sys.argv[1], encoding='utf8') as f: |
||||
with open(sys.argv[1], encoding="utf8") as f: |
||||
d1 = json.load(f) |
||||
|
||||
with open(sys.argv[2], encoding='utf8') as f: |
||||
with open(sys.argv[2], encoding="utf8") as f: |
||||
d2 = json.load(f) |
||||
|
||||
|
||||
# Remove description field to allow non deterministic print |
||||
for elem in d1: |
||||
if 'description' in elem: |
||||
del elem['description'] |
||||
if "description" in elem: |
||||
del elem["description"] |
||||
for elem in d2: |
||||
if 'description' in elem: |
||||
del elem['description'] |
||||
|
||||
if "description" in elem: |
||||
del elem["description"] |
||||
|
||||
|
||||
pprint(DeepDiff(d1, d2, ignore_order=True, verbose_level=2)) |
||||
|
@ -1,31 +1,29 @@ |
||||
from setuptools import setup, find_packages |
||||
|
||||
setup( |
||||
name='slither-analyzer', |
||||
description='Slither is a Solidity static analysis framework written in Python 3.', |
||||
url='https://github.com/crytic/slither', |
||||
author='Trail of Bits', |
||||
version='0.6.12', |
||||
name="slither-analyzer", |
||||
description="Slither is a Solidity static analysis framework written in Python 3.", |
||||
url="https://github.com/crytic/slither", |
||||
author="Trail of Bits", |
||||
version="0.6.12", |
||||
packages=find_packages(), |
||||
python_requires='>=3.6', |
||||
install_requires=['prettytable>=0.7.2', |
||||
'pysha3>=1.0.2', |
||||
'crytic-compile>=0.1.8'], |
||||
# 'crytic-compile'], |
||||
# dependency_links=['git+https://github.com/crytic/crytic-compile.git@master#egg=crytic-compile'], |
||||
license='AGPL-3.0', |
||||
long_description=open('README.md').read(), |
||||
python_requires=">=3.6", |
||||
install_requires=["prettytable>=0.7.2", "pysha3>=1.0.2", "crytic-compile>=0.1.8"], |
||||
# 'crytic-compile'], |
||||
# dependency_links=['git+https://github.com/crytic/crytic-compile.git@master#egg=crytic-compile'], |
||||
license="AGPL-3.0", |
||||
long_description=open("README.md").read(), |
||||
entry_points={ |
||||
'console_scripts': [ |
||||
'slither = slither.__main__:main', |
||||
'slither-check-upgradeability = slither.tools.upgradeability.__main__:main', |
||||
'slither-find-paths = slither.tools.possible_paths.__main__:main', |
||||
'slither-simil = slither.tools.similarity.__main__:main', |
||||
'slither-flat = slither.tools.flattening.__main__:main', |
||||
'slither-format = slither.tools.slither_format.__main__:main', |
||||
'slither-check-erc = slither.tools.erc_conformance.__main__:main', |
||||
'slither-check-kspec = slither.tools.kspec_coverage.__main__:main', |
||||
'slither-prop = slither.tools.properties.__main__:main' |
||||
"console_scripts": [ |
||||
"slither = slither.__main__:main", |
||||
"slither-check-upgradeability = slither.tools.upgradeability.__main__:main", |
||||
"slither-find-paths = slither.tools.possible_paths.__main__:main", |
||||
"slither-simil = slither.tools.similarity.__main__:main", |
||||
"slither-flat = slither.tools.flattening.__main__:main", |
||||
"slither-format = slither.tools.slither_format.__main__:main", |
||||
"slither-check-erc = slither.tools.erc_conformance.__main__:main", |
||||
"slither-check-kspec = slither.tools.kspec_coverage.__main__:main", |
||||
"slither-prop = slither.tools.properties.__main__:main", |
||||
] |
||||
} |
||||
}, |
||||
) |
||||
|
Loading…
Reference in new issue