Skip to content
DoS Audit finding Intermediate

The BitcoinCoreClient::get_tx_info does not support coinbase transactions, which may cause sBTC to be attacked by btc miners or sBTC donations to be lost

The BitcoinCoreClient::get_tx_info function fails to parse coinbase transactions because the BitcoinTxInfo struct requires a vin field that coinbase transactions lack. A malicious miner could include a small output to a signer's address in a coinbase transaction, causing the signer to fail parsing and ignore all transactions in that block, including user deposits.

f4lc0n Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#38582 [BC-High] The `BitcoinCoreClient::get_tx_info` does not support coinbase transactions, which

Submitted on Jan 7th 2025 at 09:31:52 UTC by @f4lc0n for Attackathon | Stacks

Description

Brief/Intro

The BitcoinCoreClient::get_tx_info function is used to get tx data from bitcoin RPC and parse it. It will parse the bitcoin RPC response data into a BitcoinTxInfo structure.

The BitcoinTxInfo structure requires that the bitcoin RPC response data must have a vin field. However, the coinbase tx in bitcoin does not contain vin. So when parsing the coinbase tx with the get_tx_info function, it fails to parse and returns an error.

This may have the following impact:

  • Malicious bitcoin miner sets 1 output transfer 1 sat to signers address in coinbase tx each time. Then, sBTC signer will try to parse the coinbase tx and fail, and then all txs in the block will be ignored, and the user's deposits also be ignored.
  • Honest bitcoin miners donating BTC to sBTC in coinbase tx will be ignored by sBTC signers.

Vulnerability Details

The signer/src/bitcoin/rpc.rs::BitcoinTxInfo structure is as follows.

Rust
    /// The inputs into the transaction.
    pub vin: Vec<BitcoinTxVin>,
    /// A description of the transactions outputs. This object is missing
    /// the `desc` field in the `scriptPubKey` object. That field is the
    /// "Inferred descriptor for the output".
    pub vout: Vec<BitcoinTxInfoVout>,

The vin field is not optional. Therefore, if the data of the bitcoin RPC response does not contain vin, the get_tx_info will fail to parse it.

The signer/src/block_observer.rs::process_bitcoin_block code is as follows.

Rust
    async fn process_bitcoin_block(&self, block_header: BitcoinBlockHeader) -> Result<(), Error> {
        let block = self
            .context
            .get_bitcoin_client()
            .get_block(&block_header.hash)
            .await?
            .ok_or(Error::BitcoinCoreMissingBlock(block_header.hash))?;
        let db_block = model::BitcoinBlock::from(&block);

        self.context
            .get_storage_mut()
            .write_bitcoin_block(&db_block)
            .await?;
        self.extract_sbtc_transactions(block_header.hash, &block.txdata)
            .await?;

        tracing::debug!("finished processing bitcoin block");
        Ok(())
    }

Note its calling order:

  1. call write_bitcoin_block
  2. call extract_sbtc_transactions

It first executes write_bitcoin_block, and then executes extract_sbtc_transactions. When extract_sbtc_transactions fails to parse coinbase tx, the block will no longer be processed.

Impact Details

  1. malicious bitcoin miners can use this bug to make sBTC signers ignore user deposits
  2. coinbase tx donations from honest bitcoin miners will be ignored

References

None

Proof of Concept

Proof of Concept

  1. Base on: https://github.com/stacks-network/sbtc/releases/tag/0.0.9-rc4

  2. Run docker

    Shell
    make devenv-up
    make devenv-down
    
  3. Get signers bitcoin address

    Shell
    ./signers.sh info
    
  4. Enter the docker-bitcoin-miner-1 docker

    Shell
    docker exec -it docker-bitcoin-miner-1 bash
    
  5. Run the following command inside the docker-bitcoin-miner-1 docker to mine a block to signers bitcoin address

    Shell
    bitcoin-cli -rpcwallet=main -rpcconnect=bitcoin generatetoaddress 1 "<signers bitcoin address>"
    
  6. Check the log of sbtc-signer-1 and you will find that sBTC signer has a parsing error

    2025-01-07T08:59:09.420166379Z  WARN block-observer:process_bitcoin_block{block_hash=309c10993443ff41a3becb8ba6f3bc8575ef42387754261bb545d95e305964e0}: signer::util: failover client call failed error=failed to retrieve the raw transaction for txid ef66dba196015cd9f4df07da8d45bc2654e8fb116c4e91e18dbb82ed3de56535 from bitcoin-core. JSON-RPC error: JSON decode error: missing field `prevout` at line 1 column 368 retry_num=0 max_retries=1
    

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

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 BitcoinTxInfo struct defines the vin field as mandatory, but coinbase transactions do not have a vin field, causing deserialization to fail.

Impact

A malicious miner could cause sBTC signers to ignore all transactions in a block, including user deposits, and honest miners' coinbase donations to sBTC would be lost.

What the attacker needed

Malicious miner can mine a block; miner includes output to signer address

How it was found

  1. Start the development environment with docker.
  2. Get the signers' Bitcoin address.
  3. Enter the bitcoin miner docker container.
  4. Mine a block to the signers' Bitcoin address using bitcoin-cli.
  5. Check the sBTC signer logs to observe a parsing error.

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 rewards; it has no real inputs. The sBTC signer software expects every transaction to have inputs, so when it sees a coinbase transaction it crashes and stops processing the whole block. A miner could exploit this to make the signer ignore legitimate user deposits.

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.

More by f4lc0n

View all

14 more disclosed reports, best first.

More from Stacks

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.