Skip to content

Update to a dev version latest bitcoin master 0e2e55971275da64ceb62e8991a0a5fa962cb8b1 #289

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

Merged
merged 2 commits into from
Jan 12, 2022
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Miniscript: a subset of Bitcoin Script designed for analysis"
license = "CC0-1.0"

[features]
fuzztarget = ["bitcoin/fuzztarget"]
fuzztarget = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In f3c38b8:

We should drop fuzztarget entirely.

compiler = []
trace = []
unstable = []
Expand All @@ -16,7 +16,8 @@ use-serde = ["bitcoin/use-serde", "serde"]
rand = ["bitcoin/rand"]

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

[dependencies.serde]
version = "1.0"
Expand Down
7 changes: 4 additions & 3 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
extern crate bitcoin;
extern crate miniscript;

use bitcoin::blockdata::witness::Witness;
use bitcoin::secp256k1; // secp256k1 re-exported from rust-bitcoin
use miniscript::DescriptorTrait;
use std::collections::HashMap;
Expand All @@ -34,7 +35,7 @@ fn main() {
previous_output: Default::default(),
script_sig: bitcoin::Script::new(),
sequence: 0xffffffff,
witness: vec![],
witness: Witness::default(),
}],
output: vec![bitcoin::TxOut {
script_pubkey: bitcoin::Script::new(),
Expand Down Expand Up @@ -63,15 +64,15 @@ fn main() {
let bitcoin_sig = (
// copied at random off the blockchain; this is not actually a valid
// signature for this transaction; Miniscript does not verify
secp256k1::Signature::from_str(
secp256k1::ecdsa::Signature::from_str(
"3045\
0221\
00f7c3648c390d87578cd79c8016940aa8e3511c4104cb78daa8fb8e429375efc1\
0220\
531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177",
)
.unwrap(),
bitcoin::SigHashType::All,
bitcoin::EcdsaSigHashType::All,
);

let descriptor_str = format!(
Expand Down
11 changes: 6 additions & 5 deletions examples/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn main() {
0xa9, 0x14, 0x92, 0x09, 0xa8, 0xf9, 0x0c, 0x58, 0x4b, 0xb5, 0x97, 0x4d, 0x58, 0x68, 0x72,
0x49, 0xe5, 0x32, 0xde, 0x59, 0xf4, 0xbc, 0x87,
]);

let mut interpreter = miniscript::Interpreter::from_txdata(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to change the parameter type in from_txdata (and in inner::from_txdata) to &Witness avoiding the step of converting to vec?

If I am looking correctly it's used only for iteration and we have Witness::iter which doesn't allocate

Copy link
Member Author

@sanket1729 sanket1729 Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is an already planned change in a follow-up PR that changes the interpreter API for taproot support. Wanted to keep things simple here (as in just resolving compile errors).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense for psbt FINAL_SCRIPT_WITNESS to be Witness type instead of Vec<Vec<u8>>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a follow up commit and discovered that rust-miniscript needs rust-bitcoin/rust-bitcoin#774 for a cleaner non-allocating API.

&spk_input_1,
&transaction.input[0].script_sig,
Expand Down Expand Up @@ -134,11 +133,13 @@ fn main() {

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

println!("\nExample two");
Expand All @@ -155,7 +156,6 @@ fn main() {
// what happens given an apparently invalid script
let secp = secp256k1::Secp256k1::new();
let message = secp256k1::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash");

let mut interpreter = miniscript::Interpreter::from_txdata(
&spk_input_1,
&transaction.input[0].script_sig,
Expand All @@ -166,7 +166,8 @@ fn main() {
.unwrap();

let iter = interpreter.iter(|pk, (sig, sighashtype)| {
sighashtype == bitcoin::SigHashType::All && secp.verify(&message, &sig, &pk.key).is_ok()
sighashtype == bitcoin::EcdsaSigHashType::All
&& secp.verify_ecdsa(&message, &sig, &pk.key).is_ok()
});
println!("\nExample three");
for elem in iter {
Expand Down
8 changes: 4 additions & 4 deletions examples/xpub_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ fn main() {
"wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH))",
)
.unwrap()
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
.unwrap()
.address(bitcoin::Network::Bitcoin).unwrap();

let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
"wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB))",
)
.unwrap()
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
.unwrap()
.address(bitcoin::Network::Bitcoin).unwrap();
let expected = bitcoin::Address::from_str(
Expand All @@ -52,7 +52,7 @@ fn main() {
)
.unwrap()
.derive(5)
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
.unwrap()
.address(bitcoin::Network::Bitcoin).unwrap();

Expand All @@ -61,7 +61,7 @@ fn main() {
)
.unwrap()
.derive(5)
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx).map(bitcoin::PublicKey::new))
.unwrap()
.address(bitcoin::Network::Bitcoin).unwrap();
let expected = bitcoin::Address::from_str("325zcVBN5o2eqqqtGwPjmtDd8dJRyYP82s").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ authors = ["Steven Roose <[email protected]>", "Sanket K <sanket1729@gmail.
miniscript = {path = "../"}

# Until 0.26 support is released on rust-bitcoincore-rpc
bitcoincore-rpc = "0.14.0"
bitcoin = "0.27.1"
bitcoincore-rpc = {git = "https://github.com/sanket1729/rust-bitcoincore-rpc",rev = "ae3ad6cac0a83454f267cb7d5191f6607bb80297"}
bitcoin = {git = "https://github.com/rust-bitcoin/rust-bitcoin", rev = "0e2e55971275da64ceb62e8991a0a5fa962cb8b1"}
log = "0.4"
37 changes: 16 additions & 21 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern crate miniscript;
use bitcoincore_rpc::{json, Auth, Client, RpcApi};

use bitcoin::secp256k1;
use bitcoin::util::bip143;
use bitcoin::util::psbt;
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
use bitcoin::{Amount, OutPoint, Transaction, TxIn, TxOut, Txid};
Expand Down Expand Up @@ -133,18 +132,16 @@ fn main() {
let mut psbts = vec![];
for (ms, txid) in ms_vec.iter().zip(txids) {
let mut psbt = Psbt {
global: psbt::Global {
unsigned_tx: Transaction {
version: 2,
lock_time: 1_603_866_330, // time at 10/28/2020 @ 6:25am (UTC)
input: vec![],
output: vec![],
},
unknown: BTreeMap::new(),
proprietary: BTreeMap::new(),
xpub: BTreeMap::new(),
version: 0,
unsigned_tx: Transaction {
version: 2,
lock_time: 1_603_866_330, // time at 10/28/2020 @ 6:25am (UTC)
input: vec![],
output: vec![],
},
unknown: BTreeMap::new(),
proprietary: BTreeMap::new(),
xpub: BTreeMap::new(),
version: 0,
inputs: vec![],
outputs: vec![],
};
Expand All @@ -156,14 +153,14 @@ fn main() {
// processed correctly.
// We waited 50 blocks, keep 49 for safety
txin.sequence = 49;
psbt.global.unsigned_tx.input.push(txin);
psbt.unsigned_tx.input.push(txin);
// Get a new script pubkey from the node so that
// the node wallet tracks the receiving transaction
// and we can check it by gettransaction RPC.
let addr = cl
.get_new_address(None, Some(json::AddressType::Bech32))
.unwrap();
psbt.global.unsigned_tx.output.push(TxOut {
psbt.unsigned_tx.output.push(TxOut {
value: 99_999_000,
script_pubkey: addr.script_pubkey(),
});
Expand Down Expand Up @@ -197,9 +194,9 @@ fn main() {
.collect();
// Get the required sighash message
let amt = btc(1).as_sat();
let mut sighash_cache = bip143::SigHashCache::new(&psbts[i].global.unsigned_tx);
let sighash_ty = bitcoin::SigHashType::All;
let sighash = sighash_cache.signature_hash(0, &ms.encode(), amt, sighash_ty);
let mut sighash_cache = bitcoin::util::sighash::SigHashCache::new(&psbts[i].unsigned_tx);
let sighash_ty = bitcoin::EcdsaSigHashType::All;
let sighash = sighash_cache.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty).unwrap();

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

// Finally construct the signature and add to psbt
for sk in sks_reqd {
let sig = secp.sign(&msg, &sk);
let sig = secp.sign_ecdsa(&msg, &sk);
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
let mut sig = sig.serialize_der().to_vec();
sig.push(0x01u8); //sighash all flag
psbts[i].inputs[0].partial_sigs.insert(pk, sig);
psbts[i].inputs[0].partial_sigs.insert(pk, bitcoin::EcdsaSig { sig, hash_ty: sighash_ty });
}
// Add the hash preimages to the psbt
psbts[i].inputs[0].sha256_preimages.insert(
Expand Down
6 changes: 3 additions & 3 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
.xkey
.derive_priv(&secp, &deriv_on_hardened)
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
let xpub = bip32::ExtendedPubKey::from_private(&secp, &derived_xprv);
let xpub = bip32::ExtendedPubKey::from_priv(&secp, &derived_xprv);

let origin = match &self.origin {
&Some((fingerprint, ref origin_path)) => Some((
Expand Down Expand Up @@ -439,9 +439,9 @@ impl DescriptorPublicKey {
pub fn derive_public_key<C: secp256k1::Verification>(
&self,
secp: &Secp256k1<C>,
) -> Result<bitcoin::PublicKey, ConversionError> {
) -> Result<secp256k1::PublicKey, ConversionError> {
match *self {
DescriptorPublicKey::SinglePub(ref pk) => Ok(pk.key),
DescriptorPublicKey::SinglePub(ref pk) => Ok(pk.key.key),
DescriptorPublicKey::XPub(ref xpk) => match xpk.wildcard {
Wildcard::Unhardened => Err(ConversionError::Wildcard),
Wildcard::Hardened => Err(ConversionError::HardenedWildcard),
Expand Down
Loading