mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
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:
parent
e46ddf7a5f
commit
28f1a09ee4
@ -210,23 +210,25 @@ bool static CheckPubKeyEncoding(const valtype &vchSig, unsigned int flags, Scrip
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool static CheckMinimalPush(const valtype& data, opcodetype opcode) {
|
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) {
|
if (data.size() == 0) {
|
||||||
// Could have used OP_0.
|
// Should have used OP_0.
|
||||||
return opcode == OP_0;
|
return opcode == OP_0;
|
||||||
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
|
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
|
||||||
// Could have used OP_1 .. OP_16.
|
// Should have used OP_1 .. OP_16.
|
||||||
return opcode == OP_1 + (data[0] - 1);
|
return false;
|
||||||
} else if (data.size() == 1 && data[0] == 0x81) {
|
} else if (data.size() == 1 && data[0] == 0x81) {
|
||||||
// Could have used OP_1NEGATE.
|
// Should have used OP_1NEGATE.
|
||||||
return opcode == OP_1NEGATE;
|
return false;
|
||||||
} else if (data.size() <= 75) {
|
} 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();
|
return opcode == data.size();
|
||||||
} else if (data.size() <= 255) {
|
} else if (data.size() <= 255) {
|
||||||
// Could have used OP_PUSHDATA.
|
// Must have used OP_PUSHDATA.
|
||||||
return opcode == OP_PUSHDATA1;
|
return opcode == OP_PUSHDATA1;
|
||||||
} else if (data.size() <= 65535) {
|
} else if (data.size() <= 65535) {
|
||||||
// Could have used OP_PUSHDATA2.
|
// Must have used OP_PUSHDATA2.
|
||||||
return opcode == OP_PUSHDATA2;
|
return opcode == OP_PUSHDATA2;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user