diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index dab79483b..74fe9dece 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -45,7 +45,7 @@ func intrinsicGas*(data: openarray[byte], fork: Fork): GasInt = else: result += gasFees[fork][GasTXDataNonZero] -proc intrinsicGas*(tx: TxTypes, fork: Fork): GasInt = +proc intrinsicGas*(tx: LegacyTx, fork: Fork): GasInt = # Compute the baseline gas cost for this transaction. This is the amount # of gas needed to send this transaction (but that is not actually used # for computation) @@ -54,6 +54,25 @@ proc intrinsicGas*(tx: TxTypes, fork: Fork): GasInt = if tx.isContractCreation: result = result + gasFees[fork][GasTXCreate] +proc intrinsicGas*(tx: AccessListTx, fork: Fork): GasInt = + const + ADDRESS_COST = 2400 + STORAGE_KEY_COST = 1900 + + # Compute the baseline gas cost for this transaction. This is the amount + # of gas needed to send this transaction (but that is not actually used + # for computation) + result = tx.payload.intrinsicGas(fork) + + result = result + tx.accessList.len * ADDRESS_COST + var numKeys = 0 + for n in tx.accessList: + inc(numKeys, n.storageKeys.len) + + result = result + numKeys * STORAGE_KEY_COST + if tx.isContractCreation: + result = result + gasFees[fork][GasTXCreate] + proc intrinsicGas*(tx: Transaction, fork: Fork): GasInt = txc(intrinsicGas, fork) diff --git a/nimbus/transaction/call_evm.nim b/nimbus/transaction/call_evm.nim index 8b1acf367..bb2086c25 100644 --- a/nimbus/transaction/call_evm.nim +++ b/nimbus/transaction/call_evm.nim @@ -191,6 +191,13 @@ proc txInitialAccessListEIP2929(tx: Transaction, sender: EthAddress, vmState: Ba for c in activePrecompiles(): db.accessList(c) + # EIP2930 optional access list + if tx.txType == AccessListTxType: + for n in tx.accessListTx.accessList: + db.accessList(n.address) + for x in n.storageKeys: + db.accessList(n.address, UInt256.fromBytesBE(x)) + proc txCallEvm*(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork: Fork): GasInt = txInitialAccessListEIP2929(tx, sender, vmState, fork)