diff options
-rw-r--r-- | vm.cpp | 34 | ||||
-rw-r--r-- | vm.h | 9 | ||||
-rw-r--r-- | vmSystemOperationsTestFiller.json | 18 |
3 files changed, 30 insertions, 31 deletions
@@ -22,7 +22,7 @@ #include "vm.h" -//#define FILL_TESTS +#define FILL_TESTS using namespace std; using namespace json_spirit; @@ -30,12 +30,15 @@ using namespace dev; using namespace dev::eth; using namespace dev::test; +FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock): + ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock) {} + h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc) { m_s.noteSending(myAddress); m_ms.internal.resize(m_ms.internal.size() + 1); auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &suicides, &posts, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1); - if ( !m_ms.internal.back().from) + if (!m_ms.internal.back().from) m_ms.internal.pop_back(); if (get<0>(addresses[myAddress]) >= _endowment) @@ -58,18 +61,14 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc, Address, Address) { string codeOf_receiveAddress = toHex(get<3>(addresses[_receiveAddress]) ); - string sizeOfCode = toHex(toCompactBigEndian(codeOf_receiveAddress.size())); + string sizeOfCode = toHex(toCompactBigEndian((codeOf_receiveAddress.size()+1)/2)); - if (codeOf_receiveAddress.size() > 255) - { - cnote << "codesize too large for FakeExtVM\n"; - return false; - } - else if (codeOf_receiveAddress.size()) + if (codeOf_receiveAddress.size()) { - string initStringHex = "0x60" + sizeOfCode + "80600c6000396000f200" + codeOf_receiveAddress; - bytes initBytes = fromHex(initStringHex.substr(2)); - + // create init code that returns given contract code + string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfCode + " ) 0x" + sizeOfCode + ") (RETURN 0 0x" + sizeOfCode +")}"; + bytes initBytes = compileLLL(initStringHex, true, NULL); + initBytes += fromHex(codeOf_receiveAddress); bytesConstRef init(&initBytes); if (!m_s.addresses().count(_receiveAddress)) @@ -77,7 +76,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, m_s.noteSending(myAddress); m_ms.internal.resize(m_ms.internal.size() + 1); auto na = m_s.create(myAddress, 0, gasPrice, _gas, init, origin, &suicides, &posts, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1); - if ( !m_ms.internal.back().from) + if (!m_ms.internal.back().from) m_ms.internal.pop_back(); if (!m_s.addresses().count(_receiveAddress)) { @@ -130,11 +129,13 @@ void FakeExtVM::setTransaction(Address _caller, u256 _value, u256 _gasPrice, byt data = &(thisTxData = _data); gasPrice = _gasPrice; } + void FakeExtVM::setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, map<u256, u256> const& _storage, bytes const& _code) { myAddress = _myAddress; set(myAddress, _myBalance, _myNonce, _storage, _code); } + void FakeExtVM::set(Address _a, u256 _myBalance, u256 _myNonce, map<u256, u256> const& _storage, bytes const& _code) { get<0>(addresses[_a]) = _myBalance; @@ -400,7 +401,6 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) } - namespace dev { namespace test { void doTests(json_spirit::mValue& v, bool _fillin) @@ -428,6 +428,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = &fev.thisTxCode; } + vm.reset(fev.gas); bytes output; try @@ -523,7 +524,8 @@ void doTests(json_spirit::mValue& v, bool _fillin) return json_spirit::write_string(json_spirit::mValue(o), true); }*/ -void executeTests(const string& _name){ +void executeTests(const string& _name) +{ #ifdef FILL_TESTS try { @@ -603,5 +605,3 @@ BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) { dev::test::executeTests("vmSystemOperationsTest"); } - - @@ -23,9 +23,10 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #pragma once -#include <libethereum/State.h> #include <fstream> #include <cstdint> +#include <boost/test/unit_test.hpp> +#include "JsonSpiritHeaders.h" #include <libdevcore/Log.h> #include <libevmface/Instruction.h> #include <libevm/ExtVMFace.h> @@ -33,8 +34,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <liblll/Compiler.h> #include <libethereum/Transaction.h> #include <libethereum/ExtVM.h> -#include "JsonSpiritHeaders.h" -#include <boost/test/unit_test.hpp> +#include <libethereum/State.h> namespace dev { namespace test { @@ -42,8 +42,7 @@ class FakeExtVM: public eth::ExtVMFace { public: FakeExtVM() {} - FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock): - ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock) {} + FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock); u256 store(u256 _n) { return std::get<2>(addresses[myAddress])[_n]; } void setStore(u256 _n, u256 _v) { std::get<2>(addresses[myAddress])[_n] = _v; } diff --git a/vmSystemOperationsTestFiller.json b/vmSystemOperationsTestFiller.json index 4ce73d75..34235e04 100644 --- a/vmSystemOperationsTestFiller.json +++ b/vmSystemOperationsTestFiller.json @@ -165,7 +165,7 @@ }, "945304eb96065b2a98b57a48a06ae28d285a71b5" : { "balance" : "23", - "code" : "0x603760005560026000f2", + "code" : "0x6001600157603760005560026000f2", "nonce" : "0", "storage" : { } @@ -196,7 +196,7 @@ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "balance" : "1000000000000000000", "nonce" : 0, - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) [[ 0 ]] (POST 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 ) }", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) (POST 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 ) }", "storage": {} }, "945304eb96065b2a98b57a48a06ae28d285a71b5" : { @@ -232,12 +232,12 @@ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "balance" : "1000000000000000000", "nonce" : 0, - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) [[ 0 ]] (CALLSTATELESS 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 0 2 ) }", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) [[ 0 ]] (CALLSTATELESS 500 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 0 2 ) }", "storage": {} }, "945304eb96065b2a98b57a48a06ae28d285a71b5" : { "balance" : "23", - "code" : "0x603760005560026000f2", + "code" : "0x6001600157603760005560026000f2", "nonce" : "0", "storage" : { } @@ -473,7 +473,7 @@ } }, - "CallToNameRegistratorForeverLoop": { + "CallRecursiveBomb": { "env" : { "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", "currentNumber" : "0", @@ -486,13 +486,13 @@ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "balance" : "20000000", "nonce" : 0, - "code" : "{ (MSTORE 0 0x601c80600c6000396000f2006001600056016000576000600060006000601730) (MSTORE 32 0x620f4240f1600157000000000000000000000000000000000000000000000000) [[ 0 ]] (CREATE 10000000 0 40) (CALL 10000000 (SLOAD 0) 9000000 0 0 0 0) }", + "code" : "{ (CALL 100000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 0 0 0) }", "storage": {} }, - "945304eb96065b2a98b57a48a06ae28d285a71aa" : { + "945304eb96065b2a98b57a48a06ae28d285a71b5" : { "balance" : "1000000000000000000", "nonce" : 0, - "code" : "{ [[ 0 ]] (+ (SLOAD 0) 1) [[ 1 ]] (CALL 1000000 (ADDRESS) 23 0 0 0 0) }", + "code" : "{ [[ 0 ]] (+ (SLOAD 0) 1) [[ 1 ]] (CALL (- (GAS) 224) (ADDRESS) 0 0 0 0 0) } ", "storage": {} } }, @@ -718,7 +718,7 @@ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "balance" : "1000000000000000000", "nonce" : 0, - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) [[ 0 ]] (POST 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 ) }", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa ) (POST 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 ) }", "storage": {} }, "945304eb96065b2a98b57a48a06ae28d285a71b5" : { |