diff options
author | artur-zawlocki <artur.zawlocki@gmail.com> | 2014-10-29 19:02:37 +0800 |
---|---|---|
committer | artur-zawlocki <artur.zawlocki@gmail.com> | 2014-10-29 19:02:37 +0800 |
commit | ec9330609fa965b8928a99fd8e9b1e10a7c45fa0 (patch) | |
tree | 4228317d344014175e85fcc3dde0966bf6c2f092 /vm.h | |
parent | 621d7fa4b04a030b8f6c828d18c6976c600683f2 (diff) | |
parent | f73a461e13b1d8f88e93b57c66933549bb855b8c (diff) | |
download | dexon-solidity-ec9330609fa965b8928a99fd8e9b1e10a7c45fa0.tar.gz dexon-solidity-ec9330609fa965b8928a99fd8e9b1e10a7c45fa0.tar.zst dexon-solidity-ec9330609fa965b8928a99fd8e9b1e10a7c45fa0.zip |
Merge branch 'develop-evmcc' of github.com:imapp-pl/ethereum into develop-evmcc
Conflicts:
test/vm.cpp
Diffstat (limited to 'vm.h')
-rw-r--r-- | vm.h | 58 |
1 files changed, 47 insertions, 11 deletions
@@ -28,6 +28,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <boost/test/unit_test.hpp> #include "JsonSpiritHeaders.h" #include <libdevcore/Log.h> +#include <libdevcore/CommonIO.h> #include <libevmface/Instruction.h> #include <libevm/ExtVMFace.h> #include <libevm/VM.h> @@ -44,24 +45,24 @@ class FakeState: public eth::State { public: /// Execute a contract-creation transaction. - h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = Address(), std::set<Address>* o_suicides = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = eth::OnOpFunc(), unsigned _level = 0); + h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_sub = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0); }; class FakeExtVM: public eth::ExtVMFace { public: - FakeExtVM() {} + FakeExtVM() = default; FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth = 0); - u256 store(u256 _n) override { return std::get<2>(addresses[myAddress])[_n]; } - void setStore(u256 _n, u256 _v) override { std::get<2>(addresses[myAddress])[_n] = _v; } - u256 balance(Address _a) override { return std::get<0>(addresses[_a]); } - void subBalance(u256 _a) override { std::get<0>(addresses[myAddress]) -= _a; } - u256 txCount(Address _a) override { return std::get<1>(addresses[_a]); } - void suicide(Address _a) override { std::get<0>(addresses[_a]) += std::get<0>(addresses[myAddress]); addresses.erase(myAddress); } - bytes const& codeAt(Address _a) override { return std::get<3>(addresses[_a]); } - h160 create(u256 _endowment, u256* _gas, bytesConstRef _init, eth::OnOpFunc const&) override; - bool call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, eth::OnOpFunc const&, Address, Address) override; + virtual u256 store(u256 _n) override { return std::get<2>(addresses[myAddress])[_n]; } + virtual void setStore(u256 _n, u256 _v) override { std::get<2>(addresses[myAddress])[_n] = _v; } + virtual u256 balance(Address _a) override { return std::get<0>(addresses[_a]); } + virtual void subBalance(u256 _a) override { std::get<0>(addresses[myAddress]) -= _a; } + virtual u256 txCount(Address _a) override { return std::get<1>(addresses[_a]); } + virtual void suicide(Address _a) override { std::get<0>(addresses[_a]) += std::get<0>(addresses[myAddress]); addresses.erase(myAddress); } + virtual bytes const& codeAt(Address _a) override { return std::get<3>(addresses[_a]); } + virtual h160 create(u256 _endowment, u256* _gas, bytesConstRef _init, eth::OnOpFunc const&) override; + virtual bool call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, eth::OnOpFunc const&, Address, Address) override; void setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const& _data); void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code); void set(Address _a, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code); @@ -79,6 +80,13 @@ public: void importExec(json_spirit::mObject& _o); json_spirit::mArray exportCallCreates(); void importCallCreates(json_spirit::mArray& _callcreates); + void setVMKind(eth::VMFace::Kind _kind) { m_s.setVMKind(_kind); } + eth::VMFace::Kind getVMKind() const { return m_s.getVMKind(); } + + template<typename ExtVMType> + eth::OnOpFunc simpleTrace(); + + FakeState state() const { return m_s; } std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses; eth::Transactions callcreates; @@ -91,4 +99,32 @@ private: eth::Manifest m_ms; }; +template<typename ExtVMType> +eth::OnOpFunc FakeExtVM::simpleTrace() +{ + return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt) + { + ExtVMType const& ext = *(ExtVMType const*)voidExt; + eth::VM& vm = *(eth::VM*)voidVM; + + std::ostringstream o; + o << std::endl << " STACK" << std::endl; + for (auto i: vm.stack()) + o << (h256)i << std::endl; + o << " MEMORY" << std::endl << memDump(vm.memory()); + o << " STORAGE" << std::endl; + for (auto const& i: ext.state().storage(ext.myAddress)) + o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; + dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str(); + dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]"; + + if (eth::VMTraceChannel::verbosity <= g_logVerbosity) + { + std::ofstream f; + f.open("./vmtrace.log", std::ofstream::app); + f << o.str(); + f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32"; + } + }; +} } } // Namespace Close |