From 7b90059a42c6562c00bb7ed0422dbac1ea48c86b Mon Sep 17 00:00:00 2001 From: janko33bd Date: Wed, 13 Dec 2017 00:27:05 +0100 Subject: [PATCH] make 0 value data outputs standard --- src/policy/policy.cpp | 8 ++++++++ src/script/script.cpp | 27 +++++++++++++++++++++++++++ src/script/script.h | 1 + 3 files changed, 36 insertions(+) diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index 805eaedc3..6a5750584 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -111,6 +111,14 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason) if (whichType == TX_NULL_DATA) nDataOut++; + else if (txout.nValue == 0) { + reason = "dust"; + return false; + } + if (!txout.scriptPubKey.HasCanonicalPushes()) { + reason = "scriptpubkey-non-canonical-push"; + return false; + } else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) { reason = "bare-multisig"; return false; diff --git a/src/script/script.cpp b/src/script/script.cpp index 3b622a4e9..e684b4e47 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -252,3 +252,30 @@ bool CScript::IsPushOnly() const { return this->IsPushOnly(begin()); } + +bool CScript::HasCanonicalPushes() const +{ + const_iterator pc = begin(); + while (pc < end()) + { + opcodetype opcode; + std::vector data; + if (!GetOp(pc, opcode, data)) + return false; + if (opcode > OP_16) + continue; + if (opcode < OP_PUSHDATA1 && opcode > OP_0 && (data.size() == 1 && data[0] <= 16)) + // Could have used an OP_n code, rather than a 1-byte push. + return false; + if (opcode == OP_PUSHDATA1 && data.size() < OP_PUSHDATA1) + // Could have used a normal n-byte push, rather than OP_PUSHDATA1. + return false; + if (opcode == OP_PUSHDATA2 && data.size() <= 0xFF) + // Could have used an OP_PUSHDATA1. + return false; + if (opcode == OP_PUSHDATA4 && data.size() <= 0xFFFF) + // Could have used an OP_PUSHDATA2. + return false; + } + return true; +} diff --git a/src/script/script.h b/src/script/script.h index 40feb906f..4d84276f5 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -617,6 +617,7 @@ public: /** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */ bool IsPushOnly(const_iterator pc) const; bool IsPushOnly() const; + bool HasCanonicalPushes() const; bool IsUnspendable() const {