Skip to content

Commit

Permalink
Apply clippy suggestions for all
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak committed Aug 29, 2024
1 parent f92afdf commit 1acb70e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
6 changes: 3 additions & 3 deletions core/src/musig2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ mod tests {
message,
)
.unwrap();
musig2::verify_single(musig_agg_pubkey, &final_signature, message)
musig2::verify_single(musig_agg_pubkey, final_signature, message)
.expect("Verification failed!");
println!("MuSig2 signature verified successfully!");
}
Expand Down Expand Up @@ -486,7 +486,7 @@ mod tests {
XOnlyPublicKey::from_musig2_pks(pks, merkle_root, true);
// musig2::verify_single(musig_agg_pubkey, &final_signature, message)
// .expect("Verification failed!");
let _res = utils::SECP
utils::SECP
.verify_schnorr(
&secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(),
&Message::from_digest(message),
Expand Down Expand Up @@ -575,7 +575,7 @@ mod tests {
.unwrap();
// musig2::verify_single(musig_agg_pubkey, &final_signature, message)
// .expect("Verification failed!");
let _res = utils::SECP
utils::SECP
.verify_schnorr(
&secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(),
&Message::from_digest(message),
Expand Down
21 changes: 10 additions & 11 deletions core/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn run_single_deposit(

let secret_key = secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng());

let signer_address = Actor::new(secret_key, config.network.clone())
let signer_address = Actor::new(secret_key, config.network)
.address
.as_unchecked()
.clone();
Expand Down Expand Up @@ -104,7 +104,7 @@ pub async fn run_single_deposit(
&secp,
*operator_internal_xonly_pk,
None,
config.network.clone(),
config.network,
);
let operator_funding_outpoint = rpc
.send_to_address(&operator_address, 2 * BRIDGE_AMOUNT_SATS)
Expand Down Expand Up @@ -136,7 +136,7 @@ pub async fn run_single_deposit(
tracing::debug!("Now the verifiers sequence starts");
let mut slash_or_take_partial_sigs = Vec::new();

for (_i, (client, ..)) in verifiers.iter().enumerate() {
for (client, ..) in verifiers.iter() {
let (partial_sigs, _) = client
.operator_kickoffs_generated_rpc(
deposit_outpoint,
Expand All @@ -159,14 +159,14 @@ pub async fn run_single_deposit(
deposit_outpoint,
kickoff_utxos[i].clone(),
config.verifiers_public_keys.clone(),
config.operators_xonly_pks[i].clone(),
config.operators_xonly_pks[i],
i,
&agg_nonces[i + 1 + config.operators_xonly_pks.len()].clone(),
slash_or_take_partial_sigs
.iter()
.map(|v| v.get(i).cloned().unwrap())
.collect::<Vec<_>>(),
config.network.clone(),
config.network,
)?;

slash_or_take_sigs.push(secp256k1::schnorr::Signature::from_slice(&agg_sig)?);
Expand All @@ -175,7 +175,7 @@ pub async fn run_single_deposit(
// tracing::debug!("Slash or take sigs: {:#?}", slash_or_take_sigs);
// call burn_txs_signed_rpc
let mut operator_take_partial_sigs: Vec<Vec<[u8; 32]>> = Vec::new();
for (_i, (client, _, _)) in verifiers.iter().enumerate() {
for (client, _, _) in verifiers.iter() {
let partial_sigs = client
.burn_txs_signed_rpc(deposit_outpoint, vec![], slash_or_take_sigs.clone())
.await
Expand All @@ -197,9 +197,9 @@ pub async fn run_single_deposit(
&agg_nonces[i + 1].clone(),
operator_take_partial_sigs
.iter()
.map(|v| v[i].clone())
.map(|v| v[i])
.collect(),
config.network.clone(),
config.network,
)?;

operator_take_sigs.push(secp256k1::schnorr::Signature::from_slice(&agg_sig)?);
Expand All @@ -225,7 +225,7 @@ pub async fn run_single_deposit(
config.verifiers_public_keys.clone(),
&agg_nonces[0].clone(),
move_tx_partial_sigs,
config.network.clone(),
config.network,
)?;

let move_tx_sig = secp256k1::schnorr::Signature::from_slice(&agg_move_tx_final_sig)?;
Expand All @@ -243,8 +243,7 @@ pub async fn run_single_deposit(
&nofn_xonly_pk,
config.network,
);
let mut move_tx_witness_elements = Vec::new();
move_tx_witness_elements.push(move_tx_sig.serialize().to_vec());
let move_tx_witness_elements = vec![move_tx_sig.serialize().to_vec()];
handle_taproot_witness_new(&mut move_tx_handler, &move_tx_witness_elements, 0, Some(0))?;
tracing::debug!("Move tx: {:#?}", move_tx_handler.tx);
// tracing::debug!("Move tx_hex: {:?}", move_tx_handler.tx.raw_hex());
Expand Down
38 changes: 19 additions & 19 deletions core/tests/musig2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ async fn test_musig2_key_spend() {
let sks = config.all_verifiers_secret_keys.unwrap();
let kp_vec: Vec<Keypair> = sks
.iter()
.map(|sk| Keypair::from_secret_key(&secp, &sk))
.map(|sk| Keypair::from_secret_key(&secp, sk))
.collect();
let nonce_pair_vec: Vec<MuSigNoncePair> = kp_vec
.iter()
.map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng()))
.map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng()))
.collect();
let pks = kp_vec
.iter()
Expand All @@ -50,9 +50,9 @@ async fn test_musig2_key_spend() {
let untweaked_xonly_pubkey: secp256k1::XOnlyPublicKey =
secp256k1::XOnlyPublicKey::from_slice(&untweaked_pubkey.x_only_public_key().0.serialize())
.unwrap();
let (to_address, _) = TransactionBuilder::create_taproot_address(&vec![], None, config.network);
let (to_address, _) = TransactionBuilder::create_taproot_address(&[], None, config.network);
let (from_address, from_address_spend_info) = TransactionBuilder::create_taproot_address(
&vec![],
&[],
Some(untweaked_xonly_pubkey),
config.network,
);
Expand Down Expand Up @@ -106,19 +106,19 @@ async fn test_musig2_key_spend() {
let musig_agg_xonly_pubkey_wrapped =
bitcoin::XOnlyPublicKey::from_slice(&musig_agg_xonly_pubkey.serialize()).unwrap();

musig2::verify_single(musig_agg_pubkey, &final_signature, message)
musig2::verify_single(musig_agg_pubkey, final_signature, message)
.expect("Verification failed!");
let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap();
let res = secp
secp
.verify_schnorr(
&schnorr_sig,
&Message::from_digest(message),
&musig_agg_xonly_pubkey_wrapped,
)
.unwrap();
println!("MuSig2 signature verified successfully!");
println!("SECP Verification: {:?}", res);
tx_details.tx.input[0].witness.push(&final_signature);
println!("SECP Verified Successfully");
tx_details.tx.input[0].witness.push(final_signature);
let txid = rpc.send_raw_transaction(&tx_details.tx).unwrap();
println!("Transaction sent successfully! Txid: {}", txid);
}
Expand All @@ -132,11 +132,11 @@ async fn test_musig2_key_spend_with_script() {
let sks = config.all_verifiers_secret_keys.unwrap();
let kp_vec: Vec<Keypair> = sks
.iter()
.map(|sk| Keypair::from_secret_key(&secp, &sk))
.map(|sk| Keypair::from_secret_key(&secp, sk))
.collect();
let nonce_pair_vec: Vec<MuSigNoncePair> = kp_vec
.iter()
.map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng()))
.map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng()))
.collect();
let pks = kp_vec
.iter()
Expand All @@ -156,7 +156,7 @@ async fn test_musig2_key_spend_with_script() {
.unwrap();
let dummy_script = script::Builder::new().push_int(1).into_script();
let scripts: Vec<ScriptBuf> = vec![dummy_script];
let (to_address, _) = TransactionBuilder::create_taproot_address(&vec![], None, config.network);
let (to_address, _) = TransactionBuilder::create_taproot_address(&[], None, config.network);
let (from_address, from_address_spend_info) = TransactionBuilder::create_taproot_address(
&scripts,
Some(untweaked_xonly_pubkey),
Expand Down Expand Up @@ -211,10 +211,10 @@ async fn test_musig2_key_spend_with_script() {
let musig_agg_xonly_pubkey_wrapped =
bitcoin::XOnlyPublicKey::from_slice(&musig_agg_xonly_pubkey.serialize()).unwrap();

musig2::verify_single(musig_agg_pubkey, &final_signature, message)
musig2::verify_single(musig_agg_pubkey, final_signature, message)
.expect("Verification failed!");
let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap();
let _res = secp
secp
.verify_schnorr(
&schnorr_sig,
&Message::from_digest(message),
Expand All @@ -223,7 +223,7 @@ async fn test_musig2_key_spend_with_script() {
.unwrap();
// println!("MuSig2 signature verified successfully!");
// println!("SECP Verification: {:?}", res);
tx_details.tx.input[0].witness.push(&final_signature);
tx_details.tx.input[0].witness.push(final_signature);
let _txid = rpc.send_raw_transaction(&tx_details.tx).unwrap();
// println!("Transaction sent successfully! Txid: {}", txid);
}
Expand All @@ -237,11 +237,11 @@ async fn test_musig2_script_spend() {
let sks = config.all_verifiers_secret_keys.unwrap();
let kp_vec: Vec<Keypair> = sks
.iter()
.map(|sk| Keypair::from_secret_key(&secp, &sk))
.map(|sk| Keypair::from_secret_key(&secp, sk))
.collect();
let nonce_pair_vec: Vec<MuSigNoncePair> = kp_vec
.iter()
.map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng()))
.map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng()))
.collect();
let pks = kp_vec
.iter()
Expand Down Expand Up @@ -309,17 +309,17 @@ async fn test_musig2_script_spend() {
let final_signature: [u8; 64] =
aggregate_partial_signatures(pks.clone(), None, false, &agg_nonce, partial_sigs, message)
.unwrap();
musig2::verify_single(musig_agg_pubkey, &final_signature, message)
musig2::verify_single(musig_agg_pubkey, final_signature, message)
.expect("Verification failed!");
let res = utils::SECP
utils::SECP
.verify_schnorr(
&secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(),
&Message::from_digest(message),
&musig_agg_xonly_pubkey_wrapped,
)
.unwrap();
println!("MuSig2 signature verified successfully!");
println!("SECP Verification: {:?}", res);
println!("SECP Verified Successfully");
let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap();
let witness_elements = vec![schnorr_sig.as_ref()];
handle_taproot_witness_new(&mut tx_details, &witness_elements, 0, Some(0)).unwrap();
Expand Down

0 comments on commit 1acb70e

Please sign in to comment.