Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[multisign_account] Add assert to ensure threshold <= public keys len #2615

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/rooch-types/src/bitcoin/multisign_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,6 +97,11 @@ pub fn generate_multisign_address(
threshold: usize,
public_keys: Vec<Vec<u8>>,
) -> Result<BitcoinAddress> {
ensure!(
threshold > 0 && threshold <= public_keys.len(),
"Invalid threshold: {}",
threshold
);
let mut x_only_public_keys = public_keys
.into_iter()
.map(|pk| {
Expand Down Expand Up @@ -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<XOnlyPublicKey>) -> ScriptBuf {
debug_assert!(threshold <= public_keys.len());
let mut builder = bitcoin::script::Builder::new();

for pubkey in public_keys {
Expand Down
1 change: 1 addition & 0 deletions frameworks/bitcoin-move/sources/multisign_account.move
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module bitcoin_move::multisign_account{
}

public fun generate_multisign_address(threshold: u64, public_keys: vector<vector<u8>>): 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
Expand Down
Loading