EIP-3529: Replace SSTORE_CLEARS_SCHEDULE

SSTORE_CLEARS_SCHEDULE or FeeSchedule[RefundsClear] in evm
have initial value of 15_000 when introduced by EIP-2200.

EIP-2200 also set new value for SSTORE_RESET_GAS
from 5000 to to 5000 - COLD_SLOAD_COST

Now with EIP-3529, SSTORE_CLEARS_SCHEDULE beecome
SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST

or 5000 - COLD_SLOAD_COST + ACCESS_LIST_STORAGE_KEY_COST
of 5000 - 2100 + 1900 = 4800
This commit is contained in:
jangko 2021-06-28 20:06:29 +07:00
parent 8982e6c649
commit 05d905b136
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 35 additions and 3 deletions

View File

@ -116,10 +116,15 @@ type
GasCosts* = array[Op, GasCost] GasCosts* = array[Op, GasCost]
const const
# From EIP-2929
ColdSloadCost* = 2100 ColdSloadCost* = 2100
ColdAccountAccessCost* = 2600 ColdAccountAccessCost* = 2600
WarmStorageReadCost* = 100 WarmStorageReadCost* = 100
# From EIP-2930 (Berlin).
ACCESS_LIST_STORAGE_KEY_COST* = 1900.GasInt
ACCESS_LIST_ADDRESS_COST* = 2400.GasInt
template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) = template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
## Generate the gas cost for each forks and store them in a const ## Generate the gas cost for each forks and store them in a const
@ -723,12 +728,22 @@ func berlinGasFees(previousFees: GasFeeSchedule): GasFeeSchedule =
result[GasSLoad] = 0 result[GasSLoad] = 0
result[GasCall] = WarmStorageReadCost result[GasCall] = WarmStorageReadCost
func londonGasFees(previousFees: GasFeeSchedule): GasFeeSchedule =
result = previousFees
# EIP-3529 RefundsClear(4800) =
# EIP-2929(5000 - ColdSloadCost) +
# EIP-2930(ACCESS_LIST_STORAGE_KEY_COST)
result[RefundsClear] =
5000 - ColdSloadCost +
ACCESS_LIST_STORAGE_KEY_COST
const const
HomesteadGasFees = BaseGasFees.homesteadGasFees HomesteadGasFees = BaseGasFees.homesteadGasFees
TangerineGasFees = HomesteadGasFees.tangerineGasFees TangerineGasFees = HomesteadGasFees.tangerineGasFees
SpuriousGasFees = TangerineGasFees.spuriousGasFees SpuriousGasFees = TangerineGasFees.spuriousGasFees
IstanbulGasFees = SpuriousGasFees.istanbulGasFees IstanbulGasFees = SpuriousGasFees.istanbulGasFees
BerlinGasFees = IstanbulGasFees.berlinGasFees BerlinGasFees = IstanbulGasFees.berlinGasFees
LondonGasFees = BerlinGasFees.londonGasFees
gasFees*: array[Fork, GasFeeSchedule] = [ gasFees*: array[Fork, GasFeeSchedule] = [
FkFrontier: BaseGasFees, FkFrontier: BaseGasFees,
@ -740,7 +755,7 @@ const
FkPetersburg: SpuriousGasFees, FkPetersburg: SpuriousGasFees,
FkIstanbul: IstanbulGasFees, FkIstanbul: IstanbulGasFees,
FkBerlin: BerlinGasFees, FkBerlin: BerlinGasFees,
FkLondon: BerlinGasFees FkLondon: LondonGasFees
] ]

View File

@ -111,10 +111,15 @@ type
GasCosts* = array[Op, GasCost] GasCosts* = array[Op, GasCost]
const const
# From EIP-2929
ColdSloadCost* = 2100 ColdSloadCost* = 2100
ColdAccountAccessCost* = 2600 ColdAccountAccessCost* = 2600
WarmStorageReadCost* = 100 WarmStorageReadCost* = 100
# From EIP-2930 (Berlin).
ACCESS_LIST_STORAGE_KEY_COST* = 1900.GasInt
ACCESS_LIST_ADDRESS_COST* = 2400.GasInt
template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) = template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
## Generate the gas cost for each forks and store them in a const ## Generate the gas cost for each forks and store them in a const
@ -693,12 +698,22 @@ func berlinGasFees(previousFees: GasFeeSchedule): GasFeeSchedule =
result[GasSLoad] = 0 result[GasSLoad] = 0
result[GasCall] = WarmStorageReadCost result[GasCall] = WarmStorageReadCost
func londonGasFees(previousFees: GasFeeSchedule): GasFeeSchedule =
result = previousFees
# EIP-3529 RefundsClear(4800) =
# EIP-2929(5000 - ColdSloadCost) +
# EIP-2930(ACCESS_LIST_STORAGE_KEY_COST)
result[RefundsClear] =
5000 - ColdSloadCost +
ACCESS_LIST_STORAGE_KEY_COST
const const
HomesteadGasFees = BaseGasFees.homesteadGasFees HomesteadGasFees = BaseGasFees.homesteadGasFees
TangerineGasFees = HomesteadGasFees.tangerineGasFees TangerineGasFees = HomesteadGasFees.tangerineGasFees
SpuriousGasFees = TangerineGasFees.spuriousGasFees SpuriousGasFees = TangerineGasFees.spuriousGasFees
IstanbulGasFees = SpuriousGasFees.istanbulGasFees IstanbulGasFees = SpuriousGasFees.istanbulGasFees
BerlinGasFees = IstanbulGasFees.berlinGasFees BerlinGasFees = IstanbulGasFees.berlinGasFees
LondonGasFees = BerlinGasFees.londonGasFees
gasFees*: array[Fork, GasFeeSchedule] = [ gasFees*: array[Fork, GasFeeSchedule] = [
FkFrontier: BaseGasFees, FkFrontier: BaseGasFees,
@ -710,7 +725,7 @@ const
FkPetersburg: SpuriousGasFees, FkPetersburg: SpuriousGasFees,
FkIstanbul: IstanbulGasFees, FkIstanbul: IstanbulGasFees,
FkBerlin: BerlinGasFees, FkBerlin: BerlinGasFees,
FkLondon: BerlinGasFees FkLondon: LondonGasFees
] ]

View File

@ -48,6 +48,8 @@ export
vmg.GasSHA256Word, vmg.GasSHA256Word,
vmg.WarmStorageReadCost, vmg.WarmStorageReadCost,
vmg.forkToSchedule, vmg.forkToSchedule,
vmg.gasFees vmg.gasFees,
vmg.ACCESS_LIST_STORAGE_KEY_COST,
vmg.ACCESS_LIST_ADDRESS_COST
# End # End