From 5bae571074100b25ca01741486f1d2881f65944d Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Thu, 8 Mar 2018 20:31:49 +0700 Subject: [PATCH] Refactor --- myth | 14 +++++++------- .../analysis/modules/call_to_dynamic_with_gas.py | 3 ++- mythril/analysis/symbolic.py | 6 ++---- mythril/support/truffle.py | 7 +++---- tests/svm_test.py | 6 +++--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/myth b/myth index d52e7cc1..2a3157a4 100755 --- a/myth +++ b/myth @@ -15,7 +15,7 @@ from mythril.support import signatures from mythril.support.truffle import analyze_truffle_project from mythril.support.loader import DynLoader 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.security import fire_lasers from mythril.analysis.report import Report @@ -366,16 +366,16 @@ elif (args.graph) or (args.fire_lasers): # try: 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: - states = StateSpace(contracts, max_depth=args.max_depth) + sym = SymExecWrapper(contracts, max_depth=args.max_depth) # except: # exitWithError(args.outform, "Symbolic execution error: " + str(e)) if args.enable_physics is not None: physics = True - html = generate_graph(states, args.enable_physics) + html = generate_graph(sym, args.enable_physics) try: with open(args.graph, "w") as f: @@ -392,13 +392,13 @@ elif (args.graph) or (args.fire_lasers): # try: 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: - states = StateSpace([contract], max_depth=args.max_depth) + sym = SymExecWrapper([contract], max_depth=args.max_depth) # except Exception as e: # exitWithError(args.outform, "Symbolic exection error: " + str(e)) - issues = fire_lasers(states) + issues = fire_lasers(sym) if len(issues): diff --git a/mythril/analysis/modules/call_to_dynamic_with_gas.py b/mythril/analysis/modules/call_to_dynamic_with_gas.py index 526baec0..42174e00 100644 --- a/mythril/analysis/modules/call_to_dynamic_with_gas.py +++ b/mythril/analysis/modules/call_to_dynamic_with_gas.py @@ -11,6 +11,7 @@ MODULE DESCRIPTION: Check for call.value()() to an untrusted address ''' + def execute(statespace): 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): - description += "an address provided as a function argument. " + description += "an address provided as a function argument." else: description += "the address of the transaction sender. " diff --git a/mythril/analysis/symbolic.py b/mythril/analysis/symbolic.py index b49576eb..7a88002f 100644 --- a/mythril/analysis/symbolic.py +++ b/mythril/analysis/symbolic.py @@ -4,10 +4,10 @@ import copy 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): @@ -24,8 +24,6 @@ class StateSpace: self.laser = svm.LaserEVM(self.accounts, dynamic_loader=dynloader, max_depth=max_depth) self.laser.sym_exec(ether.util.get_indexed_address(0)) - # self.modules = modules - self.nodes = self.laser.nodes self.edges = self.laser.edges diff --git a/mythril/support/truffle.py b/mythril/support/truffle.py index 2dfb0a8b..dbf5ef27 100644 --- a/mythril/support/truffle.py +++ b/mythril/support/truffle.py @@ -4,7 +4,7 @@ import sys import json from mythril.ether.ethcontract import ETHContract 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 laser.ethereum import helper @@ -36,8 +36,8 @@ def analyze_truffle_project(args): ethcontract = ETHContract(bytecode, name=name) - states = StateSpace([ethcontract], max_depth=10) - issues = fire_lasers(states) + sym = SymExecWrapper([ethcontract], max_depth=10) + issues = fire_lasers(sym) if not len(issues): if (args.outform == 'text' or args.outform == 'markdown'): @@ -56,7 +56,6 @@ def analyze_truffle_project(args): deployedSourceMap = contractdata['deployedSourceMap'].split(";") mappings = [] - i = 0 for item in deployedSourceMap: diff --git a/tests/svm_test.py b/tests/svm_test.py index 4d651065..61c99ec7 100644 --- a/tests/svm_test.py +++ b/tests/svm_test.py @@ -1,5 +1,5 @@ import unittest -from mythril.analysis.symbolic import StateSpace +from mythril.analysis.symbolic import SymExecWrapper from mythril.analysis.callgraph import generate_graph from mythril.ether.ethcontract import ETHContract @@ -11,8 +11,8 @@ class SVMTestCase(unittest.TestCase): code = "0x60606040525b603c5b60006010603e565b9050593681016040523660008237602060003683856040603f5a0204f41560545760206000f35bfe5b50565b005b73c3b2ae46792547a96b9f84405e36d0e07edcd05c5b905600a165627a7a7230582062a884f947232ada573f95940cce9c8bfb7e4e14e21df5af4e884941afb55e590029" 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)