From 1884d4c79f5c91b691e5387bc535aab3326212c7 Mon Sep 17 00:00:00 2001 From: Luca Daniel Date: Mon, 26 Nov 2018 16:34:14 +0200 Subject: [PATCH] Trim 0x prefix on codecopy state transition (Issue #705) (#729) * Trim 0x prefix on codecopy state transition * Trimming 0x before sending to `load_from_bytecode()` * Delete config.ini * Remove unused trim0x function * Reformat instructions.py with black * Update mythril/interfaces/cli.py More idiomatic, thanks Co-Authored-By: cleanunicorn * Changes based on review, more idiomatic * Trim 0x with oneliner if for code loaded from file --- mythril/interfaces/cli.py | 4 +++- mythril/laser/ethereum/instructions.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 53019fcf..90a5975d 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -325,9 +325,11 @@ def main(): if args.code: # Load from bytecode - address, _ = mythril.load_from_bytecode(args.code, args.bin_runtime) + code = args.code[2:] if args.code.startswith("0x") else args.code + address, _ = mythril.load_from_bytecode(code, args.bin_runtime) elif args.codefile: bytecode = "".join([l.strip() for l in args.codefile if len(l.strip()) > 0]) + bytecode = bytecode[2:] if bytecode.startswith("0x") else bytecode address, _ = mythril.load_from_bytecode(bytecode, args.bin_runtime) elif args.address: # Get bytecode from a contract address diff --git a/mythril/laser/ethereum/instructions.py b/mythril/laser/ethereum/instructions.py index 4cbc06c5..7ade087d 100644 --- a/mythril/laser/ethereum/instructions.py +++ b/mythril/laser/ethereum/instructions.py @@ -706,7 +706,7 @@ class Instruction: if size == 0 and isinstance( global_state.current_transaction, ContractCreationTransaction ): - if concrete_code_offset >= len(global_state.environment.code.bytecode) // 2: + if concrete_code_offset >= len(bytecode) // 2: global_state.mstate.mem_extend(concrete_memory_offset, 1) global_state.mstate.memory[ concrete_memory_offset