From 13c31880ece517cc2c22decd7fee76d60feb85d2 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 28 Aug 2019 12:31:09 +0200 Subject: [PATCH 1/4] Implement EIP-2200 in aleth-interpreter --- libaleth-interpreter/VM.cpp | 8 ++++++-- libaleth-interpreter/VM.h | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libaleth-interpreter/VM.cpp b/libaleth-interpreter/VM.cpp index 54a7110fd3b..880420315bb 100644 --- a/libaleth-interpreter/VM.cpp +++ b/libaleth-interpreter/VM.cpp @@ -1369,6 +1369,9 @@ void VM::interpretCases() if (m_message->flags & EVMC_STATIC) throwDisallowedStateChange(); + if (m_rev >= EVMC_ISTANBUL && m_io_gas <= VMSchedule::callStipend) + throwOutOfGas(); + evmc_uint256be const key = toEvmC(m_SP[0]); evmc_uint256be const value = toEvmC(m_SP[1]); auto const status = @@ -1385,8 +1388,9 @@ void VM::interpretCases() break; case EVMC_STORAGE_UNCHANGED: case EVMC_STORAGE_MODIFIED_AGAIN: - m_runGas = m_rev == EVMC_CONSTANTINOPLE ? VMSchedule::sstoreUnchangedGas : - VMSchedule::sstoreResetGas; + m_runGas = (m_rev == EVMC_CONSTANTINOPLE || m_rev >= EVMC_ISTANBUL) ? + (*m_metrics)[OP_SLOAD].gas_cost : + VMSchedule::sstoreResetGas; break; } diff --git a/libaleth-interpreter/VM.h b/libaleth-interpreter/VM.h index 6d74a4b1ad4..a3d0e248564 100644 --- a/libaleth-interpreter/VM.h +++ b/libaleth-interpreter/VM.h @@ -29,10 +29,8 @@ struct VMSchedule static constexpr int64_t stepGas6 = 20; static constexpr int64_t sha3Gas = 30; static constexpr int64_t sha3WordGas = 6; - static constexpr int64_t sloadGas = 50; static constexpr int64_t sstoreSetGas = 20000; static constexpr int64_t sstoreResetGas = 5000; - static constexpr int64_t sstoreUnchangedGas = 200; static constexpr int64_t jumpdestGas = 1; static constexpr int64_t logGas = 375; static constexpr int64_t logDataGas = 8; From 71a2236a3d72853b0017e4f993ecaeb1c21d5b1a Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 28 Aug 2019 12:39:46 +0200 Subject: [PATCH 2/4] Unit tests for SSTORE in interpreter with EIP-2200 --- test/unittests/libevm/VMTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unittests/libevm/VMTest.cpp b/test/unittests/libevm/VMTest.cpp index 6f2fb328ec9..d23d4ef2cf2 100644 --- a/test/unittests/libevm/VMTest.cpp +++ b/test/unittests/libevm/VMTest.cpp @@ -999,6 +999,16 @@ BOOST_AUTO_TEST_CASE(AlethInterpreterSstorePetersburg) testPetersburg(); } +BOOST_AUTO_TEST_CASE(AlethInterpreterSstoreIstanbul) +{ + testIstanbul(); +} + +BOOST_AUTO_TEST_CASE(AlethInterpreterSstoreBelowStipend) +{ + testSstoreBelowStipend(); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_FIXTURE_TEST_SUITE(AlethInterpreterChainIDSuite, AlethInterpreterChainIDTestFixture) From 49b231074797f3755fa5480e17fa4b068ff198ba Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 28 Aug 2019 12:39:53 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af458f6360b..09f3c052a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - Added: [#5701](https://github.com/ethereum/aleth/issues/5701) Outputs ENR text representation in admin.nodeInfo RPC. - Added: [#5705](https://github.com/ethereum/aleth/pull/5705) Istanbul support: EIP 1108 Reduce alt_bn128 precompile gas costs. - Added: [#5707](https://github.com/ethereum/aleth/pull/5707) Aleth waits for 2 seconds after sending disconnect to peer before closing socket. -- Added: [#5709](https://github.com/ethereum/aleth/pull/5709) Istanbul support: EIP-2200 Structured Definitions for Net Gas Metering. +- Added: [#5709](https://github.com/ethereum/aleth/pull/5709) [#5728](https://github.com/ethereum/aleth/pull/5728) Istanbul support: EIP-2200 Structured Definitions for Net Gas Metering. - Added: [#5751](https://github.com/ethereum/aleth/pull/5751) Istanbul support: EIP-152 Add BLAKE2 compression function `F` precompile. - Added: [#5758](https://github.com/ethereum/aleth/pull/5758) Istanbul support: activation in Ropsten config. - 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. From b025be00ff5e553551d643c2be58d87d5f1d96d9 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Tue, 24 Sep 2019 17:17:33 +0200 Subject: [PATCH 4/4] Fix tests after rebase --- libevm/ExtVMFace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevm/ExtVMFace.cpp b/libevm/ExtVMFace.cpp index 84906f4706a..b5ed71dfc63 100644 --- a/libevm/ExtVMFace.cpp +++ b/libevm/ExtVMFace.cpp @@ -42,7 +42,7 @@ evmc_storage_status EvmCHost::set_storage( EVMSchedule const& schedule = m_extVM.evmSchedule(); auto status = EVMC_STORAGE_MODIFIED; u256 const originalValue = m_extVM.originalStorageValue(index); - if (originalValue == currentValue || !schedule.eip1283Mode) + if (originalValue == currentValue || !schedule.sstoreNetGasMetering()) { if (currentValue == 0) status = EVMC_STORAGE_ADDED;