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

Add flag to only generate alive states when finalizing Manticore #1554

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions manticore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def positive(value):
help="Do not generate testcases for discovered states when analysis finishes",
)

eth_flags.add_argument(
"--only-alive-testcases",
action="store_true",
help="Do not generate testcases for invalid/throwing states when analysis finishes",
)

config_flags = parser.add_argument_group("Constants")
config.add_config_vars_to_argparse(config_flags)

Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def ethereum_main(args, logger):
)

if not args.no_testcases:
m.finalize()
m.finalize(only_alive_states=args.only_alive_testcases)
else:
m.kill()

Expand Down
8 changes: 6 additions & 2 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,13 +1601,14 @@ def _emit_trace_file(filestream, trace):
filestream.write(ln)

@ManticoreBase.at_not_running
def finalize(self, procs=None):
def finalize(self, procs=None, only_alive_states=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add only_alive_states to the docstring for this function?

"""
Terminate and generate testcases for all currently alive states (contract
states that cleanly executed to a STOP or RETURN in the last symbolic
transaction).

:param procs: force the number of local processes to use in the reporting
:param bool only_alive_states: if True, killed states (revert/throw/txerror) do not generate testscases
generation. Uses global configuration constant by default
"""
if procs is None:
Expand All @@ -1618,8 +1619,11 @@ def finalize(self, procs=None):
def finalizer(state_id):
st = self._load(state_id)
if self.fix_unsound_symbolication(st):
logger.debug("Generating testcase for state_id %d", state_id)
last_tx = st.platform.last_transaction
# Do not generate killed state if only_alive_states is True
if only_alive_states and last_tx.result in {"REVERT", "THROW", "TXERROR"}:
return
logger.debug("Generating testcase for state_id %d", state_id)
message = last_tx.result if last_tx else "NO STATE RESULT (?)"
self.generate_testcase(st, message=message)

Expand Down