Skip to content

Commit 35e2de7

Browse files
committed
Remove secp context
1 parent 69f6223 commit 35e2de7

File tree

22 files changed

+165
-310
lines changed

22 files changed

+165
-310
lines changed

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ fn setup_keys(
6565
Vec<bitcoin::secp256k1::Keypair>,
6666
Vec<XOnlyPublicKey>,
6767
) {
68-
let secp_sign = secp256k1::Secp256k1::signing_only();
6968
let mut sk = [0; 32];
7069
let mut sks = vec![];
7170
let mut pks = vec![];
@@ -76,7 +75,7 @@ fn setup_keys(
7675

7776
let sk = secp256k1::SecretKey::from_slice(&sk[..]).expect("secret key");
7877
let pk = miniscript::bitcoin::PublicKey {
79-
inner: secp256k1::PublicKey::from_secret_key(&secp_sign, &sk),
78+
inner: secp256k1::PublicKey::from_secret_key(&sk),
8079
compressed: true,
8180
};
8281
pks.push(pk);
@@ -87,7 +86,7 @@ fn setup_keys(
8786
let mut x_only_pks = vec![];
8887

8988
for sk in &sks {
90-
let keypair = bitcoin::secp256k1::Keypair::from_secret_key(&secp_sign, sk);
89+
let keypair = bitcoin::secp256k1::Keypair::from_secret_key(sk);
9190
let (xpk, _parity) = XOnlyPublicKey::from_keypair(&keypair);
9291
x_only_keypairs.push(keypair);
9392
x_only_pks.push(xpk);

bitcoind-tests/tests/test_cpp.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn get_vout(cl: &Client, txid: Txid, value: Amount) -> (OutPoint, TxOut) {
6868
}
6969

7070
pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
71-
let secp = secp256k1::Secp256k1::new();
7271
let desc_vec = parse_miniscripts(&testdata.pubdata);
7372
let sks = &testdata.secretdata.sks;
7473
let pks = &testdata.pubdata.pks;
@@ -145,7 +144,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
145144
// Sign the transactions with all keys
146145
// AKA the signer role of psbt
147146
for i in 0..psbts.len() {
148-
let wsh_derived = desc_vec[i].derived_descriptor(&secp);
147+
let wsh_derived = desc_vec[i].derived_descriptor();
149148
let ms = if let Descriptor::Wsh(wsh) = &wsh_derived {
150149
match wsh.as_inner() {
151150
miniscript::descriptor::WshInner::Ms(ms) => ms,
@@ -196,11 +195,11 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
196195
.insert(testdata.pubdata.ripemd160, testdata.secretdata.ripemd160_pre.to_vec());
197196
// Finalize the transaction using psbt
198197
// Let miniscript do it's magic!
199-
if let Err(e) = psbts[i].finalize_mall_mut(&secp) {
198+
if let Err(e) = psbts[i].finalize_mall_mut() {
200199
// All miniscripts should satisfy
201200
panic!("Could not satisfy: error{} ms:{} at ind:{}", e[0], ms, i);
202201
} else {
203-
let tx = psbts[i].extract(&secp).unwrap();
202+
let tx = psbts[i].extract().unwrap();
204203

205204
// Send the transactions to bitcoin node for mining.
206205
// Regtest mode has standardness checks

bitcoind-tests/tests/test_desc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ pub fn test_desc_satisfy(
7373
testdata: &TestData,
7474
descriptor: &str,
7575
) -> Result<Witness, DescError> {
76-
let secp = secp256k1::Secp256k1::new();
7776
let sks = &testdata.secretdata.sks;
7877
let xonly_keypairs = &testdata.secretdata.x_only_keypairs;
7978
let pks = &testdata.pubdata.pks;
@@ -89,7 +88,7 @@ pub fn test_desc_satisfy(
8988
.at_derivation_index(0)
9089
.unwrap();
9190

92-
let derived_desc = definite_desc.derived_descriptor(&secp);
91+
let derived_desc = definite_desc.derived_descriptor();
9392
let desc_address = derived_desc.address(bitcoin::Network::Regtest);
9493
let desc_address = desc_address.map_err(|_x| DescError::AddressComputationError)?;
9594

@@ -169,7 +168,7 @@ pub fn test_desc_satisfy(
169168
if let Some(internal_keypair) = internal_keypair {
170169
// ---------------------- Tr key spend --------------------
171170
let internal_keypair = internal_keypair
172-
.tap_tweak(&secp, tr.spend_info().merkle_root());
171+
.tap_tweak(tr.spend_info().merkle_root());
173172
let sighash_msg = sighash_cache
174173
.taproot_key_spend_signature_hash(0, &prevouts, sighash_type)
175174
.unwrap();
@@ -278,10 +277,10 @@ pub fn test_desc_satisfy(
278277
println!("Testing descriptor: {}", definite_desc);
279278
// Finalize the transaction using psbt
280279
// Let miniscript do it's magic!
281-
if psbt.finalize_mut(&secp).is_err() {
280+
if psbt.finalize_mut().is_err() {
282281
return Err(DescError::PsbtFinalizeError);
283282
}
284-
let tx = psbt.extract(&secp).expect("Extraction error");
283+
let tx = psbt.extract().expect("Extraction error");
285284

286285
// Send the transactions to bitcoin node for mining.
287286
// Regtest mode has standardness checks

examples/big.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use miniscript::{
2020
translate_hash_fail, DefiniteDescriptorKey, Descriptor, DescriptorPublicKey, MiniscriptKey,
2121
Translator,
2222
};
23-
use secp256k1::Secp256k1;
23+
2424
fn main() {
2525
let empty = "".to_string();
2626
let mut args = std::env::args().collect::<Vec<_>>();
@@ -39,8 +39,7 @@ fn main() {
3939
.unwrap();
4040
println!("{}", a);
4141

42-
let secp = Secp256k1::new();
43-
let (d, m) = Descriptor::parse_descriptor(&secp, &i).unwrap();
42+
let (d, m) = Descriptor::parse_descriptor(&i).unwrap();
4443
use_descriptor(d);
4544
println!("{:?}", m);
4645

@@ -52,7 +51,7 @@ fn main() {
5251
println!("{:?}", h.address(bitcoin::Network::Bitcoin));
5352

5453
let psbt: bitcoin::Psbt = i.parse().unwrap();
55-
let psbt = psbt.finalize(&secp).unwrap();
54+
let psbt = psbt.finalize().unwrap();
5655
let mut tx = psbt.extract_tx().unwrap();
5756
println!("{:?}", tx);
5857

examples/psbt_sign_finalize.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use miniscript::psbt::{PsbtExt, PsbtInputExt};
1818
use miniscript::Descriptor;
1919

2020
fn main() {
21-
let secp256k1 = secp256k1::Secp256k1::new();
22-
2321
let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn";
2422
let bridge_descriptor = Descriptor::from_str(s).unwrap();
2523
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
@@ -142,7 +140,7 @@ fn main() {
142140
println!("{:#?}", psbt);
143141
println!("{}", psbt);
144142

145-
psbt.finalize_mut(&secp256k1).unwrap();
143+
psbt.finalize_mut().unwrap();
146144
println!("{:#?}", psbt);
147145

148146
let tx = psbt.extract_tx().expect("failed to extract tx");

examples/taptree_of_horror/helper_fns.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bitcoin::bip32::{DerivationPath, Xpriv};
44
use bitcoin::hashes::{ripemd160, sha256};
55
use miniscript::descriptor::DescriptorSecretKey;
66
use miniscript::ToPublicKey;
7-
use secp256k1::Secp256k1;
87

98
use crate::KEYS_PER_PERSONA;
109

@@ -28,7 +27,6 @@ pub fn produce_kelly_hash(secret: &str) -> (sha256::Hash, sha256::Hash) {
2827

2928
pub fn produce_key_pairs(
3029
desc: DescriptorSecretKey,
31-
secp: &Secp256k1<secp256k1::All>,
3230
derivation_without_index: &str,
3331
_alias: &str,
3432
) -> (Vec<bitcoin::PublicKey>, Vec<Xpriv>) {
@@ -42,7 +40,7 @@ pub fn produce_key_pairs(
4240

4341
for i in 0..KEYS_PER_PERSONA {
4442
let pk = desc
45-
.to_public(secp)
43+
.to_public()
4644
.unwrap()
4745
.at_derivation_index(i.try_into().unwrap())
4846
.unwrap()

examples/taptree_of_horror/taptree_of_horror.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ mod helper_fns;
1515
pub const KEYS_PER_PERSONA: usize = 9;
1616

1717
fn main() {
18-
let secp: &secp256k1::Secp256k1<secp256k1::All> = &secp256k1::Secp256k1::new();
19-
2018
// ====== 1. Setup Hardcoded Values for all of the Personas ======
2119

2220
// Define derivation paths that will be used
@@ -59,7 +57,7 @@ fn main() {
5957
// ====== 2. Derive Keys, Preimages, Hashes, and Timelocks for Policy and Signing ======
6058

6159
let internal_xpub: miniscript::DescriptorPublicKey =
62-
internal_desc_secret.to_public(secp).unwrap();
60+
internal_desc_secret.to_public().unwrap();
6361

6462
// example of how defining the internal xpriv that can be used for signing.
6563
// let internal_xpriv: DescriptorXKey<bitcoin::bip32::Xpriv> = match internal_desc_secret {
@@ -68,20 +66,20 @@ fn main() {
6866
// }
6967
// .unwrap();
7068

71-
let (a_pks, a_prvs) = produce_key_pairs(a_descriptor_desc_secret, secp, normal_path, "alice");
72-
let (b_pks, b_prvs) = produce_key_pairs(b_descriptor_desc_secret, secp, normal_path, "bob");
73-
let (c_pks, c_prvs) = produce_key_pairs(c_descriptor_desc_secret, secp, normal_path, "charlie");
74-
let (d_pks, d_prvs) = produce_key_pairs(d_descriptor_desc_secret, secp, weird_path, "dave");
75-
let (e_pks, e_prvs) = produce_key_pairs(e_descriptor_desc_secret, secp, normal_path, "eve");
76-
let (f_pks, f_prvs) = produce_key_pairs(f_descriptor_desc_secret, secp, normal_path, "frank");
77-
let (h_pks, h_prvs) = produce_key_pairs(h_descriptor_desc_secret, secp, normal_path, "heather");
78-
let (i_pks, i_prvs) = produce_key_pairs(i_descriptor_desc_secret, secp, unhardened_path, "ian");
79-
let (j_pks, j_prvs) = produce_key_pairs(j_descriptor_desc_secret, secp, normal_path, "judy");
80-
let (l_pks, l_prvs) = produce_key_pairs(l_descriptor_desc_secret, secp, normal_path, "liam");
69+
let (a_pks, a_prvs) = produce_key_pairs(a_descriptor_desc_secret, normal_path, "alice");
70+
let (b_pks, b_prvs) = produce_key_pairs(b_descriptor_desc_secret, normal_path, "bob");
71+
let (c_pks, c_prvs) = produce_key_pairs(c_descriptor_desc_secret, normal_path, "charlie");
72+
let (d_pks, d_prvs) = produce_key_pairs(d_descriptor_desc_secret, weird_path, "dave");
73+
let (e_pks, e_prvs) = produce_key_pairs(e_descriptor_desc_secret, normal_path, "eve");
74+
let (f_pks, f_prvs) = produce_key_pairs(f_descriptor_desc_secret, normal_path, "frank");
75+
let (h_pks, h_prvs) = produce_key_pairs(h_descriptor_desc_secret, normal_path, "heather");
76+
let (i_pks, i_prvs) = produce_key_pairs(i_descriptor_desc_secret, unhardened_path, "ian");
77+
let (j_pks, j_prvs) = produce_key_pairs(j_descriptor_desc_secret, normal_path, "judy");
78+
let (l_pks, l_prvs) = produce_key_pairs(l_descriptor_desc_secret, normal_path, "liam");
8179
let (s_pks, _s_prvs) =
82-
produce_key_pairs(s_descriptor_desc_secret, secp, normal_path, "s_backup1");
80+
produce_key_pairs(s_descriptor_desc_secret, normal_path, "s_backup1");
8381
let (x_pks, _x_prvs) =
84-
produce_key_pairs(x_descriptor_desc_secret, secp, normal_path, "x_backup2");
82+
produce_key_pairs(x_descriptor_desc_secret, normal_path, "x_backup2");
8583

8684
// For this example we are grabbing the 9 keys for each persona
8785
let [a0, a1, a2, a3, a4, a5, a6, a7, a8]: [PublicKey; KEYS_PER_PERSONA] =
@@ -201,8 +199,6 @@ fn main() {
201199

202200
// ====== 4. Construct an Unsigned Transaction from the Tapscript ======
203201

204-
let secp: &secp256k1::Secp256k1<secp256k1::All> = &secp256k1::Secp256k1::new();
205-
206202
let tx_in = TxIn {
207203
previous_output: bitcoin::OutPoint {
208204
txid: "8888888899999999aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffff"
@@ -273,7 +269,7 @@ fn main() {
273269
.insert(grim.1, grim.0.to_byte_array().to_vec());
274270

275271
// Finalize PSBT now that we have all the required signatures and hash preimages.
276-
psbt.finalize_mut(secp).unwrap();
272+
psbt.finalize_mut().unwrap();
277273

278274
// Now extract the tx
279275
let signed_tx = psbt.extract_tx().unwrap();

examples/verify_tx.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::str::FromStr;
66

77
use miniscript::bitcoin::consensus::Decodable;
88
use miniscript::bitcoin::script::ScriptPubKeyBuf;
9-
use miniscript::bitcoin::secp256k1::Secp256k1;
109
use miniscript::bitcoin::{absolute, sighash, Sequence};
1110
use miniscript::interpreter::KeySigPair;
1211

@@ -64,13 +63,12 @@ fn main() {
6463
// as having participated in the script
6564

6665
println!("\n\nExample two:\n");
67-
let secp = Secp256k1::new();
6866

6967
// We can set prevouts to be empty list because this is a legacy transaction
7068
// and this information is not required for sighash computation.
7169
let prevouts = sighash::Prevouts::All::<bitcoin::TxOut>(&[]);
7270

73-
for elem in interpreter.iter(&secp, &tx, 0, &prevouts) {
71+
for elem in interpreter.iter(&tx, 0, &prevouts) {
7472
if let miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } =
7573
elem.expect("no evaluation error")
7674
{

examples/xpub_descriptors.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@
44
55
use std::str::FromStr;
66

7-
use miniscript::bitcoin::secp256k1::{Secp256k1, Verification};
87
use miniscript::bitcoin::{Address, Network};
98
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey};
109

1110
const XPUB_1: &str = "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB";
1211
const XPUB_2: &str = "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH";
1312

1413
fn main() {
15-
// For deriving from descriptors, we need to provide a secp context.
16-
let secp = Secp256k1::verification_only();
17-
1814
// P2WSH and single xpubs.
19-
let _ = p2wsh(&secp);
15+
let _ = p2wsh();
2016

2117
// P2WSH-P2SH and ranged xpubs.
22-
let _ = p2sh_p2wsh(&secp);
18+
let _ = p2sh_p2wsh();
2319
}
2420

2521
/// Parses a P2WSH descriptor, returns the associated address.
26-
fn p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
22+
fn p2wsh() -> Address {
2723
// It does not matter what order the two xpubs go in, the same address will be generated.
2824
let s = format!("wsh(sortedmulti(1,{},{}))", XPUB_1, XPUB_2);
2925
// let s = format!("wsh(sortedmulti(1,{},{}))", XPUB_2, XPUB_1);
3026

3127
let address = Descriptor::<DefiniteDescriptorKey>::from_str(&s)
3228
.unwrap()
33-
.derived_descriptor(secp)
29+
.derived_descriptor()
3430
.address(Network::Bitcoin)
3531
.unwrap();
3632

@@ -45,14 +41,14 @@ fn p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
4541
}
4642

4743
/// Parses a P2SH-P2WSH descriptor, returns the associated address.
48-
fn p2sh_p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
44+
fn p2sh_p2wsh() -> Address {
4945
// It does not matter what order the two xpubs go in, the same address will be generated.
5046
let s = format!("sh(wsh(sortedmulti(1,{}/1/0/*,{}/0/0/*)))", XPUB_1, XPUB_2);
5147
// let s = format!("sh(wsh(sortedmulti(1,{}/1/0/*,{}/0/0/*)))", XPUB_2, XPUB_1);
5248

5349
let address = Descriptor::<DescriptorPublicKey>::from_str(&s)
5450
.unwrap()
55-
.derived_descriptor(secp, 5)
51+
.derived_descriptor(5)
5652
.unwrap()
5753
.address(Network::Bitcoin)
5854
.unwrap();

fuzz/fuzz_targets/parse_descriptor_priv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use miniscript::Descriptor;
66

77
fn do_test(data: &[u8]) {
88
let data_str = String::from_utf8_lossy(data);
9-
let secp = &secp256k1::Secp256k1::signing_only();
109

11-
if let Ok((desc, _)) = Descriptor::parse_descriptor(secp, &data_str) {
10+
if let Ok((desc, _)) = Descriptor::parse_descriptor(&data_str) {
1211
let _output = desc.to_string();
1312
let _sanity_check = desc.sanity_check();
1413
}

0 commit comments

Comments
 (0)