Skip to content

Commit d54bbc5

Browse files
committed
update to latest bitcoin master
1 parent 13e7552 commit d54bbc5

File tree

19 files changed

+188
-159
lines changed

19 files changed

+188
-159
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "Miniscript: a subset of Bitcoin Script designed for analysis"
77
license = "CC0-1.0"
88

99
[features]
10-
fuzztarget = ["bitcoin/fuzztarget"]
10+
fuzztarget = []
1111
compiler = []
1212
trace = []
1313
unstable = []
@@ -16,7 +16,8 @@ use-serde = ["bitcoin/use-serde", "serde"]
1616
rand = ["bitcoin/rand"]
1717

1818
[dependencies]
19-
bitcoin = "0.27"
19+
# bitcoin = "0.27"
20+
bitcoin = {git = "https://github.com/rust-bitcoin/rust-bitcoin", rev = "0e2e55971275da64ceb62e8991a0a5fa962cb8b1"}
2021

2122
[dependencies.serde]
2223
version = "1.0"

examples/sign_multisig.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20+
use bitcoin::blockdata::witness::Witness;
2021
use bitcoin::secp256k1; // secp256k1 re-exported from rust-bitcoin
2122
use miniscript::DescriptorTrait;
2223
use std::collections::HashMap;
@@ -34,7 +35,7 @@ fn main() {
3435
previous_output: Default::default(),
3536
script_sig: bitcoin::Script::new(),
3637
sequence: 0xffffffff,
37-
witness: vec![],
38+
witness: Witness::default(),
3839
}],
3940
output: vec![bitcoin::TxOut {
4041
script_pubkey: bitcoin::Script::new(),
@@ -63,15 +64,15 @@ fn main() {
6364
let bitcoin_sig = (
6465
// copied at random off the blockchain; this is not actually a valid
6566
// signature for this transaction; Miniscript does not verify
66-
secp256k1::Signature::from_str(
67+
secp256k1::ecdsa::Signature::from_str(
6768
"3045\
6869
0221\
6970
00f7c3648c390d87578cd79c8016940aa8e3511c4104cb78daa8fb8e429375efc1\
7071
0220\
7172
531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177",
7273
)
7374
.unwrap(),
74-
bitcoin::SigHashType::All,
75+
bitcoin::EcdsaSigHashType::All,
7576
);
7677

7778
let descriptor_str = format!(

examples/verify_tx.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ fn main() {
8383
0xa9, 0x14, 0x92, 0x09, 0xa8, 0xf9, 0x0c, 0x58, 0x4b, 0xb5, 0x97, 0x4d, 0x58, 0x68, 0x72,
8484
0x49, 0xe5, 0x32, 0xde, 0x59, 0xf4, 0xbc, 0x87,
8585
]);
86-
86+
let wit = transaction.input[0].witness.to_vec();
8787
let mut interpreter = miniscript::Interpreter::from_txdata(
8888
&spk_input_1,
8989
&transaction.input[0].script_sig,
90-
&transaction.input[0].witness,
90+
&wit,
9191
0,
9292
0,
9393
)
@@ -123,22 +123,25 @@ fn main() {
123123
// from the MiniscriptKey which can supplied by `to_pk_ctx` parameter. For example,
124124
// when calculating the script pubkey of a descriptor with xpubs, the secp context and
125125
// child information maybe required.
126+
let wit = transaction.input[0].witness.to_vec();
126127
let mut interpreter = miniscript::Interpreter::from_txdata(
127128
&spk_input_1,
128129
&transaction.input[0].script_sig,
129-
&transaction.input[0].witness,
130+
&wit,
130131
0,
131132
0,
132133
)
133134
.unwrap();
134135

135136
// We can set the amount passed to `sighash_verify` to 0 because this is a legacy
136137
// transaction and so the amount won't actually be checked by the signature
137-
let vfyfn = interpreter.sighash_verify(&secp, &transaction, 0, 0);
138+
let vfyfn = interpreter
139+
.sighash_verify(&secp, &transaction, 0, 0)
140+
.expect("Can only fail in sighash single when corresponding output is not present");
138141
// Restrict to sighash_all just to demonstrate how to add additional filters
139142
// `&_` needed here because of https://github.com/rust-lang/rust/issues/79187
140143
let vfyfn = move |pk: &_, bitcoinsig: miniscript::BitcoinSig| {
141-
bitcoinsig.1 == bitcoin::SigHashType::All && vfyfn(pk, bitcoinsig)
144+
bitcoinsig.1 == bitcoin::EcdsaSigHashType::All && vfyfn(pk, bitcoinsig)
142145
};
143146

144147
println!("\nExample two");
@@ -155,18 +158,19 @@ fn main() {
155158
// what happens given an apparently invalid script
156159
let secp = secp256k1::Secp256k1::new();
157160
let message = secp256k1::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash");
158-
161+
let wit = transaction.input[0].witness.to_vec();
159162
let mut interpreter = miniscript::Interpreter::from_txdata(
160163
&spk_input_1,
161164
&transaction.input[0].script_sig,
162-
&transaction.input[0].witness,
165+
&wit,
163166
0,
164167
0,
165168
)
166169
.unwrap();
167170

168171
let iter = interpreter.iter(|pk, (sig, sighashtype)| {
169-
sighashtype == bitcoin::SigHashType::All && secp.verify(&message, &sig, &pk.key).is_ok()
172+
sighashtype == bitcoin::EcdsaSigHashType::All
173+
&& secp.verify_ecdsa(&message, &sig, &pk.key).is_ok()
170174
});
171175
println!("\nExample three");
172176
for elem in iter {

examples/xpub_descriptors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ fn main() {
2828
"wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH))",
2929
)
3030
.unwrap()
31-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
31+
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
3232
.unwrap()
3333
.address(bitcoin::Network::Bitcoin).unwrap();
3434

3535
let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
3636
"wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB))",
3737
)
3838
.unwrap()
39-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
39+
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
4040
.unwrap()
4141
.address(bitcoin::Network::Bitcoin).unwrap();
4242
let expected = bitcoin::Address::from_str(
@@ -52,7 +52,7 @@ fn main() {
5252
)
5353
.unwrap()
5454
.derive(5)
55-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
55+
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
5656
.unwrap()
5757
.address(bitcoin::Network::Bitcoin).unwrap();
5858

@@ -61,7 +61,7 @@ fn main() {
6161
)
6262
.unwrap()
6363
.derive(5)
64-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
64+
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
6565
.unwrap()
6666
.address(bitcoin::Network::Bitcoin).unwrap();
6767
let expected = bitcoin::Address::from_str("325zcVBN5o2eqqqtGwPjmtDd8dJRyYP82s").unwrap();

integration_test/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ authors = ["Steven Roose <[email protected]>", "Sanket K <sanket1729@gmail.
77
miniscript = {path = "../"}
88

99
# Until 0.26 support is released on rust-bitcoincore-rpc
10-
bitcoincore-rpc = "0.14.0"
11-
bitcoin = "0.27.1"
10+
bitcoincore-rpc = {git = "https://github.com/sanket1729/rust-bitcoincore-rpc",rev = "ae3ad6cac0a83454f267cb7d5191f6607bb80297"}
11+
bitcoin = {git = "https://github.com/rust-bitcoin/rust-bitcoin", rev = "0e2e55971275da64ceb62e8991a0a5fa962cb8b1"}
1212
log = "0.4"

integration_test/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn main() {
198198
// Get the required sighash message
199199
let amt = btc(1).as_sat();
200200
let mut sighash_cache = bip143::SigHashCache::new(&psbts[i].global.unsigned_tx);
201-
let sighash_ty = bitcoin::SigHashType::All;
201+
let sighash_ty = bitcoin::EcdsaSigHashType::All;
202202
let sighash = sighash_cache.signature_hash(0, &ms.encode(), amt, sighash_ty);
203203

204204
// requires both signing and verification because we check the tx
@@ -208,7 +208,7 @@ fn main() {
208208

209209
// Finally construct the signature and add to psbt
210210
for sk in sks_reqd {
211-
let sig = secp.sign(&msg, &sk);
211+
let sig = secp.sign_ecdsa(&msg, &sk);
212212
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
213213
let mut sig = sig.serialize_der().to_vec();
214214
sig.push(0x01u8); //sighash all flag

src/descriptor/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
168168
.xkey
169169
.derive_priv(&secp, &deriv_on_hardened)
170170
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
171-
let xpub = bip32::ExtendedPubKey::from_private(&secp, &derived_xprv);
171+
let xpub = bip32::ExtendedPubKey::from_priv(&secp, &derived_xprv);
172172

173173
let origin = match &self.origin {
174174
&Some((fingerprint, ref origin_path)) => Some((
@@ -439,9 +439,9 @@ impl DescriptorPublicKey {
439439
pub fn derive_public_key<C: secp256k1::Verification>(
440440
&self,
441441
secp: &Secp256k1<C>,
442-
) -> Result<bitcoin::PublicKey, ConversionError> {
442+
) -> Result<secp256k1::PublicKey, ConversionError> {
443443
match *self {
444-
DescriptorPublicKey::SinglePub(ref pk) => Ok(pk.key),
444+
DescriptorPublicKey::SinglePub(ref pk) => Ok(pk.key.key),
445445
DescriptorPublicKey::XPub(ref xpk) => match xpk.wildcard {
446446
Wildcard::Unhardened => Err(ConversionError::Wildcard),
447447
Wildcard::Hardened => Err(ConversionError::HardenedWildcard),

src/descriptor/mod.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::{
2929
str::{self, FromStr},
3030
};
3131

32+
use bitcoin::blockdata::witness::Witness;
3233
use bitcoin::secp256k1;
3334
use bitcoin::{self, Script};
3435

@@ -140,7 +141,7 @@ pub trait DescriptorTrait<Pk: MiniscriptKey> {
140141
{
141142
// easy default implementation
142143
let (witness, script_sig) = self.get_satisfaction(satisfier)?;
143-
txin.witness = witness;
144+
txin.witness = Witness::from_vec(witness);
144145
txin.script_sig = script_sig;
145146
Ok(())
146147
}
@@ -647,7 +648,7 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
647648
#[cfg(test)]
648649
mod tests {
649650
use super::checksum::desc_checksum;
650-
use super::DescriptorTrait;
651+
use super::*;
651652
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
652653
use bitcoin::blockdata::script::Instruction;
653654
use bitcoin::blockdata::{opcodes, script};
@@ -939,19 +940,19 @@ mod tests {
939940
};
940941
let msg = secp256k1::Message::from_slice(&b"michael was a message, amusingly"[..])
941942
.expect("32 bytes");
942-
let sig = secp.sign(&msg, &sk);
943+
let sig = secp.sign_ecdsa(&msg, &sk);
943944
let mut sigser = sig.serialize_der().to_vec();
944945
sigser.push(0x01); // sighash_all
945946

946947
struct SimpleSat {
947-
sig: secp256k1::Signature,
948+
sig: secp256k1::ecdsa::Signature,
948949
pk: bitcoin::PublicKey,
949950
}
950951

951952
impl Satisfier<bitcoin::PublicKey> for SimpleSat {
952953
fn lookup_sig(&self, pk: &bitcoin::PublicKey) -> Option<BitcoinSig> {
953954
if *pk == self.pk {
954-
Some((self.sig, bitcoin::SigHashType::All))
955+
Some((self.sig, bitcoin::EcdsaSigHashType::All))
955956
} else {
956957
None
957958
}
@@ -965,7 +966,7 @@ mod tests {
965966
previous_output: bitcoin::OutPoint::default(),
966967
script_sig: bitcoin::Script::new(),
967968
sequence: 100,
968-
witness: vec![],
969+
witness: Witness::default(),
969970
};
970971
let bare = Descriptor::new_bare(ms.clone()).unwrap();
971972

@@ -976,7 +977,7 @@ mod tests {
976977
previous_output: bitcoin::OutPoint::default(),
977978
script_sig: script::Builder::new().push_slice(&sigser[..]).into_script(),
978979
sequence: 100,
979-
witness: vec![],
980+
witness: Witness::default(),
980981
}
981982
);
982983
assert_eq!(bare.unsigned_script_sig(), bitcoin::Script::new());
@@ -992,7 +993,7 @@ mod tests {
992993
.push_key(&pk)
993994
.into_script(),
994995
sequence: 100,
995-
witness: vec![],
996+
witness: Witness::default(),
996997
}
997998
);
998999
assert_eq!(pkh.unsigned_script_sig(), bitcoin::Script::new());
@@ -1005,7 +1006,7 @@ mod tests {
10051006
previous_output: bitcoin::OutPoint::default(),
10061007
script_sig: bitcoin::Script::new(),
10071008
sequence: 100,
1008-
witness: vec![sigser.clone(), pk.to_bytes(),],
1009+
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
10091010
}
10101011
);
10111012
assert_eq!(wpkh.unsigned_script_sig(), bitcoin::Script::new());
@@ -1026,7 +1027,7 @@ mod tests {
10261027
.push_slice(&redeem_script[..])
10271028
.into_script(),
10281029
sequence: 100,
1029-
witness: vec![sigser.clone(), pk.to_bytes(),],
1030+
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
10301031
}
10311032
);
10321033
assert_eq!(
@@ -1048,7 +1049,7 @@ mod tests {
10481049
.push_slice(&ms.encode()[..])
10491050
.into_script(),
10501051
sequence: 100,
1051-
witness: vec![],
1052+
witness: Witness::default(),
10521053
}
10531054
);
10541055
assert_eq!(sh.unsigned_script_sig(), bitcoin::Script::new());
@@ -1063,7 +1064,7 @@ mod tests {
10631064
previous_output: bitcoin::OutPoint::default(),
10641065
script_sig: bitcoin::Script::new(),
10651066
sequence: 100,
1066-
witness: vec![sigser.clone(), ms.encode().into_bytes(),],
1067+
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
10671068
}
10681069
);
10691070
assert_eq!(wsh.unsigned_script_sig(), bitcoin::Script::new());
@@ -1078,7 +1079,7 @@ mod tests {
10781079
.push_slice(&ms.encode().to_v0_p2wsh()[..])
10791080
.into_script(),
10801081
sequence: 100,
1081-
witness: vec![sigser.clone(), ms.encode().into_bytes(),],
1082+
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
10821083
}
10831084
);
10841085
assert_eq!(
@@ -1136,13 +1137,13 @@ mod tests {
11361137
"02937402303919b3a2ee5edd5009f4236f069bf75667b8e6ecf8e5464e20116a0e",
11371138
)
11381139
.unwrap();
1139-
let sig_a = secp256k1::Signature::from_str("3045022100a7acc3719e9559a59d60d7b2837f9842df30e7edcd754e63227e6168cec72c5d022066c2feba4671c3d99ea75d9976b4da6c86968dbf3bab47b1061e7a1966b1778c").unwrap();
1140+
let sig_a = secp256k1::ecdsa::Signature::from_str("3045022100a7acc3719e9559a59d60d7b2837f9842df30e7edcd754e63227e6168cec72c5d022066c2feba4671c3d99ea75d9976b4da6c86968dbf3bab47b1061e7a1966b1778c").unwrap();
11401141

11411142
let b = bitcoin::PublicKey::from_str(
11421143
"02eb64639a17f7334bb5a1a3aad857d6fec65faef439db3de72f85c88bc2906ad3",
11431144
)
11441145
.unwrap();
1145-
let sig_b = secp256k1::Signature::from_str("3044022075b7b65a7e6cd386132c5883c9db15f9a849a0f32bc680e9986398879a57c276022056d94d12255a4424f51c700ac75122cb354895c9f2f88f0cbb47ba05c9c589ba").unwrap();
1146+
let sig_b = secp256k1::ecdsa::Signature::from_str("3044022075b7b65a7e6cd386132c5883c9db15f9a849a0f32bc680e9986398879a57c276022056d94d12255a4424f51c700ac75122cb354895c9f2f88f0cbb47ba05c9c589ba").unwrap();
11461147

11471148
let descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&format!(
11481149
"wsh(and_v(v:pk({A}),pk({B})))",
@@ -1155,13 +1156,13 @@ mod tests {
11551156
previous_output: bitcoin::OutPoint::default(),
11561157
script_sig: bitcoin::Script::new(),
11571158
sequence: 0,
1158-
witness: vec![],
1159+
witness: Witness::default(),
11591160
};
11601161
let satisfier = {
11611162
let mut satisfier = HashMap::with_capacity(2);
11621163

1163-
satisfier.insert(a, (sig_a.clone(), ::bitcoin::SigHashType::All));
1164-
satisfier.insert(b, (sig_b.clone(), ::bitcoin::SigHashType::All));
1164+
satisfier.insert(a, (sig_a.clone(), ::bitcoin::EcdsaSigHashType::All));
1165+
satisfier.insert(b, (sig_b.clone(), ::bitcoin::EcdsaSigHashType::All));
11651166

11661167
satisfier
11671168
};
@@ -1170,11 +1171,12 @@ mod tests {
11701171
descriptor.satisfy(&mut txin, &satisfier).unwrap();
11711172

11721173
// assert
1173-
let witness0 = &txin.witness[0];
1174-
let witness1 = &txin.witness[1];
1174+
let wit = txin.witness.to_vec();
1175+
let witness0 = &wit[0];
1176+
let witness1 = &wit[1];
11751177

1176-
let sig0 = secp256k1::Signature::from_der(&witness0[..witness0.len() - 1]).unwrap();
1177-
let sig1 = secp256k1::Signature::from_der(&witness1[..witness1.len() - 1]).unwrap();
1178+
let sig0 = secp256k1::ecdsa::Signature::from_der(&witness0[..witness0.len() - 1]).unwrap();
1179+
let sig1 = secp256k1::ecdsa::Signature::from_der(&witness1[..witness1.len() - 1]).unwrap();
11781180

11791181
// why are we asserting this way?
11801182
// The witness stack is evaluated from top to bottom. Given an `and` instruction, the left arm of the and is going to evaluate first,
@@ -1351,12 +1353,18 @@ mod tests {
13511353

13521354
// Same address
13531355
let addr_one = desc_one
1354-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
1356+
.translate_pk2(|xpk| {
1357+
xpk.derive_public_key(&secp_ctx)
1358+
.map(bitcoin::PublicKey::new)
1359+
})
13551360
.unwrap()
13561361
.address(bitcoin::Network::Bitcoin)
13571362
.unwrap();
13581363
let addr_two = desc_two
1359-
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
1364+
.translate_pk2(|xpk| {
1365+
xpk.derive_public_key(&secp_ctx)
1366+
.map(bitcoin::PublicKey::new)
1367+
})
13601368
.unwrap()
13611369
.address(bitcoin::Network::Bitcoin)
13621370
.unwrap();

0 commit comments

Comments
 (0)