Skip to content
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

Upgrade bitcoin dependency to v0.29.0 #450

Merged
merged 3 commits into from
Sep 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ std = ["bitcoin/std", "bitcoin/secp-recovery"]
no-std = ["hashbrown", "bitcoin/no-std"]
compiler = []
trace = []

unstable = []
serde = ["actual-serde", "bitcoin/use-serde"]
serde = ["actual-serde", "bitcoin/serde"]
rand = ["bitcoin/rand"]

[dependencies]
bitcoin = { version = "0.28.1", default-features = false }
bitcoin = { version = "0.29.1", default-features = false }
hashbrown = { version = "0.11", optional = true }

# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1.0", optional = true }


[dev-dependencies]
bitcoind = {version = "0.26.1", features=["22_0"]}
bitcoind = { version = "0.27.0", features=["23_0"] }
actual-rand = { package = "rand", version = "0.8.4"}
secp256k1 = {version = "0.22.1", features = ["rand-std"]}
secp256k1 = {version = "0.24.0", features = ["rand-std"]}

[[example]]
name = "htlc"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ or in [the `examples/` directory](https://github.com/apoelstra/rust-miniscript/t
This library should always compile with any combination of features (minus
`no-std`) on **Rust 1.41.1** or **Rust 1.47** with `no-std`.

Some dependencies do not play nicely with our MSRV, if you are running the tests
you may need to pin as follows:

```
cargo update --package url --precise 2.2.2
cargo update --package form_urlencoded --precise 1.0.1
```

## Contributing
Contributions are generally welcome. If you intend to make larger changes please
discuss them in an issue before PRing them to avoid duplicate work and
Expand Down
18 changes: 12 additions & 6 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ set -e

FEATURES="compiler serde rand"

# Use toolchain if explicitly specified
if [ -n "$TOOLCHAIN" ]
then
alias cargo="cargo +$TOOLCHAIN"
fi

cargo update -p serde --precise 1.0.142
cargo update -p serde_derive --precise 1.0.142

cargo --version
rustc --version

# Work out if we are using a nightly toolchain.
MSRV=false
if cargo --version | grep "1\.41\.0"; then
MSRV=true
fi

# form_urlencoded 1.1.0 breaks MSRV.
if [ "$MSRV" = true ]; then
cargo update -p url --precise 2.2.2
cargo update -p form_urlencoded --precise 1.0.1
fi

# Format if told to
if [ "$DO_FMT" = true ]
then
Expand Down
6 changes: 3 additions & 3 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::blockdata::witness::Witness;
use bitcoin::secp256k1;
use bitcoin::{secp256k1, PackedLockTime, Sequence};

fn main() {
let mut tx = spending_transaction();
Expand Down Expand Up @@ -91,11 +91,11 @@ fn main() {
fn spending_transaction() -> bitcoin::Transaction {
bitcoin::Transaction {
version: 2,
lock_time: 0,
lock_time: PackedLockTime::ZERO,
input: vec![bitcoin::TxIn {
previous_output: Default::default(),
script_sig: bitcoin::Script::new(),
sequence: 0xffffffff,
sequence: Sequence::MAX,
witness: Witness::default(),
}],
output: vec![bitcoin::TxOut {
Expand Down
2 changes: 1 addition & 1 deletion examples/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn main() {
let secp = secp256k1::Secp256k1::new();
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
// Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor
let unspendable_pubkey = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);
let (unspendable_pubkey, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);

pk_map.insert("UNSPENDABLE_KEY".to_string(), unspendable_pubkey);
let pubkeys = hardcoded_xonlypubkeys();
Expand Down
5 changes: 3 additions & 2 deletions examples/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::str::FromStr;
use bitcoin::consensus::Decodable;
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::util::sighash;
use bitcoin::{LockTime, Sequence};
use miniscript::interpreter::KeySigPair;

fn main() {
Expand All @@ -33,8 +34,8 @@ fn main() {
&spk_input_1,
&tx.input[0].script_sig,
&tx.input[0].witness,
0,
0,
Sequence::ZERO,
LockTime::ZERO,
)
.unwrap();

Expand Down
20 changes: 10 additions & 10 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ mod tests {
use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::hashes::{hash160, sha256};
use bitcoin::util::bip32;
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey};
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey, Sequence};

use super::checksum::desc_checksum;
use super::tr::Tr;
Expand Down Expand Up @@ -1155,7 +1155,7 @@ mod tests {
let mut txin = bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
script_sig: bitcoin::Script::new(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::default(),
};
let bare = Descriptor::new_bare(ms.clone()).unwrap();
Expand All @@ -1166,7 +1166,7 @@ mod tests {
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
script_sig: script::Builder::new().push_slice(&sigser[..]).into_script(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::default(),
}
);
Expand All @@ -1182,7 +1182,7 @@ mod tests {
.push_slice(&sigser[..])
.push_key(&pk)
.into_script(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::default(),
}
);
Expand All @@ -1195,7 +1195,7 @@ mod tests {
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
script_sig: bitcoin::Script::new(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
}
);
Expand All @@ -1216,7 +1216,7 @@ mod tests {
script_sig: script::Builder::new()
.push_slice(&redeem_script[..])
.into_script(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
}
);
Expand All @@ -1238,7 +1238,7 @@ mod tests {
.push_slice(&sigser[..])
.push_slice(&ms.encode()[..])
.into_script(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::default(),
}
);
Expand All @@ -1253,7 +1253,7 @@ mod tests {
bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
script_sig: bitcoin::Script::new(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
}
);
Expand All @@ -1268,7 +1268,7 @@ mod tests {
script_sig: script::Builder::new()
.push_slice(&ms.encode().to_v0_p2wsh()[..])
.into_script(),
sequence: 100,
sequence: Sequence::from_height(100),
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
}
);
Expand Down Expand Up @@ -1401,7 +1401,7 @@ mod tests {
let mut txin = bitcoin::TxIn {
previous_output: bitcoin::OutPoint::default(),
script_sig: bitcoin::Script::new(),
sequence: 0,
sequence: Sequence::ZERO,
witness: Witness::default(),
};
let satisfier = {
Expand Down
23 changes: 2 additions & 21 deletions src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::{fmt, hash};

use bitcoin::blockdata::opcodes;
use bitcoin::util::taproot::{
LeafVersion, TaprootBuilder, TaprootBuilderError, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
};
use bitcoin::{secp256k1, Address, Network, Script};
Expand Down Expand Up @@ -238,26 +238,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
// Assert builder cannot error here because we have a well formed descriptor
match builder.finalize(&secp, self.internal_key.to_x_only_pubkey()) {
Ok(data) => data,
Err(e) => match e {
TaprootBuilderError::InvalidMerkleTreeDepth(_) => {
unreachable!("Depth checked in struct construction")
}
TaprootBuilderError::NodeNotInDfsOrder => {
unreachable!("Insertion is called in DFS order")
}
TaprootBuilderError::OverCompleteTree => {
unreachable!("Taptree is a well formed tree")
}
TaprootBuilderError::InvalidInternalKey(_) => {
unreachable!("Internal key checked for validity")
}
TaprootBuilderError::IncompleteTree => {
unreachable!("Taptree is a well formed tree")
}
TaprootBuilderError::EmptyTree => {
unreachable!("Taptree is a well formed tree with atleast 1 element")
}
},
Err(_) => unreachable!("We know the builder can be finalized"),
}
};
let spend_info = Arc::new(data);
Expand Down
8 changes: 8 additions & 0 deletions src/interpreter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use crate::prelude::*;
pub enum Error {
/// Could not satisfy, absolute locktime not met
AbsoluteLocktimeNotMet(u32),
/// Could not satisfy, lock time values are different units
AbsoluteLocktimeComparisonInvalid(u32, u32),
/// Cannot Infer a taproot descriptor
/// Key spends cannot infer the internal key of the descriptor
/// Inferring script spends is possible, but is hidden nodes are currently
Expand Down Expand Up @@ -129,6 +131,11 @@ impl fmt::Display for Error {
"required absolute locktime CLTV of {} blocks, not met",
n
),
Error::AbsoluteLocktimeComparisonInvalid(n, lock_time) => write!(
f,
"could not satisfy, lock time values are different units n: {} lock_time: {}",
n, lock_time
),
Error::CannotInferTrDescriptors => write!(f, "Cannot infer taproot descriptors"),
Error::ControlBlockParse(ref e) => write!(f, "Control block parse error {}", e),
Error::ControlBlockVerificationError => {
Expand Down Expand Up @@ -198,6 +205,7 @@ impl error::Error for Error {

match self {
AbsoluteLocktimeNotMet(_)
| AbsoluteLocktimeComparisonInvalid(_, _)
| CannotInferTrDescriptors
| ControlBlockVerificationError
| CouldNotEvaluate
Expand Down
37 changes: 21 additions & 16 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use core::str::FromStr;
use bitcoin::blockdata::witness::Witness;
use bitcoin::hashes::{hash160, ripemd160, sha256};
use bitcoin::util::{sighash, taproot};
use bitcoin::{self, secp256k1, TxOut};
use bitcoin::{self, secp256k1, LockTime, Sequence, TxOut};

use crate::miniscript::context::NoChecks;
use crate::miniscript::ScriptContext;
Expand All @@ -48,8 +48,8 @@ pub struct Interpreter<'txin> {
/// For non-Taproot spends, the scriptCode; for Taproot script-spends, this
/// is the leaf script; for key-spends it is `None`.
script_code: Option<bitcoin::Script>,
age: u32,
lock_time: u32,
age: Sequence,
lock_time: LockTime,
}

// A type representing functions for checking signatures that accept both
Expand Down Expand Up @@ -173,8 +173,8 @@ impl<'txin> Interpreter<'txin> {
spk: &bitcoin::Script,
script_sig: &'txin bitcoin::Script,
witness: &'txin Witness,
age: u32, // CSV, relative lock time.
lock_time: u32, // CLTV, absolute lock time.
age: Sequence, // CSV, relative lock time.
lock_time: LockTime, // CLTV, absolute lock time.
) -> Result<Self, Error> {
let (inner, stack, script_code) = inner::from_txdata(spk, script_sig, witness)?;
Ok(Interpreter {
Expand Down Expand Up @@ -491,12 +491,12 @@ pub enum SatisfiedConstraint {
///Relative Timelock for CSV.
RelativeTimelock {
/// The value of RelativeTimelock
time: u32,
n: Sequence,
},
///Absolute Timelock for CLTV.
AbsoluteTimelock {
/// The value of Absolute timelock
time: u32,
n: LockTime,
Copy link

Choose a reason for hiding this comment

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

time was definitely a better name than n.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its a block height or a block time. n is from n OP_CLTV and nLockTime - that's why I used n.

Copy link

Choose a reason for hiding this comment

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

n in nLockTime literally means number. It's meaningless. I do see that time is confusing, so lock_time would be better because most people already know it can be height.

Copy link
Member Author

Choose a reason for hiding this comment

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

Used lock_time for this field and similarly sequence for SatisfiedConstraint::RelativeTimelock field.

},
}

Expand Down Expand Up @@ -531,8 +531,8 @@ pub struct Iter<'intp, 'txin: 'intp> {
public_key: Option<&'intp BitcoinKey>,
state: Vec<NodeEvaluationState<'intp>>,
stack: Stack<'txin>,
age: u32,
lock_time: u32,
age: Sequence,
lock_time: LockTime,
has_errored: bool,
}

Expand Down Expand Up @@ -619,7 +619,7 @@ where
Terminal::After(ref n) => {
debug_assert_eq!(node_state.n_evaluated, 0);
debug_assert_eq!(node_state.n_satisfied, 0);
let res = self.stack.evaluate_after(n, self.lock_time);
let res = self.stack.evaluate_after(&n.into(), self.lock_time);
if res.is_some() {
return res;
}
Expand Down Expand Up @@ -1094,8 +1094,9 @@ mod tests {
pks.push(pk);
der_sigs.push(sigser);

let keypair = bitcoin::KeyPair::from_secret_key(&secp, sk);
x_only_pks.push(bitcoin::XOnlyPublicKey::from_keypair(&keypair));
let keypair = bitcoin::KeyPair::from_secret_key(&secp, &sk);
tcharding marked this conversation as resolved.
Show resolved Hide resolved
let (x_only_pk, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&keypair);
x_only_pks.push(x_only_pk);
let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]);
let schnorr_sig = bitcoin::SchnorrSig {
sig: schnorr_sig,
Expand Down Expand Up @@ -1144,8 +1145,8 @@ mod tests {
n_evaluated: 0,
n_satisfied: 0,
}],
age: 1002,
lock_time: 1002,
age: Sequence::from_height(1002),
lock_time: LockTime::from_height(1002).unwrap(),
has_errored: false,
}
}
Expand Down Expand Up @@ -1208,7 +1209,9 @@ mod tests {
let after_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert_eq!(
after_satisfied.unwrap(),
vec![SatisfiedConstraint::AbsoluteTimelock { time: 1000 }]
vec![SatisfiedConstraint::AbsoluteTimelock {
n: LockTime::from_height(1000).unwrap()
}]
);

//Check Older
Expand All @@ -1218,7 +1221,9 @@ mod tests {
let older_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert_eq!(
older_satisfied.unwrap(),
vec![SatisfiedConstraint::RelativeTimelock { time: 1000 }]
vec![SatisfiedConstraint::RelativeTimelock {
n: Sequence::from_height(1000)
}]
);

//Check Sha256
Expand Down