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

Commit

Permalink
Implement EIP-2200: Structured Definitions for Net Gas Metering… (#5709)
Browse files Browse the repository at this point in the history
Implement EIP-2200: Structured Definitions for Net Gas Metering in LegacyVM
  • Loading branch information
gumb0 authored Sep 24, 2019
2 parents f564479 + 604b44b commit 0f41bb1
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 201 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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: [#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
6 changes: 5 additions & 1 deletion libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct EVMSchedule
bool eip150Mode = false;
bool eip158Mode = false;
bool eip1283Mode = false;
bool eip2200Mode = false;
bool haveBitwiseShifting = false;
bool haveRevert = false;
bool haveReturnData = false;
Expand All @@ -40,7 +41,6 @@ struct EVMSchedule
unsigned sstoreResetGas = 5000;
unsigned sstoreUnchangedGas = 200;
unsigned sstoreRefundGas = 15000;
unsigned sstoreRefundNonzeroGas = 4800;
unsigned jumpdestGas = 1;
unsigned logGas = 375;
unsigned logDataGas = 8;
Expand Down Expand Up @@ -73,6 +73,8 @@ struct EVMSchedule
bool staticCallDepthLimit() const { return !eip150Mode; }
bool emptinessIsNonexistence() const { return eip158Mode; }
bool zeroValueTransferChargesNewAccountGas() const { return !eip158Mode; }
bool sstoreNetGasMetering() const { return eip1283Mode || eip2200Mode; }
bool sstoreThrowsIfGasBelowCallStipend() const { return eip2200Mode; }
};

static const EVMSchedule DefaultSchedule = EVMSchedule();
Expand Down Expand Up @@ -143,6 +145,8 @@ static const EVMSchedule IstanbulSchedule = [] {
schedule.extcodehashGas = 700;
schedule.haveChainID = true;
schedule.haveSelfbalance = true;
schedule.eip2200Mode = true;
schedule.sstoreUnchangedGas = 800;
return schedule;
}();

Expand Down
4 changes: 2 additions & 2 deletions libevm/ExtVMFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ evmc_storage_status EvmCHost::set_storage(
if (originalValue == newValue)
{
if (originalValue == 0)
m_extVM.sub.refunds += schedule.sstoreRefundGas + schedule.sstoreRefundNonzeroGas;
m_extVM.sub.refunds += schedule.sstoreSetGas - schedule.sstoreUnchangedGas;
else
m_extVM.sub.refunds += schedule.sstoreRefundNonzeroGas;
m_extVM.sub.refunds += schedule.sstoreResetGas - schedule.sstoreUnchangedGas;
}
}

Expand Down
11 changes: 7 additions & 4 deletions libevm/LegacyVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ void LegacyVM::adjustStack(unsigned _removed, unsigned _added)

void LegacyVM::updateSSGas()
{
if (m_schedule->sstoreThrowsIfGasBelowCallStipend() && m_io_gas <= m_schedule->callStipend)
throwOutOfGas();

u256 const currentValue = m_ext->store(m_SP[0]);
u256 const newValue = m_SP[1];

if (m_schedule->eip1283Mode)
if (m_schedule->sstoreNetGasMetering())
updateSSGasEIP1283(currentValue, newValue);
else
updateSSGasPreEIP1283(currentValue, newValue);
Expand Down Expand Up @@ -137,10 +140,10 @@ void LegacyVM::updateSSGasEIP1283(u256 const& _currentValue, u256 const& _newVal
if (originalValue == _newValue)
{
if (originalValue == 0)
m_ext->sub.refunds +=
m_schedule->sstoreRefundGas + m_schedule->sstoreRefundNonzeroGas;
m_ext->sub.refunds += m_schedule->sstoreSetGas - m_schedule->sstoreUnchangedGas;
else
m_ext->sub.refunds += m_schedule->sstoreRefundNonzeroGas;
m_ext->sub.refunds +=
m_schedule->sstoreResetGas - m_schedule->sstoreUnchangedGas;
}
}
}
Expand Down
Loading

0 comments on commit 0f41bb1

Please sign in to comment.