From 9aea601b05b3541fcc7e0c45cba8fd2178224809 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 24 Sep 2013 00:45:18 +0200 Subject: Move IsPushOnly() to script.cpp --- src/script.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/script.cpp') diff --git a/src/script.cpp b/src/script.cpp index 2b66bc73d..b2d8a67f9 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1863,6 +1863,24 @@ bool CScript::IsPayToScriptHash() const this->at(22) == OP_EQUAL); } +bool CScript::IsPushOnly() const +{ + const_iterator pc = begin(); + while (pc < end()) + { + opcodetype opcode; + if (!GetOp(pc, opcode)) + return false; + // Note that IsPushOnly() *does* consider OP_RESERVED to be a + // push-type opcode, however execution of OP_RESERVED fails, so + // it's not relevant to P2SH as the scriptSig would fail prior to + // the P2SH special validation code being executed. + if (opcode > OP_16) + return false; + } + return true; +} + class CScriptVisitor : public boost::static_visitor { private: -- cgit v1.2.3 From 87fe71e1fc810ee120a10063fdd26c3245686d54 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 24 Sep 2013 00:48:00 +0200 Subject: Add HasCanonicalPushes(), and use it in IsStandardTx --- src/script.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/script.cpp') diff --git a/src/script.cpp b/src/script.cpp index b2d8a67f9..83fc91956 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1881,6 +1881,33 @@ bool CScript::IsPushOnly() const return true; } +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; +} + class CScriptVisitor : public boost::static_visitor { private: -- cgit v1.2.3