@@ -4,6 +4,8 @@ import akka.util.ByteString
44
55import io .iohk .ethereum
66
7+ import io .iohk .ethereum .domain .AccessListItem
8+ import io .iohk .ethereum .domain .TransactionWithAccessList
79import io .iohk .ethereum .domain .UInt256
810import io .iohk .ethereum .utils .BlockchainConfig
911import io .iohk .ethereum .vm
@@ -196,12 +198,20 @@ case class EvmConfig(
196198
197199 /** Calculates transaction intrinsic gas. See YP section 6.2
198200 */
199- def calcTransactionIntrinsicGas (txData : ByteString , isContractCreation : Boolean ): BigInt = {
201+ def calcTransactionIntrinsicGas (
202+ txData : ByteString ,
203+ isContractCreation : Boolean ,
204+ accessList : Seq [AccessListItem ]
205+ ): BigInt = {
200206 val txDataZero = txData.count(_ == 0 )
201207 val txDataNonZero = txData.length - txDataZero
202208
209+ val accessListPrice =
210+ accessList.size * G_access_list_address +
211+ accessList.map(_.storageKeys.size).sum * G_access_list_storage
212+
203213 txDataZero * G_txdatazero +
204- txDataNonZero * G_txdatanonzero +
214+ txDataNonZero * G_txdatanonzero + accessListPrice +
205215 (if (isContractCreation) G_txcreate else 0 ) +
206216 G_transaction
207217 }
@@ -262,9 +272,13 @@ object FeeSchedule {
262272 override val G_copy = 3
263273 override val G_blockhash = 20
264274 override val G_extcode = 20
275+
276+ // note: the access list and cold/warm access do not exist until magneto hard fork
265277 override val G_cold_sload = 2100
266278 override val G_cold_account_access = 2600
267279 override val G_warm_storage_read = 100
280+ override val G_access_list_address = 2400
281+ override val G_access_list_storage = 1900
268282 }
269283
270284 class HomesteadFeeSchedule extends FrontierFeeSchedule {
@@ -300,6 +314,8 @@ object FeeSchedule {
300314 class MagnetoFeeSchedule extends PhoenixFeeSchedule {
301315 override val G_sload : BigInt = G_warm_storage_read
302316 override val G_sreset : BigInt = 5000 - G_cold_sload
317+ override val G_access_list_address : BigInt = 2400
318+ override val G_access_list_storage : BigInt = 1900
303319 }
304320}
305321
@@ -342,4 +358,6 @@ trait FeeSchedule {
342358 val G_cold_sload : BigInt
343359 val G_cold_account_access : BigInt
344360 val G_warm_storage_read : BigInt
361+ val G_access_list_address : BigInt
362+ val G_access_list_storage : BigInt
345363}
0 commit comments