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

Commit 41c94e1

Browse files
authored
Merge pull request #5728 from ethereum/eip-2200-interpreter
Implement EIP-2200: Structured Definitions for Net Gas Metering in aleth-interpreter
2 parents 0f41bb1 + b025be0 commit 41c94e1

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Added: [#5701](https://github.com/ethereum/aleth/issues/5701) Outputs ENR text representation in admin.nodeInfo RPC.
2121
- Added: [#5705](https://github.com/ethereum/aleth/pull/5705) Istanbul support: EIP 1108 Reduce alt_bn128 precompile gas costs.
2222
- Added: [#5707](https://github.com/ethereum/aleth/pull/5707) Aleth waits for 2 seconds after sending disconnect to peer before closing socket.
23-
- Added: [#5709](https://github.com/ethereum/aleth/pull/5709) Istanbul support: EIP-2200 Structured Definitions for Net Gas Metering.
23+
- 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.
2424
- Added: [#5751](https://github.com/ethereum/aleth/pull/5751) Istanbul support: EIP-152 Add BLAKE2 compression function `F` precompile.
2525
- Added: [#5758](https://github.com/ethereum/aleth/pull/5758) Istanbul support: activation in Ropsten config.
2626
- 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.

libaleth-interpreter/VM.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,9 @@ void VM::interpretCases()
13691369
if (m_message->flags & EVMC_STATIC)
13701370
throwDisallowedStateChange();
13711371

1372+
if (m_rev >= EVMC_ISTANBUL && m_io_gas <= VMSchedule::callStipend)
1373+
throwOutOfGas();
1374+
13721375
evmc_uint256be const key = toEvmC(m_SP[0]);
13731376
evmc_uint256be const value = toEvmC(m_SP[1]);
13741377
auto const status =
@@ -1385,8 +1388,9 @@ void VM::interpretCases()
13851388
break;
13861389
case EVMC_STORAGE_UNCHANGED:
13871390
case EVMC_STORAGE_MODIFIED_AGAIN:
1388-
m_runGas = m_rev == EVMC_CONSTANTINOPLE ? VMSchedule::sstoreUnchangedGas :
1389-
VMSchedule::sstoreResetGas;
1391+
m_runGas = (m_rev == EVMC_CONSTANTINOPLE || m_rev >= EVMC_ISTANBUL) ?
1392+
(*m_metrics)[OP_SLOAD].gas_cost :
1393+
VMSchedule::sstoreResetGas;
13901394
break;
13911395
}
13921396

libaleth-interpreter/VM.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ struct VMSchedule
2929
static constexpr int64_t stepGas6 = 20;
3030
static constexpr int64_t sha3Gas = 30;
3131
static constexpr int64_t sha3WordGas = 6;
32-
static constexpr int64_t sloadGas = 50;
3332
static constexpr int64_t sstoreSetGas = 20000;
3433
static constexpr int64_t sstoreResetGas = 5000;
35-
static constexpr int64_t sstoreUnchangedGas = 200;
3634
static constexpr int64_t jumpdestGas = 1;
3735
static constexpr int64_t logGas = 375;
3836
static constexpr int64_t logDataGas = 8;

libevm/ExtVMFace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ evmc_storage_status EvmCHost::set_storage(
4242
EVMSchedule const& schedule = m_extVM.evmSchedule();
4343
auto status = EVMC_STORAGE_MODIFIED;
4444
u256 const originalValue = m_extVM.originalStorageValue(index);
45-
if (originalValue == currentValue || !schedule.eip1283Mode)
45+
if (originalValue == currentValue || !schedule.sstoreNetGasMetering())
4646
{
4747
if (currentValue == 0)
4848
status = EVMC_STORAGE_ADDED;

test/unittests/libevm/VMTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,16 @@ BOOST_AUTO_TEST_CASE(AlethInterpreterSstorePetersburg)
999999
testPetersburg();
10001000
}
10011001

1002+
BOOST_AUTO_TEST_CASE(AlethInterpreterSstoreIstanbul)
1003+
{
1004+
testIstanbul();
1005+
}
1006+
1007+
BOOST_AUTO_TEST_CASE(AlethInterpreterSstoreBelowStipend)
1008+
{
1009+
testSstoreBelowStipend();
1010+
}
1011+
10021012
BOOST_AUTO_TEST_SUITE_END()
10031013

10041014
BOOST_FIXTURE_TEST_SUITE(AlethInterpreterChainIDSuite, AlethInterpreterChainIDTestFixture)

0 commit comments

Comments
 (0)