Merge #11900: [script] simplify CheckMinimalPush checks, add safety assert

0749808a7 CheckMinimalPush comments are prescriptive (Gregory Sanders)
176db6147 simplify CheckMinimalPush checks, add safety assert (Gregory Sanders)

Pull request description:

  the two conditions could simply never be hit as `true`, as those opcodes have a push payload of size 0 in `data`.

  Added the assert for clarity for future readers(matching the gating in the interpreter) and safety for future use.

  This effects policy only.

Tree-SHA512: f49028a1d5e907ef697b9bf5104c81ba8f6a331dbe5d60d8d8515ac17d2d6bfdc9dcc856a7e3dbd54814871b7d0695584d28da6553e2d9d7715430223f0b3690
This commit is contained in:
Wladimir J. van der Laan 2018-03-07 17:17:09 +01:00
commit 842f61a675
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D

View File

@ -226,23 +226,25 @@ bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, co
}
bool static CheckMinimalPush(const valtype& data, opcodetype opcode) {
// Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
assert(0 <= opcode && opcode <= OP_PUSHDATA4);
if (data.size() == 0) {
// Could have used OP_0.
// Should have used OP_0.
return opcode == OP_0;
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
// Could have used OP_1 .. OP_16.
return opcode == OP_1 + (data[0] - 1);
// Should have used OP_1 .. OP_16.
return false;
} else if (data.size() == 1 && data[0] == 0x81) {
// Could have used OP_1NEGATE.
return opcode == OP_1NEGATE;
// Should have used OP_1NEGATE.
return false;
} else if (data.size() <= 75) {
// Could have used a direct push (opcode indicating number of bytes pushed + those bytes).
// Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
return opcode == data.size();
} else if (data.size() <= 255) {
// Could have used OP_PUSHDATA.
// Must have used OP_PUSHDATA.
return opcode == OP_PUSHDATA1;
} else if (data.size() <= 65535) {
// Could have used OP_PUSHDATA2.
// Must have used OP_PUSHDATA2.
return opcode == OP_PUSHDATA2;
}
return true;