From 85f531c6abed4524f2680ae421b5b10dd23dc49e Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Fri, 20 Sep 2019 20:17:07 -0700 Subject: [PATCH 1/4] Implement EIP1380 (call self) in aleth-interpreter --- libaleth-interpreter/VM.h | 1 + libaleth-interpreter/VMCalls.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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..3b130379558 100644 --- a/libaleth-interpreter/VMCalls.cpp +++ b/libaleth-interpreter/VMCalls.cpp @@ -192,7 +192,13 @@ 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; + else + m_runGas = evmc_get_instruction_metrics_table(m_rev)[static_cast(m_OP)].gas_cost; switch (m_OP) { @@ -214,8 +220,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)) { From d843b9b2dd1308d951932fc52cc4698057e1752e Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Fri, 20 Sep 2019 20:22:39 -0700 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46d9dcdcc9..f8abffef5d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Added: [#5755](https://github.com/ethereum/aleth/pull/5755) testeth now runs `stChainId`, `stSLoadTest`, `stSelfBalance` tests for Istanbul. - Added: [#5758](https://github.com/ethereum/aleth/pull/5758) Istanbul support: activation in Ropsten config. - Added: [#5762](https://github.com/ethereum/aleth/pull/5762) aleth-vm supports `--network Istanbul` option. +- Added: [#5753](https://github.com/ethereum/aleth/pull/5753) Implement EIP1380 (lower gas costs for call-to-self) in aleth-interpreter. - Changed: [#5532](https://github.com/ethereum/aleth/pull/5532) The leveldb is upgraded to 1.22. This is breaking change on Windows and the old databases are not compatible. - Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages. - Changed: [#5568](https://github.com/ethereum/aleth/pull/5568) Improve rlpx handshake log messages and create new rlpx log channel. From b65ceee079a9478e99ebbfe4aa5b697b2ba083c3 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Fri, 4 Oct 2019 13:49:57 +0200 Subject: [PATCH 3/4] Move EIP-1380 changelog item to version 1.8.0 --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8abffef5d8..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 @@ -31,7 +31,6 @@ - Added: [#5755](https://github.com/ethereum/aleth/pull/5755) testeth now runs `stChainId`, `stSLoadTest`, `stSelfBalance` tests for Istanbul. - Added: [#5758](https://github.com/ethereum/aleth/pull/5758) Istanbul support: activation in Ropsten config. - Added: [#5762](https://github.com/ethereum/aleth/pull/5762) aleth-vm supports `--network Istanbul` option. -- Added: [#5753](https://github.com/ethereum/aleth/pull/5753) Implement EIP1380 (lower gas costs for call-to-self) in aleth-interpreter. - Changed: [#5532](https://github.com/ethereum/aleth/pull/5532) The leveldb is upgraded to 1.22. This is breaking change on Windows and the old databases are not compatible. - Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages. - Changed: [#5568](https://github.com/ethereum/aleth/pull/5568) Improve rlpx handshake log messages and create new rlpx log channel. From be4d2b7dcae9069b1aba4627a7948c0df66f6e6a Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Fri, 4 Oct 2019 13:58:15 +0200 Subject: [PATCH 4/4] Remove redundant CALL gas cost assignment --- libaleth-interpreter/VMCalls.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libaleth-interpreter/VMCalls.cpp b/libaleth-interpreter/VMCalls.cpp index 3b130379558..56a98c42494 100644 --- a/libaleth-interpreter/VMCalls.cpp +++ b/libaleth-interpreter/VMCalls.cpp @@ -197,8 +197,6 @@ bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output) // Check for call-to-self (eip1380) and adjust gas accordingly if (m_rev >= EVMC_BERLIN && m_message->destination == destination) m_runGas = VMSchedule::callSelfGas; - else - m_runGas = evmc_get_instruction_metrics_table(m_rev)[static_cast(m_OP)].gas_cost; switch (m_OP) {