pull/62/merge
Bernhard Mueller 7 years ago
parent c31da1d39d
commit 5bae571074
  1. 14
      myth
  2. 3
      mythril/analysis/modules/call_to_dynamic_with_gas.py
  3. 6
      mythril/analysis/symbolic.py
  4. 7
      mythril/support/truffle.py
  5. 6
      tests/svm_test.py

14
myth

@ -15,7 +15,7 @@ from mythril.support import signatures
from mythril.support.truffle import analyze_truffle_project from mythril.support.truffle import analyze_truffle_project
from mythril.support.loader import DynLoader from mythril.support.loader import DynLoader
from mythril.exceptions import CompilerError, NoContractFoundError from mythril.exceptions import CompilerError, NoContractFoundError
from mythril.analysis.symbolic import StateSpace from mythril.analysis.symbolic import SymExecWrapper
from mythril.analysis.callgraph import generate_graph from mythril.analysis.callgraph import generate_graph
from mythril.analysis.security import fire_lasers from mythril.analysis.security import fire_lasers
from mythril.analysis.report import Report from mythril.analysis.report import Report
@ -366,16 +366,16 @@ elif (args.graph) or (args.fire_lasers):
# try: # try:
if (args.dynld): if (args.dynld):
states = StateSpace(contracts, dynloader=DynLoader(eth), max_depth=args.max_depth) sym = SymExecWrapper(contracts, dynloader=DynLoader(eth), max_depth=args.max_depth)
else: else:
states = StateSpace(contracts, max_depth=args.max_depth) sym = SymExecWrapper(contracts, max_depth=args.max_depth)
# except: # except:
# exitWithError(args.outform, "Symbolic execution error: " + str(e)) # exitWithError(args.outform, "Symbolic execution error: " + str(e))
if args.enable_physics is not None: if args.enable_physics is not None:
physics = True physics = True
html = generate_graph(states, args.enable_physics) html = generate_graph(sym, args.enable_physics)
try: try:
with open(args.graph, "w") as f: with open(args.graph, "w") as f:
@ -392,13 +392,13 @@ elif (args.graph) or (args.fire_lasers):
# try: # try:
if (args.dynld): if (args.dynld):
states = StateSpace([contract], dynloader=DynLoader(eth), max_depth=args.max_depth) sym = SymExecWrapper([contract], dynloader=DynLoader(eth), max_depth=args.max_depth)
else: else:
states = StateSpace([contract], max_depth=args.max_depth) sym = SymExecWrapper([contract], max_depth=args.max_depth)
# except Exception as e: # except Exception as e:
# exitWithError(args.outform, "Symbolic exection error: " + str(e)) # exitWithError(args.outform, "Symbolic exection error: " + str(e))
issues = fire_lasers(states) issues = fire_lasers(sym)
if len(issues): if len(issues):

@ -11,6 +11,7 @@ MODULE DESCRIPTION:
Check for call.value()() to an untrusted address Check for call.value()() to an untrusted address
''' '''
def execute(statespace): def execute(statespace):
logging.debug("Executing module: CALL_TO_DYNAMIC_WITH_GAS") logging.debug("Executing module: CALL_TO_DYNAMIC_WITH_GAS")
@ -36,7 +37,7 @@ def execute(statespace):
if ("calldata" in target or "caller" in target): if ("calldata" in target or "caller" in target):
if ("calldata" in target): if ("calldata" in target):
description += "an address provided as a function argument. " description += "an address provided as a function argument."
else: else:
description += "the address of the transaction sender. " description += "the address of the transaction sender. "

@ -4,10 +4,10 @@ import copy
from .ops import * from .ops import *
class StateSpace: class SymExecWrapper:
''' '''
Symbolic EVM wrapper Wrapper class for the LASER Symbolic virtual machine. Symbolically executes the code and does a bit of pre-analysis for convenience.
''' '''
def __init__(self, contracts, dynloader=None, max_depth=12): def __init__(self, contracts, dynloader=None, max_depth=12):
@ -24,8 +24,6 @@ class StateSpace:
self.laser = svm.LaserEVM(self.accounts, dynamic_loader=dynloader, max_depth=max_depth) self.laser = svm.LaserEVM(self.accounts, dynamic_loader=dynloader, max_depth=max_depth)
self.laser.sym_exec(ether.util.get_indexed_address(0)) self.laser.sym_exec(ether.util.get_indexed_address(0))
# self.modules = modules
self.nodes = self.laser.nodes self.nodes = self.laser.nodes
self.edges = self.laser.edges self.edges = self.laser.edges

@ -4,7 +4,7 @@ import sys
import json import json
from mythril.ether.ethcontract import ETHContract from mythril.ether.ethcontract import ETHContract
from mythril.analysis.security import fire_lasers from mythril.analysis.security import fire_lasers
from mythril.analysis.symbolic import StateSpace from mythril.analysis.symbolic import SymExecWrapper
from mythril.analysis.report import Report from mythril.analysis.report import Report
from laser.ethereum import helper from laser.ethereum import helper
@ -36,8 +36,8 @@ def analyze_truffle_project(args):
ethcontract = ETHContract(bytecode, name=name) ethcontract = ETHContract(bytecode, name=name)
states = StateSpace([ethcontract], max_depth=10) sym = SymExecWrapper([ethcontract], max_depth=10)
issues = fire_lasers(states) issues = fire_lasers(sym)
if not len(issues): if not len(issues):
if (args.outform == 'text' or args.outform == 'markdown'): if (args.outform == 'text' or args.outform == 'markdown'):
@ -56,7 +56,6 @@ def analyze_truffle_project(args):
deployedSourceMap = contractdata['deployedSourceMap'].split(";") deployedSourceMap = contractdata['deployedSourceMap'].split(";")
mappings = [] mappings = []
i = 0
for item in deployedSourceMap: for item in deployedSourceMap:

@ -1,5 +1,5 @@
import unittest import unittest
from mythril.analysis.symbolic import StateSpace from mythril.analysis.symbolic import SymExecWrapper
from mythril.analysis.callgraph import generate_graph from mythril.analysis.callgraph import generate_graph
from mythril.ether.ethcontract import ETHContract from mythril.ether.ethcontract import ETHContract
@ -11,8 +11,8 @@ class SVMTestCase(unittest.TestCase):
code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029" code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029"
contract = ETHContract(code) contract = ETHContract(code)
statespace = StateSpace([contract]) sym = SymExecWrapper([contract])
html = generate_graph(statespace) html = generate_graph(sym)
self.assertTrue("0 PUSH1 0x60\\n2 PUSH1 0x40\\n4 MSTORE\\n5 JUMPDEST" in html) self.assertTrue("0 PUSH1 0x60\\n2 PUSH1 0x40\\n4 MSTORE\\n5 JUMPDEST" in html)

Loading…
Cancel
Save