aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-04-04 17:50:14 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-04-04 17:50:32 -0400
commitbfaed1ab2ec7fb3a1a6a7ed0b84503c2ed461c67 (patch)
tree74246fee62fb82a37244ac1e59ed584c46975f58 /src/script
parent2106c4c64c364ceebb556ebee3f429fb7e2f0d5a (diff)
parentf8c249ab918b0b4d326b8c441816c64d046455bf (diff)
downloadbitcoin-bfaed1ab2ec7fb3a1a6a7ed0b84503c2ed461c67.tar.xz
Merge #12460: Assert CPubKey::ValidLength to the pubkey's header-relevant size
f8c249ab91 Assert CPubKey::ValidLength to the pubkey's header-relevent size (Ben Woosley) Pull request description: A pubkey's length is specific to its type which is indicated by its header value. GetLen returns the header-indicated length, so this change ensures that a key matches its header-indicated length. And replace some magic values with their constant equivalents. Tree-SHA512: b727b39a631babe0932326396fc4d796ade8ec1e37454ff0c709ae9b78ecbd0cfdf59d84089ba8415e6efa7bc180e3cd39a14ddaf0871cbac54b96851e1b7b44
Diffstat (limited to 'src/script')
-rw-r--r--src/script/interpreter.cpp8
-rw-r--r--src/script/standard.cpp4
2 files changed, 6 insertions, 6 deletions
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
index 07b2292d46..85dd0a8a81 100644
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -61,17 +61,17 @@ static inline void popstack(std::vector<valtype>& stack)
}
bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
- if (vchPubKey.size() < 33) {
+ if (vchPubKey.size() < CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
// Non-canonical public key: too short
return false;
}
if (vchPubKey[0] == 0x04) {
- if (vchPubKey.size() != 65) {
+ if (vchPubKey.size() != CPubKey::PUBLIC_KEY_SIZE) {
// Non-canonical public key: invalid length for uncompressed key
return false;
}
} else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
- if (vchPubKey.size() != 33) {
+ if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
// Non-canonical public key: invalid length for compressed key
return false;
}
@@ -83,7 +83,7 @@ bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
}
bool static IsCompressedPubKey(const valtype &vchPubKey) {
- if (vchPubKey.size() != 33) {
+ if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) {
// Non-canonical public key: invalid length for compressed key
return false;
}
diff --git a/src/script/standard.cpp b/src/script/standard.cpp
index cfb3c58588..0b9053d7fc 100644
--- a/src/script/standard.cpp
+++ b/src/script/standard.cpp
@@ -132,7 +132,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
// Template matching opcodes:
if (opcode2 == OP_PUBKEYS)
{
- while (vch1.size() >= 33 && vch1.size() <= 65)
+ while (CPubKey::ValidSize(vch1))
{
vSolutionsRet.push_back(vch1);
if (!script1.GetOp(pc1, opcode1, vch1))
@@ -146,7 +146,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
if (opcode2 == OP_PUBKEY)
{
- if (vch1.size() < 33 || vch1.size() > 65)
+ if (!CPubKey::ValidSize(vch1))
break;
vSolutionsRet.push_back(vch1);
}