Fix t8n: blobGasUsed exceeds allowance issue (#2407)
* Fix t8n: blobGasUsed exceeds allowance issue * Put blobGasUsed validation into transaction precessing pipeline
This commit is contained in:
parent
6b68ff92d3
commit
99ff8dc876
|
@ -21,6 +21,7 @@ import
|
||||||
../../evm/state,
|
../../evm/state,
|
||||||
../../evm/types,
|
../../evm/types,
|
||||||
../../constants,
|
../../constants,
|
||||||
|
../eip4844,
|
||||||
../validate
|
../validate
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -92,6 +93,12 @@ proc processTransactionImpl(
|
||||||
|
|
||||||
vmState.gasPool -= tx.gasLimit
|
vmState.gasPool -= tx.gasLimit
|
||||||
|
|
||||||
|
let blobGasUsed = tx.getTotalBlobGas
|
||||||
|
if vmState.blobGasUsed + blobGasUsed > MAX_BLOB_GAS_PER_BLOCK:
|
||||||
|
return err("blobGasUsed " & $blobGasUsed &
|
||||||
|
" exceeds maximum allowance " & $MAX_BLOB_GAS_PER_BLOCK)
|
||||||
|
vmState.blobGasUsed += blobGasUsed
|
||||||
|
|
||||||
# Actually, the eip-1559 reference does not mention an early exit.
|
# Actually, the eip-1559 reference does not mention an early exit.
|
||||||
#
|
#
|
||||||
# Even though database was not changed yet but, a `persist()` directive
|
# Even though database was not changed yet but, a `persist()` directive
|
||||||
|
|
|
@ -22,7 +22,7 @@ import
|
||||||
../../../common/common,
|
../../../common/common,
|
||||||
../../../utils/utils,
|
../../../utils/utils,
|
||||||
../../../constants,
|
../../../constants,
|
||||||
"../.."/[dao, executor, validate, eip4844, casper],
|
"../.."/[dao, executor, validate, casper],
|
||||||
../../../transaction/call_evm,
|
../../../transaction/call_evm,
|
||||||
../../../transaction,
|
../../../transaction,
|
||||||
../../../evm/state,
|
../../../evm/state,
|
||||||
|
@ -39,7 +39,6 @@ type
|
||||||
tr: CoreDbMptRef
|
tr: CoreDbMptRef
|
||||||
cleanState: bool
|
cleanState: bool
|
||||||
balance: UInt256
|
balance: UInt256
|
||||||
blobGasUsed: uint64
|
|
||||||
numBlobPerBlock: int
|
numBlobPerBlock: int
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -131,10 +130,6 @@ proc runTxCommit(pst: TxPackerStateRef; item: TxItemRef; gasBurned: GasInt)
|
||||||
vmState.cumulativeGasUsed += gasBurned
|
vmState.cumulativeGasUsed += gasBurned
|
||||||
vmState.receipts[inx] = vmState.makeReceipt(item.tx.txType)
|
vmState.receipts[inx] = vmState.makeReceipt(item.tx.txType)
|
||||||
|
|
||||||
# EIP-4844, count blobGasUsed
|
|
||||||
if item.tx.txType >= TxEip4844:
|
|
||||||
pst.blobGasUsed += item.tx.getTotalBlobGas
|
|
||||||
|
|
||||||
# Update txRoot
|
# Update txRoot
|
||||||
pst.tr.merge(rlp.encode(inx), rlp.encode(item.tx)).isOkOr:
|
pst.tr.merge(rlp.encode(inx), rlp.encode(item.tx)).isOkOr:
|
||||||
raiseAssert "runTxCommit(): merge failed, " & $$error
|
raiseAssert "runTxCommit(): merge failed, " & $$error
|
||||||
|
@ -262,7 +257,7 @@ proc vmExecCommit(pst: TxPackerStateRef)
|
||||||
if vmState.com.forkGTE(Cancun):
|
if vmState.com.forkGTE(Cancun):
|
||||||
# EIP-4844
|
# EIP-4844
|
||||||
xp.chain.excessBlobGas = Opt.some(vmState.blockCtx.excessBlobGas)
|
xp.chain.excessBlobGas = Opt.some(vmState.blockCtx.excessBlobGas)
|
||||||
xp.chain.blobGasUsed = Opt.some(pst.blobGasUsed)
|
xp.chain.blobGasUsed = Opt.some(vmState.blobGasUsed)
|
||||||
|
|
||||||
proc balanceDelta: UInt256 =
|
proc balanceDelta: UInt256 =
|
||||||
let postBalance = vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient)
|
let postBalance = vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient)
|
||||||
|
|
|
@ -36,6 +36,7 @@ proc init(
|
||||||
self.tracer = tracer
|
self.tracer = tracer
|
||||||
self.stateDB = ac
|
self.stateDB = ac
|
||||||
self.flags = flags
|
self.flags = flags
|
||||||
|
self.blobGasUsed = 0'u64
|
||||||
|
|
||||||
func blockCtx(com: CommonRef, header: BlockHeader):
|
func blockCtx(com: CommonRef, header: BlockHeader):
|
||||||
BlockContext =
|
BlockContext =
|
||||||
|
|
|
@ -66,6 +66,7 @@ type
|
||||||
receipts* : seq[Receipt]
|
receipts* : seq[Receipt]
|
||||||
cumulativeGasUsed*: GasInt
|
cumulativeGasUsed*: GasInt
|
||||||
gasCosts* : GasCosts
|
gasCosts* : GasCosts
|
||||||
|
blobGasUsed* : uint64
|
||||||
|
|
||||||
Computation* = ref object
|
Computation* = ref object
|
||||||
# The execution computation
|
# The execution computation
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Nimbus
|
# Nimbus
|
||||||
# Copyright (c) 2022 Status Research & Development GmbH
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
@ -569,6 +569,15 @@ const
|
||||||
output: T8nOutput(trace: true, result: true),
|
output: T8nOutput(trace: true, result: true),
|
||||||
expOut: "istanbul.txt",
|
expOut: "istanbul.txt",
|
||||||
),
|
),
|
||||||
|
TestSpec(
|
||||||
|
name : "Blob gas used exceeds max allowance",
|
||||||
|
base : "testdata/00-523",
|
||||||
|
input : t8nInput(
|
||||||
|
"alloc.json", "txs.rlp", "env.json", "Cancun", "0",
|
||||||
|
),
|
||||||
|
output: T8nOutput(result: true),
|
||||||
|
expOut: "exp.json",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
|
||||||
|
"balance": "0x00",
|
||||||
|
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
|
||||||
|
"nonce": "0x01",
|
||||||
|
"storage": {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
|
||||||
|
"balance": "0x1db38f",
|
||||||
|
"code": "0x",
|
||||||
|
"nonce": "0x00",
|
||||||
|
"storage": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"blockHashes": {
|
||||||
|
"0": "0x142abad1cb1f9c8a277d59f52cc29560472cf7bf4c46e12bfca8cf6b728acee2",
|
||||||
|
"1": "0x13af3033e1f55060b7d587ab559289599c74454c74403f3d8f05c6e237bb619e"
|
||||||
|
},
|
||||||
|
"currentBaseFee": "0x7",
|
||||||
|
"currentBlobGasUsed": "0xe0000",
|
||||||
|
"currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
||||||
|
"currentDifficulty": "0x0",
|
||||||
|
"currentExcessBlobGas": "0xe0000",
|
||||||
|
"currentGasLimit": "0x16345785d8a0000",
|
||||||
|
"currentNumber": "0x1",
|
||||||
|
"currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"currentTimestamp": "0xc",
|
||||||
|
"parentBaseFee": "0x7",
|
||||||
|
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"parentBlobGasUsed": "0x0",
|
||||||
|
"parentDifficulty": "0x0",
|
||||||
|
"parentExcessBlobGas": "0x140000",
|
||||||
|
"parentGasLimit": "0x16345785d8a0000",
|
||||||
|
"parentGasUsed": "0x0",
|
||||||
|
"parentTimestamp": "0x0",
|
||||||
|
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
||||||
|
"withdrawals": [
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"stateRoot": "0x2d5a3738dc0d76c5d1625b96d1597549c4cd218934167a672be4cc364646bdfc",
|
||||||
|
"txRoot": "0x3836ad4f15ec36789c84c94fb8342a0e5765d80446986c417b22954d1c9a5e8b",
|
||||||
|
"receiptsRoot": "0xc88bbb6ffab5658b295a44086ed7e77d4526e07e4025496e68a55042b24c81be",
|
||||||
|
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"receipts": [
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0x5208",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0x2f68a5bb6b843147e9ef8628047b6c5d5a0df834dc572007af7d4fce8e644c20",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x0",
|
||||||
|
"type": "0x3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0xa410",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0xfd836af5a833b60c4b07612a7d77f4fc9d9412841c03f94c6eef90ab2e716bf6",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x1",
|
||||||
|
"type": "0x3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0xf618",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0xa15a612ac2c6c92a62da1c8e8431a0335ad67066f078ea0434ee6bd48243caa5",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x2",
|
||||||
|
"type": "0x3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0x14820",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0x53402f0a35345a4a4b6d47eb19fedfcaa21ba2239ed3997a080e317377f1b777",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x3",
|
||||||
|
"type": "0x3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0x19a28",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0x5bd89296bd9454785bed316caeba5e6381552ed1f24f8386ee4774e390d6823e",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x4",
|
||||||
|
"type": "0x3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root": "0x",
|
||||||
|
"status": "0x1",
|
||||||
|
"cumulativeGasUsed": "0x1ec30",
|
||||||
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"logs": null,
|
||||||
|
"transactionHash": "0xdbb3a1b212d44a97f43b0b9f0db7e47d91c3d8baf3745accffe16b607901eba7",
|
||||||
|
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||||
|
"gasUsed": "0x5208",
|
||||||
|
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"transactionIndex": "0x5",
|
||||||
|
"type": "0x3"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"currentDifficulty": null,
|
||||||
|
"gasUsed": "0x1ec30",
|
||||||
|
"rejected": [
|
||||||
|
{
|
||||||
|
"index": 6,
|
||||||
|
"error": "blobGasUsed 917504 exceeds maximum allowance 786432"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"currentBaseFee": "0x7",
|
||||||
|
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||||
|
"currentExcessBlobGas": "0xe0000",
|
||||||
|
"blobGasUsed": "0xe0000"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
"0xf903c6b88803f885018080078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000001a0a8f4757869fbb831ba4ed3a7c8f868b0e2e0c1eda97937aab035560fffdedf3ca019d9b041540e3d6f5f56dc29deb8834a08171e92037cf567b922357e70f8e54ab88803f885010180078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000001a0ef4c93a2afbe03bc2f31334b5c42654f2b88f3d1526e2719454638d2c87f3eaaa06234b91bfba07b555f8e11d44486319ef599f61fdb70bd5ec02085a41ff8e2ccb88803f885010280078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000080a0fe46a6659784d1c49e66bfe79f53c9282521940f406d321a953600d3297498e1a011d6bd31ffcfc37bd89923bd565eca3df245ab923b95799811f227502a95a429b88803f885010380078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000001a05d87fd0644fda3b8ae7c840519b0a51c86e54097b63c394a8ebfb13f0212da78a07054fc9d2468c15c2d8257a54e42419e6a53fe0d4568ccf95ecd4414e3481cdeb88803f885010480078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000001a0903154f2ee69dbdc29f7369ac4270a31d32b8af6c28959d5c6b2b2ba696e9e7da06989cf772024d3efa30b4b99bc1e1dee27813964f39448d07377537a2681d139b88803f885010580078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000080a07efec980ef3b40c74b2de3dee9e9f081b9b4ae4ae1732d64ba0e9553aaf08dc4a0464e6720d2d74b4d68f37f339608278be3a16802b61a46dc9895b898a70939eab88803f885010680078252089400000000000000000000000000000000000001000180c001e1a0010000000000000000000000000000000000000000000000000000000000000001a02145ded5025c6144b8f5ae446db8b617c5ff760eb7c17fa439dedb576ada3ab3a03a15f5307cc6a12f853f6f3732a1d2598d117a387256ab0f8f49d9431caf43bf"
|
|
@ -234,7 +234,6 @@ proc exec(ctx: var TransContext,
|
||||||
vmState.processBeaconBlockRoot(ctx.env.parentBeaconBlockRoot.get).isOkOr:
|
vmState.processBeaconBlockRoot(ctx.env.parentBeaconBlockRoot.get).isOkOr:
|
||||||
raise newError(ErrorConfig, error)
|
raise newError(ErrorConfig, error)
|
||||||
|
|
||||||
var blobGasUsed = 0'u64
|
|
||||||
for txIndex, txRes in txList:
|
for txIndex, txRes in txList:
|
||||||
if txRes.isErr:
|
if txRes.isErr:
|
||||||
rejected.add RejectedTx(
|
rejected.add RejectedTx(
|
||||||
|
@ -274,7 +273,6 @@ proc exec(ctx: var TransContext,
|
||||||
rec, tx, sender, txIndex, gasUsed
|
rec, tx, sender, txIndex, gasUsed
|
||||||
)
|
)
|
||||||
includedTx.add tx
|
includedTx.add tx
|
||||||
blobGasUsed += tx.getTotalBlobGas
|
|
||||||
|
|
||||||
# Add mining reward? (-1 means rewards are disabled)
|
# Add mining reward? (-1 means rewards are disabled)
|
||||||
if stateReward.isSome and stateReward.get >= 0:
|
if stateReward.isSome and stateReward.get >= 0:
|
||||||
|
@ -323,7 +321,7 @@ proc exec(ctx: var TransContext,
|
||||||
)
|
)
|
||||||
|
|
||||||
if fork >= FkCancun:
|
if fork >= FkCancun:
|
||||||
result.result.blobGasUsed = Opt.some blobGasUsed
|
result.result.blobGasUsed = Opt.some vmState.blobGasUsed
|
||||||
if ctx.env.currentExcessBlobGas.isSome:
|
if ctx.env.currentExcessBlobGas.isSome:
|
||||||
result.result.currentExcessBlobGas = ctx.env.currentExcessBlobGas
|
result.result.currentExcessBlobGas = ctx.env.currentExcessBlobGas
|
||||||
elif ctx.env.parentExcessBlobGas.isSome and ctx.env.parentBlobGasUsed.isSome:
|
elif ctx.env.parentExcessBlobGas.isSome and ctx.env.parentBlobGasUsed.isSome:
|
||||||
|
|
Loading…
Reference in New Issue