From be20e199913fa95eb1ddf95f25e52f818e1b1bf1 Mon Sep 17 00:00:00 2001 From: jangko Date: Sun, 15 Jan 2023 14:37:19 +0700 Subject: [PATCH] fix EIP-3860 intrinsic gas once again --- nimbus/transaction.nim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index 6857749c2..7c4bb004a 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -7,11 +7,19 @@ import ./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 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 = result = gasFees[fork][GasTransaction] for i in data: @@ -29,7 +37,9 @@ proc intrinsicGas*(tx: Transaction, fork: EVMFork): GasInt = if tx.contractCreation: result = result + gasFees[fork][GasTXCreate] 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: result = result + tx.accessList.len * ACCESS_LIST_ADDRESS_COST