diff options
author | josibake <josibake@protonmail.com> | 2024-08-03 14:58:28 +0200 |
---|---|---|
committer | josibake <josibake@protonmail.com> | 2024-08-04 08:52:22 +0200 |
commit | ec973dd19719541dbcd6f3a6facf6f5dd7cf439c (patch) | |
tree | 23913a95df3310d67e59563226b5ad249697dd29 /src/key.cpp | |
parent | 72a5822d43d47431b2838ebfcb1f2e21210f5ccb (diff) |
refactor: remove un-tested early returns
Replace early returns in KeyPair::KeyPair() with asserts.
The if statements imply there is an error we are handling, but keypair_xonly_pub
and xonly_pubkey_serialize can only fail if the keypair object is malformed, i.e.,
it was created with a bad secret key. Since we check that the keypair was created
successfully before attempting to extract the public key, using asserts more
accurately documents what we expect here and removes untested branches from the code.
Diffstat (limited to 'src/key.cpp')
-rw-r--r-- | src/key.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/key.cpp b/src/key.cpp index 37b78d8e77..360a1f46d3 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -414,9 +414,9 @@ KeyPair::KeyPair(const CKey& key, const uint256* merkle_root) bool success = secp256k1_keypair_create(secp256k1_context_sign, keypair, UCharCast(key.data())); if (success && merkle_root) { secp256k1_xonly_pubkey pubkey; - if (!secp256k1_keypair_xonly_pub(secp256k1_context_sign, &pubkey, nullptr, keypair)) return; unsigned char pubkey_bytes[32]; - if (!secp256k1_xonly_pubkey_serialize(secp256k1_context_sign, pubkey_bytes, &pubkey)) return; + assert(secp256k1_keypair_xonly_pub(secp256k1_context_sign, &pubkey, nullptr, keypair)); + assert(secp256k1_xonly_pubkey_serialize(secp256k1_context_sign, pubkey_bytes, &pubkey)); uint256 tweak = XOnlyPubKey(pubkey_bytes).ComputeTapTweakHash(merkle_root->IsNull() ? nullptr : merkle_root); success = secp256k1_keypair_xonly_tweak_add(secp256k1_context_static, keypair, tweak.data()); } |