API crash preventing correct processing of deposits
Description
Brief/Intro
When a signer acts as a coordinator, it will initiate some sBTC stacks contract calls.
The problem now is that the signer does not check the nonce of the stacks transaction requested by the coordinator. A malicious coordinator can request nonces in batches in advance, and then DoS their contract calls when other signers become coordinators.
For example, if the current nonce is 100, the attacker can request nonces 101...200 in advance when becoming a coordinator. Then, when another signer becomes a coordinator, the attacker submits a transaction with a nonce of 101 to DoS the current coordinator's transaction.
Vulnerability Details
The signer/src/transaction_signer.rs::handle_stacks_transaction_sign_request code is as follows.
It does not check request.nonce and set it to the wallet's nonce.
Impact Details
The attacker can DoS other signers' Stacks transactions and can control whether deposits are executed or the order in which they are executed.
References
None
Proof of Concept
Proof of Concept
Base on: https://github.com/stacks-network/sbtc/releases/tag/0.0.9-rc4
Patch signer/src/config/mod.rs, add attacker flag config
Patch signer/src/main.rs, load attacker flag
Patch docker/docker-compose.yml, add attacker flag
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
This PoC sets sbtc-signer-3 as the attacker. Once it is sbtc-signer-3's turn as the coordinator, it will request signatures for a batch of Stacks transactions with different nonces and submit them to the Stacks network every 1 second
Then, check the logs of sbtc-signer-1 and sbtc-signer-2, and you will find that the deposits Stacks transactions they submitted failed due to CONFLICTING_NONCE_IN_MEMPOOL
async fn handle_stacks_transaction_sign_request(
&mut self,
request: &StacksTransactionSignRequest,
bitcoin_chain_tip: &model::BitcoinBlockHash,
origin_public_key: &PublicKey,
) -> Result<(), Error> {
let instant = std::time::Instant::now();
let validation_status = self
.assert_valid_stacks_tx_sign_request(request, bitcoin_chain_tip, origin_public_key)
.await;
metrics::histogram!(
Metrics::ValidationDurationSeconds,
"blockchain" => STACKS_BLOCKCHAIN,
"kind" => request.tx_kind(),
)
.record(instant.elapsed());
metrics::counter!(
Metrics::SignRequestsTotal,
"blockchain" => STACKS_BLOCKCHAIN,
"kind" => request.tx_kind(),
"status" => if validation_status.is_ok() { "success" } else { "failed" },
)
.increment(1);
validation_status?;
// We need to set the nonce in order to get the exact transaction
// that we need to sign.
let wallet = SignerWallet::load(&self.context, bitcoin_chain_tip).await?;
wallet.set_nonce(request.nonce);
let multi_sig = MultisigTx::new_tx(&request.contract_tx, &wallet, request.tx_fee);
let txid = multi_sig.tx().txid();
debug_assert_eq!(txid, request.txid);
let signature = crate::signature::sign_stacks_tx(multi_sig.tx(), &self.signer_private_key);
let msg = message::StacksTransactionSignature { txid, signature };
self.send_message(msg, bitcoin_chain_tip).await?;
Ok(())
}
/// 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 {
);
// 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.