Skip to content

Commit da1af85

Browse files
author
MarcoFalke
committed
Merge #17275: pubkey: Assert CPubKey's ECCVerifyHandle precondition
d8daa8f pubkey: Assert CPubKey's ECCVerifyHandle precondition (practicalswift) Pull request description: Assert `CPubKey`'s `ECCVerifyHandle` precondition. This makes it more clear for fuzzing harness writers and others that `ECCVerifyHandle` is expected to be held when interacting with `CPubKey`. Related PR #17274. ACKs for top commit: sipa: ACK d8daa8f Tree-SHA512: 9e74086599799dc9b5c3fb8357445b662e5bf896d826af63d6d6b6ddb616612966f3bb5de3bd3ae0e692c47de85672f64b8ab6d3a1c45899dc25ba46990b5ec7
2 parents cb11324 + d8daa8f commit da1af85

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/pubkey.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchS
171171
return false;
172172
secp256k1_pubkey pubkey;
173173
secp256k1_ecdsa_signature sig;
174+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
174175
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) {
175176
return false;
176177
}
@@ -190,6 +191,7 @@ bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned cha
190191
bool fComp = ((vchSig[0] - 27) & 4) != 0;
191192
secp256k1_pubkey pubkey;
192193
secp256k1_ecdsa_recoverable_signature sig;
194+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
193195
if (!secp256k1_ecdsa_recoverable_signature_parse_compact(secp256k1_context_verify, &sig, &vchSig[1], recid)) {
194196
return false;
195197
}
@@ -207,13 +209,15 @@ bool CPubKey::IsFullyValid() const {
207209
if (!IsValid())
208210
return false;
209211
secp256k1_pubkey pubkey;
212+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
210213
return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size());
211214
}
212215

213216
bool CPubKey::Decompress() {
214217
if (!IsValid())
215218
return false;
216219
secp256k1_pubkey pubkey;
220+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
217221
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) {
218222
return false;
219223
}
@@ -232,6 +236,7 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
232236
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
233237
memcpy(ccChild.begin(), out+32, 32);
234238
secp256k1_pubkey pubkey;
239+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
235240
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) {
236241
return false;
237242
}
@@ -273,6 +278,7 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int _nChild) const {
273278

274279
/* static */ bool CPubKey::CheckLowS(const std::vector<unsigned char>& vchSig) {
275280
secp256k1_ecdsa_signature sig;
281+
assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
276282
if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, vchSig.data(), vchSig.size())) {
277283
return false;
278284
}

0 commit comments

Comments
 (0)