fix EIP-3860 intrinsic gas once again
This commit is contained in:
parent
6814140c63
commit
be20e19991
|
@ -7,11 +7,19 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
./constants, ./errors, eth/[common, keys], ./utils/utils,
|
./constants, ./errors, eth/[common, keys], ./utils/utils,
|
||||||
common/evmforks, ./vm_gas_costs, ./vm_internals
|
common/evmforks, ./vm_gas_costs
|
||||||
|
|
||||||
import eth/common/transaction as common_transaction
|
import eth/common/transaction as common_transaction
|
||||||
export common_transaction, errors
|
export common_transaction, errors
|
||||||
|
|
||||||
|
proc toWordSize(size: GasInt): GasInt =
|
||||||
|
# Round input to the nearest bigger multiple of 32
|
||||||
|
# tx validation will ensure the value is not too big
|
||||||
|
if size > GasInt.high-31:
|
||||||
|
return (GasInt.high shr 5) + 1
|
||||||
|
|
||||||
|
(size + 31) shr 5
|
||||||
|
|
||||||
func intrinsicGas*(data: openArray[byte], fork: EVMFork): GasInt =
|
func intrinsicGas*(data: openArray[byte], fork: EVMFork): GasInt =
|
||||||
result = gasFees[fork][GasTransaction]
|
result = gasFees[fork][GasTransaction]
|
||||||
for i in data:
|
for i in data:
|
||||||
|
@ -29,7 +37,9 @@ proc intrinsicGas*(tx: Transaction, fork: EVMFork): GasInt =
|
||||||
if tx.contractCreation:
|
if tx.contractCreation:
|
||||||
result = result + gasFees[fork][GasTXCreate]
|
result = result + gasFees[fork][GasTXCreate]
|
||||||
if fork >= FkShanghai:
|
if fork >= FkShanghai:
|
||||||
result = result + (gasFees[fork][GasInitcodeWord] * tx.payload.len.wordCount)
|
# cannot use wordCount here, it will raise unlisted exception
|
||||||
|
let numWords = toWordSize(tx.payload.len)
|
||||||
|
result = result + (gasFees[fork][GasInitcodeWord] * numWords)
|
||||||
|
|
||||||
if tx.txType > TxLegacy:
|
if tx.txType > TxLegacy:
|
||||||
result = result + tx.accessList.len * ACCESS_LIST_ADDRESS_COST
|
result = result + tx.accessList.len * ACCESS_LIST_ADDRESS_COST
|
||||||
|
|
Loading…
Reference in New Issue