Skip to content

Commit

Permalink
Add signature verification to aggregate_partial_signatures (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak authored Jan 15, 2025
1 parent 6d83a3f commit 4922146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum BridgeError {
/// Returned when the secp256k1 crate returns an error
/// Returned when the bitcoin::secp256k1 crate returns an error
#[error("Secpk256Error: {0}")]
Secp256k1Error(#[from] bitcoin::secp256k1::Error),
BitcoinSecp256k1Error(#[from] bitcoin::secp256k1::Error),
/// Returned when the bitcoin crate returns an error in the sighash taproot module
#[error("BitcoinSighashTaprootError: {0}")]
BitcoinSighashTaprootError(#[from] bitcoin::sighash::TaprootError),
/// Returned when the secp256k1 crate returns an error
#[error("Secp256k1Error: {0}")]
Secp256k1Error(#[from] secp256k1::Error),
/// Returned when a non finalized deposit request is found
#[error("DepositNotFinalized")]
DepositNotFinalized,
Expand Down
16 changes: 9 additions & 7 deletions core/src/musig2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bitcoin::{
};
use secp256k1::{
musig::{
new_musig_nonce_pair, MusigAggNonce, MusigKeyAggCache, MusigPartialSignature,
self, new_musig_nonce_pair, MusigAggNonce, MusigKeyAggCache, MusigPartialSignature,
MusigPubNonce, MusigSecNonce, MusigSecRand, MusigSession,
},
rand::Rng,
Expand Down Expand Up @@ -117,15 +117,17 @@ pub fn aggregate_partial_signatures(
message: Message,
) -> Result<schnorr::Signature, BridgeError> {
let musig_key_agg_cache = create_key_agg_cache(pks, tweak);
let secp_message = to_secp_msg(&message);

let session = MusigSession::new(
SECP256K1,
&musig_key_agg_cache,
agg_nonce,
to_secp_msg(&message),
);
let session = MusigSession::new(SECP256K1, &musig_key_agg_cache, agg_nonce, secp_message);

let partial_sigs: Vec<&MusigPartialSignature> = partial_sigs.iter().collect();
let final_sig = session.partial_sig_agg(&partial_sigs);
SECP256K1.verify_schnorr(
&final_sig,
secp_message.as_ref(),
&musig_key_agg_cache.agg_pk(),
)?; // TODO: Change this later

Ok(from_secp_sig(session.partial_sig_agg(&partial_sigs)))
}
Expand Down

0 comments on commit 4922146

Please sign in to comment.