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

Manticore verifier #1717

Merged
merged 116 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 112 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
0cd1bc5
Add ONE failing test
feliam May 13, 2020
609a37e
Fix test
feliam May 13, 2020
b29f3ac
Try fix get-related
feliam May 13, 2020
5bad00f
Snapshots
feliam May 15, 2020
5bb6e48
CC
feliam May 17, 2020
f78e1c2
Allow snapshooting just from main()
feliam May 17, 2020
8cc6f6c
A test
feliam May 18, 2020
5997dab
Test and fix is_main
feliam May 18, 2020
252b10b
CC
feliam May 18, 2020
384de08
review
feliam May 26, 2020
d044b07
ismain vs is_running
feliam May 26, 2020
ec8440e
is main to is main script
feliam May 26, 2020
25d8b26
Remove unused member variable
feliam May 27, 2020
62360a0
Merge branch 'master' into dev-checkpoints
feliam May 27, 2020
f912266
initial import manticore verifier
feliam May 27, 2020
63557e5
Fix verifier installation
feliam May 27, 2020
b49f4af
clear ready states
feliam May 28, 2020
f275e3a
CC and smoke test
feliam May 28, 2020
84f1e5a
CC
feliam May 28, 2020
6cb271c
Increase cov
feliam May 28, 2020
79aa5cc
Move regression to other
feliam Jun 2, 2020
7339eb9
blkn
feliam Jun 2, 2020
c121c38
blkn
feliam Jun 2, 2020
3ff6b95
Move get related
feliam Jun 5, 2020
4414987
merge
feliam Jun 5, 2020
02b4c69
Merge branch 'master' into dev-get-related
feliam Jun 5, 2020
00e8199
CC
feliam Jun 5, 2020
6b7f671
fix concolic
feliam Jun 5, 2020
6732eb2
lint
feliam Jun 5, 2020
4adeac2
DivByZero default to zero
feliam Jun 5, 2020
7565b4a
blkn
feliam Jun 5, 2020
1680397
Update manticore/core/smtlib/solver.py
feliam Jun 5, 2020
cbe55b9
Update manticore/core/smtlib/constraints.py
feliam Jun 5, 2020
315ef64
Update manticore/core/smtlib/constraints.py
feliam Jun 5, 2020
6155a4d
remove odd string
feliam Jun 5, 2020
38dbfd6
Merge branch 'dev-get-related' of github.com:trailofbits/manticore in…
feliam Jun 5, 2020
1491cbd
lint
feliam Jun 5, 2020
264eb04
mypy lint
feliam Jun 5, 2020
e0130a4
Update manticore/core/smtlib/visitors.py
feliam Jun 5, 2020
d0e9abf
lint
feliam Jun 5, 2020
9807b37
Add Docs
feliam Jun 8, 2020
728e021
Merge branch 'master' into dev-get-related
feliam Jun 9, 2020
0630832
Merge branch 'master' into dev-verifier
feliam Jun 9, 2020
5d30b13
blkn
feliam Jun 9, 2020
e584fb2
merge
feliam Jun 9, 2020
be0d2f5
blkn
feliam Jun 9, 2020
bf3a2b9
Replace modulo with masks
Jun 10, 2020
3eb96f8
Blacken
Jun 10, 2020
5e54189
blkn
feliam Jun 10, 2020
a0ab429
Merge branch 'dev-get-related' of github.com:trailofbits/manticore in…
feliam Jun 10, 2020
536ec71
fix mypy
feliam Jun 10, 2020
a83e8c2
fix mypy
feliam Jun 10, 2020
4447b87
merge
feliam Jun 10, 2020
36292fb
More commandline arguments
feliam Jun 10, 2020
37144d9
Add tests for signed LT behavior
Jun 10, 2020
1b8754d
New test
feliam Jun 10, 2020
787e51f
Fix constant folding
feliam Jun 10, 2020
dca9adb
merge
feliam Jun 10, 2020
dfa7a84
lint
feliam Jun 10, 2020
0ebece8
blkn
feliam Jun 10, 2020
b841038
lint
feliam Jun 10, 2020
fa2ef90
Fixes...
feliam Jun 10, 2020
735a963
lint
feliam Jun 10, 2020
b54a448
Unittesting power
feliam Jun 10, 2020
02563cd
Permisive read_buffer
feliam Jun 10, 2020
1dcb9ed
Merge branch 'dev-get-related' into dev-verifier
feliam Jun 10, 2020
451ba59
Fix optimize
feliam Jun 10, 2020
3fab981
Preserve precision in constant folding
Jun 10, 2020
f7fb8bb
Strip left-in print debugging
Jun 11, 2020
2b05f8b
blkn
feliam Jun 11, 2020
f9120de
remove wasm_sym temporarily
feliam Jun 11, 2020
a502b61
Better simplification for constants
feliam Jun 11, 2020
a7c3c18
Add json
feliam Jun 11, 2020
816b29a
blkn
feliam Jun 11, 2020
9a15dff
Better commmandline args
feliam Jun 11, 2020
88318fe
blkn
feliam Jun 11, 2020
2f5d4d2
fix wasm
feliam Jun 11, 2020
18064f8
Merge branch 'dev-get-related' of github.com:trailofbits/manticore in…
feliam Jun 11, 2020
52d8eb4
Fix
feliam Jun 11, 2020
4eeb74b
better commanlining
feliam Jun 12, 2020
f1dfb80
REmove get_related from the default path and fix arm test
feliam Jun 12, 2020
d5b577e
blkn
feliam Jun 12, 2020
79b42ed
fix related to tests
feliam Jun 12, 2020
ec8489f
blkn
feliam Jun 12, 2020
3377856
merge get-related
feliam Jun 12, 2020
2113a73
Fix bug in test and disable debug messages in Solver
feliam Jun 12, 2020
c2a21ba
smtlib config to disable multiple check-sat in newer z3
feliam Jun 12, 2020
962d454
Merge branch 'dev-get-related' into dev-verifier
feliam Jun 12, 2020
f87e1e2
Disable log test and fix merging poc vs variable migration
feliam Jun 15, 2020
2eb630d
blkn
feliam Jun 15, 2020
8818ea3
Avoid exception in some callbacks
feliam Jun 15, 2020
ebb118e
Merge branch 'dev-get-related' into dev-verifier
feliam Jun 15, 2020
35b61d0
can_rais at did_will
feliam Jun 15, 2020
009cad5
yikes!
feliam Jun 16, 2020
12068eb
blkn
feliam Jun 16, 2020
b1998ea
Yices found one more states in truffle
feliam Jun 16, 2020
d620bdc
merge
feliam Jun 17, 2020
f3049ec
Add a config constant to ignore symbolic balances
feliam Jun 17, 2020
ac86c60
Add a config constant to ignore symbolic balances 2
feliam Jun 17, 2020
cc3ee9d
Relax truffle state count
feliam Jun 17, 2020
c25e363
Relax truffle state count 2
feliam Jun 17, 2020
0d070b1
Change cli name and test
feliam Jun 18, 2020
32ec10d
Clear redy states in verifier workspace
feliam Jun 18, 2020
c982275
Clear ready states in verifier workspace
feliam Jun 18, 2020
81316aa
Relative ws path on verifier output. Clean CREATE testcase example
feliam Jun 18, 2020
d093783
Blkn
feliam Jun 18, 2020
cfe4316
Merge branch 'master' into dev-verifier
feliam Jun 22, 2020
5543e29
Improve coverage and funcid solving
feliam Jun 23, 2020
ec308e2
lint
feliam Jun 23, 2020
90de280
Better testcase generation at verifier
feliam Jun 24, 2020
27fb790
Better testcase generation at verifier and typos
feliam Jun 24, 2020
8c80a1d
merge
feliam Jun 24, 2020
08f39ae
Better output and default re
feliam Jun 25, 2020
d421061
Test must revert
feliam Jun 25, 2020
1e362ac
Better output and default re
feliam Jun 25, 2020
6d4a8e3
move generate_testcase_ex to private method
feliam Jun 26, 2020
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
4 changes: 1 addition & 3 deletions manticore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ def positive(value):
)

eth_flags.add_argument(
"--limit-loops",
action="store_true",
help="Avoid exploring constant functions for human transactions",
"--limit-loops", action="store_true", help="Limit loops depth",
)

eth_flags.add_argument(
Expand Down
19 changes: 14 additions & 5 deletions manticore/core/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ..utils.helpers import PickleSerializer
from ..utils.log import set_verbosity
from ..utils.nointerrupt import WithKeyboardInterruptAs
from .workspace import Workspace
from .workspace import Workspace, Testcase
from .worker import WorkerSingle, WorkerThread, WorkerProcess

from multiprocessing.managers import SyncManager
Expand Down Expand Up @@ -403,8 +403,7 @@ def goto_snapshot(self):
in a snapshot """
if not self._snapshot:
raise ManticoreError("No snapshot to go to")
for state_id in tuple(self._ready_states):
self._ready_states.remove(state_id)
self.clear_ready_states()
for state_id in self._snapshot:
self._ready_states.append(state_id)
self._snapshot = None
Expand All @@ -421,13 +420,23 @@ def clear_snapshot(self):
@sync
@at_not_running
def clear_terminated_states(self):
""" Simply remove all states from terminated list """
""" Remove all states from the terminated list """
terminated_states_ids = tuple(self._terminated_states)
for state_id in terminated_states_ids:
self._terminated_states.remove(state_id)
self._remove(state_id)
assert self.count_terminated_states() == 0

@sync
@at_not_running
def clear_ready_states(self):
feliam marked this conversation as resolved.
Show resolved Hide resolved
""" Remove all states from the ready list """
ready_states_ids = tuple(self._ready_states)
for state_id in ready_states_ids:
self._ready_states.remove(state_id)
self._remove(state_id)
assert self.count_ready_states() == 0

def __str__(self):
return f"<{str(type(self))[8:-2]}| Alive States: {self.count_ready_states()}; Running States: {self.count_busy_states()} Terminated States: {self.count_terminated_states()} Killed States: {self.count_killed_states()} Started: {self._running.value} Killed: {self._killed.value}>"

Expand Down Expand Up @@ -833,7 +842,7 @@ def count_terminated_states(self):
""" Terminated states count """
return len(self._terminated_states)

def generate_testcase(self, state, message: str = "test", name: str = "test"):
def generate_testcase(self, state, message: str = "test", name: str = "test") -> Testcase:
if message == "test" and hasattr(state, "_terminated_by") and state._terminated_by:
message = str(state._terminated_by)
testcase = self._output.testcase(prefix=name)
Expand Down
2 changes: 1 addition & 1 deletion manticore/core/smtlib/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def get_value(self, constraints: ConstraintSet, *expressions):
"""
values = []
start = time.time()
with constraints as temp_cs:
with constraints.related_to(*expressions) as temp_cs:
for expression in expressions:
if not issymbolic(expression):
values.append(expression)
Expand Down
8 changes: 4 additions & 4 deletions manticore/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __exit__(self, *excinfo):
consts.add("dir", default=".", description="Location of where to create workspace directories")


class WorkspaceTestcase:
class Testcase:
"""
A `WorkspaceTestCase` represents a test case input generated by Manticore.
"""
Expand Down Expand Up @@ -519,8 +519,8 @@ def __init__(self, desc=None):
self._descriptor = desc
self._store = Store.fromdescriptor(desc)

def testcase(self, prefix: str = "test") -> WorkspaceTestcase:
return WorkspaceTestcase(self, prefix)
def testcase(self, prefix: str = "test") -> Testcase:
return Testcase(self, prefix)

@property
def store(self):
Expand Down Expand Up @@ -587,7 +587,7 @@ def _named_stream(self, name, binary=False, lock=False):
yield s

# Remove/move ...
def save_testcase(self, state: StateBase, testcase: WorkspaceTestcase, message: str = ""):
def save_testcase(self, state: StateBase, testcase: Testcase, message: str = ""):
"""
Save the environment from `state` to storage. Return a state id
describing it, which should be an int or a string.
Expand Down
56 changes: 30 additions & 26 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from crytic_compile import CryticCompile, InvalidCompilation, is_supported

from ..core.manticore import ManticoreBase
from ..core.manticore import ManticoreBase, Testcase, ManticoreError

from ..core.smtlib import (
ConstraintSet,
Array,
Expand Down Expand Up @@ -1536,10 +1537,6 @@ def current_location(self, state):

def generate_testcase(self, state, message="", only_if=None, name="user"):
"""
Generate a testcase to the workspace for the given program state. The details of what
a testcase is depends on the type of Platform the state is, but involves serializing the state,
and generating an input (concretizing symbolic variables) to trigger this state.

The only_if parameter should be a symbolic expression. If this argument is provided, and the expression
*can be true* in this state, a testcase is generated such that the expression will be true in the state.
If it *is impossible* for the expression to be true in the state, a testcase is not generated.
Expand All @@ -1552,29 +1549,38 @@ def generate_testcase(self, state, message="", only_if=None, name="user"):

m.generate_testcase(state, 'balance CAN be 0', only_if=balance == 0)
# testcase generated with an input that will violate invariant (make balance == 0)
"""
try:
with state as temp_state:
if only_if is not None:
temp_state.constrain(only_if)
return self.generate_testcase_ex(temp_state, message, name=name)
except ManticoreError:
return None

def generate_testcase_ex(self, state, message="", name="user"):
"""
Generate a testcase in the outputspace for the given program state.
An exception is raised if the state is unsound or unfeasible

On return you get a Testcase containing all the informations about the state.
A Testcase is a collection of files living at the OutputSpace.
Registered plugins and other parts of Manticore add files to the Testcase.
User can add more streams to is like this:

testcase = m.generate_testcase_ex(state)
with testcase.open_stream("txt") as descf:
descf.write("This testcase is interesting!")

:param manticore.core.state.State state:
:param str message: longer description of the testcase condition
:param manticore.core.smtlib.Bool only_if: only if this expr can be true, generate testcase. if is None, generate testcase unconditionally.
:param str name: short string used as the prefix for the workspace key (e.g. filename prefix for testcase files)
:return: If a testcase was generated
:param str name: short string used as the prefix for the outputspace key (e.g. filename prefix for testcase files)
:return: a Testcase
:rtype: bool
"""
"""
Create a serialized description of a given state.
:param state: The state to generate information about
:param message: Accompanying message
"""
# Refuse to generate a testcase from an unsound state
if not self.fix_unsound_symbolication(state):
return False

if only_if is not None:
ehennenfent marked this conversation as resolved.
Show resolved Hide resolved
with state as temp_state:
temp_state.constrain(only_if)
if temp_state.is_feasible():
return self.generate_testcase(temp_state, message, only_if=None, name=name)
else:
return False
raise ManticoreError("Trying to generate a testcase out of an unsound state path")

blockchain = state.platform

Expand All @@ -1584,8 +1590,6 @@ def generate_testcase(self, state, message="", only_if=None, name="user"):
testcase = super().generate_testcase(
state, message + f"({len(blockchain.human_transactions)} txs)", name=name
)
# TODO(mark): Refactor ManticoreOutput to let the platform be more in control
# so this function can be fully ported to EVMWorld.generate_workspace_files.

local_findings = set()
for detector in self.detectors.values():
Expand Down Expand Up @@ -1865,8 +1869,8 @@ def ready_sound_states(self):
This tries to solve any symbolic imprecision added by unsound_symbolication
and then iterates over the resultant set.

This is the recommended to iterate over resultant steas after an exploration
that included unsound symbolication
This is the recommended way to iterate over the resultant states after
an exploration that included unsound symbolication

"""
self.fix_unsound_all()
Expand Down
Loading