From 9d283150c95691c374144f1e81537d1effdcfd91 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sun, 31 Aug 2014 16:43:26 -0700 Subject: [PATCH] Fix GT/LT/GTEQ/LTEQ handling to not compare bools I was trying to do something clever by making sure that the numeric bounds were consistent with whatever ordering relation we were checking, AND that the boolean values were also consistent...this is Wrong is the case of negative numbers, and pointless anyway since I recently fixed `set_bool_value`, `set_num_lo` and `set_num_hi` to update both numeric and boolean information if possible, so they will always contain the same info. --- src/blockdata/script.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 5632bd4..be52caa 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -937,37 +937,29 @@ impl AbstractStackElem { /// Whether an element could possibly be less than another pub fn may_be_lt(&self, other: &AbstractStackElem) -> bool { self.num_lo() < other.num_hi() && - (self.num_value().is_none() || other.num_value().is_none() || - self.num_value().unwrap() < other.num_value().unwrap()) && - (self.bool_value().is_none() || other.bool_value().is_none() || - self.bool_value().unwrap() < other.bool_value().unwrap()) + self.num_value().is_none() || other.num_value().is_none() || + self.num_value().unwrap() < other.num_value().unwrap() } /// Whether an element could possibly be greater than another pub fn may_be_gt(&self, other: &AbstractStackElem) -> bool { self.num_hi() > other.num_lo() && (self.num_value().is_none() || other.num_value().is_none() || - self.num_value().unwrap() > other.num_value().unwrap()) && - (self.bool_value().is_none() || other.bool_value().is_none() || - self.bool_value().unwrap() >= other.bool_value().unwrap()) + self.num_value().unwrap() > other.num_value().unwrap()) } /// Whether an element could possibly be less than or equal to another pub fn may_be_lteq(&self, other: &AbstractStackElem) -> bool { self.num_lo() <= other.num_hi() && - (self.num_value().is_none() || other.num_value().is_none() || - self.num_value().unwrap() <= other.num_value().unwrap()) && - (self.bool_value().is_none() || other.bool_value().is_none() || - self.bool_value().unwrap() <= other.bool_value().unwrap()) + self.num_value().is_none() || other.num_value().is_none() || + self.num_value().unwrap() <= other.num_value().unwrap() } /// Whether an element could possibly be greater than or equal to another pub fn may_be_gteq(&self, other: &AbstractStackElem) -> bool { self.num_hi() >= other.num_lo() && (self.num_value().is_none() || other.num_value().is_none() || - self.num_value().unwrap() >= other.num_value().unwrap()) && - (self.bool_value().is_none() || other.bool_value().is_none() || - self.bool_value().unwrap() >= other.bool_value().unwrap()) + self.num_value().unwrap() >= other.num_value().unwrap()) } /// Whether an element could possibly be a 20-byte hash @@ -2720,6 +2712,8 @@ mod test { assert_eq!(Script(ThinVec::from_vec("522103bb52138972c48a132fc1f637858c5189607dd0f7fe40c4f20f6ad65f2d389ba42103bb52138972c48a132fc1f637858c5189607dd0f7fe40c4f20f6ad65f2d389ba45f6054ae".from_hex().unwrap())).is_provably_unspendable(), false); // This one is on mainnet oeO assert_eq!(Script(ThinVec::from_vec("827651a0698faaa9a8a7a687".from_hex().unwrap())).is_provably_unspendable(), false); + // gmaxwell found this one + assert_eq!(Script(ThinVec::from_vec("76009f69905160a56b210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad6c".from_hex().unwrap())).is_provably_unspendable(), false); } }