diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 994f565404623..0145f9bf367cc 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1213,23 +1213,18 @@ bool TransactionSignatureChecker::CheckSequence(const CScriptNum& nSequence) con // Mask off any bits that do not have consensus-enforced meaning // before doing the integer comparisons - const uint32_t nLockTimeMask = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | CTxIn::LEGACY_SEQUENCE_LOCKTIME_MASK; - const int64_t txToSequenceMasked = txToSequence & nLockTimeMask; - const CScriptNum nSequenceMasked = nSequence & nLockTimeMask; + const int64_t txToSequenceMasked = txToSequence & CTxIn::DIP0001_SEQUENCE_LOCKTIME_MASK; + const CScriptNum nSequenceMasked = nSequence & CTxIn::DIP0001_SEQUENCE_LOCKTIME_MASK; // There are two kinds of nSequence: lock-by-blockheight // and lock-by-blocktime, distinguished by whether - // nSequenceMasked < CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG. + // CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG is set. // // We want to compare apples to apples, so fail the script - // unless the type of nSequenceMasked being tested is the same as - // the nSequenceMasked in the transaction. - if (!( - (txToSequenceMasked < CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked < CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) || - (txToSequenceMasked >= CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked >= CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) - )) { + // unless the type of nSequence being tested is the same as + // the nSequence in the transaction. + if (((nSequence ^ txToSequence) & CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) != 0) return false; - } // Now that we know we're comparing apples-to-apples, the // comparison is a simple numeric one. diff --git a/src/script/script.h b/src/script/script.h index 32cb200a9f47e..a1e5c540c8637 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -265,6 +265,11 @@ class CScriptNum inline CScriptNum& operator&=( const CScriptNum& rhs) { return operator&=(rhs.m_value); } + inline CScriptNum operator^( const int64_t& rhs) const { return CScriptNum(m_value ^ rhs);} + inline CScriptNum operator^( const CScriptNum& rhs) const { return operator^(rhs.m_value); } + + inline CScriptNum& operator^=( const CScriptNum& rhs) { return operator^=(rhs.m_value); } + inline CScriptNum operator-() const { assert(m_value != std::numeric_limits::min()); @@ -299,6 +304,12 @@ class CScriptNum return *this; } + inline CScriptNum& operator^=( const int64_t& rhs) + { + m_value ^= rhs; + return *this; + } + int getint() const { if (m_value > std::numeric_limits::max())