Commit Graph
923 Commits
Author SHA1 Message Date
Samuel Moelius 4412c66102 Add optimization. 2020-06-09 19:21:08 +00:00
Samuel Moelius 5fe64f4ced Renaming: "transaction reordering" -> "transaction displacement" 2020-06-03 13:22:26 +00:00
Samuel Moelius 62c1a88e9d Merge remote-tracking branch 'origin/master' into dev-detect-transaction-reordering 2020-05-07 16:07:38 +00:00
Samuel Moelius f48617da3e Add test. 2020-05-07 16:03:50 +00:00
Samuel Moelius d29c711d5a Minor rewording. 2020-05-07 16:03:06 +00:00
Samuel Moelius 1d09a8d1c2 Try to get matcoin tests to pass. 2020-05-07 16:01:43 +00:00
Samuel Moelius 37ad9e7acd Initial commit of dev-detect-transaction-reordering. 2020-05-07 12:54:07 +00:00
feliamandEric Hennenfent f3dcd63a3f Try getting more coverage from truffle-test (#1694)
* Try getting more coverage from truffle-test

* Update codecov.yml

Co-authored-by: Eric Hennenfent <[email protected]>

* Try getting more coverage from truffle-test

* Update ci.yml

* Fix truffle tst state count

* Generate coverage file

Co-authored-by: Eric Hennenfent <[email protected]>
2020-05-05 13:21:46 -07:00
Samuel E. Moelius 4746e5d9a2 Eliminate deprecation warning in solidity_create_contract. (#1692) 2020-05-05 10:10:50 -07:00
Langston BarrettandEric Hennenfent 0bdcea4f78 Fix a few documentation typos in ManticoreBase (#1687)
* Fix a few documentation typos in ManticoreBase

* Fix documentation in ManticoreBase: 'vervosity' -> 'verbosity'

Co-authored-by: Eric Hennenfent <[email protected]>
2020-05-04 15:41:56 -07:00
Langston BarrettandEric Hennenfent 2b04eeee5c Add set_verbosity to the documentation (#1688)
Co-authored-by: Eric Hennenfent <[email protected]>
2020-05-04 15:41:09 -07:00
Samuel E. Moelius 4b26ced556 Adjust z3 options. (#1691) 2020-05-04 14:32:01 -07:00
Samuel E. MoeliusandEric Hennenfent ad5c48bd51 Improve concretize log messages (#1686)
* Improve concretize log messages.

* Update manticore/core/worker.py

Co-authored-by: Eric Hennenfent <[email protected]>

Co-authored-by: Eric Hennenfent <[email protected]>
2020-05-04 14:30:03 -07:00
feliam 894d22efb5 Move truffle to its own CI type (#1693)
* Move truffle thing to it own CI

* Cosmetic changes to ci
2020-05-04 16:59:00 -03:00
Eric Hennenfent 96bfc80ea0 Remove default gas limit (#1689)
Reverts one of the changes from #1652 to fix the sporadically-failing `test_integer_overflow_multitx_onefunc_feasible` test in `ethereum_bench`
2020-05-01 10:23:21 -07:00
feliam 522896264c Better argument names in manticoreEVM api (#1652)
* Better argument names in manticoreEVM api

* blkn

* bugfix
2020-04-28 12:48:14 -07:00
Eric Hennenfent 8a77ad4680 Blacken non-compliant files (#1680) 2020-04-24 13:57:59 -07:00
Samuel E. Moelius 2dfba13fbf Disable core __get_related logic (#1674)
There is a flaw in how __get_related works: when called on certain
unsatisfiable sets, it can return a satisfiable one. The flaw arises when:
  * self consists of a single constraint C
  * C is the value of the related_to parameter
  * C contains no variables
  * C is unsatisfiable
Since C contains no variables, it is not considered "related to" itself and is thrown out
by __get_related. Since C was the sole element of self, __get_related returns the empty
set. Thus, __get_related was called on an unsatisfiable set, {C}, but it returned a
satisfiable one, {}.
2020-04-24 10:22:16 -07:00
Eric Hennenfent 1e82ec457c Make CodeCov wait for reports from all CI jobs (#1661)
* Make CodeCov wait for reports from all CI jobs

This should prevent the red 'X' from appearing as soon as the first job finishes.

* Make CI step fail if codecov fails to upload

* Run examples with coverage

* Copy coverage file appropriately

* Fix path to coverage file

* Add comment about n builds

* Disable failing CI upon error.
2020-04-23 13:57:09 -07:00
feliam 96d65e5fe9 New instructions (#1644)
* New instructions

* Update evm.py

* Link pyevmasm master

* blkn

* Fix pyevmasm dep

* Fix pyevmasm link

* Fix pyevmasm link

* Fix deps

* Remove bad merge
2020-04-23 15:44:25 -03:00
Brad Larsen 4c51644aa7 Rework syscall invocation for proper behavior under typeguard (#1672)
* Rework syscall invocation for proper behavior under typeguard

Previously, using Typeguard with Manticore would break several emulated
syscalls.  With this commit, it does not.

Some background information:

When a syscall is made from an emulated binary, Manticore uses the
syscall number to look up the appropriate Python method that models that
syscall, and then uses Python introspection to massage arguments to that
syscall model function as deemed appropriate.

Previously, this mechanism used the deprecated `inspect.getfullargspec`
to determine the number of arguments to the model function, and whether
or not it takes varargs.

However, `inspect.getfullargspec` doesn't look through wrapper
functions; it looks only at exactly the function object it is given.
This is an issue, however, when trying to inspect _decorated_ functions.
(The use of a decorator in Python introduces a _new_ function object
that wraps the decorated item.)

How did that break Manticore when using Typeguard?  It turns out that
When using Typeguard via the `--typeguard-packages=manticore` option to
`pytest`, the Typeguard plugin implicitly adds a `@typeguard.check_types`
decorator on _every_ function & method in the `manticore` package.

In this way, each syscall implementation function in Manticore ends up
with a wrapper around it, and the syscall invocation mechanism based on
`inspect.getfullargspec` would somewhat quietly cause syscalls to break.

Now, instead of using `inspect.getfullargspec`, Manticore's syscall
invocation mechansim uses the non-deprecated `inspect.signature` API to
get the needed information.  This API _does_ look through wrapper
functions. Additionally, it allows us to get rid of some conditional
logic, about whether `self` appears in a function's parameter list or
not.

* Update manticore/native/cpu/abstractcpu.py

* Get rid of the `wrapt` library

We only were using `wrapt` in a single place -- to implement the
`unimplemented` syscall decorator.  That dependency was added in #1384,
so that the old syscall mechanism could work with the decorator.

Now, with the rework of Manticore's syscall mechanism, this is no longer
necessary, and a "regular" Python decorator implemented using
`functools.wraps` should work just fine.

* Fix rewrite of `unimplemented`

* Rework platform `unimplemented` decorator, take 3

Additionally, add some extra tests for the decorator, to get better
coverage from where it is used.

* Clean up `test_sycalls.py` imports

* Fix an unbound variable error

(found with `mypy --check-untyped-defs` and some grep)

* Get rid of some unused imports
2020-04-22 18:42:42 -04:00
Samuel E. Moelius e9c5c535a3 printable_bytes (#1671)
Extract printable bytes from return data in the same way as it is
currently done for logs.
2020-04-17 13:10:44 -07:00
Brad Larsen 52f215e2f0 Fix several incorrect type hints (#1668)
* Delete simultaneously dead & broken code

* Fix an overly specific type hint in smtlib `Bool.cast`

* Fix type confusion in Solver internal methods

* Fix type confusion in Linux symbolic file support

* Fix type confusion in Linux platform & abstract CPU

* Fix an incorrect type hint & clarify documentation in Linux `sys_open`

* Fix type confusion in `unimplemented` decorator

* Remove some `Generator` return type signatures; mypy/typeguard/`@contextmanager` do not agree with each other

* Delete a couple bad type hints

The `dirfd` and `buf` parameters can be symbolic, and the type-checking
that mypy does has trouble understanding `issymbolic`.  So, un-type-hintify
those parameters.

* Add type hints & fix typing issues in manticore.core.workspace

* Remove some wrong type hints from AbstractCpu

It turns out that the type of `data` in a couple methods is pretty flexible,
and our tests use more than just `str`, `bytes`, and `List` types for that
parameter.

It is not quite clear what requirements there actually are on `data`, and so at
least for now, get rid of the type hint there.

* Add type hints & fix a typing issue in manticore.native.cpu.x86

**kwargs could not have possibly worked in `AMD64Operand`.

* Make the type hint of `Z3Solver._send` tighter.

* Update manticore/core/workspace.py

Remove unused import (thanks @ehennenfent!)

* Use more specific types (thanks @ehennenfent!)
2020-04-17 12:08:03 -07:00
Brad LarsenandEric Kilmer 9b0302512b Add type hints to several parts of Manticore (#1667)
* Add type hints

* Add type hints in manticore/core/smtlib/solver.py

* Add type hints to the `unsigned_hexlify` helper function

* Add type hints & more robust error checking to a Solver internal method

* Add type hints in native memory code

* Add type hints to Linux platform test methods

* Add type hints for Linux `sys_access`

* Add type hints for AbstractCPU; rephrase a couple bits to appease mypy

* Add type hints to manticore/platforms/linux.py

* Add type hints for Workspace members

* Add type hints for `Operand`

* Add a return type hint per @ekilmer

Co-Authored-By: Eric Kilmer <[email protected]>
2020-04-16 18:21:20 -04:00
Brad Larsen a6ae85aeee Fix type confusion in manual CPU tests; delete dead testing code (#1669) 2020-04-16 14:04:54 -07:00
Brad Larsen c8a6fc8ae7 Rework WASM Imports and Fix Typos (#1666)
* Cleanup: add missing space in a description string

* Cleanup: ignore a derived example file

* Cleanup: sort WASM type import lists
2020-04-16 10:14:58 -07:00
Eric Hennenfent 1e23f7abcb Work on "Model is not Available" errors in tests (#1659)
* Check disk/memory usage if we get unsat results

* Expand "Model unavailable" message

* Ignore missing psutil imports

* Add resource checks to CLI application
2020-04-09 17:29:32 -07:00
Eric Hennenfent d08228438e Fix TypeGuard Errors in WASM Module (#1601)
* Make WASM module pass typeguard

* Add ConstraintSet to eligible _send types

* Fix lingering mypy errors

* Blacken
2020-04-09 17:13:07 -04:00
feliamandEric Hennenfent 43ea70f96e Remove unused arg ans separate output from workspace (#1651)
* Remove unused arg ans separate output from workspace

* Update docstring on ManticoreBase

Fix missing docstring for outputspace_url

Co-authored-by: Eric Hennenfent <[email protected]>
2020-04-09 10:43:22 -07:00
Brad Larsen 014b779456 Add a badge to README.md for LGTM (#1647)
* Normalize capitalization in badges

* Add a badge for LGTM for this project
2020-04-08 14:00:18 -07:00
Brad Larsen d059a0370c Fix 2 problems in Linux sys_open support & add type hints (#1657)
* Add type hints to some Linux syscalls

* Fix a type error & add a type hint in Linux `sys_open`

* Add an example program that can exercise symbolic file support

* Add a test case based on the `fileio` example

Note, The `fileio_linux_amd64` test binary was manually copied from the
examples directory and added to Git.  Maybe one day we will come up with
a more principled mechanism for this.

Also note, this test case currently fails, even with the `sys_open` type
fixes.  Multiple errors are revealed by this test case.

* Add a type hint

* Add type hints to manticore workspace code

* Make an optional parameter non-optional

This function never seems to be used without specifying the formerly
optional value.

* Fix choice of abbreviation in comments

* Allow keys with `/` in them in `FilesystemStore`.

This is an expedient fix -- a more proper fix would nail down the API of
which characters are allowed in keys, maximum length etc, at the level
of the `Store` class.

* Have `fileio` exit with 0 on incorrect usage

Our GitHub CI has one step where it builds each of the example programs,
and then attempts to run them with no arguments and no standard input,
checking that they exit with code 0.  Rather than rework this approach
to support more general invocation patterns for example programs, it's
easier to change the `fileio` example I added.

* Blacken manticore/core/workspace.py
2020-04-08 13:58:50 -07:00
Eric HennenfentandBrad Larsen 8565705f79 Fix LGTM Errors (#1656)
* py/missing-call-to-init

* Remove deprecated should_profile argument

* WASM __init__ call and variable names

* Mute warnings about printing evm account IDs

LGTM thinks we're logging potentially sensitive data when we create a symbolic account and print the user ID. I can't imagine a context where we would ever care about this alert in general, so I'm going to disable it.

* Fix mixed attribute/function names

* Another missing __init__ call

* Remove single-op form of _bitwise_instruction

It's never used

* Use built-in ops instead of lambda

* Missing import

* Some unreachable code

Still missing some in evm.py

* Blacken

* Tag examples as examples

* NotImplemented -> NotImplementedError

* Fix unnecessary `pass`

* Revert "Remove single-op form of _bitwise_instruction"

This reverts commit 1b7a4110f4.

* Mute overzealous call argument error

Co-authored-by: Brad Larsen <[email protected]>
2020-04-08 13:49:28 -07:00
Jim Posen 8fcdf0dc1f Delay WASM Branch Condition Concretization (#1641)
* Fix typos.

* Create StackItem type alias.

* New failing tests demonstrating Wasm branching bugs.

The issue is that the Wasm symbolic execution engine concretizes the
integer input to branching instructions. Aside frome being
inefficient, the concretization logic prevents forking into more than
a small number of values and silently skips exploration of other
values.

* Fix for wasm if and br_if execution.

The engine raises a ConcretizeCondition exception to determine the
branch path and constrain the state minimally.

* Remove unnecessary bitwise AND.

It's unnecessary because c_int32 truncates to 32 bits and it's weird
because this bitwise and isn't there for I64.

* Failing tests demonstrating bug in br_table and call_indirect.

* Fix bugs with br_table and call_indirect using concrete conditions.

* Fix typing errors.

* Try to get wasm tests passing.

* Move advice conditions from Stack to separate structure.

* Fix so that multiple conditions may be concretized.

* Update incorrect comment on StateBase.concretize.

* Appease type checker.
2020-04-07 14:56:28 -07:00
Eric Kilmer 924a13997f Add feature for SymbolicSocket through sys_accept (#1618)
* Add feature for SymbolicSocket through sys_accept

SymbolicSocket will generate symbolic bytes and variables on-demand
through interaction with the relevant system calls

* Fix comma in comment

* Add test for sys_read of symbolic socket

* Add type hints for Socket
2020-04-07 08:45:55 -07:00
Brad Larsen ba4090699c Add a bunch of type hints & fix a few issues with Linux platform emulation (#1645)
* Add type hints for a couple abstract CPU functions

* Make sys_open / sys_openat debug log messages more descriptive

* Fix & comment out dead load_vdso code

* Add type hints in Linux platform code

* Add type hints & fix Liskov-substitution-principle-violating `seek` method overrides

* Add several more type hints for native memory code

* Eliminate a couple misleading log messages

* Add type hints & fix several edge cases in Linux filesystem emulation

* Refine logger messages from Linux syscalls

* Simplify a bit of code & add a type hint that got lost earlier

* Delete dead VDSO code in the Linux platform

* Add type hints & fix issues in memory map objects

There has been an inconsistency in the `__init__` methods of the `Map`
superclass and its subclasses, specifically with regard to `**kwargs`.
Example: previously, in `Arraymap`, `**kwargs` would be taken but
silently ignored.

* Eliminate parameter types from docstrings when type hints have been used instead

Additionally, add some more type hints from looking at methods that
immediately `assert isinstance(SOME_PARAM, SOME_TYPE)`.  (These ought to
be non-controversial types.)

* Make a type more precise, courtesy of @ekilmer

* Restore an accidentally-deleted type signature

* Fix broken type hints

`Eventful` is not yet defined at the point the hint is used,
so use a forward reference instead.  Similar with the use of `Cpu`.

* Fix bungled type hint

* Blacken manticore/native/cpu/abstractcpu.py
2020-04-07 08:43:33 -07:00
Eric Hennenfent e28168f417 Bump to CheckoutV2 (#1654)
* Bump version of checkout script and some Python packages

Unicorn, black, and mypy

* Fix typing issue with potential missing file descriptor
2020-04-06 13:51:10 -07:00
Brad Larsen 20c146f558 Add support for sys_arm_fadvise64_64 (#1648)
* Add a type signature for `sys_fadvise64`

* Add a no-op syscall implementation for `sys_arm_fadvise64_64`
2020-04-02 10:51:34 -07:00
Eric Hennenfent a4b3d2cbd9 Add __slots__ to expressions (#1635)
* Restructure SMTLib to avoid multiple inheritance

* Attempt to fix usage of Constant/Variable/Operation outside of expressions

* Fix init arguments

* Fix missing return statement in visit_ArraySelect

* Add Missing ArrayVariable

* Extraneous return statement

* Rename ConstantType, VariableType, and OperationType

Remove the 'Type' to make the diff smaller

* Add __slots__ in Expressions

* Blacken...

* Fix mypy

* Fix dropped array operand

* Return output from visit_operation properly

* Shrink diff

* Shrink Diff 2

* Clean up visitor rewrite

Much smaller diff now

* Maybe this will fix the truffle tests?

Who knows...

* Remove NVM

* Use setdefault for taint

* Add test to check for required properties
2020-04-02 10:27:29 -07:00
Brad Larsen 86bf9e3359 Swap remaining uses of Z3Solver() to use the singleton interface (#1649)
It turns out that in smaller programs, like
examples/linux/binaries/multiple-styles, something like 15-20% of total
runtime is spent redundantly initializing the Z3 solver!
2020-04-02 09:34:30 -07:00
Brad Larsen 87b6badaab CI: have pytest report 100 slowest tests (#1646) 2020-03-31 18:50:31 -05:00
Brad Larsen 969cf9f3d2 Add a syscall implementation for llseek (#1640) (and some type hints)
* Add an implementation of sys_llseek for Linux

* Reformat a couple funny string literals

* Add a docstring for `sys_llseek`

This was taken mainly from the manpage.

* Fix a broken log format string

* Improve logging & exception messages in linux platform

* Update docstring for sys_lseek

* Remove redundant space in mmap mode strings

* Clean up temp files after linux platform tests

* Add some tests for the `sys_lseek`

* blacken tests/native/test_syscalls.py

* Fix implementation of sys_llseek; expand & refine tests

* blacken manticore/platforms/linux.py

* Add some type signatures

* Fix type signatures; add more signatures

* Fix a bad variable reference

* More type signatures; fix typing issues with linux `sys_write()`
2020-03-30 13:24:56 -07:00
sschriner f5e8d7ec4c Added support for proc/self/maps (#1639)
* Added support for proc/self/maps

* Corrected formatting

* Updated ProcSelfMaps object

* Fix for codeclimate

* Updates according to Eric H.'s feedback

* Added a data class for ProcSelfMapInfo. May make a few more adustments to this

* Changed address to a property in ProcSelfMapInfo

* adding a rust binary test

* Added a test for proc self to test_linux

* Updated the address and perms property tests to use a regex

* Updated the regex check
2020-03-30 12:59:07 -07:00
Brad Larsen c5745b6afe Add missing support for ARM modified immediate encodings (#1638)
* Add unit tests for ARMv7 MVN instruction

* Add unit tests for ARMv7 MOV instruction

* Add unit tests for ARMv7 ADD instruction

* Add unit tests for ARMv7 ADC instruction

* Add unit tests for ARMv7 ADR instruction

* Add unit tests for ARMv7 CMN instruction

* Add unit tests for ARMv7 CMP instruction

* Add unit tests for ARMv7 SUB instruction

* Add unit tests for ARMv7 RSC instruction

* Add unit tests for ARMv7 SBC instruction

* Add unit tests for ARMv7 ORR instruction

* Add unit tests for ARMv7 EOR instruction

* Add unit tests for ARMv7 TST instruction

* Add unit tests for ARMv7 TEQ instruction

* Add unit tests for ARMv7 AND instruction

* Add unit tests for ARMv7 RSB instruction

* Add unit tests for ARMv7 BIC instruction

* blacken test_armv7cpu.py

* Enhance the ARMv7 `instruction` decorator to normalize modified immediate values that are split

* Simplify the `Armv7Cpu._bitwise_instruction` method

* Fix ARMv7 MOV implementation for modified immediates

* Fix ARMv7 ADC implementation for modified immediates

* Fix ARMv7 ADD implementation for modified immediates

* Fix ARMv7 RSB implementation for modified immediates

* Fix ARMv7 RSC implementation for modified immediates

* Fix ARMv7 SUB implementation for modified immediates

* Fix ARMv7 SBC implementation for modified immediates

* Fix ARMv7 CMP implementation for modified immediates

* Fix ARMv7 ORR implementation for modified immediates

* Fix ARMv7 ORN implementation for modified immediates

* Fix ARMv7 EOR implementation for modified immediates

* Fix ARMv7 AND implementation for modified immediates

* Fix ARMv7 TEQ implementation for modified immediates

* Fix ARMv7 TST implementation for modified immediates

* Fix ARMv7 CMN implementation for modified immediates

* Fix ARMv7 MVN implementation for modified immediates

* Fix ARMv7 BIC implementation for modified immediates

* blacken manticore/native/cpu/arm.py

* Expand comments about modified immediates; simplify decorator slightly

* Rename parameter to avoid shadowing
2020-03-24 08:11:38 -07:00
Brad LarsenandEric Hennenfent bb0415d519 Transparently compress & decompress persisted state files (#1624)
* `PickleSerializer`: transparently use gzip

* Move an import to the module top-level

* Rename `manticore.core.workspace.Testcase` class to avoid pytest collection warning

* Fix a deprecation warning in workspace test code

* Use a lower compression level on serialized states

The default for Python's GzipFile is `9`, the highest possible
compression level.  This is analagous to the compression level option
for the `gzip` command-line program.

I ran some experiments, and with the default compression level of 9,
serialized state files end up _much_ smaller.  However, Manticore ends
up running measurably slower.  With this change to set the compression
level to `5`, the serialized state files are still much smaller (~13x
smaller than uncompressed), and Manticore runs _faster_ than without any
compression of state files.

* Add a comment & parameterize a magic number

* Use `.pkl.gz` for compressed pickle state file extension

* Decrease compression level to gzip minimum

This maybe makes things run faster, but also does not seem to decrease
the compression ratio seen for state pickle files.

* Revert "Use `.pkl.gz` for compressed pickle state file extension"

This reverts commit c148e61f9f.

* Add config variable to disable compression

* Fix missing decompression parameter

Co-authored-by: Eric Hennenfent <[email protected]>
2020-03-23 10:11:04 -07:00
Eric Hennenfent e86bffef33 Attempt to fix Truffle tests (#1637)
* Maybe this will fix the truffle tests?

Who knows...

* Remove NVM
2020-03-21 14:04:41 -07:00
feliam 9829324582 Skip basic blocks that unavoidably end in REVERT. (#1630)
* Skip revert quick mode fix 1593

* blkn

* Debuging tests
2020-03-20 15:38:09 -07:00
feliam 384e670d78 Fix gas (#1633) 2020-03-13 15:42:59 -03:00
Samuel E. Moelius abb4fc05a3 Include invalid transaction type in exception message (#1632)
* Update evm.py

* Update evm.py
2020-03-13 10:30:28 -03:00
Samuel E. Moelius 2c774db3e7 Update make_VMTests.py (#1628) 2020-03-10 12:45:59 -07:00
Samuel E. Moelius 95e6c81554 Update manticore.py (#1627) 2020-03-10 07:56:53 -07:00