Skip to content
Business logic Audit finding Advanced

Btcstaking module allows `stakingTx` to be coinbase transaction which is unslashable for 100 blocks

The staking module did not check whether a staking transaction was a coinbase transaction, which cannot be spent for 100 blocks. A miner could use a coinbase transaction as their staking transaction and double-sign without being slashed for 100 blocks.

n4nika Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-babylon-judging/issues/6

Found by

n4nika

Summary

Coinbase transactions have a special property of not being spendable for 100 bocks after creation. If now a staker uses such a transaction as a staking transaction (by adding the required outputs), that transaction will be recognized as a valid staking TX but if the owner of it double-signs, he cannot be slashed for 100 blocks due to the unspendability of the coinbase TX.

Root Cause

Looking at CreateBTCDelegation and ValidateParsedMessageAgainstTheParams which does verification on the provided TX, there are no specific checks for whether a transaction is a coinbase transaction.

Internal Pre-conditions

None

External Pre-conditions

Attacker needs to be the creator of a block (a miner) in order to build the coinbase TX like they want

Attack Path

  • Create a coinbase TX which is a valid staking TX
  • Call CreateBTCDelegation with that TX
  • It gets accepted and its value added as voting power

Impact

The README states under High impact: Inability to slash BTC stake for which the voting power was involved in double-signing.

That is exactly what happens here. Even if the staker's delegator misbehaves, the staker's stakingTx cannot be spent until 100 blocks after. Adding to the impact, if now the minimum staking time is less than 100 bitcoin blocks, this allows the malicious staker to unstake before getting slashed (if the slashing even gets retried after 100 blocks)

PoC

No response

Mitigation

Coinbase transactions can be identified since the ID of their input must be all zeros. Therefore consider checking whether a staking transaction has one input with an ID of all-zeros and reject it if so.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/babylonlabs-io/babylon/pull/563

The original report as published on Sherlock, by n4nika. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

Impact

A staker could double-sign and not be slashed for 100 blocks, and if the minimum staking time is less than 100 blocks they could unstake before being slashed.

What the attacker needed

Attacker is a miner; minimum staking time under 100 blocks (for unstake)

The fix

The protocol team fixed this issue by checking for coinbase transactions and rejecting them.

How it was found

  1. Create a coinbase transaction that is also a valid staking transaction.
  2. Call CreateBTCDelegation with that transaction.
  3. The transaction is accepted and its value is added as voting power.

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.

A coinbase transaction is the special transaction a miner creates to collect their reward; it cannot be spent until 100 blocks later. The staking system accepted such a transaction as a stake, so a miner could misbehave and the system could not take their stake away for 100 blocks.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by n4nika

View all

13 more disclosed reports, best first.

More from Babylon Chain Launch (Phase-2)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.