From b3fc16ed9a51e91736a26c7e95cf210399a70d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 9 Mar 2016 11:32:23 +0100 Subject: [PATCH] Fixing bug in multiplication implementation --- util/bigint/src/uint.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/bigint/src/uint.rs b/util/bigint/src/uint.rs index 801c5f5bd..69aaa5809 100644 --- a/util/bigint/src/uint.rs +++ b/util/bigint/src/uint.rs @@ -407,7 +407,7 @@ macro_rules! uint_overflowing_mul_reg { let (b_u, b_l) = split(you[i]); for j in 0..$n_words { - if me[j] == 0 { + if me[j] == 0 && carry2 == 0 { continue; } @@ -1640,6 +1640,14 @@ mod tests { assert_eq!(U256::from(1u64) * U256::from(10u64), U256::from(10u64)); } + #[test] + pub fn uint256_mul2() { + let a = U512::from_str("10000000000000000fffffffffffffffe").unwrap(); + let b = U512::from_str("ffffffffffffffffffffffffffffffff").unwrap(); + + assert_eq!(a * b, U512::from_str("10000000000000000fffffffffffffffcffffffffffffffff0000000000000002").unwrap()); + } + #[test] pub fn uint256_overflowing_mul() { assert_eq!(