Simplify OP_RETURN handling.
authorCryptoManiac <balthazar@yandex.ru>
Sun, 21 Feb 2016 18:06:08 +0000 (21:06 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Sun, 21 Feb 2016 18:06:08 +0000 (21:06 +0300)
src/script.cpp
src/script.h

index 6b8e163..570e8a4 100644 (file)
@@ -1248,6 +1248,8 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
         mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA));
     }
 
+    vSolutionsRet.clear();
+
     // Shortcut for pay-to-script-hash, which are more constrained than the other types:
     // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
     if (scriptPubKey.IsPayToScriptHash())
@@ -1258,6 +1260,16 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
         return true;
     }
 
+    // Provably prunable, data-carrying output
+    //
+    // So long as script passes the IsUnspendable() test and all but the first
+    // byte passes the IsPushOnly() test we don't care what exactly is in the
+    // script.
+    if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) {
+        typeRet = TX_NULL_DATA;
+        return true;
+    }
+
     // Scan templates
     const CScript& script1 = scriptPubKey;
     BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates)
index e9afde8..a99bcbc 100644 (file)
@@ -540,10 +540,8 @@ public:
 
     bool IsPayToScriptHash() const;
 
-    // Called by CTransaction::IsStandard and P2SH VerifyScript (which makes it consensus-critical).
-    bool IsPushOnly() const
+    bool IsPushOnly(const_iterator pc) const
     {
-        const_iterator pc = begin();
         while (pc < end())
         {
             opcodetype opcode;
@@ -555,6 +553,12 @@ public:
         return true;
     }
 
+    // Called by CTransaction::IsStandard and P2SH VerifyScript (which makes it consensus-critical).
+    bool IsPushOnly() const
+    {
+        return this->IsPushOnly(begin());
+    }
+
     // Called by CTransaction::IsStandard.
     bool HasCanonicalPushes() const;