From 5c04a059d5c6365934013cd05841fa8542550564 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:24:57 +0100 Subject: [PATCH 1/6] Change some static assertions to debug_assert --- src/consensus/encode.rs | 2 +- src/util/endian.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index bdda57c7..05004055 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -249,7 +249,7 @@ macro_rules! decoder_fn { ($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => { #[inline] fn $name(&mut self) -> Result<$val_type, Error> { - assert_eq!(::std::mem::size_of::<$val_type>(), $byte_len); // size_of isn't a constfn in 1.22 + debug_assert_eq!(::std::mem::size_of::<$val_type>(), $byte_len); // size_of isn't a constfn in 1.22 let mut val = [0; $byte_len]; self.read_exact(&mut val[..]).map_err(Error::Io)?; Ok(endian::$readfn(&val)) diff --git a/src/util/endian.rs b/src/util/endian.rs index 37b59a19..d4ae5ec4 100644 --- a/src/util/endian.rs +++ b/src/util/endian.rs @@ -28,7 +28,7 @@ macro_rules! define_be_to_array { ($name: ident, $type: ty, $byte_len: expr) => { #[inline] pub fn $name(val: $type) -> [u8; $byte_len] { - assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 + debug_assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 let mut res = [0; $byte_len]; for i in 0..$byte_len { res[i] = ((val >> ($byte_len - i - 1)*8) & 0xff) as u8; @@ -41,7 +41,7 @@ macro_rules! define_le_to_array { ($name: ident, $type: ty, $byte_len: expr) => { #[inline] pub fn $name(val: $type) -> [u8; $byte_len] { - assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 + debug_assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 let mut res = [0; $byte_len]; for i in 0..$byte_len { res[i] = ((val >> i*8) & 0xff) as u8; From cc095a4ba7cc25c4df7d7e0842ad7402491bfd58 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:27:06 +0100 Subject: [PATCH 2/6] Remove assert in Uint256::from_i64 and return None instead --- src/util/uint.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/uint.rs b/src/util/uint.rs index 5aba6129..376dc7d2 100644 --- a/src/util/uint.rs +++ b/src/util/uint.rs @@ -83,8 +83,11 @@ macro_rules! construct_uint { /// Create an object from a given signed 64-bit integer #[inline] pub fn from_i64(init: i64) -> Option<$name> { - assert!(init >= 0); - $name::from_u64(init as u64) + if init >= 0 { + $name::from_u64(init as u64) + } else { + None + } } /// Creates big integer value from a byte slice array using From ab9514983bfcc4a0e6a035010f785057f9072a13 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:28:22 +0100 Subject: [PATCH 3/6] Add explanation to witness program version assertion --- src/blockdata/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 54caed7b..2bdc40bd 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -252,7 +252,7 @@ impl Script { /// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script pub fn new_witness_program(ver: ::bech32::u5, program: &[u8]) -> Script { let mut verop = ver.to_u8(); - assert!(verop <= 16); + assert!(verop <= 16, "incorrect witness version provided: {}", verop); if verop > 0 { verop = 0x50 + verop; } From 545965d9e392b5d02a51527c46f925d6f32fabd0 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:28:49 +0100 Subject: [PATCH 4/6] Change consensus::encode::serialize assert to debug_assert This is just a sanity check on our own serialization code. --- src/consensus/encode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 05004055..9507734f 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -147,7 +147,7 @@ impl From for Error { pub fn serialize(data: &T) -> Vec { let mut encoder = Vec::new(); let len = data.consensus_encode(&mut encoder).unwrap(); - assert_eq!(len, encoder.len()); + debug_assert_eq!(len, encoder.len()); encoder } From 90e1125eff8ff090f3282b501d69172da36002a2 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 21:28:46 +0100 Subject: [PATCH 5/6] Remove debug_assert in PublicKey::write_into --- src/util/key.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/key.rs b/src/util/key.rs index bf9b9cc3..2c4e6a35 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -102,12 +102,11 @@ impl PublicKey { /// Write the public key into a writer pub fn write_into(&self, mut writer: W) { - let write_res: io::Result<()> = if self.compressed { + let _: io::Result<()> = if self.compressed { writer.write_all(&self.key.serialize()) } else { writer.write_all(&self.key.serialize_uncompressed()) }; - debug_assert!(write_res.is_ok()); } /// Serialize the public key to bytes From e07ee5165adb368e3a21a7ddb7b6d9a79d5cd32e Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Mon, 26 Oct 2020 15:44:19 +0000 Subject: [PATCH 6/6] Bump version to v0.25.2 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dd5a708..45c460ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +# 0.25.1 - 2020-10-26 + +- Remove an incorrect `debug_assert` that can cause a panic when running using + the dev profile. + # 0.25.1 - 2020-10-07 - [Expose methods on `Script`](https://github.com/rust-bitcoin/rust-bitcoin/pull/387) to generate various scriptpubkeys diff --git a/Cargo.toml b/Cargo.toml index 8573d32e..05ec1ae6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bitcoin" -version = "0.25.1" +version = "0.25.2" authors = ["Andrew Poelstra "] license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"