From 834aebf37578a9cd4e52d7ca5a26741cd167b669 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me@tobin.cc>
Date: Wed, 16 Oct 2024 17:34:33 +1100
Subject: [PATCH] WIP: Track rust-bitcoin master branch

As we develop `primitives` it is useful to have crates using the changes
to catch mistakes as we go.
---
 Cargo-minimal.lock                      | 76 ++++++++++++++++---------
 Cargo-recent.lock                       | 76 ++++++++++++++++---------
 Cargo.toml                              | 34 ++++++++++-
 bitcoind-tests/Cargo.toml               | 44 ++++++++++++++
 bitcoind-tests/tests/setup/test_util.rs |  2 +-
 bitcoind-tests/tests/test_cpp.rs        |  5 +-
 bitcoind-tests/tests/test_desc.rs       |  7 ++-
 examples/psbt_sign_finalize.rs          |  3 +-
 examples/sign_multisig.rs               |  4 +-
 src/descriptor/bare.rs                  |  3 +-
 src/descriptor/key.rs                   | 15 +++--
 src/descriptor/mod.rs                   | 47 ++++++++++-----
 src/descriptor/segwitv0.rs              | 17 ++++--
 src/descriptor/sh.rs                    |  5 +-
 src/interpreter/error.rs                |  6 +-
 src/interpreter/inner.rs                | 44 +++++++-------
 src/interpreter/mod.rs                  |  4 +-
 src/interpreter/stack.rs                |  4 +-
 src/lib.rs                              | 12 ++--
 src/miniscript/astelem.rs               | 25 ++++----
 src/miniscript/decode.rs                |  2 +-
 src/miniscript/iter.rs                  |  2 +-
 src/miniscript/lex.rs                   | 11 ++--
 src/miniscript/mod.rs                   | 37 ++++++++++--
 src/plan.rs                             |  4 +-
 src/policy/compiler.rs                  | 11 ++--
 src/psbt/finalizer.rs                   | 26 ++++-----
 src/psbt/mod.rs                         | 14 +++--
 src/util.rs                             | 40 ++++++++++---
 29 files changed, 395 insertions(+), 185 deletions(-)

diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock
index 4969b5a85..39cff966d 100644
--- a/Cargo-minimal.lock
+++ b/Cargo-minimal.lock
@@ -20,18 +20,17 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
 [[package]]
 name = "base58ck"
 version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-internals",
- "bitcoin_hashes",
+ "bitcoin_hashes 0.15.0",
 ]
 
 [[package]]
 name = "base64"
-version = "0.21.7"
+version = "0.22.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
 
 [[package]]
 name = "bech32"
@@ -41,43 +40,57 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
 
 [[package]]
 name = "bitcoin"
-version = "0.32.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea"
+version = "0.33.0-alpha"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "base58ck",
  "base64",
  "bech32",
  "bitcoin-internals",
  "bitcoin-io",
+ "bitcoin-primitives",
  "bitcoin-units",
- "bitcoin_hashes",
+ "bitcoin_hashes 0.15.0",
+ "bitcoinconsensus",
  "hex-conservative",
- "hex_lit",
  "secp256k1",
  "serde",
 ]
 
 [[package]]
 name = "bitcoin-internals"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
+version = "0.4.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
+ "hex-conservative",
  "serde",
 ]
 
 [[package]]
 name = "bitcoin-io"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "17e5b76b88667412087beea1882980ad843b660490bbf6cce0a6cfc999c5b989"
+version = "0.2.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
+dependencies = [
+ "bitcoin-internals",
+]
+
+[[package]]
+name = "bitcoin-primitives"
+version = "0.100.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
+dependencies = [
+ "bitcoin-internals",
+ "bitcoin-io",
+ "bitcoin-units",
+ "bitcoin_hashes 0.15.0",
+ "hex-conservative",
+ "serde",
+]
 
 [[package]]
 name = "bitcoin-units"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8d437fd727271c866d6fd5e71eb2c886437d4c97f80d89246be3189b1da4e58b"
+version = "0.2.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-internals",
  "serde",
@@ -88,12 +101,29 @@ name = "bitcoin_hashes"
 version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
+dependencies = [
+ "hex-conservative",
+]
+
+[[package]]
+name = "bitcoin_hashes"
+version = "0.15.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-io",
  "hex-conservative",
  "serde",
 ]
 
+[[package]]
+name = "bitcoinconsensus"
+version = "0.106.0+26.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e12cba9cce5043cdda968e07b9df6d05ec6b0b38aa27a9a40bb575cf3e521ae9"
+dependencies = [
+ "cc",
+]
+
 [[package]]
 name = "cc"
 version = "1.0.28"
@@ -135,12 +165,6 @@ dependencies = [
  "arrayvec",
 ]
 
-[[package]]
-name = "hex_lit"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
-
 [[package]]
 name = "honggfuzz"
 version = "0.5.56"
@@ -276,7 +300,7 @@ version = "0.29.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
 dependencies = [
- "bitcoin_hashes",
+ "bitcoin_hashes 0.14.0",
  "rand",
  "secp256k1-sys",
  "serde",
diff --git a/Cargo-recent.lock b/Cargo-recent.lock
index 4969b5a85..39cff966d 100644
--- a/Cargo-recent.lock
+++ b/Cargo-recent.lock
@@ -20,18 +20,17 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
 [[package]]
 name = "base58ck"
 version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-internals",
- "bitcoin_hashes",
+ "bitcoin_hashes 0.15.0",
 ]
 
 [[package]]
 name = "base64"
-version = "0.21.7"
+version = "0.22.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
 
 [[package]]
 name = "bech32"
@@ -41,43 +40,57 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
 
 [[package]]
 name = "bitcoin"
-version = "0.32.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea"
+version = "0.33.0-alpha"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "base58ck",
  "base64",
  "bech32",
  "bitcoin-internals",
  "bitcoin-io",
+ "bitcoin-primitives",
  "bitcoin-units",
- "bitcoin_hashes",
+ "bitcoin_hashes 0.15.0",
+ "bitcoinconsensus",
  "hex-conservative",
- "hex_lit",
  "secp256k1",
  "serde",
 ]
 
 [[package]]
 name = "bitcoin-internals"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
+version = "0.4.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
+ "hex-conservative",
  "serde",
 ]
 
 [[package]]
 name = "bitcoin-io"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "17e5b76b88667412087beea1882980ad843b660490bbf6cce0a6cfc999c5b989"
+version = "0.2.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
+dependencies = [
+ "bitcoin-internals",
+]
+
+[[package]]
+name = "bitcoin-primitives"
+version = "0.100.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
+dependencies = [
+ "bitcoin-internals",
+ "bitcoin-io",
+ "bitcoin-units",
+ "bitcoin_hashes 0.15.0",
+ "hex-conservative",
+ "serde",
+]
 
 [[package]]
 name = "bitcoin-units"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8d437fd727271c866d6fd5e71eb2c886437d4c97f80d89246be3189b1da4e58b"
+version = "0.2.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-internals",
  "serde",
@@ -88,12 +101,29 @@ name = "bitcoin_hashes"
 version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
+dependencies = [
+ "hex-conservative",
+]
+
+[[package]]
+name = "bitcoin_hashes"
+version = "0.15.0"
+source = "git+https://github.com/rust-bitcoin/rust-bitcoin?branch=master#2edfcedde13fe226d6c01d768108957592dcfd67"
 dependencies = [
  "bitcoin-io",
  "hex-conservative",
  "serde",
 ]
 
+[[package]]
+name = "bitcoinconsensus"
+version = "0.106.0+26.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e12cba9cce5043cdda968e07b9df6d05ec6b0b38aa27a9a40bb575cf3e521ae9"
+dependencies = [
+ "cc",
+]
+
 [[package]]
 name = "cc"
 version = "1.0.28"
@@ -135,12 +165,6 @@ dependencies = [
  "arrayvec",
 ]
 
-[[package]]
-name = "hex_lit"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
-
 [[package]]
 name = "honggfuzz"
 version = "0.5.56"
@@ -276,7 +300,7 @@ version = "0.29.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
 dependencies = [
- "bitcoin_hashes",
+ "bitcoin_hashes 0.14.0",
  "rand",
  "secp256k1-sys",
  "serde",
diff --git a/Cargo.toml b/Cargo.toml
index 764ef1adb..8163067a9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,14 +24,14 @@ base64 = ["bitcoin/base64"]
 
 [dependencies]
 bech32 = { version = "0.11.0", default-features = false }
-bitcoin = { version = "0.32.0", default-features = false }
+bitcoin = { version = "0.33.0-alpha", default-features = false }
 
 # Do NOT use this as a feature! Use the `serde` feature instead.
 actual-serde = { package = "serde", version = "1.0.103", optional = true }
 
 [dev-dependencies]
 serde_test = "1.0.147"
-bitcoin = { version = "0.32.0", features = ["base64"] }
+bitcoin = { version = "0.33.0-alpha", features = ["base64"] }
 secp256k1 = {version = "0.29.0", features = ["rand-std"]}
 
 [[example]]
@@ -69,3 +69,33 @@ required-features = ["std", "base64", "compiler"]
 [workspace]
 members = ["fuzz"]
 exclude = ["embedded", "bitcoind-tests"]
+
+# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).
+
+[patch.crates-io.base58ck]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin_hashes]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-internals]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-io]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-primitives]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-units]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
diff --git a/bitcoind-tests/Cargo.toml b/bitcoind-tests/Cargo.toml
index 25ed2e787..e41ca49bf 100644
--- a/bitcoind-tests/Cargo.toml
+++ b/bitcoind-tests/Cargo.toml
@@ -32,3 +32,47 @@ secp256k1 = {version = "0.29.0", features = ["rand-std"]}
 "0_19_1" = ["bitcoind/0_19_1"]
 "0_18_1" = ["bitcoind/0_18_1"]
 "0_17_1" = ["bitcoind/0_17_1"]
+
+# Patch crates from bitcoind-json-rpc repo.
+
+[patch.crates-io.bitcoind-json-rpc-client]
+git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
+branch = "track-bitcoin-master"
+
+[patch.crates-io.bitcoind-json-rpc-regtest]
+git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
+branch = "track-bitcoin-master"
+
+[patch.crates-io.bitcoind-json-rpc-types]
+git = "https://github.com/tcharding/rust-bitcoind-json-rpc"
+branch = "track-bitcoin-master"
+
+# Patch rust-bitcoin crates, use `branch` here because its easier when testing new branches (worktrees).
+
+[patch.crates-io.base58ck]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin_hashes]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-internals]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-io]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-primitives]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
+
+[patch.crates-io.bitcoin-units]
+git = "https://github.com/rust-bitcoin/rust-bitcoin"
+branch = "master"
diff --git a/bitcoind-tests/tests/setup/test_util.rs b/bitcoind-tests/tests/setup/test_util.rs
index 64ffa6f5a..79660314e 100644
--- a/bitcoind-tests/tests/setup/test_util.rs
+++ b/bitcoind-tests/tests/setup/test_util.rs
@@ -20,7 +20,7 @@
 use std::str::FromStr;
 
 use actual_rand as rand;
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
+use bitcoin::hashes::{hash160, ripemd160, sha256};
 use bitcoin::hex::DisplayHex;
 use bitcoin::secp256k1;
 use miniscript::descriptor::{SinglePub, SinglePubKey};
diff --git a/bitcoind-tests/tests/test_cpp.rs b/bitcoind-tests/tests/test_cpp.rs
index 2836212e2..b4350bb66 100644
--- a/bitcoind-tests/tests/test_cpp.rs
+++ b/bitcoind-tests/tests/test_cpp.rs
@@ -9,8 +9,9 @@ use std::fs::File;
 use std::io::{self, BufRead};
 use std::path::Path;
 
-use bitcoin::hashes::{sha256d, Hash};
+use bitcoin::hashes::sha256d;
 use bitcoin::psbt::Psbt;
+use bitcoin::transaction::OutPointExt as _;
 use bitcoin::{
     psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
 };
@@ -119,7 +120,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
             // processed correctly.
             // We waited 50 blocks, keep 49 for safety
             sequence: Sequence::from_height(49),
-            ..Default::default()
+            ..TxIn::EMPTY_COINBASE
         };
         psbt.unsigned_tx.input.push(txin);
         // Get a new script pubkey from the node so that
diff --git a/bitcoind-tests/tests/test_desc.rs b/bitcoind-tests/tests/test_desc.rs
index 99b93584b..4d02d49d4 100644
--- a/bitcoind-tests/tests/test_desc.rs
+++ b/bitcoind-tests/tests/test_desc.rs
@@ -9,10 +9,11 @@ use std::{error, fmt};
 
 use actual_rand as rand;
 use bitcoin::blockdata::witness::Witness;
-use bitcoin::hashes::{sha256d, Hash};
+use bitcoin::hashes::sha256d;
 use bitcoin::psbt::Psbt;
 use bitcoin::sighash::SighashCache;
-use bitcoin::taproot::{LeafVersion, TapLeafHash};
+use bitcoin::taproot::{LeafVersion, TapLeafHash, TapTweakHashExt as _, TapLeafHashExt as _};
+use bitcoin::transaction::OutPointExt as _;
 use bitcoin::{
     absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
     TxOut, Txid,
@@ -127,7 +128,7 @@ pub fn test_desc_satisfy(
         // processed correctly.
         // We waited 2 blocks, keep 1 for safety
         sequence: Sequence::from_height(1),
-        ..Default::default()
+        ..TxIn::EMPTY_COINBASE
     };
     psbt.unsigned_tx.input.push(txin);
     // Get a new script pubkey from the node so that
diff --git a/examples/psbt_sign_finalize.rs b/examples/psbt_sign_finalize.rs
index b7c2a62f3..1db8b967f 100644
--- a/examples/psbt_sign_finalize.rs
+++ b/examples/psbt_sign_finalize.rs
@@ -3,6 +3,7 @@
 use std::collections::BTreeMap;
 use std::str::FromStr;
 
+use bitcoin::transaction::OutPointExt as _;
 use miniscript::bitcoin::consensus::encode::deserialize;
 use miniscript::bitcoin::hashes::hex::FromHex;
 use miniscript::bitcoin::psbt::{self, Psbt};
@@ -84,7 +85,7 @@ fn main() {
     let txin = TxIn {
         previous_output: outpoint,
         sequence: Sequence::from_height(26),
-        ..Default::default()
+        ..TxIn::EMPTY_COINBASE
     };
     psbt.unsigned_tx.input.push(txin);
 
diff --git a/examples/sign_multisig.rs b/examples/sign_multisig.rs
index b1117c102..e0f756f90 100644
--- a/examples/sign_multisig.rs
+++ b/examples/sign_multisig.rs
@@ -6,7 +6,7 @@ use std::collections::HashMap;
 use std::str::FromStr;
 
 use bitcoin::blockdata::witness::Witness;
-use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence};
+use bitcoin::{absolute, ecdsa, transaction, Amount, OutPoint, Sequence};
 
 fn main() {
     let mut tx = spending_transaction();
@@ -81,7 +81,7 @@ fn spending_transaction() -> bitcoin::Transaction {
         version: transaction::Version::TWO,
         lock_time: absolute::LockTime::ZERO,
         input: vec![bitcoin::TxIn {
-            previous_output: Default::default(),
+            previous_output: OutPoint::COINBASE_PREVOUT,
             script_sig: bitcoin::ScriptBuf::new(),
             sequence: Sequence::MAX,
             witness: Witness::default(),
diff --git a/src/descriptor/bare.rs b/src/descriptor/bare.rs
index 176137ad8..f25d29c52 100644
--- a/src/descriptor/bare.rs
+++ b/src/descriptor/bare.rs
@@ -9,6 +9,7 @@
 
 use core::fmt;
 
+use bitcoin::address::script_pubkey::BuilderExt as _;
 use bitcoin::script::{self, PushBytes};
 use bitcoin::{Address, Network, ScriptBuf, Weight};
 
@@ -300,7 +301,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
                     // serialize() does not allocate here
                     sig.serialize().as_ref(),
                 )
-                .push_key(&self.pk.to_public_key())
+                .push_key(self.pk.to_public_key())
                 .into_script();
             let witness = vec![];
             Ok((witness, script_sig))
diff --git a/src/descriptor/key.rs b/src/descriptor/key.rs
index bcb74cdf6..fdb2bf128 100644
--- a/src/descriptor/key.rs
+++ b/src/descriptor/key.rs
@@ -6,8 +6,8 @@ use core::str::FromStr;
 #[cfg(feature = "std")]
 use std::error;
 
-use bitcoin::bip32::{self, XKeyIdentifier};
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
+use bitcoin::bip32;
+use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
 use bitcoin::key::XOnlyPublicKey;
 use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
 
@@ -220,10 +220,7 @@ impl DescriptorXKey<bip32::Xpriv> {
         let hardened_path = &self.derivation_path[..last_hardened_idx];
         let unhardened_path = &self.derivation_path[last_hardened_idx..];
 
-        let xprv = self
-            .xkey
-            .derive_priv(secp, &hardened_path)
-            .map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
+        let xprv = self.xkey.derive_priv(secp, &hardened_path);
         let xpub = bip32::Xpub::from_priv(secp, &xprv);
 
         let origin = match &self.origin {
@@ -524,15 +521,17 @@ impl DescriptorPublicKey {
                 if let Some((fingerprint, _)) = single.origin {
                     fingerprint
                 } else {
-                    let mut engine = XKeyIdentifier::engine();
+                    let mut engine = hash160::Hash::engine();
                     match single.key {
                         SinglePubKey::FullKey(pk) => {
                             pk.write_into(&mut engine).expect("engines don't error")
                         }
                         SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()),
                     };
+                    // FIXME: Fix the bip32 API for creating fingerprint?
+                    let xkey_id = hash160::Hash::from_engine(engine);
                     bip32::Fingerprint::from(
-                        &XKeyIdentifier::from_engine(engine)[..4]
+                        &xkey_id.as_byte_array()[..4]
                             .try_into()
                             .expect("4 byte slice"),
                     )
diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs
index 862fc58c6..e83c484da 100644
--- a/src/descriptor/mod.rs
+++ b/src/descriptor/mod.rs
@@ -405,7 +405,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
             Descriptor::Pkh(ref pkh) => pkh.script_pubkey(),
             Descriptor::Wpkh(ref wpkh) => wpkh.script_pubkey(),
             Descriptor::Wsh(ref wsh) => wsh.script_pubkey(),
-            Descriptor::Sh(ref sh) => sh.script_pubkey(),
+            Descriptor::Sh(ref sh) => sh.script_pubkey().expect("TODO: Handle error"),
             Descriptor::Tr(ref tr) => tr.script_pubkey(),
         }
     }
@@ -1010,13 +1010,14 @@ pub(crate) use write_descriptor;
 mod tests {
     use core::convert::TryFrom;
 
+    use bitcoin::address::script_pubkey::{BuilderExt as _, ScriptExt as _};
     use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
     use bitcoin::blockdata::script::Instruction;
     use bitcoin::blockdata::{opcodes, script};
     use bitcoin::hashes::hex::FromHex;
-    use bitcoin::hashes::Hash;
-    use bitcoin::script::PushBytes;
+    use bitcoin::script::{PushBytes, ScriptBufExt as _, ScriptExt as _};
     use bitcoin::sighash::EcdsaSighashType;
+    use bitcoin::witness::WitnessExt;
     use bitcoin::{bip32, PublicKey, Sequence};
 
     use super::checksum::desc_checksum;
@@ -1305,7 +1306,7 @@ mod tests {
         let ms = ms_str!("c:pk_k({})", pk);
 
         let mut txin = bitcoin::TxIn {
-            previous_output: bitcoin::OutPoint::default(),
+            previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
             script_sig: bitcoin::ScriptBuf::new(),
             sequence: Sequence::from_height(100),
             witness: Witness::default(),
@@ -1316,7 +1317,7 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: script::Builder::new()
                     .push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
                     .into_script(),
@@ -1331,10 +1332,10 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: script::Builder::new()
                     .push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
-                    .push_key(&pk)
+                    .push_key(pk)
                     .into_script(),
                 sequence: Sequence::from_height(100),
                 witness: Witness::default(),
@@ -1347,7 +1348,7 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: bitcoin::ScriptBuf::new(),
                 sequence: Sequence::from_height(100),
                 witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes()]),
@@ -1368,7 +1369,7 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: script::Builder::new()
                     .push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
                     .into_script(),
@@ -1389,7 +1390,7 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: script::Builder::new()
                     .push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
                     .push_slice(<&PushBytes>::try_from(ms.encode().as_bytes()).unwrap())
@@ -1407,7 +1408,7 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: bitcoin::ScriptBuf::new(),
                 sequence: Sequence::from_height(100),
                 witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1420,9 +1421,17 @@ mod tests {
         assert_eq!(
             txin,
             bitcoin::TxIn {
-                previous_output: bitcoin::OutPoint::default(),
+                previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
                 script_sig: script::Builder::new()
-                    .push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
+                    .push_slice(
+                        <&PushBytes>::try_from(
+                            ms.encode()
+                                .to_p2wsh()
+                                .expect("TODO: Handle error")
+                                .as_bytes()
+                        )
+                        .unwrap()
+                    )
                     .into_script(),
                 sequence: Sequence::from_height(100),
                 witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1431,7 +1440,15 @@ mod tests {
         assert_eq!(
             shwsh.unsigned_script_sig(),
             script::Builder::new()
-                .push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
+                .push_slice(
+                    <&PushBytes>::try_from(
+                        ms.encode()
+                            .to_p2wsh()
+                            .expect("TODO: Handle error")
+                            .as_bytes()
+                    )
+                    .unwrap()
+                )
                 .into_script()
         );
     }
@@ -1549,7 +1566,7 @@ mod tests {
         .unwrap();
 
         let mut txin = bitcoin::TxIn {
-            previous_output: bitcoin::OutPoint::default(),
+            previous_output: bitcoin::OutPoint::COINBASE_PREVOUT,
             script_sig: bitcoin::ScriptBuf::new(),
             sequence: Sequence::ZERO,
             witness: Witness::default(),
diff --git a/src/descriptor/segwitv0.rs b/src/descriptor/segwitv0.rs
index 2f2532b85..acb5d59cc 100644
--- a/src/descriptor/segwitv0.rs
+++ b/src/descriptor/segwitv0.rs
@@ -8,6 +8,7 @@
 use core::convert::TryFrom;
 use core::fmt;
 
+use bitcoin::address::script_pubkey::ScriptExt;
 use bitcoin::{Address, Network, ScriptBuf, Weight};
 
 use super::checksum::verify_checksum;
@@ -144,13 +145,19 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
 
 impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
     /// Obtains the corresponding script pubkey for this descriptor.
-    pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_p2wsh() }
+    pub fn script_pubkey(&self) -> ScriptBuf {
+        self.inner_script().to_p2wsh().expect("TODO: Handle error")
+    }
 
     /// Obtains the corresponding script pubkey for this descriptor.
     pub fn address(&self, network: Network) -> Address {
         match self.inner {
-            WshInner::SortedMulti(ref smv) => Address::p2wsh(&smv.encode(), network),
-            WshInner::Ms(ref ms) => Address::p2wsh(&ms.encode(), network),
+            WshInner::SortedMulti(ref smv) => {
+                Address::p2wsh(&smv.encode(), network).expect("TODO: Handle error")
+            }
+            WshInner::Ms(ref ms) => {
+                Address::p2wsh(&ms.encode(), network).expect("TODO: Handle error")
+            }
         }
     }
 
@@ -384,7 +391,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
         let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
             .expect("wpkh descriptors have compressed keys");
 
-        let addr = Address::p2wpkh(&compressed, Network::Bitcoin);
+        let addr = Address::p2wpkh(compressed, Network::Bitcoin);
         addr.script_pubkey()
     }
 
@@ -394,7 +401,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
         let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
             .expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors");
 
-        Address::p2wpkh(&compressed, network)
+        Address::p2wpkh(compressed, network)
     }
 
     /// Obtains the underlying miniscript for this descriptor.
diff --git a/src/descriptor/sh.rs b/src/descriptor/sh.rs
index cf05c1b71..0ce11e7f4 100644
--- a/src/descriptor/sh.rs
+++ b/src/descriptor/sh.rs
@@ -10,6 +10,7 @@
 use core::convert::TryFrom;
 use core::fmt;
 
+use bitcoin::address::script_pubkey::ScriptExt;
 use bitcoin::script::PushBytes;
 use bitcoin::{script, Address, Network, ScriptBuf, Weight};
 
@@ -277,7 +278,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
 
 impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
     /// Obtains the corresponding script pubkey for this descriptor.
-    pub fn script_pubkey(&self) -> ScriptBuf {
+    pub fn script_pubkey(&self) -> Result<ScriptBuf, bitcoin::script::RedeemScriptSizeError> {
         match self.inner {
             ShInner::Wsh(ref wsh) => wsh.script_pubkey().to_p2sh(),
             ShInner::Wpkh(ref wpkh) => wpkh.script_pubkey().to_p2sh(),
@@ -341,7 +342,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
         match self.inner {
             ShInner::Wsh(ref wsh) => {
                 // wsh explicit must contain exactly 1 element
-                let witness_script = wsh.inner_script().to_p2wsh();
+                let witness_script = wsh.inner_script().to_p2wsh().expect("TODO: Handle error");
                 let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes())
                     .expect("Witness script is not too large");
                 script::Builder::new().push_slice(push_bytes).into_script()
diff --git a/src/interpreter/error.rs b/src/interpreter/error.rs
index 4e47932a6..69672efe2 100644
--- a/src/interpreter/error.rs
+++ b/src/interpreter/error.rs
@@ -33,7 +33,7 @@ pub enum Error {
     /// General Interpreter error.
     CouldNotEvaluate,
     /// ECDSA Signature related error
-    EcdsaSig(bitcoin::ecdsa::Error),
+    EcdsaSig(bitcoin::ecdsa::DecodeError),
     /// We expected a push (including a `OP_1` but no other numeric pushes)
     ExpectedPush,
     /// The preimage to the hash function must be exactly 32 bytes.
@@ -247,8 +247,8 @@ impl From<bitcoin::sighash::InvalidSighashTypeError> for Error {
 }
 
 #[doc(hidden)]
-impl From<bitcoin::ecdsa::Error> for Error {
-    fn from(e: bitcoin::ecdsa::Error) -> Error { Error::EcdsaSig(e) }
+impl From<bitcoin::ecdsa::DecodeError> for Error {
+    fn from(e: bitcoin::ecdsa::DecodeError) -> Error { Error::EcdsaSig(e) }
 }
 
 #[doc(hidden)]
diff --git a/src/interpreter/inner.rs b/src/interpreter/inner.rs
index 49134c6de..49c333066 100644
--- a/src/interpreter/inner.rs
+++ b/src/interpreter/inner.rs
@@ -1,7 +1,9 @@
 // Written in 2019 by Sanket Kanjular and Andrew Poelstra
 // SPDX-License-Identifier: CC0-1.0
 
-use bitcoin::hashes::{hash160, sha256, Hash};
+use bitcoin::address::script_pubkey::{ScriptBufExt as _, ScriptExt as _};
+use bitcoin::hashes::{hash160, sha256};
+use bitcoin::script::ScriptExt as _;
 use bitcoin::taproot::{ControlBlock, TAPROOT_ANNEX_PREFIX};
 use bitcoin::Witness;
 
@@ -130,7 +132,7 @@ pub(super) fn from_txdata<'txin>(
                 Some(elem) => {
                     let pk = pk_from_stack_elem(&elem, false)?;
                     if *spk
-                        == bitcoin::ScriptBuf::new_p2pkh(&pk.to_pubkeyhash(SigType::Ecdsa).into())
+                        == bitcoin::ScriptBuf::new_p2pkh(pk.to_pubkeyhash(SigType::Ecdsa).into())
                     {
                         Ok((
                             Inner::PublicKey(pk.into(), PubkeyType::Pkh),
@@ -153,11 +155,11 @@ pub(super) fn from_txdata<'txin>(
                 Some(elem) => {
                     let pk = pk_from_stack_elem(&elem, true)?;
                     let hash160 = pk.to_pubkeyhash(SigType::Ecdsa);
-                    if *spk == bitcoin::ScriptBuf::new_p2wpkh(&hash160.into()) {
+                    if *spk == bitcoin::ScriptBuf::new_p2wpkh(hash160.into()) {
                         Ok((
                             Inner::PublicKey(pk.into(), PubkeyType::Wpkh),
                             wit_stack,
-                            Some(bitcoin::ScriptBuf::new_p2pkh(&hash160.into())), // bip143, why..
+                            Some(bitcoin::ScriptBuf::new_p2pkh(hash160.into())), // bip143, why..
                         ))
                     } else {
                         Err(Error::IncorrectWPubkeyHash)
@@ -177,7 +179,7 @@ pub(super) fn from_txdata<'txin>(
                     let script = miniscript.encode();
                     let miniscript = miniscript.to_no_checks_ms();
                     let scripthash = sha256::Hash::hash(script.as_bytes());
-                    if *spk == bitcoin::ScriptBuf::new_p2wsh(&scripthash.into()) {
+                    if *spk == bitcoin::ScriptBuf::new_p2wsh(scripthash.into()) {
                         Ok((Inner::Script(miniscript, ScriptType::Wsh), wit_stack, Some(script)))
                     } else {
                         Err(Error::IncorrectWScriptHash)
@@ -248,7 +250,7 @@ pub(super) fn from_txdata<'txin>(
             Some(elem) => {
                 if let stack::Element::Push(slice) = elem {
                     let scripthash = hash160::Hash::hash(slice);
-                    if *spk != bitcoin::ScriptBuf::new_p2sh(&scripthash.into()) {
+                    if *spk != bitcoin::ScriptBuf::new_p2sh(scripthash.into()) {
                         return Err(Error::IncorrectScriptHash);
                     }
                     // ** p2sh-wrapped wpkh **
@@ -261,13 +263,12 @@ pub(super) fn from_txdata<'txin>(
                                     let pk = pk_from_stack_elem(&elem, true)?;
                                     let hash160 = pk.to_pubkeyhash(SigType::Ecdsa);
                                     if slice
-                                        == bitcoin::ScriptBuf::new_p2wpkh(&hash160.into())
-                                            .as_bytes()
+                                        == bitcoin::ScriptBuf::new_p2wpkh(hash160.into()).as_bytes()
                                     {
                                         Ok((
                                             Inner::PublicKey(pk.into(), PubkeyType::ShWpkh),
                                             wit_stack,
-                                            Some(bitcoin::ScriptBuf::new_p2pkh(&hash160.into())), // bip143, why..
+                                            Some(bitcoin::ScriptBuf::new_p2pkh(hash160.into())), // bip143, why..
                                         ))
                                     } else {
                                         Err(Error::IncorrectWScriptHash)
@@ -289,7 +290,7 @@ pub(super) fn from_txdata<'txin>(
                                     let miniscript = miniscript.to_no_checks_ms();
                                     let scripthash = sha256::Hash::hash(script.as_bytes());
                                     if slice
-                                        == bitcoin::ScriptBuf::new_p2wsh(&scripthash.into())
+                                        == bitcoin::ScriptBuf::new_p2wsh(scripthash.into())
                                             .as_bytes()
                                     {
                                         Ok((
@@ -312,7 +313,7 @@ pub(super) fn from_txdata<'txin>(
                 let miniscript = miniscript.to_no_checks_ms();
                 if wit_stack.is_empty() {
                     let scripthash = hash160::Hash::hash(script.as_bytes());
-                    if *spk == bitcoin::ScriptBuf::new_p2sh(&scripthash.into()) {
+                    if *spk == bitcoin::ScriptBuf::new_p2sh(scripthash.into()) {
                         Ok((Inner::Script(miniscript, ScriptType::Sh), ssig_stack, Some(script)))
                     } else {
                         Err(Error::IncorrectScriptHash)
@@ -397,6 +398,7 @@ mod tests {
     use core::convert::TryFrom;
     use core::str::FromStr;
 
+    use bitcoin::address::script_pubkey::BuilderExt as _;
     use bitcoin::blockdata::script;
     use bitcoin::hashes::hex::FromHex;
     use bitcoin::script::PushBytes;
@@ -434,22 +436,22 @@ mod tests {
 
             let pkhash = key.to_pubkeyhash(SigType::Ecdsa).into();
             let wpkhash = key.to_pubkeyhash(SigType::Ecdsa).into();
-            let wpkh_spk = bitcoin::ScriptBuf::new_p2wpkh(&wpkhash);
+            let wpkh_spk = bitcoin::ScriptBuf::new_p2wpkh(wpkhash);
             let wpkh_scripthash = hash160::Hash::hash(wpkh_spk.as_bytes()).into();
 
             KeyTestData {
-                pk_spk: bitcoin::ScriptBuf::new_p2pk(&key),
-                pkh_spk: bitcoin::ScriptBuf::new_p2pkh(&pkhash),
+                pk_spk: bitcoin::ScriptBuf::new_p2pk(key),
+                pkh_spk: bitcoin::ScriptBuf::new_p2pkh(pkhash),
                 pk_sig: script::Builder::new().push_slice(dummy_sig).into_script(),
                 pkh_sig: script::Builder::new()
                     .push_slice(dummy_sig)
-                    .push_key(&key)
+                    .push_key(key)
                     .into_script(),
-                pkh_sig_justkey: script::Builder::new().push_key(&key).into_script(),
+                pkh_sig_justkey: script::Builder::new().push_key(key).into_script(),
                 wpkh_spk: wpkh_spk.clone(),
                 wpkh_stack: Witness::from_slice(&[dummy_sig_vec.clone(), key.to_bytes()]),
                 wpkh_stack_justkey: Witness::from_slice(&[key.to_bytes()]),
-                sh_wpkh_spk: bitcoin::ScriptBuf::new_p2sh(&wpkh_scripthash),
+                sh_wpkh_spk: bitcoin::ScriptBuf::new_p2sh(wpkh_scripthash),
                 sh_wpkh_sig: script::Builder::new()
                     .push_slice(<&PushBytes>::try_from(wpkh_spk[..].as_bytes()).unwrap())
                     .into_script(),
@@ -718,7 +720,7 @@ mod tests {
         let (miniscript, redeem_script) = ms_inner_script(&format!("hash160({})", hash));
         let rs_hash = hash160::Hash::hash(redeem_script.as_bytes()).into();
 
-        let spk = ScriptBuf::new_p2sh(&rs_hash);
+        let spk = ScriptBuf::new_p2sh(rs_hash);
         let script_sig = script::Builder::new()
             .push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
             .into_script();
@@ -754,7 +756,7 @@ mod tests {
         let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
         let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);
 
-        let spk = ScriptBuf::new_p2wsh(&wit_hash);
+        let spk = ScriptBuf::new_p2wsh(wit_hash);
         let blank_script = bitcoin::ScriptBuf::new();
 
         // wsh without witness
@@ -789,14 +791,14 @@ mod tests {
         let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
         let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);
 
-        let redeem_script = ScriptBuf::new_p2wsh(&wit_hash);
+        let redeem_script = ScriptBuf::new_p2wsh(wit_hash);
         let script_sig = script::Builder::new()
             .push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
             .into_script();
         let blank_script = bitcoin::ScriptBuf::new();
 
         let rs_hash = hash160::Hash::hash(redeem_script.as_bytes()).into();
-        let spk = ScriptBuf::new_p2sh(&rs_hash);
+        let spk = ScriptBuf::new_p2sh(rs_hash);
 
         // shwsh without witness or scriptsig
         let err = from_txdata(&spk, &blank_script, &Witness::default()).unwrap_err();
diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs
index a7b316f23..a4fa12c96 100644
--- a/src/interpreter/mod.rs
+++ b/src/interpreter/mod.rs
@@ -11,7 +11,8 @@
 use core::fmt;
 use core::str::FromStr;
 
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
+use bitcoin::hashes::{hash160, ripemd160, sha256};
+use bitcoin::taproot::TapLeafHashExt as _;
 use bitcoin::{absolute, relative, secp256k1, sighash, taproot, Sequence, TxOut, Witness};
 
 use crate::miniscript::context::{NoChecks, SigType};
@@ -1050,7 +1051,6 @@ fn verify_sersig<'txin>(
 
 #[cfg(test)]
 mod tests {
-
     use bitcoin::secp256k1::Secp256k1;
 
     use super::inner::ToNoChecks;
diff --git a/src/interpreter/stack.rs b/src/interpreter/stack.rs
index 4cf5450af..a32e4e783 100644
--- a/src/interpreter/stack.rs
+++ b/src/interpreter/stack.rs
@@ -4,7 +4,7 @@
 //! Interpreter stack
 
 use bitcoin::blockdata::{opcodes, script};
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
+use bitcoin::hashes::{hash160, ripemd160, sha256};
 use bitcoin::{absolute, relative, Sequence};
 
 use super::error::PkEvalErrInner;
@@ -282,7 +282,7 @@ impl<'txin> Stack<'txin> {
             if preimage.len() != 32 {
                 return Some(Err(Error::HashPreimageLengthMismatch));
             }
-            if hash256::Hash::hash(preimage) == *hash {
+            if bitcoin::hashes::sha256d::Hash::hash(preimage) == (*hash).into() {
                 self.push(Element::Satisfied);
                 Some(Ok(SatisfiedConstraint::HashLock {
                     hash: HashLockType::Hash256(*hash),
diff --git a/src/lib.rs b/src/lib.rs
index 63885ab75..1809bcdf2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -132,7 +132,7 @@ use core::{fmt, hash, str};
 #[cfg(feature = "std")]
 use std::error;
 
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
+use bitcoin::hashes::{hash160, ripemd160, sha256};
 use bitcoin::hex::DisplayHex;
 use bitcoin::{script, Opcode};
 
@@ -423,7 +423,7 @@ pub enum Error {
     /// rust-bitcoin address error
     AddrError(bitcoin::address::ParseError),
     /// rust-bitcoin p2sh address error
-    AddrP2shError(bitcoin::address::P2shError),
+    RedeemScriptSizeError(bitcoin::script::RedeemScriptSizeError),
     /// A `CHECKMULTISIG` opcode was preceded by a number > 20
     CmsTooManyKeys(u32),
     /// A tapscript multi_a cannot support more than Weight::MAX_BLOCK/32 keys
@@ -508,7 +508,7 @@ impl fmt::Display for Error {
             },
             Error::Script(ref e) => fmt::Display::fmt(e, f),
             Error::AddrError(ref e) => fmt::Display::fmt(e, f),
-            Error::AddrP2shError(ref e) => fmt::Display::fmt(e, f),
+            Error::RedeemScriptSizeError(ref e) => fmt::Display::fmt(e, f),
             Error::CmsTooManyKeys(n) => write!(f, "checkmultisig with {} keys", n),
             Error::Unprintable(x) => write!(f, "unprintable character 0x{:02x}", x),
             Error::ExpectedChar(c) => write!(f, "expected {}", c),
@@ -590,7 +590,7 @@ impl error::Error for Error {
             | MultipathDescLenMismatch => None,
             Script(e) => Some(e),
             AddrError(e) => Some(e),
-            AddrP2shError(e) => Some(e),
+            RedeemScriptSizeError(e) => Some(e),
             Secp(e) => Some(e),
             #[cfg(feature = "compiler")]
             CompilerError(e) => Some(e),
@@ -639,8 +639,8 @@ impl From<bitcoin::address::ParseError> for Error {
 }
 
 #[doc(hidden)]
-impl From<bitcoin::address::P2shError> for Error {
-    fn from(e: bitcoin::address::P2shError) -> Error { Error::AddrP2shError(e) }
+impl From<bitcoin::script::RedeemScriptSizeError> for Error {
+    fn from(e: bitcoin::script::RedeemScriptSizeError) -> Error { Error::RedeemScriptSizeError(e) }
 }
 
 #[doc(hidden)]
diff --git a/src/miniscript/astelem.rs b/src/miniscript/astelem.rs
index 08ddd71d3..d3db71672 100644
--- a/src/miniscript/astelem.rs
+++ b/src/miniscript/astelem.rs
@@ -9,7 +9,8 @@
 
 use core::str::FromStr;
 
-use bitcoin::hashes::{hash160, Hash};
+use bitcoin::address::script_pubkey::BuilderExt;
+use bitcoin::hashes::hash160;
 use bitcoin::{absolute, opcodes, script};
 use sync::Arc;
 
@@ -144,35 +145,35 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
                 .push_slice(hash.to_byte_array())
                 .push_opcode(opcodes::all::OP_EQUALVERIFY),
             Terminal::After(t) => builder
-                .push_int(absolute::LockTime::from(t).to_consensus_u32() as i64)
+                .push_int_unchecked(absolute::LockTime::from(t).to_consensus_u32() as i64)
                 .push_opcode(opcodes::all::OP_CLTV),
             Terminal::Older(t) => builder
-                .push_int(t.to_consensus_u32().into())
+                .push_int_unchecked(t.to_consensus_u32() as i64)
                 .push_opcode(opcodes::all::OP_CSV),
             Terminal::Sha256(ref h) => builder
                 .push_opcode(opcodes::all::OP_SIZE)
-                .push_int(32)
+                .push_int_unchecked(32)
                 .push_opcode(opcodes::all::OP_EQUALVERIFY)
                 .push_opcode(opcodes::all::OP_SHA256)
                 .push_slice(Pk::to_sha256(h).to_byte_array())
                 .push_opcode(opcodes::all::OP_EQUAL),
             Terminal::Hash256(ref h) => builder
                 .push_opcode(opcodes::all::OP_SIZE)
-                .push_int(32)
+                .push_int_unchecked(32)
                 .push_opcode(opcodes::all::OP_EQUALVERIFY)
                 .push_opcode(opcodes::all::OP_HASH256)
                 .push_slice(Pk::to_hash256(h).to_byte_array())
                 .push_opcode(opcodes::all::OP_EQUAL),
             Terminal::Ripemd160(ref h) => builder
                 .push_opcode(opcodes::all::OP_SIZE)
-                .push_int(32)
+                .push_int_unchecked(32)
                 .push_opcode(opcodes::all::OP_EQUALVERIFY)
                 .push_opcode(opcodes::all::OP_RIPEMD160)
                 .push_slice(Pk::to_ripemd160(h).to_byte_array())
                 .push_opcode(opcodes::all::OP_EQUAL),
             Terminal::Hash160(ref h) => builder
                 .push_opcode(opcodes::all::OP_SIZE)
-                .push_int(32)
+                .push_int_unchecked(32)
                 .push_opcode(opcodes::all::OP_EQUALVERIFY)
                 .push_opcode(opcodes::all::OP_HASH160)
                 .push_slice(Pk::to_hash160(h).to_byte_array())
@@ -241,17 +242,17 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
                     builder = builder.push_astelem(sub).push_opcode(opcodes::all::OP_ADD);
                 }
                 builder
-                    .push_int(thresh.k() as i64)
+                    .push_int_unchecked(thresh.k() as i64)
                     .push_opcode(opcodes::all::OP_EQUAL)
             }
             Terminal::Multi(ref thresh) => {
                 debug_assert!(Ctx::sig_type() == SigType::Ecdsa);
-                builder = builder.push_int(thresh.k() as i64);
+                builder = builder.push_int_unchecked(thresh.k() as i64);
                 for pk in thresh.data() {
-                    builder = builder.push_key(&pk.to_public_key());
+                    builder = builder.push_key(pk.to_public_key());
                 }
                 builder
-                    .push_int(thresh.n() as i64)
+                    .push_int_unchecked(thresh.n() as i64)
                     .push_opcode(opcodes::all::OP_CHECKMULTISIG)
             }
             Terminal::MultiA(ref thresh) => {
@@ -264,7 +265,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
                     builder = builder.push_opcode(opcodes::all::OP_CHECKSIGADD);
                 }
                 builder
-                    .push_int(thresh.k() as i64)
+                    .push_int_unchecked(thresh.k() as i64)
                     .push_opcode(opcodes::all::OP_NUMEQUAL)
             }
         }
diff --git a/src/miniscript/decode.rs b/src/miniscript/decode.rs
index 0090b7516..494bfd214 100644
--- a/src/miniscript/decode.rs
+++ b/src/miniscript/decode.rs
@@ -9,7 +9,7 @@ use core::{fmt, mem};
 #[cfg(feature = "std")]
 use std::error;
 
-use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
+use bitcoin::hashes::{hash160, ripemd160, sha256};
 use sync::Arc;
 
 use crate::iter::TreeLike;
diff --git a/src/miniscript/iter.rs b/src/miniscript/iter.rs
index a9373abf5..53cea7647 100644
--- a/src/miniscript/iter.rs
+++ b/src/miniscript/iter.rs
@@ -203,7 +203,7 @@ impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkIter<'a, Pk, Ctx>
 // dependent libraries for their own tasts based on Miniscript AST
 #[cfg(test)]
 pub mod test {
-    use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
+    use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
 
     use super::Miniscript;
     use crate::miniscript::context::Segwitv0;
diff --git a/src/miniscript/lex.rs b/src/miniscript/lex.rs
index 6184572dd..fec8e7bf4 100644
--- a/src/miniscript/lex.rs
+++ b/src/miniscript/lex.rs
@@ -8,6 +8,7 @@
 use core::fmt;
 
 use bitcoin::blockdata::{opcodes, script};
+use bitcoin::script::ScriptExt;
 
 use super::Error;
 use crate::prelude::*;
@@ -213,15 +214,15 @@ pub fn lex(script: &'_ script::Script) -> Result<Vec<Token<'_>>, Error> {
                     33 => ret.push(Token::Bytes33(bytes.as_bytes())),
                     65 => ret.push(Token::Bytes65(bytes.as_bytes())),
                     _ => {
-                        match script::read_scriptint(bytes.as_bytes()) {
+                        match bytes.read_scriptint() {
                             Ok(v) if v >= 0 => {
                                 // check minimality of the number
-                                if script::Builder::new().push_int(v).into_script()[1..].as_bytes()
-                                    != bytes.as_bytes()
-                                {
+                                let builder = script::Builder::new().push_int_unchecked(v as i64);
+                                if builder.into_script()[1..].as_bytes() == bytes.as_bytes() {
+                                    ret.push(Token::Num(v as u32));
+                                } else {
                                     return Err(Error::InvalidPush(bytes.to_owned().into()));
                                 }
-                                ret.push(Token::Num(v as u32));
                             }
                             Ok(_) => return Err(Error::InvalidPush(bytes.to_owned().into())),
                             Err(e) => return Err(Error::Script(e)),
diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs
index 02829ac5f..8e94b70c1 100644
--- a/src/miniscript/mod.rs
+++ b/src/miniscript/mod.rs
@@ -16,7 +16,7 @@ use core::{hash, str};
 
 use bitcoin::hashes::hash160;
 use bitcoin::script;
-use bitcoin::taproot::{LeafVersion, TapLeafHash};
+use bitcoin::taproot::{LeafVersion, TapLeafHash, TapLeafHashExt as _};
 
 use self::analyzable::ExtParams;
 pub use self::context::{BareCtx, Legacy, Segwitv0, Tap};
@@ -802,15 +802,40 @@ impl<Pk: FromStrKey, Ctx: ScriptContext> str::FromStr for Miniscript<Pk, Ctx> {
 
 serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext);
 
-/// Provides a Double SHA256 `Hash` type that displays forwards.
+/// Provides a general purpose Double SHA256 `Hash` type that displays forwards.
 pub mod hash256 {
-    use bitcoin::hashes::{hash_newtype, sha256d};
+    use bitcoin::hashes::{hash_newtype, sha256d, GeneralHash, HashEngine as _};
 
     hash_newtype! {
         /// A hash256 of preimage.
         #[hash_newtype(forward)]
         pub struct Hash(sha256d::Hash);
     }
+
+    impl Hash {
+        /// Constructs a new engine.
+        pub fn engine() -> sha256d::HashEngine { sha256d::HashEngine::default() }
+
+        /// Produces a hash from the current state of a given engine.
+        pub fn from_engine(e: sha256d::HashEngine) -> Self {
+            let sha256d = sha256d::Hash::from_engine(e);
+            Hash(sha256d)
+        }
+
+        /// Hashes some bytes.
+        pub fn hash(data: &[u8]) -> Self {
+            let mut engine = Self::engine();
+            engine.input(data);
+            Self::from_engine(engine)
+        }
+    }
+
+    impl GeneralHash for Hash {
+        type Engine = sha256d::HashEngine;
+
+        fn engine() -> Self::Engine { Hash::engine() }
+        fn from_engine(e: Self::Engine) -> Self { Self::from_engine(e) }
+    }
 }
 
 #[cfg(test)]
@@ -819,7 +844,7 @@ mod tests {
     use core::str;
     use core::str::FromStr;
 
-    use bitcoin::hashes::{hash160, sha256, Hash};
+    use bitcoin::hashes::{hash160, sha256};
     use bitcoin::secp256k1::XOnlyPublicKey;
     use bitcoin::taproot::TapLeafHash;
     use sync::Arc;
@@ -1429,7 +1454,7 @@ mod tests {
             "02c2fd50ceae468857bb7eb32ae9cd4083e6c7e42fbbec179d81134b3e3830586c",
         )
         .unwrap();
-        let hash160 = pk.pubkey_hash().to_raw_hash();
+        let hash160 = pk.pubkey_hash();
         let ms_str = &format!("c:expr_raw_pkh({})", hash160);
         type SegwitMs = Miniscript<bitcoin::PublicKey, Segwitv0>;
 
@@ -1446,7 +1471,7 @@ mod tests {
 
         // Try replacing the raw_pkh with a pkh
         let mut map = BTreeMap::new();
-        map.insert(hash160, pk);
+        map.insert(hash160::Hash::from_byte_array(hash160.to_byte_array()), pk);
         let ms_no_raw = ms.substitute_raw_pkh(&map);
         assert_eq!(ms_no_raw.to_string(), format!("pkh({})", pk),);
     }
diff --git a/src/plan.rs b/src/plan.rs
index f3f148273..c3e2a672a 100644
--- a/src/plan.rs
+++ b/src/plan.rs
@@ -18,6 +18,7 @@
 
 use core::iter::FromIterator;
 
+use bitcoin::address::script_pubkey::ScriptExt as _;
 use bitcoin::hashes::{hash160, ripemd160, sha256};
 use bitcoin::key::XOnlyPublicKey;
 use bitcoin::script::PushBytesBuf;
@@ -417,7 +418,8 @@ impl Plan {
                 Descriptor::Sh(sh) => match sh.as_inner() {
                     descriptor::ShInner::Wsh(wsh) => {
                         input.witness_script = Some(wsh.inner_script());
-                        input.redeem_script = Some(wsh.inner_script().to_p2wsh());
+                        input.redeem_script =
+                            Some(wsh.inner_script().to_p2wsh().expect("TODO: Handle erorr"));
                     }
                     descriptor::ShInner::Wpkh(..) => input.redeem_script = Some(sh.inner_script()),
                     descriptor::ShInner::SortedMulti(_) | descriptor::ShInner::Ms(_) => {
diff --git a/src/policy/compiler.rs b/src/policy/compiler.rs
index 63e16579e..3212dcbf4 100644
--- a/src/policy/compiler.rs
+++ b/src/policy/compiler.rs
@@ -1220,6 +1220,7 @@ where
 mod tests {
     use core::str::FromStr;
 
+    use bitcoin::address::script_pubkey::BuilderExt as _;
     use bitcoin::blockdata::{opcodes, script};
     use bitcoin::hashes;
 
@@ -1340,7 +1341,7 @@ mod tests {
         assert_eq!(
             ms.encode(),
             script::Builder::new()
-                .push_key(&keys[0])
+                .push_key(keys[0])
                 .push_opcode(opcodes::all::OP_CHECKSIG)
                 .into_script()
         );
@@ -1357,12 +1358,12 @@ mod tests {
             ms.encode(),
             script::Builder::new()
                 .push_opcode(opcodes::all::OP_PUSHNUM_2)
-                .push_key(&keys[5])
-                .push_key(&keys[6])
-                .push_key(&keys[7])
+                .push_key(keys[5])
+                .push_key(keys[6])
+                .push_key(keys[7])
                 .push_opcode(opcodes::all::OP_PUSHNUM_3)
                 .push_opcode(opcodes::all::OP_CHECKMULTISIGVERIFY)
-                .push_int(10000)
+                .push_int_unchecked(10000)
                 .push_opcode(opcodes::all::OP_CSV)
                 .into_script()
         );
diff --git a/src/psbt/finalizer.rs b/src/psbt/finalizer.rs
index af25bfd33..e63b0afa0 100644
--- a/src/psbt/finalizer.rs
+++ b/src/psbt/finalizer.rs
@@ -11,8 +11,10 @@
 use core::convert::TryFrom;
 use core::mem;
 
+use bitcoin::address::script_pubkey::ScriptExt as _;
 use bitcoin::hashes::hash160;
 use bitcoin::key::XOnlyPublicKey;
+use bitcoin::script::ScriptExt as _;
 #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
 use bitcoin::secp256k1;
 use bitcoin::secp256k1::Secp256k1;
@@ -150,8 +152,8 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
         let public_keys = psbt_input.bip32_derivation.keys();
         for key in public_keys {
             let bitcoin_key = bitcoin::PublicKey::new(*key);
-            let hash = bitcoin_key.pubkey_hash().to_raw_hash();
-            map.insert(hash, bitcoin_key);
+            let hash = bitcoin_key.pubkey_hash().to_byte_array();
+            map.insert(hash160::Hash::from_byte_array(hash), bitcoin_key);
         }
     }
 
@@ -189,7 +191,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
                 Ok(compressed) => {
                     // Indirect way to check the equivalence of pubkey-hashes.
                     // Create a pubkey hash and check if they are the same.
-                    let addr = bitcoin::Address::p2wpkh(&compressed, bitcoin::Network::Bitcoin);
+                    let addr = bitcoin::Address::p2wpkh(compressed, bitcoin::Network::Bitcoin);
                     *script_pubkey == addr.script_pubkey()
                 }
                 Err(_) => false,
@@ -205,7 +207,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
             return Err(InputError::NonEmptyRedeemScript);
         }
         if let Some(ref witness_script) = inp.witness_script {
-            if witness_script.to_p2wsh() != *script_pubkey {
+            if witness_script.to_p2wsh().expect("TODO: Handle error") != *script_pubkey {
                 return Err(InputError::InvalidWitnessScript {
                     witness_script: witness_script.clone(),
                     p2wsh_expected: script_pubkey.clone(),
@@ -223,7 +225,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
         match inp.redeem_script {
             None => Err(InputError::MissingRedeemScript),
             Some(ref redeem_script) => {
-                if redeem_script.to_p2sh() != *script_pubkey {
+                if redeem_script.to_p2sh().expect("TODO: Handle error") != *script_pubkey {
                     return Err(InputError::InvalidRedeemScript {
                         redeem: redeem_script.clone(),
                         p2sh_expected: script_pubkey.clone(),
@@ -232,7 +234,8 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
                 if redeem_script.is_p2wsh() {
                     // 5. `ShWsh` case
                     if let Some(ref witness_script) = inp.witness_script {
-                        if witness_script.to_p2wsh() != *redeem_script {
+                        if witness_script.to_p2wsh().expect("TODO: Handle error") != *redeem_script
+                        {
                             return Err(InputError::InvalidWitnessScript {
                                 witness_script: witness_script.clone(),
                                 p2wsh_expected: redeem_script.clone(),
@@ -251,10 +254,8 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
                     let partial_sig_contains_pk = inp.partial_sigs.iter().find(|&(&pk, _sig)| {
                         match bitcoin::key::CompressedPublicKey::try_from(pk) {
                             Ok(compressed) => {
-                                let addr = bitcoin::Address::p2wpkh(
-                                    &compressed,
-                                    bitcoin::Network::Bitcoin,
-                                );
+                                let addr =
+                                    bitcoin::Address::p2wpkh(compressed, bitcoin::Network::Bitcoin);
                                 *redeem_script == addr.script_pubkey()
                             }
                             Err(_) => false,
@@ -316,10 +317,9 @@ pub fn interpreter_check<C: secp256k1::Verification>(
         let witness = input
             .final_script_witness
             .as_ref()
-            .map(|wit_slice| Witness::from_slice(&wit_slice.to_vec())) // TODO: Update rust-bitcoin psbt API to use witness
-            .unwrap_or(empty_witness);
+            .unwrap_or(&empty_witness);
 
-        interpreter_inp_check(psbt, secp, index, utxos, &witness, script_sig)?;
+        interpreter_inp_check(psbt, secp, index, utxos, witness, script_sig)?;
     }
     Ok(())
 }
diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs
index 96615df4c..e06b83be8 100644
--- a/src/psbt/mod.rs
+++ b/src/psbt/mod.rs
@@ -12,13 +12,16 @@ use core::fmt;
 #[cfg(feature = "std")]
 use std::error;
 
-use bitcoin::hashes::{hash160, sha256d, Hash};
+use bitcoin::address::script_pubkey::ScriptExt as _;
+use bitcoin::hashes::{hash160, sha256d};
 use bitcoin::psbt::{self, Psbt};
+use bitcoin::script::ScriptExt as _;
 #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
 use bitcoin::secp256k1;
 use bitcoin::secp256k1::{Secp256k1, VerifyOnly};
 use bitcoin::sighash::{self, SighashCache};
-use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapLeafHash};
+use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapLeafHash, TapLeafHashExt as _};
+use bitcoin::transaction::TxInExt as _;
 use bitcoin::{absolute, bip32, relative, transaction, Script, ScriptBuf};
 
 use crate::miniscript::context::SigType;
@@ -1199,7 +1202,8 @@ fn update_item_with_descriptor_helper<F: PsbtFields>(
             Descriptor::Sh(sh) => match sh.as_inner() {
                 descriptor::ShInner::Wsh(wsh) => {
                     *item.witness_script() = Some(wsh.inner_script());
-                    *item.redeem_script() = Some(wsh.inner_script().to_p2wsh());
+                    *item.redeem_script() =
+                        Some(wsh.inner_script().to_p2wsh().expect("TODO: Handle error"));
                 }
                 descriptor::ShInner::Wpkh(..) => *item.redeem_script() = Some(sh.inner_script()),
                 descriptor::ShInner::SortedMulti(_) | descriptor::ShInner::Ms(_) => {
@@ -1413,7 +1417,9 @@ mod tests {
     use bitcoin::consensus::encode::deserialize;
     use bitcoin::hashes::hex::FromHex;
     use bitcoin::key::XOnlyPublicKey;
+    use bitcoin::script::ScriptBufExt as _;
     use bitcoin::secp256k1::PublicKey;
+    use bitcoin::transaction::VersionExt as _;
     use bitcoin::{Amount, OutPoint, TxIn, TxOut};
 
     use super::*;
@@ -1621,7 +1627,7 @@ mod tests {
             lock_time: absolute::LockTime::ZERO,
             input: vec![TxIn {
                 previous_output: OutPoint { txid: non_witness_utxo.compute_txid(), vout: 0 },
-                ..Default::default()
+                ..TxIn::EMPTY_COINBASE
             }],
             output: vec![],
         };
diff --git a/src/util.rs b/src/util.rs
index d2cfde6d0..dcf4526be 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -2,16 +2,25 @@
 
 use core::convert::TryFrom;
 
-use bitcoin::constants::MAX_SCRIPT_ELEMENT_SIZE;
-use bitcoin::hashes::Hash;
+use bitcoin::address::script_pubkey::BuilderExt as _;
+use bitcoin::constants::MAX_REDEEM_SCRIPT_SIZE;
+use bitcoin::hashes::hash160;
 use bitcoin::script::{self, PushBytes, ScriptBuf};
-use bitcoin::PubkeyHash;
 
 use crate::miniscript::context;
 use crate::miniscript::satisfy::Placeholder;
 use crate::prelude::*;
 use crate::{MiniscriptKey, ScriptContext, ToPublicKey};
-pub(crate) fn varint_len(n: usize) -> usize { bitcoin::VarInt(n as u64).size() }
+
+// Copied from `bitcoin_internals::compact_size`.
+pub(crate) fn varint_len(n: usize) -> usize {
+    match n {
+        0..=0xFC => 1,
+        0xFD..=0xFFFF => 3,
+        0x10000..=0xFFFFFFFF => 5,
+        _ => 9,
+    }
+}
 
 pub(crate) trait ItemSize {
     fn size(&self) -> usize;
@@ -49,15 +58,25 @@ pub(crate) fn witness_size<T: ItemSize>(wit: &[T]) -> usize {
 }
 
 pub(crate) fn witness_to_scriptsig(witness: &[Vec<u8>]) -> ScriptBuf {
+    let read_scriptint = |slice: &[u8]| {
+        if let Ok(push) = <&PushBytes>::try_from(slice) {
+            if let Ok(n) = push.read_scriptint() {
+                return Some(n);
+            }
+        }
+        None
+    };
+
     let mut b = script::Builder::new();
     for (i, wit) in witness.iter().enumerate() {
-        if let Ok(n) = script::read_scriptint(wit) {
-            b = b.push_int(n);
+        if let Some(n) = read_scriptint(wit) {
+            // FIXME: Use `push_int` and handle errors.
+            b = b.push_int_unchecked(n);
         } else {
             if i != witness.len() - 1 {
                 assert!(wit.len() < 73, "All pushes in miniscript are < 73 bytes");
             } else {
-                assert!(wit.len() <= MAX_SCRIPT_ELEMENT_SIZE, "P2SH redeem script is <= 520 bytes");
+                assert!(wit.len() <= MAX_REDEEM_SCRIPT_SIZE, "P2SH redeem script is <= 520 bytes");
             }
             let push = <&PushBytes>::try_from(wit.as_slice()).expect("checked above");
             b = b.push_slice(push)
@@ -88,7 +107,7 @@ impl MsKeyBuilder for script::Builder {
         Ctx: ScriptContext,
     {
         match Ctx::sig_type() {
-            context::SigType::Ecdsa => self.push_key(&key.to_public_key()),
+            context::SigType::Ecdsa => self.push_key(key.to_public_key()),
             context::SigType::Schnorr => self.push_slice(key.to_x_only_pubkey().serialize()),
         }
     }
@@ -101,7 +120,10 @@ impl MsKeyBuilder for script::Builder {
         match Ctx::sig_type() {
             context::SigType::Ecdsa => self.push_slice(key.to_public_key().pubkey_hash()),
             context::SigType::Schnorr => {
-                self.push_slice(PubkeyHash::hash(&key.to_x_only_pubkey().serialize()))
+                let hash = hash160::Hash::hash(&key.to_x_only_pubkey().serialize());
+                self.push_slice(
+                    <&PushBytes>::try_from(hash.as_byte_array()).expect("32 bytes is fine to push"),
+                )
             }
         }
     }