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

Implement EIP-2200: Structured Definitions for Net Gas Metering in aleth-interpreter #5728

Merged
merged 4 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libevm/ExtVMFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions test/unittests/libevm/VMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down