diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -943,6 +943,12 @@ // Disabled opcode. return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); } + // 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: diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -288,6 +288,12 @@ inline CScriptNum &operator-=(const CScriptNum &rhs) { 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 int64_t &rhs) const { return CScriptNum(m_value & rhs);