Skip to content

Commit 923c5e9

Browse files
committed
Merge pull request #6818
b48da5c script: Remove magic numbers (David Hill)
2 parents fa1d252 + b48da5c commit 923c5e9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/script/interpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
273273
return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
274274

275275
// Note how OP_RESERVED does not count towards the opcode limit.
276-
if (opcode > OP_16 && ++nOpCount > 201)
276+
if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT)
277277
return set_error(serror, SCRIPT_ERR_OP_COUNT);
278278

279279
if (opcode == OP_CAT ||
@@ -869,10 +869,10 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
869869
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
870870

871871
int nKeysCount = CScriptNum(stacktop(-i), fRequireMinimal).getint();
872-
if (nKeysCount < 0 || nKeysCount > 20)
872+
if (nKeysCount < 0 || nKeysCount > MAX_PUBKEYS_PER_MULTISIG)
873873
return set_error(serror, SCRIPT_ERR_PUBKEY_COUNT);
874874
nOpCount += nKeysCount;
875-
if (nOpCount > 201)
875+
if (nOpCount > MAX_OPS_PER_SCRIPT)
876876
return set_error(serror, SCRIPT_ERR_OP_COUNT);
877877
int ikey = ++i;
878878
i += nKeysCount;

src/script/script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ unsigned int CScript::GetSigOpCount(bool fAccurate) const
170170
if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16)
171171
n += DecodeOP_N(lastOpcode);
172172
else
173-
n += 20;
173+
n += MAX_PUBKEYS_PER_MULTISIG;
174174
}
175175
lastOpcode = opcode;
176176
}

src/script/script.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
#include <string>
1818
#include <vector>
1919

20-
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
20+
// Maximum number of bytes pushable to the stack
21+
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
22+
23+
// Maximum number of non-push operations per script
24+
static const int MAX_OPS_PER_SCRIPT = 201;
25+
26+
// Maximum number of public keys per multisig
27+
static const int MAX_PUBKEYS_PER_MULTISIG = 20;
2128

2229
// Threshold for nLockTime: below this value it is interpreted as block number,
2330
// otherwise as UNIX timestamp.

0 commit comments

Comments
 (0)