#38582 [BC-High] 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
Submitted on Jan 7th 2025 at 09:31:52 UTC by @f4lc0n for Attackathon | Stacks
Report ID: #38582
Report Type: Blockchain/DLT
Report severity: High
Target: https://github.com/stacks-network/sbtc/tree/immunefi_attackaton_0.9/signer
Impacts:
Direct loss of funds
API crash preventing correct processing of deposits
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.
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.
Note its calling order:
call
write_bitcoin_block
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
malicious bitcoin miners can use this bug to make sBTC signers ignore user deposits
coinbase tx donations from honest bitcoin miners will be ignored
References
None
Proof of Concept
Proof of Concept
Base on: https://github.com/stacks-network/sbtc/releases/tag/0.0.9-rc4
Run docker
Get signers bitcoin address
Enter the
docker-bitcoin-miner-1
dockerRun the following command inside the
docker-bitcoin-miner-1
docker to mine a block to signers bitcoin addressCheck the log of sbtc-signer-1 and you will find that sBTC signer has a parsing error
Was this helpful?