Index: src/script/interpreter.cpp =================================================================== --- src/script/interpreter.cpp +++ src/script/interpreter.cpp @@ -335,9 +335,8 @@ return set_error(serror, SCRIPT_ERR_OP_COUNT); } - if (opcode == OP_RIGHT || opcode == OP_INVERT || opcode == OP_2MUL || - opcode == OP_2DIV || opcode == OP_MUL || opcode == OP_LSHIFT || - opcode == OP_RSHIFT) { + if (opcode == OP_INVERT || opcode == OP_2MUL || opcode == OP_2DIV || + opcode == OP_MUL || opcode == OP_LSHIFT || opcode == OP_RSHIFT) { // Disabled opcodes. return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); } @@ -1306,6 +1305,39 @@ stack.push_back(num.getvch()); } break; + case OP_NUM2BIN: { + if (stack.size() < 2) { + return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); + } + CScriptNum bn(stacktop(-2), fRequireMinimal); + int64_t sz = CScriptNum(stacktop(-1), fRequireMinimal).getint(); + if (sz<1 || static_cast(sz) > CScriptNum::nDefaultMaxNumSize) { + return set_error(serror, SCRIPT_ERR_INVALID_NUM2BIN_OPERATION); + } + valtype v=bn.getvch(); //LE + if (static_cast(sz) < v.size()) { + return set_error(serror, SCRIPT_ERR_INVALID_NUM2BIN_OPERATION); + } + valtype ans; + ans.reserve(sz); + bool neg{false}; + if (!v.empty()) { + neg=*v.rbegin()&0x80; + *v.rbegin()&=~0x80; //make it positive + } + size_t pad=sz-v.size(); + for (uint8_t i=0; i