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 LegacyVM #5709

Merged
merged 7 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
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.
- 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.
Expand Down
6 changes: 5 additions & 1 deletion libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 @@ -53,7 +54,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 @@ -86,6 +86,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 @@ -156,6 +158,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 @@ -78,9 +78,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 @@ -97,10 +97,13 @@ void LegacyVM::adjustStack(unsigned _removed, unsigned _added)

void LegacyVM::updateSSGas()
{
if (m_schedule->sstoreThrowsIfGasBelowCallStipend() && m_io_gas <= m_schedule->callStipend)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only throw OOG if EIP2200 is enabled, I'd expect us to always throw OOG if we don't have enough gas to cover the call stipend?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is introduced only in EIP-2200.
(without it we normally throw in case of OOG from the updateIOGas call here

updateIOGas();
)

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 @@ -150,10 +153,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