#38427 [BC-Low] Discrepancy in Intrinsic Gas Calculation between Txpool and EVM Execution
Submitted on Jan 3rd 2025 at 00:46:07 UTC by @CertiK for Attackathon | Ethereum Protocol
Report ID: #38427
Report Type: Blockchain/DLT
Report severity: Low
Target: https://github.com/ledgerwatch/erigon
Impacts:
(Specifications) A bug in specifications with no direct impact on client implementations
Description
Brief/Intro
The intrinsic gas amount is the minimal amount of gas required for a transaction calculated solely based on the transaction structure before the actual transaction execution. Both transaction validation in txpool and evm execution enforce the gas limit provided in the transaction larger than the intrinsic gas to be included into a block and execution.
In Erigon (https://github.com/erigontech/erigon ), the intrinsic gas amount calculated in txpool is less than the transaction execution for transaction type AccessListTxType (they should be the same), which could possibly lead to DoS attack with many spam transactions entered into the txpool or user accidentally provides gas limit larger than the intrinsic gas amount in txpool but less than the execution, but the transaction ultimately will not be included in a block for execution.
Vulnerability Details
Affected Codebase: https://github.com/erigontech/erigon/releases/tag/v3.0.0-alpha7
The function validateTx() is intended to validate the transaction when entering the mempool (txpool):
https://github.com/erigontech/erigon/blob/v3.0.0-alpha7/txnprovider/txpool/pool.go#L815
Which calls the function CalcIntrinsicGas() to compute the intrinsic gas amount for the transaction.
https://github.com/erigontech/erigon/blob/v3.0.0-alpha7/txnprovider/txpool/txpoolcfg/txpoolcfg.go#L194
In case that the gas limit provided in the transaction is less than the intrinsic gas amount, the transaction will be discarded immediately.
However, the inputs of the function miss the accesslist of the transaction:
During the execution of the transaction, a similar computation is performed within in function IntrinsicGas() :
https://github.com/erigontech/erigon/blob/v3.0.0-alpha7/core/state_transition.go#L111C1-L126C2
In this case, the access list of the transaction is provided for the intrinsic gas. Consequently, the intrinsic gas of a transaction with access list calculated in the txpool (mempool) is less than that in the execution
https://github.com/erigontech/erigon/blob/v3.0.0-alpha7/core/state_transition.go#L463
This would allow spam transactions to flood into the txpool (mempool) with a gas limit larger than the intrinsic gas in mempool but less than the execution, which could potentially lead to DoS attack to the txpool.
Impact Details
The difference in the intrinsic gas computation in the txpool (mempool) and execution would allow spam transactions to flood into the mempool, which could potentially lead to DoS attack to the txpool (mempool).
References
https://github.com/erigontech/erigon/releases/tag/v3.0.0-alpha7
Proof of Concept
Proof of Concept
We create the following unit test to show that the intrinsic gas computed in txpool is less than the intrinsic gas in execution. Moreover, the gas limit lies in between them.
Create a transaction of type AccessListTxType of non-empty access list and compute the intrinsic gas in txpool and execution:
The test result shows that the intrinsic gas in txpool is less than that in execution.
Was this helpful?