Skip to content

Commit 176db61

Browse files
committed
simplify CheckMinimalPush checks, add safety assert
1 parent c66adb2 commit 176db61

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/script/interpreter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,17 @@ bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, co
220220
}
221221

222222
bool static CheckMinimalPush(const valtype& data, opcodetype opcode) {
223+
// Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
224+
assert(0 <= opcode && opcode <= OP_PUSHDATA4);
223225
if (data.size() == 0) {
224226
// Could have used OP_0.
225227
return opcode == OP_0;
226228
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
227229
// Could have used OP_1 .. OP_16.
228-
return opcode == OP_1 + (data[0] - 1);
230+
return false;
229231
} else if (data.size() == 1 && data[0] == 0x81) {
230232
// Could have used OP_1NEGATE.
231-
return opcode == OP_1NEGATE;
233+
return false;
232234
} else if (data.size() <= 75) {
233235
// Could have used a direct push (opcode indicating number of bytes pushed + those bytes).
234236
return opcode == data.size();

0 commit comments

Comments
 (0)