diff options
author | Ava Chow <github@achow101.com> | 2024-06-04 21:57:36 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-06-04 21:57:36 -0400 |
commit | 23b3dc2dd13dc9bf13790a87b046a64cbbfccc43 (patch) | |
tree | c683d5a6925a1573dc0031e7970b5671af40924a /src | |
parent | c29314ecfcc09db4f3d3656a825c13158974578c (diff) | |
parent | 8801e319d51209fe3a3b06e2aab5f96ceead290d (diff) |
Merge bitcoin/bitcoin#30218: refactor: remove unused `CKey::Negate` method
8801e319d51209fe3a3b06e2aab5f96ceead290d refactor: remove unused `CKey::Negate` method (Sebastian Falbesoner)
Pull request description:
This method was introduced as a pre-requirement for the v2 transport protocol back then (see PR #14047, commit 463921bb), when it was still BIP151. With the replacement BIP324, this is not needed anymore, and it's also unlikely that for any other proposal we'd ever need to negate private keys at this abstraction level. I'd argue that this operation is usually something that should happen within a secp256k1 module (like e.g. done in MuSig2, Silent Payments...).
(If there is really demand in the future, it's also trivial to reintroduce the method.)
ACKs for top commit:
laanwj:
ACK 8801e319d51209fe3a3b06e2aab5f96ceead290d
sipa:
ACK 8801e319d51209fe3a3b06e2aab5f96ceead290d
achow101:
ACK 8801e319d51209fe3a3b06e2aab5f96ceead290d
Tree-SHA512: 7bc1566399635c5c6e4940a2724c865d5443eb190024379099330c023c516f1e4f423ed9e8c42bc93413b723a5464ec79d3f879f58c0e598fe24f495238df4ec
Diffstat (limited to 'src')
-rw-r--r-- | src/key.cpp | 6 | ||||
-rw-r--r-- | src/key.h | 3 | ||||
-rw-r--r-- | src/test/fuzz/key.cpp | 10 | ||||
-rw-r--r-- | src/test/key_tests.cpp | 31 |
4 files changed, 0 insertions, 50 deletions
diff --git a/src/key.cpp b/src/key.cpp index e8458f2e3b..97d7821e74 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -166,12 +166,6 @@ void CKey::MakeNewKey(bool fCompressedIn) { fCompressed = fCompressedIn; } -bool CKey::Negate() -{ - assert(keydata); - return secp256k1_ec_seckey_negate(secp256k1_context_sign, keydata->data()); -} - CPrivKey CKey::GetPrivKey() const { assert(keydata); CPrivKey seckey; @@ -124,9 +124,6 @@ public: //! Generate a new private key using a cryptographic PRNG. void MakeNewKey(bool fCompressed); - //! Negate private key - bool Negate(); - /** * Convert the private key to a CPrivKey (serialized OpenSSL private key data). * This is expensive. diff --git a/src/test/fuzz/key.cpp b/src/test/fuzz/key.cpp index d389a29575..82973803f8 100644 --- a/src/test/fuzz/key.cpp +++ b/src/test/fuzz/key.cpp @@ -78,16 +78,6 @@ FUZZ_TARGET(key, .init = initialize_key) assert(copied_key == key); } - { - CKey negated_key = key; - negated_key.Negate(); - assert(negated_key.IsValid()); - assert(!(negated_key == key)); - - negated_key.Negate(); - assert(negated_key == key); - } - const uint256 random_uint256 = Hash(buffer); { diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index aaf4ca4977..1ec6de78cb 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -201,37 +201,6 @@ BOOST_AUTO_TEST_CASE(key_signature_tests) BOOST_CHECK(found_small); } -BOOST_AUTO_TEST_CASE(key_key_negation) -{ - // create a dummy hash for signature comparison - unsigned char rnd[8]; - std::string str = "Bitcoin key verification\n"; - GetRandBytes(rnd); - uint256 hash{Hash(str, rnd)}; - - // import the static test key - CKey key = DecodeSecret(strSecret1C); - - // create a signature - std::vector<unsigned char> vch_sig; - std::vector<unsigned char> vch_sig_cmp; - key.Sign(hash, vch_sig); - - // negate the key twice - BOOST_CHECK(key.GetPubKey().data()[0] == 0x03); - key.Negate(); - // after the first negation, the signature must be different - key.Sign(hash, vch_sig_cmp); - BOOST_CHECK(vch_sig_cmp != vch_sig); - BOOST_CHECK(key.GetPubKey().data()[0] == 0x02); - key.Negate(); - // after the second negation, we should have the original key and thus the - // same signature - key.Sign(hash, vch_sig_cmp); - BOOST_CHECK(vch_sig_cmp == vch_sig); - BOOST_CHECK(key.GetPubKey().data()[0] == 0x03); -} - static CPubKey UnserializePubkey(const std::vector<uint8_t>& data) { DataStream stream{}; |