From f5adccd4718a584331c32c6851bccd10efb1f6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 15 Oct 2018 14:53:51 +0200 Subject: [PATCH] evm: Change Executive::m_gas to int64_t --- libethereum/Executive.cpp | 16 +++++++++------- libethereum/Executive.h | 6 +++++- test/tools/jsontests/StateTests.cpp | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index cc491fcc1ed..6eabfd607d1 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -322,7 +322,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co } else { - m_gas = (u256)(_p.gas - g); + m_gas = static_cast(_p.gas - g); bytes output; bool success; tie(success, output) = m_sealEngine.executePrecompiled(_p.codeAddress, _p.data, m_envInfo.number()); @@ -338,7 +338,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co } else { - m_gas = _p.gas; + m_gas = static_cast(_p.gas); if (m_s.addressHasCode(_p.codeAddress)) { bytes const& c = m_s.code(_p.codeAddress); @@ -386,7 +386,7 @@ bool Executive::executeCreate(Address const& _sender, u256 const& _endowment, u2 // We can allow for the reverted state (i.e. that with which m_ext is constructed) to contain the m_orig.address, since // we delete it explicitly if we decide we need to revert. - m_gas = _gas; + m_gas = static_cast(_gas); bool accountAlreadyExist = (m_s.addressHasCode(m_newAddress) || m_s.getNonce(m_newAddress) > 0); if (accountAlreadyExist) { @@ -449,9 +449,11 @@ bool Executive::go(OnOpFunc const& _onOp) { // Create VM instance. Force Interpreter if tracing requested. auto vm = VMFactory::create(); + u256 vmGas = m_gas; + auto out = vm->exec(vmGas, *m_ext, _onOp); + m_gas = static_cast(vmGas); if (m_isCreation) { - auto out = vm->exec(m_gas, *m_ext, _onOp); if (m_res) { m_res->gasForDeposit = m_gas; @@ -459,7 +461,7 @@ bool Executive::go(OnOpFunc const& _onOp) } if (out.size() > m_ext->evmSchedule().maxCodeSize) BOOST_THROW_EXCEPTION(OutOfGas()); - else if (out.size() * m_ext->evmSchedule().createDataGas <= m_gas) + else if (int64_t(out.size()) * m_ext->evmSchedule().createDataGas <= m_gas) { if (m_res) m_res->codeDeposit = CodeDeposit::Success; @@ -481,7 +483,7 @@ bool Executive::go(OnOpFunc const& _onOp) m_s.setCode(m_ext->myAddress, out.toVector()); } else - m_output = vm->exec(m_gas, *m_ext, _onOp); + m_output = std::move(out); } catch (RevertInstruction& _e) { @@ -541,7 +543,7 @@ bool Executive::finalize() // Refunds must be applied before the miner gets the fees. assert(m_ext->sub.refunds >= 0); - int64_t maxRefund = (static_cast(m_t.gas()) - static_cast(m_gas)) / 2; + int64_t maxRefund = (static_cast(m_t.gas()) - m_gas) / 2; m_gas += min(maxRefund, m_ext->sub.refunds); } diff --git a/libethereum/Executive.h b/libethereum/Executive.h index b88742b9b03..9ec42e43023 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -200,7 +200,11 @@ class Executive unsigned m_depth = 0; ///< The context's call-depth. TransactionException m_excepted = TransactionException::None; ///< Details if the VM's execution resulted in an exception. int64_t m_baseGasRequired; ///< The base amount of gas requried for executing this transaction. - u256 m_gas = 0; ///< The gas for EVM code execution. Initial amount before go() execution, final amount after go() execution. + + /// The amount of gas for EVM execution. + /// + /// Initial amount before go() execution, the amount of gas left after go() execution. + int64_t m_gas = 0; Transaction m_t; ///< The original transaction. Set by setup(). LogEntries m_logs; ///< The log entries created by this transaction. Set by finalize(). diff --git a/test/tools/jsontests/StateTests.cpp b/test/tools/jsontests/StateTests.cpp index 0ad5dd8d3fa..c4a7df3eaa7 100644 --- a/test/tools/jsontests/StateTests.cpp +++ b/test/tools/jsontests/StateTests.cpp @@ -208,6 +208,7 @@ BOOST_AUTO_TEST_CASE(stBugs){} //Constantinople Tests BOOST_AUTO_TEST_CASE(stShift){} BOOST_AUTO_TEST_CASE(stCreate2){} +BOOST_AUTO_TEST_CASE(stSStoreTest){} //Stress Tests BOOST_AUTO_TEST_CASE(stAttackTest){}