Skip to content
Business logic Audit finding Advanced

Key rotations bricks the system due to incorrect aggregate_key being used to spend the peg UTXO when signing a sweep transaction

After a key rotation, the coordinator signs the sweep transaction for the previous peg UTXO using the new aggregate key instead of the key that the UTXO is actually locked to. The resulting signature cannot spend the UTXO, so sweep transactions stop working and the system halts.

n4nika Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#37718 [BC-High] Key rotations bricks the system due to incorrect `aggregate_key` being used to spen

Submitted on Dec 13th 2024 at 08:31:21 UTC by @n4nika for Attackathon | Stacks

Description

Summary

When the coordinator gets the signatures to spend the previous peg-UTXO, they need to pass the aggregate_key which matches the key of that UTXO's key-only spendable taproot output. Currently this is not the case if we rotated the keys in the current signing round. This causes the coordinator to get a signature for the sweep transaction which cannot actually spend it. Since there is no programmed fallback to fix this, this will completely shutdown the system.

Finding Description

In the coordinator we have the following flow:

  1. get requests from emily
  2. deploy smart contracts if needed
  3. handle key rotation
  4. get pre-signature (just pre-validation)
  5. handle sweep transactions
  6. handle sBTC deposit transactions (s-deposit) (these mint sBTC)
    1. get signatures from signers
    2. submit the TX to Stacks

If we look at the code, we see that the newly gotten aggregate_key is used if we just rotated the keys:

RS
let aggregate_key = match maybe_aggregate_key {
    Some(key) => key,
    // This function returns the new DKG aggregate key.
    None => {
        let dkg_result = self.coordinate_dkg(&bitcoin_chain_tip).await?;
        self.get_signer_set_and_aggregate_key(&bitcoin_chain_tip)
            .await
            .ok()
            .and_then(|res| res.0)
            .unwrap_or(dkg_result)
    }
};

self.deploy_smart_contracts(&bitcoin_chain_tip, &aggregate_key)
    .await?;

self.check_and_submit_rotate_key_transaction(&bitcoin_chain_tip, &aggregate_key)
    .await?;

self.construct_and_sign_bitcoin_sbtc_transactions(
    &bitcoin_chain_tip,
    &aggregate_key, // [1] <-----
    &signer_public_keys,
)
.await?;

At [1], we pass it to the function handling the sweep transactions (which includes handling of the peg UTXO).

That function then calls sign_and_broadcast which then coordinates signing rounds in order to spend the peg UTXO and all user deposits. What is important here, is the signing of the peg UTXO:

RS
let mut coordinator_state_machine = CoordinatorStateMachine::load(
    &mut self.context.get_storage_mut(),
    *aggregate_key, // [2] <-----
    signer_public_keys.clone(),
    self.threshold,
    self.private_key,
)
.await?;
// [...]
let signature = self
    .coordinate_signing_round(
        bitcoin_chain_tip,
        &mut coordinator_state_machine, // [3] <-----
        txid,
        &msg,
        SignatureType::Taproot(None),
    )
    .await;

At [2] we create the state machine used for signing with the aggregate_key and request signatures using that state machine at [3].

Scenario

This becomes an issue if we rotate the keys:

  • we have an aggregate_key (keyA) which we use to sign peg UTXOs. This means all our newly generated UTXOs can only be spent with keyA!
  • we now rotate our keys, generating a new key (keyB)
  • since we use keyB in sign_and_broadcast now, the resulting signature will NOT be able to spend the previous UTXO since it is only spendable with keyA!

Impact

This will cause a full system halt since we cannot execute new sweep transactions and our previous peg UTXO is locked until we execute a signer upgrade.

Mitigation

In order to fix this, I would recommend getting the needed aggregate_key from the previous peg UTXO itself. This should work since signers are still able to sign for old aggregate_keys even after a rotation (according to the team).

Proof of Concept

Note to immunefi

This issue was discussed in discord and I was asked by @djordon to submit it explicitly without the requirement to write a PoC

The original report as published on Immunefi, by n4nika. 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

Likely the coordinator passes the freshly rotated aggregate key into the signing state machine for the sweep transaction instead of the aggregate key that the previous peg UTXO was created with.

Impact

This will cause a full system halt since new sweep transactions cannot be executed and the previous peg UTXO stays locked until a signer upgrade is performed.

What the attacker needed

A key rotation has occurred; the system holds a previous peg UTXO

The fix

The needed aggregate key should be taken from the previous peg UTXO itself, since signers can still sign for old aggregate keys after a rotation.

How it was found

  1. The coordinator fetches requests and handles any key rotation, producing a new aggregate key.
  2. It passes that new aggregate key into the function that constructs and signs the bitcoin sBTC transactions.
  3. That function loads the signing state machine with the new aggregate key and requests a signature for the sweep transaction.
  4. The signature is produced for the new key, but the previous peg UTXO is only spendable with the old key, so the sweep cannot be broadcast.

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 peg UTXO is a pool of bitcoin that the system controls, and it can only be spent with one specific key. When the operators change their keys, the code keeps using the new key to sign a transaction for the old pool, so the signature is rejected and the money cannot be moved. Because nothing falls back to the old key, the whole service stops working.

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