Giter Club home page Giter Club logo

dry-analyzer's Introduction

Dr. Y's Ethereum Contract Analyzer

Online version

How to use

  • Install OCaml (4.02.3 works) and opam
  • opam install lwt cohttp coq getopt batteries ocamlnet
  • make
  • ./main.native -p 9999
  • access localhost:9999
  • paste some EVM bytecode (beginning from 0x) in the text box
  • hit "Analyze" button
  • the analyzer tells what the bytecode does, to some point

LICENSE

  • big.ml comes from the Coq development team under LGPL version 2.1
  • The other files are currently distributed with LGPL version 2.1.

dry-analyzer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dry-analyzer's Issues

VM trace log enricher

geth has a method traceTransaction that prints a log of EVM execution. The log contains stack elements, but it is not immediate to know the origin of the numbers in the stack.

This issue keeps track of creating a command-line tool that enriches the log with more information.

Input has:

stack: ["00000000000000000000000000000000000000000000000000000000d67cbec9"],

The output should contain:

stack: [{val: "00000000000000000000000000000000000000000000000000000000d67cbec9",
            symbol: "blocknumber"
           }],

Consider divide by zero

A division instruction should produce two behaviors, one for divide by zero and the other for divide by non-zero. (When the divisor is known to be non-zero, only one behavior is fine.)

Instructions involving division return zero when the divisor is zero. This should be taken into account for *DIV and *MOD instructions.

Design classification of expressions

For #28, it is necessary to classify abstract expressions according to if they are controllable by the caller.

This issue keeps track of creating a classification.

Error: The implementation CoqNat.ml does not match the interface CoqNat.cmi: Values do not match: val zero : int is not included in val zero : Decimal.int File "CoqNat.mli", line 6, characters 0-14: Expected declaration File "CoqNat.ml", line 8, characters 4-8: Actual declaration Command exited with code 2. Compilation unsuccessful after building 38 targets (0 cached) in 00:00:01.

when I make ,errors blow.Can you help me?

Error: The implementation CoqNat.ml does not match the interface CoqNat.cmi:
Values do not match:
val zero : int
is not included in
val zero : Decimal.int
File "CoqNat.mli", line 6, characters 0-14: Expected declaration
File "CoqNat.ml", line 8, characters 4-8: Actual declaration
Command exited with code 2.
Compilation unsuccessful after building 38 targets (0 cached) in 00:00:01.

Build failure: Nat.ltb was not found in the current environment

make command as per the instruction in README failed with coqc compile error.

$ make
coqc evm.v
File "/home/dcsandr/software/dry-analyzer/evm.v", line 1263, characters 21-28:
Error: The reference Nat.ltb was not found in the current environment.
Makefile:15: recipe for target 'evm.vo' failed
make: *** [evm.vo] Error 1

Following is my version of coqc:

$ coqc --version
The Coq Proof Assistant, version 8.4pl4 (November 2015)
compiled on Nov 04 2015 12:56:53 with OCaml 4.02.3

I'm using Ubuntu 16.04.

Consider the max size of the stack

The yellow paper now says the run-time stack has the limit of 1024 items. The stack has a maximum size of 1024. The analyzer should be made aware of this, and when the stack size exceeds the limit, the resulting state should be failure.

What happens after `CALL`

Currently the analyzer stops at a CALL instruction. This issue keeps track of fixing this. After the call there would be three cases

  1. the callee returns
  2. the callee fails
  3. the callee somehow calls back the original contract

exit criteria
Cases 1. and 2. should be implemented. A message should be shown for case 3. Also a github issue should be created for dealing with reentrancy in the analyzer.

if taken memory is known, do not continue

(take (0x7ca) bytes at (0xc0) from
(codecopy mem: (0xc0), code: (0x23c), size: (0x7ca), on
(mem_write32 addr: (0x40) val: (0x88a) in ...

should be just

(take (0x7ca) bytes at (0xc0) from
(codecopy mem: (0xc0), code: (0x23c), size: (0x7ca), on (empty))

Focus on one execution path.

  • design a url scheme for specifying a specific execution path (a sequence of booleans?)
  • encode and decode such url scheme
  • use the decode scheme to narrow down the execution path
  • use the encode scheme to show links for "investigate this path."

Need explanation of an ouput

After clicking the "Analyze" button on the web interface, I've got the following report. How do I read it? Thanks in advance.

Behaviors

2 behaviors cover the possibilities (assuming enough gas).

back fwd
Behavior 0

under conditions:

    (value of this call) is not zero.

hits an unimplemented instruction UNKNOWN fd in this analyzer.
Behavior 1

under conditions:

    (value of this call) is zero.

returns with output
(take (0x1bd6) bytes at (0x0) from
(codecopy mem: (0x0), code: (0xd4), size: (0x1bd6), on
(mem_write32 addr: (0x20) val: (0x1) in
(mem_write32 addr: (0x0) val: ((0xffffffffffffffffffffffffffffffffffffffff) and ((0xffffffffffffffffffffffffffffffffffffffff) and (address of caller))) in
(mem_write32 addr: (0x40) val: (0x60) in
(empty)
)
)
)
)
)
and state {
last instruction: PUSH_N0x00
stack: [(0x0), (0x1bd6)](size 2)
memory:
(codecopy mem: (0x0), code: (0xd4), size: (0x1bd6), on
(mem_write32 addr: (0x20) val: (0x1) in
(mem_write32 addr: (0x0) val: ((0xffffffffffffffffffffffffffffffffffffffff) and ((0xffffffffffffffffffffffffffffffffffffffff) and (address of caller))) in
(mem_write32 addr: (0x40) val: (0x60) in
(empty)
)
)
)
)

storage:
(storage_write at: (sha3 (concat ((0xffffffffffffffffffffffffffffffffffffffff) and ((0xffffffffffffffffffffffffffffffffffffffff) and (address of caller))) (0x1))), val: ((0x1dcd6500) * ((0xa) ** ((0xff) and (0x12))))
(storage_write at: (0x0), val: ((0x1dcd6500) * ((0xa) ** ((0xff) and (0x12))))
(storage_write at: (0x3), val: ((((0xffffffffffffffffffffffffffffffffffffffff) and (address of caller)) * (0x1)) or ((not ((0xffffffffffffffffffffffffffffffffffffffff) * (0x1))) and (((0x0) * (0x10000000000000000000000000000000000000000)) or ((not ((0xff) * (0x10000000000000000000000000000000000000000))) and (get_storage (0x3) (initial storage))))))
(storage_write at: (0x3), val: (((0x0) * (0x10000000000000000000000000000000000000000)) or ((not ((0xff) * (0x10000000000000000000000000000000000000000))) and (get_storage (0x3) (initial storage))))
(initial storage)
)
)
)
)

log: XXX
remaining_program: XXX
}. 

Simplify concatenation on memory

(take (0x40) bytes at (0x0) from (mem_write32 addr: (0x20) val: (0x0) in (mem_write32 addr: (0x0) val: (get32 (0x4) (input data)) in (empty)))

can be reduced into

(concat (get32 (0x4) (input data)) (0x0))

a_mem_to_str: codecopy not implemented

In case of runtime failure, show the last instruction.

causes runtime error with state {
stack: [(0x2)](size 1)
memory:
(mem_write32 addr: (0x40) val: (0x60) in
(empty)
)

storage:
(storage_write at: (0x0), val: (0x23)
(initial storage)
)

log: XXX
remaining_program: XXX
}. 

UI/UX Update

Would love to also help out here. Do you have a specific look/feel you're going for? Also, mention: @aupiff.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.