Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
make oyente pip-installable
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson committed Jul 23, 2017
1 parent b30e1ed commit b928eee
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 23 deletions.
22 changes: 15 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
tmp/
tmp
*.pyc
contract_data
*.sol
*.disasm
*.evm
*.log
*.disasm
*.pyc
*.report
*.sol

.DS_Store
.idea/

.idea/dist/

contract_data
dist/
tmp/

current_test.pickle

bytecode
bytecode.1
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ UNIT_TEST = 3

```
# Start testing
$ python test_evm.py
$ python oyenete/run_tests.py
```

After running the testing program, the result would display a status for each testcase:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Note - If need the [version of Oyente](https://github.com/melonproject/oyente/tr
## Full install

### Install the following dependencies
#### solc v0.4.10
#### solc v0.4.13
```
$ sudo add-apt-repository ppa:ethereum/ethereum
$ sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion code.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The flow of testing:
- Compare the results (storage, memory and gas) after running oyente with the results being specified in the test data
- Report bugs

#### *test_evm.py*
#### *run_tests.py*
This is the main entry point to the testing program. The program loads a specific test data file in folder ```test_evm/test_data/``` and start running `oyente.py `with the input being specified in the loaded test data to get an exit code which is returned from `oyente.py.` From this exit code the testing program can report the bug

#### *evm_unit_test.py*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions oyente.py → oyente/oyente.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import shlex
import subprocess
import os
Expand Down
35 changes: 27 additions & 8 deletions test_evm.py → oyente/run_tests.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import json
#!/usr/bin/env python

import glob
import json
import os
import pickle
from test_evm.global_test_params import *

os.chdir(os.path.dirname(__file__))

from test_evm.global_test_params import (
PASS, FAIL, TIME_OUT, UNKOWN_INSTRUCTION, EXCEPTION, EMPTY_RESULT,
INCORRECT_GAS, PICKLE_PATH)
from test_evm.evm_unit_test import EvmUnitTest


def status(exit_code):
if exit_code == 100: return "Pass"
if exit_code == 101: return "Fail"
Expand All @@ -14,13 +22,15 @@ def status(exit_code):
if exit_code == 105: return "Empty result"
if exit_code == 106: return "Incorrect gas tracked"

return str(exit_code)


def main():
test_dir = 'test_evm/test_data'
files = glob.glob(test_dir+'/vmArithmeticTest.json')
files = glob.glob(test_dir + '/vmArithmeticTest.json')
test_cases = {}

num_tests = num_passes = num_fails = \
num_tests = num_passes = num_fails = \
num_time_outs = num_unkown_instrs = \
num_exceptions = num_empty_res = num_incorrect_gas = 0

Expand All @@ -40,14 +50,19 @@ def main():
print "===============Loading: %s====================" % testname

current_test = EvmUnitTest(testname, testdata)
pickle.dump(current_test, open("current_test.pickle", "wb"))

pickle.dump(current_test, open(PICKLE_PATH, 'wb'), pickle.HIGHEST_PROTOCOL)

exit_code = current_test.run_test()

# Special case when symExec run into exception but it is correct result
if exit_code == EXCEPTION and current_test.is_exception_case():
exit_code = PASS

print "===============%s!====================" % status(exit_code).upper()
if exit_code:
print "===============%s!====================" % status(exit_code).upper()
else:
print "no exit code returned"

testname = testname.encode('utf8')
num_tests += 1
Expand Down Expand Up @@ -93,8 +108,12 @@ def main():


def remove_temporary_files():
if os.path.isfile("./bytecode"): os.system("rm bytecode")
if os.path.isfile("./current_test.pickle"): os.system("rm current_test.pickle")
if os.path.isfile('./bytecode'):
os.unlink('./bytecode')

if os.path.isfile(PICKLE_PATH):
os.unlink(PICKLE_PATH)


if __name__ == '__main__':
main()
File renamed without changes.
6 changes: 4 additions & 2 deletions symExec.py → oyente/symExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from analysis import *
from utils import retrieveFunctionSignatures, retrieveFunctionNames
import global_params
from test_evm.global_test_params import *

from test_evm.global_test_params import (TIME_OUT, UNKOWN_INSTRUCTION,
EXCEPTION, PICKLE_PATH)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -126,7 +128,7 @@ def compare_stack_unit_test(stack):
log.warning(e.message)

def compare_storage_and_memory_unit_test(global_state, mem, analysis):
unit_test = pickle.load(open("current_test.pickle", "rb"))
unit_test = pickle.load(open(PICKLE_PATH, 'rb'))
test_status = unit_test.compare_with_symExec_result(global_state, mem, analysis)
exit(test_status)

Expand Down
Empty file added oyente/test_evm/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os

from z3 import *
from global_test_params import *

from global_params import *
from utils import to_unsigned

from .global_test_params import *


class EvmUnitTest(object):
def __init__(self, name, data):
self.name = name
Expand All @@ -28,7 +32,6 @@ def gas_info(self):
gas_remaining = long(self.data['gas'], 0)
return (gas_limit, gas_remaining)


def run_test(self):
return self._execute_vm(self.bytecode())

Expand Down Expand Up @@ -86,7 +89,6 @@ def _compare_gas_value(self, analysis):
else:
return INCORRECT_GAS


def compare_symbolic(self, global_state):
for key, value in self.storage().items():
key, value = long(key, 0), long(value, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
EXCEPTION = 104
EMPTY_RESULT = 105
INCORRECT_GAS = 106

PICKLE_PATH = 'current_test.pickle'
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from setuptools import find_packages, setup

setup(
name='oyente',
version='1.0.0',
author='Loi Luu',
# author_email='',
url='https://github.com/melonport/oyente',
description='An analysis tool for smart contracts',
long_description=open('README.md').read(),
license='GPL',
keywords='ethereum smart contracts',
classifiers=[
'Environment :: Console',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python',
'Topic :: Utilities',
],
packages=find_packages(),
package_data={
'oyente': ['state.json'],
},
entry_points={
'console_scripts': [
'oyente = oyente.oyente:main',
]
},
install_requires=[
'requests',
'web3',
]
)

0 comments on commit b928eee

Please sign in to comment.