Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.cpp
Show First 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | switch (opcode) { | ||||
case OP_INVALIDOPCODE: | case OP_INVALIDOPCODE: | ||||
return "OP_INVALIDOPCODE"; | return "OP_INVALIDOPCODE"; | ||||
default: | default: | ||||
return "OP_UNKNOWN"; | return "OP_UNKNOWN"; | ||||
} | } | ||||
} | } | ||||
bool CheckMinimalPush(const std::vector<uint8_t> &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) { | |||||
// Should have used OP_0. | |||||
return opcode == OP_0; | |||||
} | |||||
if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) { | |||||
// Should have used OP_1 .. OP_16. | |||||
return false; | |||||
} | |||||
if (data.size() == 1 && data[0] == 0x81) { | |||||
// Should have used OP_1NEGATE. | |||||
return false; | |||||
} | |||||
if (data.size() <= 75) { | |||||
// Must have used a direct push (opcode indicating number of bytes | |||||
// pushed + those bytes). | |||||
return opcode == data.size(); | |||||
} | |||||
if (data.size() <= 255) { | |||||
// Must have used OP_PUSHDATA. | |||||
return opcode == OP_PUSHDATA1; | |||||
} | |||||
if (data.size() <= 65535) { | |||||
// Must have used OP_PUSHDATA2. | |||||
return opcode == OP_PUSHDATA2; | |||||
} | |||||
return true; | |||||
} | |||||
bool CScriptNum::IsMinimallyEncoded(const std::vector<uint8_t> &vch, | bool CScriptNum::IsMinimallyEncoded(const std::vector<uint8_t> &vch, | ||||
const size_t nMaxNumSize) { | const size_t nMaxNumSize) { | ||||
if (vch.size() > nMaxNumSize) { | if (vch.size() > nMaxNumSize) { | ||||
return false; | return false; | ||||
} | } | ||||
if (vch.size() > 0) { | if (vch.size() > 0) { | ||||
// Check that the number is encoded with the minimum possible number | // Check that the number is encoded with the minimum possible number | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |