From d752ba86c1872f64a4641cf77008826d32bde65f Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 8 Oct 2014 16:29:45 -0700 Subject: Add SCRIPT_VERIFY_SIGPUSHONLY (BIP62 rule 2) --- src/script/script.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/script/script.h') diff --git a/src/script/script.h b/src/script/script.h index d450db5ca..706a85a29 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -551,7 +551,7 @@ public: bool IsPayToScriptHash() const; - // Called by IsStandardTx and P2SH VerifyScript (which makes it consensus-critical). + // Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). bool IsPushOnly() const; // Called by IsStandardTx. -- cgit v1.2.3 From 698c6abb25c1fbbc7fa4ba46b60e9f17d97332ef Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 8 Oct 2014 18:48:59 -0700 Subject: Add SCRIPT_VERIFY_MINIMALDATA (BIP62 rules 3 and 4) Also use the new flag as a standard rule, and replace the IsCanonicalPush standardness check with it (as it is more complete). --- src/script/script.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/script/script.h') diff --git a/src/script/script.h b/src/script/script.h index 706a85a29..e97967dce 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -192,10 +192,14 @@ public: m_value = n; } - explicit CScriptNum(const std::vector& vch) + explicit CScriptNum(const std::vector& vch, bool fRequireMinimal) { - if (vch.size() > nMaxNumSize) - throw scriptnum_error("CScriptNum(const std::vector&) : overflow"); + if (vch.size() > nMaxNumSize) { + throw scriptnum_error("script number overflow"); + } + if (fRequireMinimal && vch.size() > 0 && (vch.back() & 0x7f) == 0 && (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0)) { + throw scriptnum_error("non-minimally encoded script number"); + } m_value = set_vch(vch); } @@ -319,7 +323,6 @@ private: int64_t m_value; }; - /** Serialized script, used inside transaction inputs and outputs */ class CScript : public std::vector { @@ -330,6 +333,10 @@ protected: { push_back(n + (OP_1 - 1)); } + else if (n == 0) + { + push_back(OP_0); + } else { *this << CScriptNum::serialize(n); @@ -554,9 +561,6 @@ public: // Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). bool IsPushOnly() const; - // Called by IsStandardTx. - bool HasCanonicalPushes() const; - // Returns whether the script is guaranteed to fail at execution, // regardless of the initial stack. This allows outputs to be pruned // instantly when entering the UTXO set. -- cgit v1.2.3 From 6004e77b926b5588e4b8eebdff843fe6652e5885 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Tue, 14 Oct 2014 11:18:24 -0400 Subject: Improve CScriptNum() comment Edited-by: Pieter Wuille --- src/script/script.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/script/script.h') diff --git a/src/script/script.h b/src/script/script.h index e97967dce..05f2e7e3a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -197,8 +197,23 @@ public: if (vch.size() > nMaxNumSize) { throw scriptnum_error("script number overflow"); } - if (fRequireMinimal && vch.size() > 0 && (vch.back() & 0x7f) == 0 && (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0)) { - throw scriptnum_error("non-minimally encoded script number"); + if (fRequireMinimal && vch.size() > 0) { + // Check that the number is encoded with the minimum possible + // number of bytes. + // + // If the most-significant-byte - excluding the sign bit - is zero + // then we're not minimal. Note how this test also rejects the + // negative-zero encoding, 0x80. + if ((vch.back() & 0x7f) == 0) { + // One exception: if there's more than one byte and the most + // significant bit of the second-most-significant-byte is set + // it would conflict with the sign bit. An example of this case + // is +-255, which encode to 0xff00 and 0xff80 respectively. + // (big-endian). + if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) { + throw scriptnum_error("non-minimally encoded script number"); + } + } } m_value = set_vch(vch); } -- cgit v1.2.3