Skip to content

use hex-conservative 1.0 everywhere for decoding #822

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies = [
"bitcoin-io",
"bitcoin-units",
"bitcoin_hashes",
"hex-conservative",
"hex-conservative 0.2.1",
"hex_lit",
"secp256k1",
"serde",
Expand Down Expand Up @@ -90,7 +90,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
dependencies = [
"bitcoin-io",
"hex-conservative",
"hex-conservative 0.2.1",
"serde",
]

Expand Down Expand Up @@ -136,6 +136,12 @@ dependencies = [
"arrayvec",
]

[[package]]
name = "hex-conservative"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee770c000993d17c185713463d5ebfbd1af9afae4c17cc295640104383bfbf0"

[[package]]
name = "hex_lit"
version = "0.1.1"
Expand Down Expand Up @@ -196,6 +202,7 @@ version = "13.0.0"
dependencies = [
"bech32",
"bitcoin",
"hex-conservative 1.0.0",
"secp256k1",
"serde",
"serde_test",
Expand Down
11 changes: 9 additions & 2 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies = [
"bitcoin-io",
"bitcoin-units",
"bitcoin_hashes",
"hex-conservative",
"hex-conservative 0.2.1",
"hex_lit",
"secp256k1",
"serde",
Expand Down Expand Up @@ -90,7 +90,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
dependencies = [
"bitcoin-io",
"hex-conservative",
"hex-conservative 0.2.1",
"serde",
]

Expand Down Expand Up @@ -136,6 +136,12 @@ dependencies = [
"arrayvec",
]

[[package]]
name = "hex-conservative"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee770c000993d17c185713463d5ebfbd1af9afae4c17cc295640104383bfbf0"

[[package]]
name = "hex_lit"
version = "0.1.1"
Expand Down Expand Up @@ -196,6 +202,7 @@ version = "13.0.0"
dependencies = [
"bech32",
"bitcoin",
"hex-conservative 1.0.0",
"secp256k1",
"serde",
"serde_test",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ base64 = ["bitcoin/base64"]
[dependencies]
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
bitcoin = { version = "0.32.0", default-features = false }
hex = { package = "hex-conservative", default-features = false, features = ["alloc"], version = "1.0.0" }

serde = { version = "1.0.103", optional = true }

Expand Down
5 changes: 2 additions & 3 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::consensus::encode::deserialize_hex;
use miniscript::bitcoin::psbt::{self, Psbt};
use miniscript::bitcoin::sighash::SighashCache;
//use miniscript::bitcoin::secp256k1; // https://github.com/rust-lang/rust/issues/121684
Expand Down Expand Up @@ -71,7 +70,7 @@ fn main() {
};

let hex_tx = "020000000001018ff27041f3d738f5f84fd5ee62f1c5b36afebfb15f6da0c9d1382ddd0eaaa23c0000000000feffffff02b3884703010000001600142ca3b4e53f17991582d47b15a053b3201891df5200e1f50500000000220020c0ebf552acd2a6f5dee4e067daaef17b3521e283aeaa44a475278617e3d2238a0247304402207b820860a9d425833f729775880b0ed59dd12b64b9a3d1ab677e27e4d6b370700220576003163f8420fe0b9dc8df726cff22cbc191104a2d4ae4f9dfedb087fcec72012103817e1da42a7701df4db94db8576f0e3605f3ab3701608b7e56f92321e4d8999100000000";
let depo_tx: Transaction = deserialize(&Vec::<u8>::from_hex(hex_tx).unwrap()).unwrap();
let depo_tx: Transaction = deserialize_hex(hex_tx).unwrap();
Comment on lines -74 to +73
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of an unrelated change, bad Andrew no biscuit.

Copy link
Member Author

Choose a reason for hiding this comment

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

How is it unrelated? We used to have a hex library that has from_hex and now we don't.


let receiver = Address::from_str("bcrt1qsdks5za4t6sevaph6tz9ddfjzvhkdkxe9tfrcy")
.unwrap()
Expand Down
22 changes: 3 additions & 19 deletions fuzz/fuzz_targets/miniscript_satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,11 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'..=b'F' => b |= c - b'A' + 10,
b'a'..=b'f' => b |= c - b'a' + 10,
b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use miniscript::hex;
Copy link
Member

Choose a reason for hiding this comment

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

Nice!


#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("", &mut a);
super::do_test(&a);
let v = hex::decode_to_vec("abcd").unwrap();
super::do_test(&v);
}
}
22 changes: 3 additions & 19 deletions fuzz/fuzz_targets/roundtrip_concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,11 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'..=b'F' => b |= c - b'A' + 10,
b'a'..=b'f' => b |= c - b'a' + 10,
b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use miniscript::hex;

#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("048531e80700ae6400670000af5168", &mut a);
super::do_test(&a);
let v = hex::decode_to_vec("abcd").unwrap();
super::do_test(&v);
}
}
24 changes: 4 additions & 20 deletions fuzz/fuzz_targets/roundtrip_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,11 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'..=b'F' => b |= c - b'A' + 10,
b'a'..=b'f' => b |= c - b'a' + 10,
b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use miniscript::hex;

#[test]
fn duplicate_crash3() {
let mut a = Vec::new();
extend_vec_from_hex("747228726970656d616e645f6e5b5c79647228726970656d616e645f6e5b5c7964646464646464646464646464646464646464646464646464646b5f6872702c29", &mut a);
super::do_test(&a);
fn duplicate_crash() {
let v = hex::decode_to_vec("abcd").unwrap();
super::do_test(&v);
}
}
24 changes: 4 additions & 20 deletions fuzz/fuzz_targets/roundtrip_miniscript_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,11 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'..=b'F' => b |= c - b'A' + 10,
b'a'..=b'f' => b |= c - b'a' + 10,
b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use miniscript::hex;

#[test]
fn duplicate_crash3() {
let mut a = Vec::new();
extend_vec_from_hex("1479002d00000020323731363342740000004000000000000000000000000000000000000063630004636363639c00000000000000000000", &mut a);
super::do_test(&a);
fn duplicate_crash() {
let v = hex::decode_to_vec("abcd").unwrap();
super::do_test(&v);
}
}
22 changes: 3 additions & 19 deletions fuzz/fuzz_targets/roundtrip_miniscript_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,11 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'..=b'F' => b |= c - b'A' + 10,
b'a'..=b'f' => b |= c - b'a' + 10,
b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use miniscript::hex;

#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("1479002d00000020323731363342740000004000000000000000000000000000000000000063630004636363639c00000000000000000000", &mut a);
super::do_test(&a);
let v = hex::decode_to_vec("abcd").unwrap();
super::do_test(&v);
}
}
9 changes: 4 additions & 5 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ mod tests {
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::sighash::EcdsaSighashType;
Expand Down Expand Up @@ -1645,7 +1644,7 @@ mod tests {
.unwrap();
assert_eq!(
*descriptor.script_code().unwrap().as_bytes(),
Vec::<u8>::from_hex("76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac").unwrap()[..]
hex::decode_to_vec("76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac").unwrap()[..]
);

// P2SH-P2WPKH (from bip143 test vectors)
Expand All @@ -1655,7 +1654,7 @@ mod tests {
.unwrap();
assert_eq!(
*descriptor.script_code().unwrap().as_bytes(),
Vec::<u8>::from_hex("76a91479091972186c449eb1ded22b78e40d009bdf008988ac").unwrap()[..]
hex::decode_to_vec("76a91479091972186c449eb1ded22b78e40d009bdf008988ac").unwrap()[..]
Comment on lines -1658 to +1657
Copy link
Member

Choose a reason for hiding this comment

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

Out of interest did you find yourself cursing the f***ing hex-conservative devs or were you happy enough during the upgrade?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was happy enough, but the lack of encoding support is idiotic.

);

// P2WSH (from bitcoind's `createmultisig`)
Expand All @@ -1667,7 +1666,7 @@ mod tests {
*descriptor
.script_code().unwrap()
.as_bytes(),
Vec::<u8>::from_hex("522103789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd2103dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a6162652ae").unwrap()[..]
hex::decode_to_vec("522103789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd2103dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a6162652ae").unwrap()[..]
);

// P2SH-P2WSH (from bitcoind's `createmultisig`)
Expand All @@ -1676,7 +1675,7 @@ mod tests {
*descriptor
.script_code().unwrap()
.as_bytes(),
Vec::<u8>::from_hex("522103789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd2103dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a6162652ae")
hex::decode_to_vec("522103789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd2103dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a6162652ae")
.unwrap()[..]
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ mod tests {
use core::str::FromStr;

use bitcoin::blockdata::script;
use bitcoin::hashes::hex::FromHex;
use bitcoin::script::PushBytes;
use bitcoin::ScriptBuf;
use hex;

use super::*;

Expand All @@ -422,7 +422,7 @@ mod tests {
impl KeyTestData {
fn from_key(key: bitcoin::PublicKey) -> KeyTestData {
// what a funny looking signature..
let dummy_sig_vec = Vec::from_hex(
let dummy_sig_vec = hex::decode_to_vec(
"\
302e02153b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63\
02153b78ce563f89a0ed9414f5aa28ad0d96d6795f9c65\
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ compile_error!(
"rust-miniscript currently only supports architectures with pointers wider than 16 bits"
);

pub use bitcoin;
pub use {bitcoin, hex};

#[cfg(not(feature = "std"))]
#[macro_use]
Expand Down Expand Up @@ -677,10 +677,7 @@ fn push_opcode_size(script_size: usize) -> usize {

/// Helper function used by tests
#[cfg(test)]
fn hex_script(s: &str) -> bitcoin::ScriptBuf {
let v: Vec<u8> = bitcoin::hashes::hex::FromHex::from_hex(s).unwrap();
bitcoin::ScriptBuf::from(v)
}
fn hex_script(s: &str) -> bitcoin::ScriptBuf { bitcoin::ScriptBuf::from_hex(s).unwrap() }

#[cfg(test)]
mod tests {
Expand Down
1 change: 0 additions & 1 deletion src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
/// ```rust
/// use miniscript::{Miniscript, Segwitv0, Tap};
/// use miniscript::bitcoin::secp256k1::XOnlyPublicKey;
/// use miniscript::bitcoin::hashes::hex::FromHex;
///
/// type Segwitv0Script = Miniscript<bitcoin::PublicKey, Segwitv0>;
/// type TapScript = Miniscript<XOnlyPublicKey, Tap>;
Expand Down
Loading
Loading