Skip to content

Commit 40de191

Browse files
committed
Merge bitcoin#32118: fuzz: wallet: fix crypter target
28dc118 fuzz: wallet: fix crypter target (brunoerg) Pull request description: The crypter target has an issue, it's calling `DecryptKey` with a random secret and a random public key that will unlikely be related to the key used to encrypt, so it won't have any effect. This PR changes fixes it and also removes the `DecryptSecret` call since this function is already (and only) called within `DecryptKey`. ACKs for top commit: maflcko: lgtm ACK 28dc118 🥊 Tree-SHA512: e96b7d33879bf06eeec0726e74e8e0d7020997659bf97dfca5d7c1a7ba65c4d93c78e666b97eebde110564cef2eefc7209d3e3586e4658145827b14d1b01dfc9
2 parents 5541f7c + 28dc118 commit 40de191

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/wallet/test/fuzz/crypter.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void initialize_crypter()
2020

2121
FUZZ_TARGET(crypter, .init = initialize_crypter)
2222
{
23+
SeedRandomStateForTest(SeedRand::ZEROS);
2324
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
2425
bool good_data{true};
2526

@@ -42,6 +43,11 @@ FUZZ_TARGET(crypter, .init = initialize_crypter)
4243
/*derivation_method=*/derivation_method);
4344
}
4445

46+
CKey random_ckey;
47+
random_ckey.Set(random_key.begin(), random_key.end(), /*fCompressedIn=*/fuzzed_data_provider.ConsumeBool());
48+
if (!random_ckey.IsValid()) return;
49+
CPubKey pubkey{random_ckey.GetPubKey()};
50+
4551
LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 100)
4652
{
4753
CallOneOf(
@@ -60,26 +66,21 @@ FUZZ_TARGET(crypter, .init = initialize_crypter)
6066
(void)crypt.Decrypt(cipher_text_ed, plain_text_ed);
6167
},
6268
[&] {
63-
const CKeyingMaterial master_key(random_key.begin(), random_key.end());
64-
const uint256 iv = ConsumeUInt256(fuzzed_data_provider);
65-
(void)EncryptSecret(master_key, plain_text_ed, iv, cipher_text_ed);
69+
const CKeyingMaterial master_key(random_key.begin(), random_key.end());;
70+
(void)EncryptSecret(master_key, plain_text_ed, pubkey.GetHash(), cipher_text_ed);
6671
},
6772
[&] {
68-
const CKeyingMaterial master_key(random_key.begin(), random_key.end());
69-
const uint256 iv = ConsumeUInt256(fuzzed_data_provider);
70-
(void)DecryptSecret(master_key, cipher_text_ed, iv, plain_text_ed);
71-
},
72-
[&] {
73-
std::optional<CPubKey> random_pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);
73+
std::optional<CPubKey> random_pub_key{ConsumeDeserializable<CPubKey>(fuzzed_data_provider)};
7474
if (!random_pub_key) {
7575
good_data = false;
7676
return;
7777
}
78-
const CPubKey pub_key = *random_pub_key;
78+
pubkey = *random_pub_key;
79+
},
80+
[&] {
7981
const CKeyingMaterial master_key(random_key.begin(), random_key.end());
80-
const std::vector<unsigned char> crypted_secret = ConsumeRandomLengthByteVector(fuzzed_data_provider, 64);
8182
CKey key;
82-
(void)DecryptKey(master_key, crypted_secret, pub_key, key);
83+
(void)DecryptKey(master_key, cipher_text_ed, pubkey, key);
8384
});
8485
}
8586
}

0 commit comments

Comments
 (0)