fix EIP-4844 bugs in genesis, evmstate and blobFee

This commit is contained in:
jangko 2023-07-21 06:34:56 +07:00
parent ab79cfc775
commit 3aff8d0d61
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 28 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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