Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

evm: Change Executive::m_gas to int64_t #5317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(_p.gas - g);
bytes output;
bool success;
tie(success, output) = m_sealEngine.executePrecompiled(_p.codeAddress, _p.data, m_envInfo.number());
Expand All @@ -338,7 +338,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co
}
else
{
m_gas = _p.gas;
m_gas = static_cast<int64_t>(_p.gas);
if (m_s.addressHasCode(_p.codeAddress))
{
bytes const& c = m_s.code(_p.codeAddress);
Expand Down Expand Up @@ -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<int64_t>(_gas);
bool accountAlreadyExist = (m_s.addressHasCode(m_newAddress) || m_s.getNonce(m_newAddress) > 0);
if (accountAlreadyExist)
{
Expand Down Expand Up @@ -449,17 +449,19 @@ 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<int64_t>(vmGas);
if (m_isCreation)
{
auto out = vm->exec(m_gas, *m_ext, _onOp);
if (m_res)
{
m_res->gasForDeposit = m_gas;
m_res->depositSize = out.size();
}
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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<int64_t>(m_t.gas()) - static_cast<int64_t>(m_gas)) / 2;
int64_t maxRefund = (static_cast<int64_t>(m_t.gas()) - m_gas) / 2;
m_gas += min(maxRefund, m_ext->sub.refunds);
}

Expand Down
6 changes: 5 additions & 1 deletion libethereum/Executive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is the advantage of using signed instead of unsigned here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Transaction m_t; ///< The original transaction. Set by setup().
LogEntries m_logs; ///< The log entries created by this transaction. Set by finalize().
Expand Down
1 change: 1 addition & 0 deletions test/tools/jsontests/StateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){}
Expand Down