diff --git a/CHANGELOG.md b/CHANGELOG.md index d46d9dcdcc9..517b53369b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## [1.8.0] - Unreleased - Added: [#5699](https://github.com/ethereum/aleth/pull/5699) EIP 2046: Reduced gas cost for static calls made to precompiles. -- Added: [#5752](https://github.com/ethereum/aleth/pull/5752) Implement EIP1380 (reduced gas costs for call-to-self) in LegacyVM. +- Added: [#5752](https://github.com/ethereum/aleth/pull/5752) [#5753](https://github.com/ethereum/aleth/pull/5753) Implement EIP1380 (reduced gas costs for call-to-self). - Removed: [#5760](https://github.com/ethereum/aleth/pull/5760) Official support for Visual Studio 2015 has been dropped. Compilation with this compiler is expected to stop working after migration to C++14. ## [1.7.0] - Unreleased diff --git a/libaleth-interpreter/VM.h b/libaleth-interpreter/VM.h index 7ef0206bfb2..cff682f46a2 100644 --- a/libaleth-interpreter/VM.h +++ b/libaleth-interpreter/VM.h @@ -43,6 +43,7 @@ struct VMSchedule static constexpr int64_t valueTransferGas = 9000; static constexpr int64_t callStipend = 2300; static constexpr int64_t callNewAccount = 25000; + static constexpr int64_t callSelfGas = 40; }; class VM diff --git a/libaleth-interpreter/VMCalls.cpp b/libaleth-interpreter/VMCalls.cpp index 65b05fd6e95..56a98c42494 100644 --- a/libaleth-interpreter/VMCalls.cpp +++ b/libaleth-interpreter/VMCalls.cpp @@ -192,7 +192,11 @@ void VM::caseCall() bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output) { - m_runGas = m_rev >= EVMC_TANGERINE_WHISTLE ? 700 : 40; + auto const destination = intx::be::trunc(m_SP[1]); + + // Check for call-to-self (eip1380) and adjust gas accordingly + if (m_rev >= EVMC_BERLIN && m_message->destination == destination) + m_runGas = VMSchedule::callSelfGas; switch (m_OP) { @@ -214,8 +218,6 @@ bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output) bool const haveValueArg = m_OP == Instruction::CALL || m_OP == Instruction::CALLCODE; - auto const destination = intx::be::trunc(m_SP[1]); - if (m_OP == Instruction::CALL && (m_SP[2] > 0 || m_rev < EVMC_SPURIOUS_DRAGON) && !m_context->host->account_exists(m_context, &destination)) {