Browse Source

Document and test OP_RESERVED weirdness

Seems it was forgotten about when IsPushOnly() and the unittests were
written. A particular oddity is that OP_RESERVED doesn't count towards
the >201 opcode limit unlike every other named opcode.
0.10
Peter Todd 11 years ago
parent
commit
214d45b6b9
No known key found for this signature in database
GPG Key ID: 2481403DA5F091FB
  1. 2
      src/script.cpp
  2. 4
      src/script.h
  3. 1
      src/test/data/script_invalid.json
  4. 6
      src/test/data/script_valid.json
  5. 8
      src/test/script_tests.cpp

2
src/script.cpp

@ -327,6 +327,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co @@ -327,6 +327,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
return false;
if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
return false;
// Note how OP_RESERVED does not count towards the opcode limit.
if (opcode > OP_16 && ++nOpCount > 201)
return false;

4
src/script.h

@ -543,6 +543,10 @@ public: @@ -543,6 +543,10 @@ public:
opcodetype opcode;
if (!GetOp(pc, opcode))
return false;
// Note that IsPushOnly() *does* consider OP_RESERVED to be a
// push-type opcode, however execution of OP_RESERVED fails, so
// it's not relevant to P2SH as the scriptSig would fail prior to
// the P2SH special validation code being executed.
if (opcode > OP_16)
return false;
}

1
src/test/data/script_invalid.json

@ -251,6 +251,7 @@ @@ -251,6 +251,7 @@
["1","VER", "OP_VER is reserved"],
["1","VERIF", "OP_VERIF is reserved"],
["1","VERNOTIF", "OP_VERNOTIF is reserved"],
["1","RESERVED", "OP_RESERVED is reserved"],
["1","RESERVED1", "OP_RESERVED1 is reserved"],
["1","RESERVED2", "OP_RESERVED2 is reserved"],
["1","0xba", "0xba == OP_NOP10 + 1"],

6
src/test/data/script_valid.json

File diff suppressed because one or more lines are too long

8
src/test/script_tests.cpp

@ -32,8 +32,12 @@ ParseScript(string s) @@ -32,8 +32,12 @@ ParseScript(string s)
if (mapOpNames.size() == 0)
{
for (int op = OP_NOP; op <= OP_NOP10; op++)
for (int op = 0; op <= OP_NOP10; op++)
{
// Allow OP_RESERVED to get into mapOpNames
if (op < OP_NOP && op != OP_RESERVED)
continue;
const char* name = GetOpName((opcodetype)op);
if (strcmp(name, "OP_UNKNOWN") == 0)
continue;
@ -72,7 +76,7 @@ ParseScript(string s) @@ -72,7 +76,7 @@ ParseScript(string s)
}
else if (mapOpNames.count(w))
{
// opcode, e.g. OP_ADD or OP_1:
// opcode, e.g. OP_ADD or ADD:
result << mapOpNames[w];
}
else

Loading…
Cancel
Save