Index: src/script/interpreter.cpp =================================================================== --- src/script/interpreter.cpp +++ src/script/interpreter.cpp @@ -335,9 +335,9 @@ return set_error(serror, SCRIPT_ERR_OP_COUNT); } - if (opcode == OP_LEFT || opcode == OP_RIGHT || opcode == OP_INVERT || - opcode == OP_2MUL || opcode == OP_2DIV || opcode == OP_MUL || - opcode == OP_LSHIFT || opcode == OP_RSHIFT) { + if (opcode == OP_RIGHT || 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); } @@ -1287,6 +1287,25 @@ } } break; + // + // Conversion operations + // + case OP_BIN2NUM: { + // (in -- out) + if (stack.size() < 1) { + return set_error( + serror, SCRIPT_ERR_INVALID_STACK_OPERATION); + } + valtype bin = stacktop(-1); + std::reverse(bin.begin(), bin.end()); //be2le + CScriptNum num(bin, false); + if (num > (INT_MAX>>1) || num < (INT_MIN>>1)) { + return set_error(serror, SCRIPT_ERR_INVALID_BIN2NUM_OPERATION); + } + stack.pop_back(); + stack.push_back(num.getvch()); + } break; + default: return set_error(serror, SCRIPT_ERR_BAD_OPCODE); } Index: src/script/script.h =================================================================== --- src/script/script.h +++ src/script/script.h @@ -103,7 +103,6 @@ // splice ops OP_CAT = 0x7e, OP_SPLIT = 0x7f, - OP_LEFT = 0x80, OP_RIGHT = 0x81, OP_SIZE = 0x82, @@ -162,6 +161,7 @@ OP_CHECKMULTISIGVERIFY = 0xaf, // expansion + OP_BIN2NUM = 0x80, OP_NOP1 = 0xb0, OP_CHECKLOCKTIMEVERIFY = 0xb1, OP_NOP2 = OP_CHECKLOCKTIMEVERIFY, Index: src/script/script.cpp =================================================================== --- src/script/script.cpp +++ src/script/script.cpp @@ -123,8 +123,6 @@ return "OP_CAT"; case OP_SPLIT: return "OP_SPLIT"; - case OP_LEFT: - return "OP_LEFT"; case OP_RIGHT: return "OP_RIGHT"; case OP_SIZE: Index: src/script/script_error.h =================================================================== --- src/script/script_error.h +++ src/script/script_error.h @@ -37,6 +37,7 @@ SCRIPT_ERR_DIV_BY_ZERO, SCRIPT_ERR_MOD_BY_ZERO, SCRIPT_ERR_INVALID_SPLIT_RANGE, + SCRIPT_ERR_INVALID_BIN2NUM_OPERATION, /* CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY */ SCRIPT_ERR_NEGATIVE_LOCKTIME, Index: src/script/script_error.cpp =================================================================== --- src/script/script_error.cpp +++ src/script/script_error.cpp @@ -54,6 +54,8 @@ return "Invalid modulo operation"; case SCRIPT_ERR_INVALID_SPLIT_RANGE: return "Invalid OP_SPLIT range"; + case SCRIPT_ERR_INVALID_BIN2NUM_OPERATION: + return "Invalid OP_BIN2NUM operation (check operand values)"; case SCRIPT_ERR_NEGATIVE_LOCKTIME: return "Negative locktime"; case SCRIPT_ERR_UNSATISFIED_LOCKTIME: