MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CheckMinimalPush

Function CheckMinimalPush

src/script/script.cpp:373–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode) {
374 // Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
375 assert(0 <= opcode && opcode <= OP_PUSHDATA4);
376 if (data.size() == 0) {
377 // Should have used OP_0.
378 return opcode == OP_0;
379 } else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
380 // Should have used OP_1 .. OP_16.
381 return false;
382 } else if (data.size() == 1 && data[0] == 0x81) {
383 // Should have used OP_1NEGATE.
384 return false;
385 } else if (data.size() <= 75) {
386 // Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
387 return opcode == data.size();
388 } else if (data.size() <= 255) {
389 // Must have used OP_PUSHDATA.
390 return opcode == OP_PUSHDATA1;
391 } else if (data.size() <= 65535) {
392 // Must have used OP_PUSHDATA2.
393 return opcode == OP_PUSHDATA2;
394 }
395 return true;
396}

Callers 5

DecomposeScriptFunction · 0.85
ParseScriptNumberFunction · 0.85
GetScriptNumberFunction · 0.85
EvalScriptFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68