Fuzz test for CKey->EllSwift->CPubKey creation/decoding

Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
This commit is contained in:
dhruv 2021-11-03 10:10:10 -07:00 committed by Pieter Wuille
parent aae432a764
commit c3ac9f5cf4

View file

@ -15,10 +15,12 @@
#include <script/signingprovider.h>
#include <script/standard.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <array>
#include <cassert>
#include <cstdint>
#include <numeric>
@ -303,3 +305,22 @@ FUZZ_TARGET_INIT(key, initialize_key)
}
}
}
FUZZ_TARGET_INIT(ellswift_roundtrip, initialize_key)
{
FuzzedDataProvider fdp{buffer.data(), buffer.size()};
auto key_bytes = fdp.ConsumeBytes<uint8_t>(32);
key_bytes.resize(32);
CKey key;
key.Set(key_bytes.begin(), key_bytes.end(), true);
if (!key.IsValid()) return;
auto ent32 = fdp.ConsumeBytes<std::byte>(32);
ent32.resize(32);
auto encoded_ellswift = key.EllSwiftCreate(ent32);
auto decoded_pubkey = encoded_ellswift.Decode();
assert(key.VerifyPubKey(decoded_pubkey));
}