Skip to content

Commit

Permalink
Merge pull request #1571 from crytic/dev-add-no-fail
Browse files Browse the repository at this point in the history
Add --no-fail mode
  • Loading branch information
montyly authored Jan 9, 2023
2 parents aee2a78 + fac905b commit 5323860
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 51 deletions.
7 changes: 7 additions & 0 deletions slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ def parse_args(
default=False,
)

group_misc.add_argument(
"--no-fail",
help="Do not fail in case of parsing (echidna mode only)",
action="store_true",
default=defaults_flag_in_config["no_fail"],
)

codex.init_parser(parser)

# debugger command
Expand Down
4 changes: 4 additions & 0 deletions slither/core/slither_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def __init__(self):
# But we allow to alter this (ex: file.sol:1) for vscode integration
self.line_prefix: str = "#"

# Use by the echidna printer
# If true, partial analysis is allowed
self.no_fail = False

@property
def compilation_units(self) -> List[SlitherCompilationUnit]:
return list(self._compilation_units)
Expand Down
47 changes: 26 additions & 21 deletions slither/printers/guidance/echidna.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,27 +329,32 @@ def _call_a_parameter(slither: SlitherCore) -> Dict[str, List[Dict]]:
ret: Dict[str, List[Dict]] = defaultdict(list)
for contract in slither.contracts: # pylint: disable=too-many-nested-blocks
for function in contract.functions_entry_points:
for ir in function.all_slithir_operations():
if isinstance(ir, HighLevelCall):
for idx, parameter in enumerate(function.parameters):
if is_dependent(ir.destination, parameter, function):
ret[contract.name].append(
{
"function": _get_name(function),
"parameter_idx": idx,
"signature": _get_name(ir.function),
}
)
if isinstance(ir, LowLevelCall):
for idx, parameter in enumerate(function.parameters):
if is_dependent(ir.destination, parameter, function):
ret[contract.name].append(
{
"function": _get_name(function),
"parameter_idx": idx,
"signature": None,
}
)
try:
for ir in function.all_slithir_operations():
if isinstance(ir, HighLevelCall):
for idx, parameter in enumerate(function.parameters):
if is_dependent(ir.destination, parameter, function):
ret[contract.name].append(
{
"function": _get_name(function),
"parameter_idx": idx,
"signature": _get_name(ir.function),
}
)
if isinstance(ir, LowLevelCall):
for idx, parameter in enumerate(function.parameters):
if is_dependent(ir.destination, parameter, function):
ret[contract.name].append(
{
"function": _get_name(function),
"parameter_idx": idx,
"signature": None,
}
)
except Exception as e:
if slither.no_fail:
continue
raise e
return ret


Expand Down
48 changes: 18 additions & 30 deletions slither/slither.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self, target: Union[str, CryticCompile], **kwargs):
self.codex_max_tokens = kwargs.get("codex_max_tokens", 300)
self.codex_log = kwargs.get("codex_log", False)

self.no_fail = kwargs.get("no_fail", False)

self._parsers: List[SlitherCompilationUnitSolc] = []
try:
if isinstance(target, CryticCompile):
Expand Down Expand Up @@ -128,41 +130,27 @@ def __init__(self, target: Union[str, CryticCompile], **kwargs):

triage_mode = kwargs.get("triage_mode", False)
self._triage_mode = triage_mode
self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))

def _init_parsing_and_analyses(self, skip_analyze: bool) -> None:

for parser in self._parsers:
parser.parse_contracts()
try:
parser.parse_contracts()
except Exception as e:
if self.no_fail:
continue
raise e

# skip_analyze is only used for testing
if not kwargs.get("skip_analyze", False):
if not skip_analyze:
for parser in self._parsers:
parser.analyze_contracts()

# def _init_from_raw_json(self, filename):
# if not os.path.isfile(filename):
# raise SlitherError(
# "{} does not exist (are you in the correct directory?)".format(filename)
# )
# assert filename.endswith("json")
# with open(filename, encoding="utf8") as astFile:
# stdout = astFile.read()
# if not stdout:
# to_log = f"Empty AST file: {filename}"
# raise SlitherError(to_log)
# contracts_json = stdout.split("\n=")
#
# self._parser = SlitherCompilationUnitSolc(filename, self)
#
# for c in contracts_json:
# self._parser.parse_top_level_from_json(c)

# def _init_from_list(self, contract):
# self._parser = SlitherCompilationUnitSolc("", self)
# for c in contract:
# if "absolutePath" in c:
# path = c["absolutePath"]
# else:
# path = c["attributes"]["absolutePath"]
# self._parser.parse_top_level_from_loaded_json(c, path)
try:
parser.analyze_contracts()
except Exception as e:
if self.no_fail:
continue
raise e

@property
def detectors(self):
Expand Down
1 change: 1 addition & 0 deletions slither/utils/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"zip": None,
"zip_type": "lzma",
"show_ignored_findings": False,
"no_fail": False,
**DEFAULTS_FLAG_IN_CONFIG_CRYTIC_COMPILE,
}

Expand Down

0 comments on commit 5323860

Please sign in to comment.