Skip to content

Commit 87c9849

Browse files
committed
Merge #289: Update to a dev version latest bitcoin master 0e2e559
aa36494 Update interpreter API to Witness struct (sanket1729) f3c38b8 update to latest bitcoin master (sanket1729) Pull request description: Update to a version of dev rust-bitcoin so that we can prepare for rust-miniscript release. The integration tests are updated to point a personal fork of rust-bitcoincore-rpc to have rust semver type issues. After we have this, we can make progress on tapscript while we await finalized rust-bitcoin release. After which, we can remove the git dependencies and have crates.io dependencies instead. ACKs for top commit: apoelstra: ACK aa36494 Tree-SHA512: c8333e8ca7381bc2a2d146bae1d12f95f6883a54160bcf5de20aade5ee73a56696f51713639859450092efffc91ece650741cb6069934d635c1ed06a2900135a
2 parents 13e7552 + aa36494 commit 87c9849

File tree

20 files changed

+264
-220
lines changed

20 files changed

+264
-220
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ 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-
8786
let mut interpreter = miniscript::Interpreter::from_txdata(
8887
&spk_input_1,
8988
&transaction.input[0].script_sig,
@@ -134,11 +133,13 @@ fn main() {
134133

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

144145
println!("\nExample two");
@@ -155,7 +156,6 @@ fn main() {
155156
// what happens given an apparently invalid script
156157
let secp = secp256k1::Secp256k1::new();
157158
let message = secp256k1::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash");
158-
159159
let mut interpreter = miniscript::Interpreter::from_txdata(
160160
&spk_input_1,
161161
&transaction.input[0].script_sig,
@@ -166,7 +166,8 @@ fn main() {
166166
.unwrap();
167167

168168
let iter = interpreter.iter(|pk, (sig, sighashtype)| {
169-
sighashtype == bitcoin::SigHashType::All && secp.verify(&message, &sig, &pk.key).is_ok()
169+
sighashtype == bitcoin::EcdsaSigHashType::All
170+
&& secp.verify_ecdsa(&message, &sig, &pk.key).is_ok()
170171
});
171172
println!("\nExample three");
172173
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: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extern crate miniscript;
1111
use bitcoincore_rpc::{json, Auth, Client, RpcApi};
1212

1313
use bitcoin::secp256k1;
14-
use bitcoin::util::bip143;
1514
use bitcoin::util::psbt;
1615
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
1716
use bitcoin::{Amount, OutPoint, Transaction, TxIn, TxOut, Txid};
@@ -133,18 +132,16 @@ fn main() {
133132
let mut psbts = vec![];
134133
for (ms, txid) in ms_vec.iter().zip(txids) {
135134
let mut psbt = Psbt {
136-
global: psbt::Global {
137-
unsigned_tx: Transaction {
138-
version: 2,
139-
lock_time: 1_603_866_330, // time at 10/28/2020 @ 6:25am (UTC)
140-
input: vec![],
141-
output: vec![],
142-
},
143-
unknown: BTreeMap::new(),
144-
proprietary: BTreeMap::new(),
145-
xpub: BTreeMap::new(),
146-
version: 0,
135+
unsigned_tx: Transaction {
136+
version: 2,
137+
lock_time: 1_603_866_330, // time at 10/28/2020 @ 6:25am (UTC)
138+
input: vec![],
139+
output: vec![],
147140
},
141+
unknown: BTreeMap::new(),
142+
proprietary: BTreeMap::new(),
143+
xpub: BTreeMap::new(),
144+
version: 0,
148145
inputs: vec![],
149146
outputs: vec![],
150147
};
@@ -156,14 +153,14 @@ fn main() {
156153
// processed correctly.
157154
// We waited 50 blocks, keep 49 for safety
158155
txin.sequence = 49;
159-
psbt.global.unsigned_tx.input.push(txin);
156+
psbt.unsigned_tx.input.push(txin);
160157
// Get a new script pubkey from the node so that
161158
// the node wallet tracks the receiving transaction
162159
// and we can check it by gettransaction RPC.
163160
let addr = cl
164161
.get_new_address(None, Some(json::AddressType::Bech32))
165162
.unwrap();
166-
psbt.global.unsigned_tx.output.push(TxOut {
163+
psbt.unsigned_tx.output.push(TxOut {
167164
value: 99_999_000,
168165
script_pubkey: addr.script_pubkey(),
169166
});
@@ -197,9 +194,9 @@ fn main() {
197194
.collect();
198195
// Get the required sighash message
199196
let amt = btc(1).as_sat();
200-
let mut sighash_cache = bip143::SigHashCache::new(&psbts[i].global.unsigned_tx);
201-
let sighash_ty = bitcoin::SigHashType::All;
202-
let sighash = sighash_cache.signature_hash(0, &ms.encode(), amt, sighash_ty);
197+
let mut sighash_cache = bitcoin::util::sighash::SigHashCache::new(&psbts[i].unsigned_tx);
198+
let sighash_ty = bitcoin::EcdsaSigHashType::All;
199+
let sighash = sighash_cache.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty).unwrap();
203200

204201
// requires both signing and verification because we check the tx
205202
// after we psbt extract it
@@ -208,11 +205,9 @@ fn main() {
208205

209206
// Finally construct the signature and add to psbt
210207
for sk in sks_reqd {
211-
let sig = secp.sign(&msg, &sk);
208+
let sig = secp.sign_ecdsa(&msg, &sk);
212209
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
213-
let mut sig = sig.serialize_der().to_vec();
214-
sig.push(0x01u8); //sighash all flag
215-
psbts[i].inputs[0].partial_sigs.insert(pk, sig);
210+
psbts[i].inputs[0].partial_sigs.insert(pk, bitcoin::EcdsaSig { sig, hash_ty: sighash_ty });
216211
}
217212
// Add the hash preimages to the psbt
218213
psbts[i].inputs[0].sha256_preimages.insert(

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),

0 commit comments

Comments
 (0)