Index: src/script/interpreter.cpp =================================================================== --- src/script/interpreter.cpp +++ src/script/interpreter.cpp @@ -336,8 +336,8 @@ } if (opcode == OP_CAT || opcode == OP_SUBSTR || opcode == OP_LEFT || - opcode == OP_RIGHT || opcode == OP_INVERT || opcode == OP_2MUL || - opcode == OP_2DIV || opcode == OP_MUL || opcode == OP_MOD || + 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); @@ -787,8 +787,8 @@ return set_error( serror, SCRIPT_ERR_INVALID_STACK_OPERATION); } - valtype& vch1 = stacktop(-2); - valtype& vch2 = stacktop(-1); + valtype &vch1 = stacktop(-2); + valtype &vch2 = stacktop(-1); // throw error if inputs are not the same size if (vch1.size() != vch2.size()) { return set_error( @@ -894,6 +894,7 @@ case OP_ADD: case OP_SUB: case OP_DIV: + case OP_MOD: case OP_BOOLAND: case OP_BOOLOR: case OP_NUMEQUAL: @@ -926,11 +927,19 @@ case OP_DIV: // 2nd operand must not be 0 if (bn2 == 0) { - return set_error( - serror, SCRIPT_ERR_DIV_BY_ZERO); + return set_error(serror, + SCRIPT_ERR_DIV_BY_ZERO); } bn = bn1 / bn2; break; + case OP_MOD: + // 2nd operand must not be 0 + if (bn2 == 0) { + return set_error(serror, + SCRIPT_ERR_MOD_BY_ZERO); + } + bn = bn1 % bn2; + break; case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); Index: src/script/script.h =================================================================== --- src/script/script.h +++ src/script/script.h @@ -279,6 +279,12 @@ inline CScriptNum operator/(const CScriptNum &rhs) const { return operator/(rhs.m_value); } + inline CScriptNum operator%(const int64_t &rhs) const { + return CScriptNum(m_value % rhs); + } + inline CScriptNum operator%(const CScriptNum &rhs) const { + return operator%(rhs.m_value); + } inline CScriptNum &operator+=(const CScriptNum &rhs) { return operator+=(rhs.m_value); Index: src/script/script_error.h =================================================================== --- src/script/script_error.h +++ src/script/script_error.h @@ -35,6 +35,7 @@ SCRIPT_ERR_UNBALANCED_CONDITIONAL, SCRIPT_ERR_INVALID_BITWISE_OPERATION, SCRIPT_ERR_DIV_BY_ZERO, + SCRIPT_ERR_MOD_BY_ZERO, /* CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY */ SCRIPT_ERR_NEGATIVE_LOCKTIME, Index: src/script/script_error.cpp =================================================================== --- src/script/script_error.cpp +++ src/script/script_error.cpp @@ -50,6 +50,8 @@ return "Invalid bitwise operation (check length of inputs)"; case SCRIPT_ERR_DIV_BY_ZERO: return "Invalid division operation"; + case SCRIPT_ERR_MOD_BY_ZERO: + return "Invalid modulo operation"; case SCRIPT_ERR_NEGATIVE_LOCKTIME: return "Negative locktime"; case SCRIPT_ERR_UNSATISFIED_LOCKTIME: