From 534e2f7cc086719576105596772909c846e2d93a Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Wed, 25 Jul 2018 16:06:40 +0200 Subject: [PATCH] Adds concrete codecopy test --- mythril/laser/ethereum/instructions.py | 2 +- tests/instructions/__init__.py | 0 tests/instructions/codecopy_test.py | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/instructions/__init__.py create mode 100644 tests/instructions/codecopy_test.py diff --git a/mythril/laser/ethereum/instructions.py b/mythril/laser/ethereum/instructions.py index ba23241c..8c50219e 100644 --- a/mythril/laser/ethereum/instructions.py +++ b/mythril/laser/ethereum/instructions.py @@ -549,7 +549,7 @@ class Instruction: for i in range(concrete_size): try: global_state.mstate.memory[concrete_memory_offset + i] =\ - int(bytecode[concrete_code_offset + i: concrete_code_offset + i + 2], 16) + int(bytecode[2*(concrete_code_offset + i): 2*(concrete_code_offset + i + 1)], 16) except IndexError: global_state.mstate.memory[concrete_memory_offset + i] = \ BitVec("code({})".format(global_state.environment.active_account.contract_name), 256) diff --git a/tests/instructions/__init__.py b/tests/instructions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/instructions/codecopy_test.py b/tests/instructions/codecopy_test.py new file mode 100644 index 00000000..53ae049d --- /dev/null +++ b/tests/instructions/codecopy_test.py @@ -0,0 +1,20 @@ +from mythril.disassembler.disassembly import Disassembly +from mythril.laser.ethereum.state import MachineState, GlobalState, Environment, Account +from mythril.laser.ethereum.instructions import Instruction + + +def test_codecopy_concrete(): + # Arrange + active_account = Account("0x0", code= Disassembly("60606040")) + environment = Environment(active_account, None, None, None, None, None) + og_state = GlobalState(None, environment, None, MachineState(gas=10000000)) + + og_state.mstate.stack = [2, 2, 2] + instruction = Instruction("codecopy", dynamic_loader=None) + + # Act + new_state = instruction.evaluate(og_state)[0] + + # Assert + assert new_state.mstate.memory[2] == 96 + assert new_state.mstate.memory[3] == 64