diff --git a/alethzero/Debugger.cpp b/alethzero/Debugger.cpp index a1d246a21..21ef3b711 100644 --- a/alethzero/Debugger.cpp +++ b/alethzero/Debugger.cpp @@ -82,7 +82,7 @@ bool DebugSession::populate(dev::eth::Executive& _executive, dev::eth::Transacti bytesConstRef lastData; h256 lastHash; h256 lastDataHash; - auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, VM* voidVM, ExtVMFace const* voidExt) + auto onOp = [&](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, bigint gas, VM* voidVM, ExtVMFace const* voidExt) { VM& vm = *voidVM; ExtVM const& ext = *static_cast(voidExt); @@ -104,7 +104,7 @@ bool DebugSession::populate(dev::eth::Executive& _executive, dev::eth::Transacti levels.push_back(&history.back()); else levels.resize(ext.depth); - history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, vm.gas(), lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels})); + history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, (u256)gas, lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels})); }; _executive.go(onOp); _executive.finalize(); diff --git a/eth/main.cpp b/eth/main.cpp index cb051aad1..807fd4c50 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1462,7 +1462,7 @@ int main(int argc, char** argv) { OnOpFunc oof; if (format == "pretty") - oof = [&](uint64_t steps, Instruction instr, bigint newMemSize, bigint gasCost, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) + oof = [&](uint64_t steps, Instruction instr, bigint newMemSize, bigint gasCost, bigint gas, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) { dev::eth::VM* vm = vvm; dev::eth::ExtVM const* ext = static_cast(vextVM); @@ -1473,24 +1473,24 @@ int main(int argc, char** argv) f << " STORAGE" << endl; for (auto const& i: ext->state().storage(ext->myAddress)) f << showbase << hex << i.first << ": " << i.second << endl; - f << dec << ext->depth << " | " << ext->myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm->curPC() << " : " << dev::eth::instructionInfo(instr).name << " | " << dec << vm->gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32"; + f << dec << ext->depth << " | " << ext->myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm->curPC() << " : " << dev::eth::instructionInfo(instr).name << " | " << dec << gas << " | -" << dec << gasCost << " | " << newMemSize << "x32"; }; else if (format == "standard") - oof = [&](uint64_t, Instruction instr, bigint, bigint, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) + oof = [&](uint64_t, Instruction instr, bigint, bigint, bigint gas, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) { dev::eth::VM* vm = vvm; dev::eth::ExtVM const* ext = static_cast(vextVM); - f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; + f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)gas, 1)) << endl; }; else if (format == "standard+") - oof = [&](uint64_t, Instruction instr, bigint, bigint, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) + oof = [&](uint64_t, Instruction instr, bigint, bigint, bigint gas, dev::eth::VM* vvm, dev::eth::ExtVMFace const* vextVM) { dev::eth::VM* vm = vvm; dev::eth::ExtVM const* ext = static_cast(vextVM); if (instr == Instruction::STOP || instr == Instruction::RETURN || instr == Instruction::SUICIDE) for (auto const& i: ext->state().storage(ext->myAddress)) f << toHex(dev::toCompactBigEndian(i.first, 1)) << " " << toHex(dev::toCompactBigEndian(i.second, 1)) << endl; - f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; + f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)gas, 1)) << endl; }; e.initialize(t); if (!e.execute()) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index a856b9ef4..ecfdd7721 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -187,7 +187,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g OnOpFunc Executive::simpleTrace() { - return [](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, VM* voidVM, ExtVMFace const* voidExt) + return [](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, bigint gas, VM* voidVM, ExtVMFace const* voidExt) { ExtVM const& ext = *static_cast(voidExt); VM& vm = *voidVM; @@ -201,7 +201,7 @@ OnOpFunc Executive::simpleTrace() for (auto const& i: ext.state().storage(ext.myAddress)) o << showbase << hex << i.first << ": " << i.second << endl; dev::LogOutputStream() << o.str(); - dev::LogOutputStream() << " < " << dec << ext.depth << " : " << ext.myAddress << " : #" << steps << " : " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " : " << dec << vm.gas() << " : -" << dec << gasCost << " : " << newMemSize << "x32" << " >"; + dev::LogOutputStream() << " < " << dec << ext.depth << " : " << ext.myAddress << " : #" << steps << " : " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " : " << dec << gas << " : -" << dec << gasCost << " : " << newMemSize << "x32" << " >"; }; } diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 48fbd0b01..4bbdb36ac 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -106,7 +106,7 @@ class VM; using LastHashes = std::vector; -using OnOpFunc = std::function; +using OnOpFunc = std::function; /** * @brief Interface and null implementation of the class for specifying VM externalities. diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 8f1b47c05..695b556dd 100644 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -51,8 +51,6 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 m_curPC = 0; m_jumpDests.clear(); - m_gas = io_gas; - m_stack.reserve((unsigned)c_stackLimit); static const array c_metrics = metrics(); @@ -97,7 +95,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 auto onOperation = [&]() { if (_onOp) - _onOp(osteps - _steps - 1, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, this, &_ext); + _onOp(osteps - _steps - 1, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, io_gas, this, &_ext); }; switch (inst) @@ -195,13 +193,11 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 runGas += c_copyGas * ((copySize + 31) / 32); onOperation(); -// if (_onOp) -// _onOp(osteps - _steps - 1, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, this, &_ext); - if (m_gas < runGas) + if (io_gas < runGas) BOOST_THROW_EXCEPTION(OutOfGas()); - m_gas = (u256)((bigint)m_gas - runGas); + io_gas = (u256)((bigint)io_gas - runGas); if (newTempSize > m_temp.size()) m_temp.resize((size_t)newTempSize); @@ -560,7 +556,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 m_stack.push_back(m_temp.size()); break; case Instruction::GAS: - m_stack.push_back(m_gas); + m_stack.push_back(io_gas); break; case Instruction::JUMPDEST: break; @@ -609,7 +605,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 m_stack.pop_back(); if (_ext.balance(_ext.myAddress) >= endowment && _ext.depth < 1024) - m_stack.push_back((u160)_ext.create(endowment, m_gas, bytesConstRef(m_temp.data() + initOff, initSize), _onOp)); + m_stack.push_back((u160)_ext.create(endowment, io_gas, bytesConstRef(m_temp.data() + initOff, initSize), _onOp)); else m_stack.push_back(0); break; @@ -640,7 +636,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 else m_stack.push_back(0); - m_gas += gas; + io_gas += gas; break; } case Instruction::RETURN: @@ -649,8 +645,6 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 m_stack.pop_back(); unsigned s = (unsigned)m_stack.back(); m_stack.pop_back(); - - io_gas = m_gas; return bytesConstRef(m_temp.data() + b, s); } case Instruction::SUICIDE: @@ -660,12 +654,10 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6 // ...follow through to... } case Instruction::STOP: - io_gas = m_gas; return bytesConstRef(); } } - io_gas = m_gas; if (_steps == (uint64_t)-1) BOOST_THROW_EXCEPTION(StepsDone()); return bytesConstRef(); diff --git a/libevm/VM.h b/libevm/VM.h index a73142dad..755d820fa 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -58,7 +58,6 @@ public: void requireMem(unsigned _n) { if (m_temp.size() < _n) { m_temp.resize(_n); } } u256 curPC() const { return m_curPC; } - u256 gas() const { return m_gas; } bytes const& memory() const { return m_temp; } u256s const& stack() const { return m_stack; } @@ -67,7 +66,6 @@ private: friend class VMFactory; u256 m_curPC = 0; - u256 m_gas = 0; bytes m_temp; u256s m_stack; std::set m_jumpDests; diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index b1d8f889e..853441490 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -132,7 +132,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c bytesConstRef const* lastData = nullptr; unsigned codeIndex = 0; unsigned dataIndex = 0; - auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, void* voidVM, void const* voidExt) + auto onOp = [&](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, bigint gas, void* voidVM, void const* voidExt) { VM& vm = *static_cast(voidVM); ExtVM const& ext = *static_cast(voidExt); @@ -169,7 +169,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c else levels.resize(ext.depth); - machineStates.emplace_back(MachineState({steps, vm.curPC(), inst, newMemSize, vm.gas(), + machineStates.emplace_back(MachineState({steps, vm.curPC(), inst, newMemSize, (u256)gas, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels, codeIndex, dataIndex})); }; diff --git a/test/libevm/vm.cpp b/test/libevm/vm.cpp index 53a49f5c4..222a012f4 100644 --- a/test/libevm/vm.cpp +++ b/test/libevm/vm.cpp @@ -234,7 +234,7 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) eth::OnOpFunc FakeExtVM::simpleTrace() { - return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, dev::eth::VM* voidVM, dev::eth::ExtVMFace const* voidExt) + return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, bigint gas, dev::eth::VM* voidVM, dev::eth::ExtVMFace const* voidExt) { FakeExtVM const& ext = *static_cast(voidExt); eth::VM& vm = *voidVM; @@ -250,7 +250,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; dev::LogOutputStream() << o.str(); - dev::LogOutputStream() << " | " << 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" << " ]"; + dev::LogOutputStream() << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << gas << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]"; /*creates json stack trace*/ if (eth::VMTraceChannel::verbosity <= g_logVerbosity) @@ -279,7 +279,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() /*add all the other details*/ o_step.push_back(Pair("storage", storage)); o_step.push_back(Pair("depth", to_string(ext.depth))); - o_step.push_back(Pair("gas", (string)vm.gas())); + o_step.push_back(Pair("gas", (string)gas)); o_step.push_back(Pair("address", toString(ext.myAddress ))); o_step.push_back(Pair("step", steps )); o_step.push_back(Pair("pc", (int)vm.curPC()));