Skip to content

Commit f4e289f

Browse files
committed
script: move CheckMinimalPush from interpreter to script.h
It is used by Miniscript.
1 parent 31ec6ae commit f4e289f

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/script/interpreter.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -225,31 +225,6 @@ bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, co
225225
return true;
226226
}
227227

228-
bool CheckMinimalPush(const valtype& data, opcodetype opcode) {
229-
// Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
230-
assert(0 <= opcode && opcode <= OP_PUSHDATA4);
231-
if (data.size() == 0) {
232-
// Should have used OP_0.
233-
return opcode == OP_0;
234-
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
235-
// Should have used OP_1 .. OP_16.
236-
return false;
237-
} else if (data.size() == 1 && data[0] == 0x81) {
238-
// Should have used OP_1NEGATE.
239-
return false;
240-
} else if (data.size() <= 75) {
241-
// Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
242-
return opcode == data.size();
243-
} else if (data.size() <= 255) {
244-
// Must have used OP_PUSHDATA.
245-
return opcode == OP_PUSHDATA1;
246-
} else if (data.size() <= 65535) {
247-
// Must have used OP_PUSHDATA2.
248-
return opcode == OP_PUSHDATA2;
249-
}
250-
return true;
251-
}
252-
253228
int FindAndDelete(CScript& script, const CScript& b)
254229
{
255230
int nFound = 0;

src/script/interpreter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
344344

345345
size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags);
346346

347-
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
348-
349347
int FindAndDelete(CScript& script, const CScript& b);
350348

351349
#endif // BITCOIN_SCRIPT_INTERPRETER_H

src/script/script.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,28 @@ bool IsOpSuccess(const opcodetype& opcode)
339339
(opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) ||
340340
(opcode >= 187 && opcode <= 254);
341341
}
342+
343+
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode) {
344+
// Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
345+
assert(0 <= opcode && opcode <= OP_PUSHDATA4);
346+
if (data.size() == 0) {
347+
// Should have used OP_0.
348+
return opcode == OP_0;
349+
} else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
350+
// Should have used OP_1 .. OP_16.
351+
return false;
352+
} else if (data.size() == 1 && data[0] == 0x81) {
353+
// Should have used OP_1NEGATE.
354+
return false;
355+
} else if (data.size() <= 75) {
356+
// Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
357+
return opcode == data.size();
358+
} else if (data.size() <= 255) {
359+
// Must have used OP_PUSHDATA.
360+
return opcode == OP_PUSHDATA1;
361+
} else if (data.size() <= 65535) {
362+
// Must have used OP_PUSHDATA2.
363+
return opcode == OP_PUSHDATA2;
364+
}
365+
return true;
366+
}

src/script/script.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,6 @@ struct CScriptWitness
576576
/** Test for OP_SUCCESSx opcodes as defined by BIP342. */
577577
bool IsOpSuccess(const opcodetype& opcode);
578578

579+
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
580+
579581
#endif // BITCOIN_SCRIPT_SCRIPT_H

0 commit comments

Comments
 (0)