From bcd6383f3b51a5904e717fc1939bd25da678fc2f Mon Sep 17 00:00:00 2001 From: nandhh Date: Mon, 12 Aug 2024 16:50:24 +0800 Subject: [PATCH] feat: enable OP_CAT in tapscript --- src/script/interpreter.cpp | 26 ++++++++++++++++++++++++-- src/script/script.cpp | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 38bb11aad4..fe68fa4c17 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -451,10 +451,16 @@ bool EvalScript(std::vector >& stack, const CScript& if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) { return set_error(serror, SCRIPT_ERR_OP_COUNT); } + + // When OP_SUCCESS disabled opcodes (CVE-2010-5137) are + // redefined in tapscript, remove them from the if below + // and put them here + if (opcode == OP_CAT) { + return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes (CVE-2010-5137). + } } - if (opcode == OP_CAT || - opcode == OP_SUBSTR || + if (opcode == OP_SUBSTR || opcode == OP_LEFT || opcode == OP_RIGHT || opcode == OP_INVERT || @@ -1213,6 +1219,22 @@ bool EvalScript(std::vector >& stack, const CScript& } break; + // + // Byte string operations + // + case OP_CAT: + { + if (stack.size() < 2) + return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); + valtype& vch1 = stacktop(-2); + valtype& vch2 = stacktop(-1); + if (vch1.size() + vch2.size() > MAX_SCRIPT_ELEMENT_SIZE) + return set_error(serror, SCRIPT_ERR_PUSH_SIZE); + vch1.insert(vch1.end(), vch2.begin(), vch2.end()); + popstack(stack); + } + break; + default: return set_error(serror, SCRIPT_ERR_BAD_OPCODE); } diff --git a/src/script/script.cpp b/src/script/script.cpp index 88b4bc2f44..a177148665 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -334,7 +334,7 @@ bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator en bool IsOpSuccess(const opcodetype& opcode) { - return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) || + return opcode == 80 || opcode == 98 || (opcode >= 127 && opcode <= 129) || (opcode >= 131 && opcode <= 134) || (opcode >= 137 && opcode <= 138) || (opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) || (opcode >= 187 && opcode <= 254);