diff --git a/crates/rooch-types/src/bitcoin/multisign_account.rs b/crates/rooch-types/src/bitcoin/multisign_account.rs index 2dea7cc9a6..ddb64440cf 100644 --- a/crates/rooch-types/src/bitcoin/multisign_account.rs +++ b/crates/rooch-types/src/bitcoin/multisign_account.rs @@ -3,7 +3,7 @@ use crate::address::BitcoinAddress; use crate::addresses::BITCOIN_MOVE_ADDRESS; -use anyhow::Result; +use anyhow::{ensure, Result}; use bitcoin::bip32::{DerivationPath, Fingerprint}; use bitcoin::key::constants::SCHNORR_PUBLIC_KEY_SIZE; use bitcoin::key::Secp256k1; @@ -97,6 +97,11 @@ pub fn generate_multisign_address( threshold: usize, public_keys: Vec>, ) -> Result { + ensure!( + threshold > 0 && threshold <= public_keys.len(), + "Invalid threshold: {}", + threshold + ); let mut x_only_public_keys = public_keys .into_iter() .map(|pk| { @@ -132,6 +137,7 @@ pub fn generate_multisign_address( /// Create a multisig script, the caller should ensure the public keys are sorted fn create_multisig_script(threshold: usize, public_keys: &Vec) -> ScriptBuf { + debug_assert!(threshold <= public_keys.len()); let mut builder = bitcoin::script::Builder::new(); for pubkey in public_keys { diff --git a/frameworks/bitcoin-move/sources/multisign_account.move b/frameworks/bitcoin-move/sources/multisign_account.move index eb2880019a..4629d22071 100644 --- a/frameworks/bitcoin-move/sources/multisign_account.move +++ b/frameworks/bitcoin-move/sources/multisign_account.move @@ -104,6 +104,7 @@ module bitcoin_move::multisign_account{ } public fun generate_multisign_address(threshold: u64, public_keys: vector>): BitcoinAddress{ + assert!(vector::length(&public_keys) >= threshold, ErrorInvalidThreshold); let to_x_only_public_keys = to_x_only_public_keys(public_keys); //We need to sort the public keys to generate the same multisign address //And we sort the x_only_public_keys, not the original public keys