From 9cd76d43fd148bf287290298cac1ec979b98a39c Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 3 Nov 2014 23:49:05 +0100 Subject: [PATCH 1/3] Fix ABAcalls OOG bug --- alethzero/MainWin.cpp | 4 ++-- libethereum/ExtVM.h | 2 +- libevm/ExtVMFace.cpp | 2 +- libevm/ExtVMFace.h | 4 ++-- test/createRandomTest.cpp | 4 ++-- test/state.cpp | 4 +--- test/vm.cpp | 10 +++++----- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index f413532b7..308df9947 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1344,7 +1344,7 @@ void Main::populateDebugger(dev::bytesConstRef _r) debugFinished(); vector levels; m_codes.clear(); - bytesConstRef lastExtCode; + bytes lastExtCode; bytesConstRef lastData; h256 lastHash; h256 lastDataHash; @@ -1357,7 +1357,7 @@ void Main::populateDebugger(dev::bytesConstRef _r) lastExtCode = ext.code; lastHash = sha3(lastExtCode); if (!m_codes.count(lastHash)) - m_codes[lastHash] = ext.code.toBytes(); + m_codes[lastHash] = ext.code; } if (ext.data != lastData) { diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index cf80b2352..b1dbdbdc7 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -40,7 +40,7 @@ class ExtVM: public ExtVMFace public: /// Full constructor. ExtVM(State& _s, Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, Manifest* o_ms, unsigned _depth = 0): - ExtVMFace(_myAddress, _caller, _origin, _value, _gasPrice, _data, _code, _s.m_previousBlock, _s.m_currentBlock, _depth), m_s(_s), m_origCache(_s.m_cache), m_ms(o_ms) + ExtVMFace(_myAddress, _caller, _origin, _value, _gasPrice, _data, _code.toBytes(), _s.m_previousBlock, _s.m_currentBlock, _depth), m_s(_s), m_origCache(_s.m_cache), m_ms(o_ms) { m_s.ensureCached(_myAddress, true, true); } diff --git a/libevm/ExtVMFace.cpp b/libevm/ExtVMFace.cpp index da189d899..b30d3d77d 100644 --- a/libevm/ExtVMFace.cpp +++ b/libevm/ExtVMFace.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace dev; using namespace dev::eth; -ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth): +ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth): myAddress(_myAddress), caller(_caller), origin(_origin), diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 5b26c3792..a8ebddabb 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -96,7 +96,7 @@ public: ExtVMFace() = default; /// Full constructor. - ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth); + ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth); virtual ~ExtVMFace() = default; @@ -145,7 +145,7 @@ public: u256 value; ///< Value (in Wei) that was passed to this address. u256 gasPrice; ///< Price of gas (that we already paid). bytesConstRef data; ///< Current input data. - bytesConstRef code; ///< Current code that is executing. + bytes code; ///< Current code that is executing. BlockInfo previousBlock; ///< The previous block's information. BlockInfo currentBlock; ///< The current block's information. SubState sub; ///< Sub-band VM state (suicides, refund counter, logs). diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index 28e4342d7..457478fd1 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -134,10 +134,10 @@ void doMyTests(json_spirit::mValue& v) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code) + if (!fev.code.size()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); - fev.code = &fev.thisTxCode; + fev.code = fev.thisTxCode; } vm.reset(fev.gas); diff --git a/test/state.cpp b/test/state.cpp index 3a81821ef..cc772f2c9 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -20,8 +20,6 @@ * State test functions. */ -#define FILL_TESTS - #include #include #include "JsonSpiritHeaders.h" @@ -60,7 +58,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) if (_fillin) { importer.code = importer.m_statePre.code(importer.m_environment.myAddress); - importer.m_environment.code = &importer.code; + importer.m_environment.code = importer.code; } State theState = importer.m_statePre; diff --git a/test/vm.cpp b/test/vm.cpp index 4061d789e..876706711 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -29,7 +29,7 @@ using namespace dev::eth; using namespace dev::test; FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix. - ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock, _depth) {} + ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, _depth) {} h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&) { @@ -206,11 +206,11 @@ void FakeExtVM::importExec(mObject& _o) gas = toInt(_o["gas"]); thisTxCode.clear(); - code = &thisTxCode; + code = thisTxCode; thisTxCode = importCode(_o); if (_o["code"].type() != str_type && _o["code"].type() != array_type) - code.reset(); + code.clear(); thisTxData.clear(); thisTxData = importData(_o); @@ -303,10 +303,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code) + if (!fev.code.size()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); - fev.code = &fev.thisTxCode; + fev.code = fev.thisTxCode; } bytes output; From fb9aeba3a3c5eec240676678122d9d6addd30c6e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 14:10:00 +0100 Subject: [PATCH 2/3] Clean up state tests --- test/TestHelper.h | 1 - test/state.cpp | 14 -------------- test/tmpFiller.json | 44 -------------------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 test/tmpFiller.json diff --git a/test/TestHelper.h b/test/TestHelper.h index 622b83ac4..a4eb64d84 100644 --- a/test/TestHelper.h +++ b/test/TestHelper.h @@ -57,7 +57,6 @@ public: eth::State m_statePost; eth::ExtVMFace m_environment; eth::Transaction m_transaction; - bytes code; private: json_spirit::mObject& m_TestObject; diff --git a/test/state.cpp b/test/state.cpp index 4034b4b73..935869058 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -55,12 +55,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) ImportTest importer(o, _fillin); - if (_fillin) - { - importer.code = importer.m_statePre.code(importer.m_environment.myAddress); - importer.m_environment.code = importer.code; - } - State theState = importer.m_statePre; bytes tx = importer.m_transaction.rlp(); bytes output; @@ -124,12 +118,4 @@ BOOST_AUTO_TEST_CASE(stSystemOperationsTest) dev::test::executeTests("stSystemOperationsTest", "/StateTests", dev::test::doStateTests); } -BOOST_AUTO_TEST_CASE(tmp) -{ - int currentVerbosity = g_logVerbosity; - g_logVerbosity = 12; - dev::test::executeTests("tmp", "/StateTests", dev::test::doStateTests); - g_logVerbosity = currentVerbosity; -} - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/tmpFiller.json b/test/tmpFiller.json deleted file mode 100644 index bd27b8907..000000000 --- a/test/tmpFiller.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "ABAcalls0": { - "env" : { - "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", - "currentNumber" : "0", - "currentGasLimit" : "10000000", - "currentDifficulty" : "256", - "currentTimestamp" : 1, - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" - }, - "pre" : { - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "1000000000000000000", - "nonce" : 0, - "code" : "{ [[ (PC) ]] (CALL 1000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 24 0 0 0 0) }", - "storage": {} - }, - "945304eb96065b2a98b57a48a06ae28d285a71b5" : { - "balance" : "23", - "code" : " { [[ (PC) ]] (ADD 1 (CALL 500 0x095e7baea6a6c7c4c2dfeb977efac326af552d87 23 0 0 0 0)) } ", - "nonce" : "0", - "storage" : { - } - }, - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "1000000000000000000", - "nonce" : 0, - "code" : "", - "storage": {} - } - - }, - "transaction" : { - "nonce" : "0", - "gasPrice" : "1", - "gasLimit" : "10000", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "100000", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "data" : "" - } - } - -} From 28e7b6c6103d859e83bea39bec2d9f60ee956b5e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 15:16:42 +0100 Subject: [PATCH 3/3] style --- libevm/ExtVMFace.cpp | 2 +- libevm/ExtVMFace.h | 2 +- test/createRandomTest.cpp | 2 +- test/vm.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libevm/ExtVMFace.cpp b/libevm/ExtVMFace.cpp index b30d3d77d..8a08a290c 100644 --- a/libevm/ExtVMFace.cpp +++ b/libevm/ExtVMFace.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace dev; using namespace dev::eth; -ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth): +ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes const& _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth): myAddress(_myAddress), caller(_caller), origin(_origin), diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 5252a062a..8a6b2edc9 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -104,7 +104,7 @@ public: ExtVMFace() = default; /// Full constructor. - ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth); + ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes const& _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, unsigned _depth); virtual ~ExtVMFace() = default; diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index a9a993776..f74be9304 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -134,7 +134,7 @@ void doMyTests(json_spirit::mValue& v) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code.size()) + if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode; diff --git a/test/vm.cpp b/test/vm.cpp index a093966d4..93cf121de 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -289,7 +289,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code.size()) + if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode;