|
|
@ -11,7 +11,7 @@ from crytic_compile import CryticCompile, InvalidCompilation |
|
|
|
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification |
|
|
|
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification |
|
|
|
from slither.printers.abstract_printer import AbstractPrinter |
|
|
|
from slither.printers.abstract_printer import AbstractPrinter |
|
|
|
from .solc_parsing.slitherSolc import SlitherSolc |
|
|
|
from .solc_parsing.slitherSolc import SlitherSolc |
|
|
|
from .utils.colors import red |
|
|
|
from .exceptions import SlitherError |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("Slither") |
|
|
|
logger = logging.getLogger("Slither") |
|
|
|
logging.basicConfig() |
|
|
|
logging.basicConfig() |
|
|
@ -56,11 +56,8 @@ class Slither(SlitherSolc): |
|
|
|
crytic_compile = CryticCompile(contract, **kwargs) |
|
|
|
crytic_compile = CryticCompile(contract, **kwargs) |
|
|
|
self._crytic_compile = crytic_compile |
|
|
|
self._crytic_compile = crytic_compile |
|
|
|
except InvalidCompilation as e: |
|
|
|
except InvalidCompilation as e: |
|
|
|
logger.error('Invalid compilation') |
|
|
|
raise SlitherError('Invalid compilation: '+e) |
|
|
|
logger.error(e) |
|
|
|
|
|
|
|
exit(-1) |
|
|
|
|
|
|
|
for path, ast in crytic_compile.asts.items(): |
|
|
|
for path, ast in crytic_compile.asts.items(): |
|
|
|
|
|
|
|
|
|
|
|
self._parse_contracts_from_loaded_json(ast, path) |
|
|
|
self._parse_contracts_from_loaded_json(ast, path) |
|
|
|
self._add_source_code(path) |
|
|
|
self._add_source_code(path) |
|
|
|
|
|
|
|
|
|
|
@ -78,14 +75,12 @@ class Slither(SlitherSolc): |
|
|
|
|
|
|
|
|
|
|
|
def _init_from_raw_json(self, filename): |
|
|
|
def _init_from_raw_json(self, filename): |
|
|
|
if not os.path.isfile(filename): |
|
|
|
if not os.path.isfile(filename): |
|
|
|
logger.error('{} does not exist (are you in the correct directory?)'.format(filename)) |
|
|
|
raise SlitherError('{} does not exist (are you in the correct directory?)'.format(filename)) |
|
|
|
exit(-1) |
|
|
|
|
|
|
|
assert filename.endswith('json') |
|
|
|
assert filename.endswith('json') |
|
|
|
with open(filename, encoding='utf8') as astFile: |
|
|
|
with open(filename, encoding='utf8') as astFile: |
|
|
|
stdout = astFile.read() |
|
|
|
stdout = astFile.read() |
|
|
|
if not stdout: |
|
|
|
if not stdout: |
|
|
|
logger.info('Empty AST file: %s', filename) |
|
|
|
raise SlitherError('Empty AST file: %s', filename) |
|
|
|
sys.exit(-1) |
|
|
|
|
|
|
|
contracts_json = stdout.split('\n=') |
|
|
|
contracts_json = stdout.split('\n=') |
|
|
|
|
|
|
|
|
|
|
|
super(Slither, self).__init__(filename) |
|
|
|
super(Slither, self).__init__(filename) |
|
|
@ -173,14 +168,12 @@ class Slither(SlitherSolc): |
|
|
|
|
|
|
|
|
|
|
|
def _run_solc(self, filename, solc, disable_solc_warnings, solc_arguments, ast_format): |
|
|
|
def _run_solc(self, filename, solc, disable_solc_warnings, solc_arguments, ast_format): |
|
|
|
if not os.path.isfile(filename): |
|
|
|
if not os.path.isfile(filename): |
|
|
|
logger.error('{} does not exist (are you in the correct directory?)'.format(filename)) |
|
|
|
raise SlitherError('{} does not exist (are you in the correct directory?)'.format(filename)) |
|
|
|
exit(-1) |
|
|
|
|
|
|
|
assert filename.endswith('json') |
|
|
|
assert filename.endswith('json') |
|
|
|
with open(filename, encoding='utf8') as astFile: |
|
|
|
with open(filename, encoding='utf8') as astFile: |
|
|
|
stdout = astFile.read() |
|
|
|
stdout = astFile.read() |
|
|
|
if not stdout: |
|
|
|
if not stdout: |
|
|
|
logger.info('Empty AST file: %s', filename) |
|
|
|
raise SlitherError('Empty AST file: %s', filename) |
|
|
|
sys.exit(-1) |
|
|
|
|
|
|
|
stdout = stdout.split('\n=') |
|
|
|
stdout = stdout.split('\n=') |
|
|
|
|
|
|
|
|
|
|
|
return stdout |
|
|
|
return stdout |
|
|
|