Refactor and update unit test

pull/22/head
Bernhard Mueller 7 years ago
parent 0e3597bd69
commit 3c6f35a771
  1. 2
      myth
  2. 2
      mythril/analysis/callgraph.py
  3. 18
      mythril/analysis/ops.py
  4. 4
      mythril/analysis/symbolic.py
  5. 17
      tests/svm_test.py

@ -5,7 +5,6 @@
""" """
from mythril.ether import evm, util from mythril.ether import evm, util
from mythril.disassembler.callgraph import generate_graph
from mythril.ether.contractstorage import get_persistent_storage from mythril.ether.contractstorage import get_persistent_storage
from mythril.ether.ethcontract import ETHContract from mythril.ether.ethcontract import ETHContract
from mythril.ether.util import compile_solidity from mythril.ether.util import compile_solidity
@ -14,6 +13,7 @@ from mythril.ipc.client import EthIpc
from mythril.support.loader import DynLoader from mythril.support.loader import DynLoader
from mythril.exceptions import CompilerError from mythril.exceptions import CompilerError
from mythril.analysis.symbolic import StateSpace from mythril.analysis.symbolic import StateSpace
from mythril.analysis.callgraph import generate_graph
from mythril.analysis.security import fire_lasers from mythril.analysis.security import fire_lasers
from ethereum import utils from ethereum import utils
from pathlib import Path from pathlib import Path

@ -133,7 +133,7 @@ def serialize(statespace, color_map):
def generate_graph(statespace, physics): def generate_graph(statespace, physics = False):
i = 0 i = 0

@ -0,0 +1,18 @@
class Call:
def __init__(self, block_uid, addr, call_type, to, value):
self.block_uid = block_uid
self.addr = addr
self.to = to
self.call_type = call_type
self.value = value
class SStore:
def __init__(self, block_uid, addr, index, value):
self.index = index
self.value = value
class SLoad:
def __init__(self, index, value):
self.index = index
self.value = value

@ -25,3 +25,7 @@ class StateSpace:
self.modules = modules self.modules = modules
self.nodes = _svm.nodes self.nodes = _svm.nodes
self.edges = _svm.edges self.edges = _svm.edges
# Analysis

@ -1,19 +1,18 @@
import unittest import unittest
from mythril.disassembler.callgraph import generate_callgraph from mythril.analysis.symbolic import StateSpace
from mythril.disassembler.disassembly import Disassembly from mythril.analysis.callgraph import generate_graph
from laser.ethereum import svm from mythril.ether.ethcontract import ETHContract
class SVMTestCase(unittest.TestCase): class SVMTestCase(unittest.TestCase):
def runTest(self): def runTest(self):
modules = {} code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029"
modules['0x0000000000000000000000000000000000000000'] = {'name': 'metaCoin', 'address': '0x0000000000000000000000000000000000000000', 'creation_code': '', 'code': '60606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806327e235e314610051578063412664ae1461009e575b600080fd5b341561005c57600080fd5b610088600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506100f8565b6040518082815260200191505060405180910390f35b34156100a957600080fd5b6100de600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610110565b604051808215151515815260200191505060405180910390f35b60006020528060005260406000206000915090505481565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561016157600090506101fe565b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550600090505b929150505600a165627a7a72305820fd4fa106da498514e90965a45ffecc1da53a0cd8bb7a7135910f8612245a46370029'}
modules['0x0000000000000000000000000000000000000000']['disassembly'] = Disassembly(modules['0x0000000000000000000000000000000000000000']['code'])
_svm = svm.SVM(modules) contract = ETHContract(code)
statespace = StateSpace([contract])
html = generate_callgraph(_svm, '0x0000000000000000000000000000000000000000', False) html = generate_graph(statespace)
self.assertTrue("0 PUSH1 0x60\\n2 PUSH1 0x40\\n4 MSTORE\\n5 PUSH1 0x04\\n" in html) self.assertTrue("0 PUSH1 0x60\\n2 PUSH1 0x40\\n4 MSTORE\\n5 JUMPDEST" in html)

Loading…
Cancel
Save