Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
}
}

if (opcode == OP_CAT ||
opcode == OP_SUBSTR ||
if (opcode == OP_SUBSTR ||
opcode == OP_LEFT ||
opcode == OP_RIGHT ||
opcode == OP_INVERT ||
Expand Down Expand Up @@ -534,6 +533,31 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
case OP_NOP:
break;

case OP_CAT:
{
// OP_CAT is only available in Tapscript
if (sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0)
return set_error(serror, SCRIPT_ERR_BAD_OPCODE);

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_INVALID_STACK_OPERATION);

valtype vch3;
vch3.reserve(vch1.size() + vch2.size());
vch3.insert(vch3.end(), vch1.begin(), vch1.end());
vch3.insert(vch3.end(), vch2.begin(), vch2.end());

popstack(stack);
popstack(stack);
stack.push_back(vch3);
}

case OP_CHECKLOCKTIMEVERIFY:
{
if (!(flags & SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/data/script_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@
["NOP", "SIZE 1", "P2SH,STRICTENC", "INVALID_STACK_OPERATION"],

["TEST DISABLED OP CODES (CVE-2010-5137)"],
["'a' 'b'", "CAT", "P2SH,STRICTENC", "DISABLED_OPCODE", "CAT disabled"],
["'a' 'b' 0", "IF CAT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "CAT disabled"],
["'abc' 1 1", "SUBSTR", "P2SH,STRICTENC", "DISABLED_OPCODE", "SUBSTR disabled"],
["'abc' 1 1 0", "IF SUBSTR ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "SUBSTR disabled"],
["'abc' 2 0", "IF LEFT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "LEFT disabled"],
Expand Down
2 changes: 0 additions & 2 deletions test/functional/data/invalid_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
OP_2DIV,
OP_2MUL,
OP_AND,
OP_CAT,
OP_CHECKSIG,
OP_DIV,
OP_INVERT,
Expand Down Expand Up @@ -265,7 +264,6 @@ def get_tx(self):

# Disabled opcode tx templates (CVE-2010-5137)
DisabledOpcodeTemplates = [getDisabledOpcodeTemplate(opcode) for opcode in [
OP_CAT,
OP_SUBSTR,
OP_LEFT,
OP_RIGHT,
Expand Down