Skip to content

Commit 2cfe0e2

Browse files
committed
Merge rust-bitcoin#2834: pow: Fix off-by-one error
3298c0c pow: Unit test from_hex_internal (Tobin C. Harding) 47e4bff pow: Fix off-by-one error (Tobin C. Harding) Pull request description: Patch 1 adds the fix, patch 2 is a unit test that fails if move to the front. ACKs for top commit: apoelstra: ACK 3298c0c nice find! and lucky this just returns an error rather than panicking. may be worth backporting nonetheless brunoerg: ACK 3298c0c Tree-SHA512: 15bbd5aa4ac62c91492f5394444d179d95770bae822422bf00bb62896dcaf6c92d32f7d2e3380c352ff7242422ec6af6ff637ff78d14406cd047ef4ad5f22649
2 parents 741589c + 3298c0c commit 2cfe0e2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bitcoin/src/pow.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl U256 {
497497

498498
// Caller to ensure `s` does not contain a prefix.
499499
fn from_hex_internal(s: &str) -> Result<Self, ParseIntError> {
500-
let (high, low) = if s.len() < 32 {
500+
let (high, low) = if s.len() <= 32 {
501501
let low = parse::hex_u128_unchecked(s)?;
502502
(0, low)
503503
} else {
@@ -1652,6 +1652,14 @@ mod tests {
16521652
assert_eq!(got, val);
16531653
}
16541654

1655+
#[test]
1656+
fn u256_from_hex_32_characters_long() {
1657+
let hex = "a69b455cd41bb662a69b4555deadbeef";
1658+
let want = U256(0x00, 0xA69B_455C_D41B_B662_A69B_4555_DEAD_BEEF);
1659+
let got = U256::from_unprefixed_hex(hex).expect("failed to parse hex");
1660+
assert_eq!(got, want);
1661+
}
1662+
16551663
#[cfg(feature = "serde")]
16561664
#[test]
16571665
fn u256_serde() {

0 commit comments

Comments
 (0)