From 61babdbe21b99c93c74d7ccecbf520108071761a Mon Sep 17 00:00:00 2001 From: Yan Ivnitskiy Date: Mon, 12 Mar 2018 15:27:18 -0400 Subject: [PATCH] Fix evm RETURN implementation (#808) * Fix write_buffer issue (#807) * Add test for write_buffer fix * Use Operators.ORD instead of ord (even though were assuming concrete vals) * Cleanup --- manticore/platforms/evm.py | 6 ++---- tests/test_eth.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/manticore/platforms/evm.py b/manticore/platforms/evm.py index 261e730..81cb576 100644 --- a/manticore/platforms/evm.py +++ b/manticore/platforms/evm.py @@ -1805,10 +1805,8 @@ class EVM(Eventful): return data def write_buffer(self, offset, buf): - count = 0 - for c in buf: - self._store(offset + count, c) - count += 1 + for i, c in enumerate(buf): + self._store(offset+i, Operators.ORD(c)) def CREATE(self, value, offset, size): '''Create a new account with associated code''' diff --git a/tests/test_eth.py b/tests/test_eth.py index bbdf612..23c3b3e 100644 --- a/tests/test_eth.py +++ b/tests/test_eth.py @@ -102,3 +102,23 @@ class EthTests(unittest.TestCase): x = mevm.create_account(balance=0) contract_account = mevm.solidity_create_contract(source_code, contract_name="C", owner=owner, args=[x]) + + def test_writebuffer_doesnt_raise(self): + mevm = ManticoreEVM() + source_code = """ + contract X { + mapping(address => uint) private balance; + function f(address z) returns (uint) { return balance[z]; } + } + contract C { + X y; + function C() { + y = new X(); + uint z = y.f(0); + } + }""" + # Make sure that write_buffer (used by RETURN) succeeds without errors + owner = mevm.create_account(balance=1000) + x = mevm.create_account(balance=0) + contract_account = mevm.solidity_create_contract(source_code, + contract_name="C", owner=owner, args=[x])