From 05d905b136e7a2c1da2b07c5d7dd2f80509405bc Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 28 Jun 2021 20:06:29 +0700 Subject: [PATCH] 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 --- nimbus/vm/interpreter/gas_costs.nim | 17 ++++++++++++++++- nimbus/vm2/interpreter/gas_costs.nim | 17 ++++++++++++++++- nimbus/vm_gas_costs.nim | 4 +++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/nimbus/vm/interpreter/gas_costs.nim b/nimbus/vm/interpreter/gas_costs.nim index d3b2fd01e..8199c90f1 100644 --- a/nimbus/vm/interpreter/gas_costs.nim +++ b/nimbus/vm/interpreter/gas_costs.nim @@ -116,10 +116,15 @@ type GasCosts* = array[Op, GasCost] const + # From EIP-2929 ColdSloadCost* = 2100 ColdAccountAccessCost* = 2600 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) = ## 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[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 HomesteadGasFees = BaseGasFees.homesteadGasFees TangerineGasFees = HomesteadGasFees.tangerineGasFees SpuriousGasFees = TangerineGasFees.spuriousGasFees IstanbulGasFees = SpuriousGasFees.istanbulGasFees BerlinGasFees = IstanbulGasFees.berlinGasFees + LondonGasFees = BerlinGasFees.londonGasFees gasFees*: array[Fork, GasFeeSchedule] = [ FkFrontier: BaseGasFees, @@ -740,7 +755,7 @@ const FkPetersburg: SpuriousGasFees, FkIstanbul: IstanbulGasFees, FkBerlin: BerlinGasFees, - FkLondon: BerlinGasFees + FkLondon: LondonGasFees ] diff --git a/nimbus/vm2/interpreter/gas_costs.nim b/nimbus/vm2/interpreter/gas_costs.nim index 0d7c4133c..2ddf2ac74 100644 --- a/nimbus/vm2/interpreter/gas_costs.nim +++ b/nimbus/vm2/interpreter/gas_costs.nim @@ -111,10 +111,15 @@ type GasCosts* = array[Op, GasCost] const + # From EIP-2929 ColdSloadCost* = 2100 ColdAccountAccessCost* = 2600 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) = ## 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[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 HomesteadGasFees = BaseGasFees.homesteadGasFees TangerineGasFees = HomesteadGasFees.tangerineGasFees SpuriousGasFees = TangerineGasFees.spuriousGasFees IstanbulGasFees = SpuriousGasFees.istanbulGasFees BerlinGasFees = IstanbulGasFees.berlinGasFees + LondonGasFees = BerlinGasFees.londonGasFees gasFees*: array[Fork, GasFeeSchedule] = [ FkFrontier: BaseGasFees, @@ -710,7 +725,7 @@ const FkPetersburg: SpuriousGasFees, FkIstanbul: IstanbulGasFees, FkBerlin: BerlinGasFees, - FkLondon: BerlinGasFees + FkLondon: LondonGasFees ] diff --git a/nimbus/vm_gas_costs.nim b/nimbus/vm_gas_costs.nim index d7f15561e..d4de0a3f8 100644 --- a/nimbus/vm_gas_costs.nim +++ b/nimbus/vm_gas_costs.nim @@ -48,6 +48,8 @@ export vmg.GasSHA256Word, vmg.WarmStorageReadCost, vmg.forkToSchedule, - vmg.gasFees + vmg.gasFees, + vmg.ACCESS_LIST_STORAGE_KEY_COST, + vmg.ACCESS_LIST_ADDRESS_COST # End