diff --git a/nimbus/common/chain_config.nim b/nimbus/common/chain_config.nim index 878430b5d..4f55339bb 100644 --- a/nimbus/common/chain_config.nim +++ b/nimbus/common/chain_config.nim @@ -35,6 +35,8 @@ type gasUser* : GasInt parentHash* : Hash256 baseFeePerGas*: Option[UInt256] + dataGasUsed* : Option[uint64] # EIP-4844 + excessDataGas*: Option[uint64] # EIP-4844 GenesisAlloc* = Table[EthAddress, GenesisAccount] GenesisAccount* = object @@ -65,6 +67,8 @@ type gasUser* : GasInt parentHash* : Hash256 baseFeePerGas*: Option[UInt256] + dataGasUsed* : Option[uint64] # EIP-4844 + excessDataGas*: Option[uint64] # EIP-4844 const CustomNet* = 0.NetworkId diff --git a/nimbus/common/genesis.nim b/nimbus/common/genesis.nim index 7da265aac..a92afa748 100644 --- a/nimbus/common/genesis.nim +++ b/nimbus/common/genesis.nim @@ -97,6 +97,10 @@ proc toGenesisHeader*( if fork >= Shanghai: result.withdrawalsRoot = some(EMPTY_ROOT_HASH) + if fork >= Cancun: + result.dataGasUsed = g.dataGasUsed + result.excessDataGas = g.excessDataGas + proc toGenesisHeader*( genesis: Genesis; fork: HardFork; diff --git a/nimbus/transaction/call_common.nim b/nimbus/transaction/call_common.nim index d8bd02a76..ebd64ca78 100644 --- a/nimbus/transaction/call_common.nim +++ b/nimbus/transaction/call_common.nim @@ -94,11 +94,6 @@ func intrinsicGas*(call: CallParams, vmState: BaseVMState): GasInt {.inline.} = gas += ACCESS_LIST_ADDRESS_COST gas += account.storageKeys.len * ACCESS_LIST_STORAGE_KEY_COST - # EIP-4844 - if fork >= FkCancun: - gas += calcDataFee(call.versionedHashes.len, - vmState.parent.excessDataGas).GasInt - return gas proc initialAccessListEIP2929(call: CallParams) = @@ -237,9 +232,19 @@ proc prepareToRunComputation(host: TransactionHost, call: CallParams) = # Charge for gas. if not call.noGasCharge: - host.vmState.mutateStateDB: + let + vmState = host.vmState + fork = vmState.fork + + vmState.mutateStateDB: db.subBalance(call.sender, call.gasLimit.u256 * call.gasPrice.u256) + # EIP-4844 + if fork >= FkCancun: + let blobFee = calcDataFee(call.versionedHashes.len, + vmState.parent.excessDataGas).GasInt + db.subBalance(call.sender, blobFee.u256) + proc calculateAndPossiblyRefundGas(host: TransactionHost, call: CallParams): GasInt = let c = host.computation diff --git a/tools/evmstate/helpers.nim b/tools/evmstate/helpers.nim index 390b867d9..d4c7e1333 100644 --- a/tools/evmstate/helpers.nim +++ b/tools/evmstate/helpers.nim @@ -67,6 +67,10 @@ proc fromJson(T: type AccessList, n: JsonNode): AccessList = ap.storageKeys.add hexToByteArray(sk.getStr, 32) result.add ap +proc fromJson(T: type VersionedHashes, list: JsonNode): VersionedHashes = + for x in list: + result.add Hash256.fromJson(x) + template required(T: type, nField: string): auto = fromJson(T, n[nField]) @@ -92,6 +96,8 @@ template optional(T: type, nField: string): auto = none(T) proc txType(n: JsonNode): TxType = + if "blobVersionedHashes" in n: + return TxEip4844 if "gasPrice" notin n: return TxEip1559 if "accessLists" in n: @@ -121,7 +127,9 @@ proc parseTx*(n: JsonNode, dataIndex, gasIndex, valueIndex: int): Transaction = gasPrice: omitZero(GasInt, "gasPrice"), maxFee : omitZero(GasInt, "maxFeePerGas"), accessList: omitZero(AccessList, "accessLists", dataIndex), - maxPriorityFee: omitZero(GasInt, "maxPriorityFeePerGas") + maxPriorityFee: omitZero(GasInt, "maxPriorityFeePerGas"), + maxFeePerDataGas: omitZero(GasInt, "maxFeePerDataGas"), + versionedHashes: omitZero(VersionedHashes, "blobVersionedHashes") ) let rawTo = n["to"].getStr