aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz
diff options
context:
space:
mode:
authordhruv <856960+dhruv@users.noreply.github.com>2021-11-03 10:10:10 -0700
committerPieter Wuille <pieter@wuille.net>2023-06-23 14:22:39 -0400
commitc3ac9f5cf413e263803aac668a90a4ddd7316924 (patch)
treec1320a078e5f69ca507be22f3a7971ff104bcf6e /src/test/fuzz
parentaae432a764e4ceb7eac305458e585726225c7189 (diff)
Fuzz test for CKey->EllSwift->CPubKey creation/decoding
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
Diffstat (limited to 'src/test/fuzz')
-rw-r--r--src/test/fuzz/key.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/fuzz/key.cpp b/src/test/fuzz/key.cpp
index 3eab2e20c0..5599262836 100644
--- a/src/test/fuzz/key.cpp
+++ b/src/test/fuzz/key.cpp
@@ -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));
+}