Skip to content

Commit

Permalink
Handle issues with simplify (#1674)
Browse files Browse the repository at this point in the history
* Add exit code

* Update docs with tutorial

* Fix docs

* Reformat

* Fix the issue with loop-bound and solver-timeout

* Add test changes

* Restrict hexbytes

* Use solver over simplify
  • Loading branch information
norhh authored Sep 3, 2022
1 parent 8d863fb commit 427d40e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion mythril/analysis/module/modules/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def _handle_sstore(state: GlobalState) -> None:
return

state_annotation = _get_overflowunderflow_state_annotation(state)

for annotation in value.annotations:
if isinstance(annotation, OverUnderflowAnnotation):
state_annotation.overflowing_state_annotations.add(annotation)
Expand Down
2 changes: 1 addition & 1 deletion mythril/interfaces/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def add_analysis_args(options):
"--pruning-factor",
type=float,
default=1,
help="Checks for reachability at the rate of <pruning-factor>. Where 1 means checks every execution",
help="Checks for reachability at the rate of <pruning-factor> (range 0-1.0). Where 1.0 would mean checking for every execution",
)
options.add_argument(
"--unconstrained-storage",
Expand Down
14 changes: 11 additions & 3 deletions mythril/laser/ethereum/state/calldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from typing import Any, Union

from z3 import Model
from z3 import Model, unsat, unknown
from z3.z3types import Z3Exception

from mythril.laser.ethereum.util import get_concrete_int

from mythril.laser.smt import (
Array,
BitVec,
Expand All @@ -18,6 +19,7 @@
K,
simplify,
symbol_factory,
Solver,
)


Expand Down Expand Up @@ -73,16 +75,22 @@ def __getitem__(self, item: Union[int, slice, BitVec]) -> Any:
else symbol_factory.BitVecVal(start, 256)
)
parts = []
while simplify(current_index != stop):
while True:
s = Solver()
s.set_timeout(1000)
s.add(current_index != stop)
result = s.check()
if result in (unsat, unknown):
break
element = self._load(current_index)
if not isinstance(element, Expression):
element = symbol_factory.BitVecVal(element, 8)

parts.append(element)
current_index = simplify(current_index + step)

except Z3Exception:
raise IndexError("Invalid Calldata Slice")

return parts

raise ValueError
Expand Down

0 comments on commit 427d40e

Please sign in to comment.