Skip to content

Commit

Permalink
DRY max opcodes per script
Browse files Browse the repository at this point in the history
Currently hard-coded, this just reduces redunduncy and could prevent
future errors if the value ever changes.
  • Loading branch information
nmarley committed Jan 24, 2016
1 parent cc0fc39 commit ed4d606
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
return set_error(serror, SCRIPT_ERR_PUSH_SIZE);

// Note how OP_RESERVED does not count towards the opcode limit.
if (opcode > OP_16 && ++nOpCount > 201)
if (opcode > OP_16 && ++nOpCount > MAX_OPCODES_PER_SCRIPT)
return set_error(serror, SCRIPT_ERR_OP_COUNT);

if (opcode == OP_CAT ||
Expand Down Expand Up @@ -830,7 +830,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
if (nKeysCount < 0 || nKeysCount > 20)
return set_error(serror, SCRIPT_ERR_PUBKEY_COUNT);
nOpCount += nKeysCount;
if (nOpCount > 201)
if (nOpCount > MAX_OPCODES_PER_SCRIPT)
return set_error(serror, SCRIPT_ERR_OP_COUNT);
int ikey = ++i;
i += nKeysCount;
Expand Down
1 change: 1 addition & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>

static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
static const unsigned int MAX_OPCODES_PER_SCRIPT = 201;

template <typename T>
std::vector<unsigned char> ToByteVector(const T& in)
Expand Down

0 comments on commit ed4d606

Please sign in to comment.