diff options
| author | Gregory Maxwell <[email protected]> | 2014-02-11 12:44:42 -0800 |
|---|---|---|
| committer | Gregory Maxwell <[email protected]> | 2014-02-11 12:44:42 -0800 |
| commit | 2bc52f1c4a7d66661ed26e100a914e68df6d2bcc (patch) | |
| tree | 193f73d99ddbd70a67b5aafdcf353174f2cf4a96 /src/script.cpp | |
| parent | Merge pull request #3622 (diff) | |
| parent | Add HasCanonicalPushes(), and use it in IsStandardTx (diff) | |
| download | discoin-2bc52f1c4a7d66661ed26e100a914e68df6d2bcc.tar.xz discoin-2bc52f1c4a7d66661ed26e100a914e68df6d2bcc.zip | |
Merge pull request #3025 from sipa/noncanpush
Make signatures with non-canonical data pushes non-standard.
Diffstat (limited to 'src/script.cpp')
| -rw-r--r-- | src/script.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/script.cpp b/src/script.cpp index 2b66bc73d..83fc91956 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1863,6 +1863,51 @@ 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; +} + +bool CScript::HasCanonicalPushes() const +{ + const_iterator pc = begin(); + while (pc < end()) + { + opcodetype opcode; + std::vector<unsigned char> 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<bool> { private: |