EIP-2930: optional access list

the new AccessListTx contains address and storage keys
that will go into global access list. and this come with
prices.... in ether
This commit is contained in:
jangko 2021-05-15 20:54:34 +07:00
parent a2712c5c7a
commit 01a27ff328
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 27 additions and 1 deletions

View File

@ -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)

View File

@ -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)