Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
| Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | static bool CheckMinimalPush(const valtype &data, opcodetype opcode) { | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | ||||
| switch (opcode) { | switch (opcode) { | ||||
| case OP_CAT: | case OP_CAT: | ||||
| case OP_SPLIT: | case OP_SPLIT: | ||||
| case OP_NUM2BIN: | |||||
| case OP_INVERT: | case OP_INVERT: | ||||
| case OP_2MUL: | case OP_2MUL: | ||||
| case OP_2DIV: | case OP_2DIV: | ||||
| case OP_MUL: | case OP_MUL: | ||||
| case OP_DIV: | case OP_DIV: | ||||
| case OP_MOD: | case OP_MOD: | ||||
| case OP_LSHIFT: | case OP_LSHIFT: | ||||
| case OP_RSHIFT: | case OP_RSHIFT: | ||||
| // Disabled opcodes. | // Disabled opcodes. | ||||
| return true; | return true; | ||||
| case OP_AND: | case OP_AND: | ||||
| case OP_OR: | case OP_OR: | ||||
| case OP_XOR: | case OP_XOR: | ||||
| case OP_NUM2BIN: | |||||
| case OP_BIN2NUM: | case OP_BIN2NUM: | ||||
| // Opcodes that have been reenabled. | // Opcodes that have been reenabled. | ||||
| if ((flags & SCRIPT_ENABLE_MONOLITH_OPCODES) == 0) { | if ((flags & SCRIPT_ENABLE_MONOLITH_OPCODES) == 0) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 924 Lines • ▼ Show 20 Lines | try { | ||||
| serror, SCRIPT_ERR_CHECKMULTISIGVERIFY); | serror, SCRIPT_ERR_CHECKMULTISIGVERIFY); | ||||
| } | } | ||||
| } | } | ||||
| } break; | } break; | ||||
| // | // | ||||
| // Conversion operations | // Conversion operations | ||||
| // | // | ||||
| case OP_NUM2BIN: { | |||||
| // (in size -- out) | |||||
| if (stack.size() < 2) { | |||||
| return set_error( | |||||
| serror, SCRIPT_ERR_INVALID_STACK_OPERATION); | |||||
| } | |||||
| uint64_t size = | |||||
| CScriptNum(stacktop(-1), fRequireMinimal).getint(); | |||||
| if (size > MAX_SCRIPT_ELEMENT_SIZE) { | |||||
| return set_error(serror, SCRIPT_ERR_PUSH_SIZE); | |||||
| } | |||||
| popstack(stack); | |||||
| valtype &rawnum = stacktop(-1); | |||||
| // Try to see if we can fit that number in the number of | |||||
| // byte requested. | |||||
| CScriptNum::MinimallyEncode(rawnum); | |||||
| if (rawnum.size() > size) { | |||||
| // We definitively cannot. | |||||
| return set_error(serror, | |||||
| SCRIPT_ERR_IMPOSSIBLE_ENCODING); | |||||
| } | |||||
| // We already have an element of the right size, we | |||||
| // don't need to do anything. | |||||
| if (rawnum.size() == size) { | |||||
| break; | |||||
| } | |||||
| uint8_t signbit = 0x00; | |||||
| if (rawnum.size() > 0) { | |||||
| signbit = rawnum.back() & 0x80; | |||||
| rawnum[rawnum.size() - 1] &= 0x7f; | |||||
| } | |||||
| rawnum.reserve(size); | |||||
| while (rawnum.size() < size - 1) { | |||||
| rawnum.push_back(0x00); | |||||
| } | |||||
| rawnum.push_back(signbit); | |||||
| } break; | |||||
| case OP_BIN2NUM: { | case OP_BIN2NUM: { | ||||
| // (in -- out) | // (in -- out) | ||||
| if (stack.size() < 1) { | if (stack.size() < 1) { | ||||
| return set_error( | return set_error( | ||||
| serror, SCRIPT_ERR_INVALID_STACK_OPERATION); | serror, SCRIPT_ERR_INVALID_STACK_OPERATION); | ||||
| } | } | ||||
| valtype &n = stacktop(-1); | valtype &n = stacktop(-1); | ||||
| ▲ Show 20 Lines • Show All 462 Lines • Show Last 20 Lines | |||||