Skip to content

Commit 405f64e

Browse files
committed
Fuzz tests for CPubKey<->EllSq
1 parent 9a5cebc commit 405f64e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/fuzz/key.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <test/fuzz/fuzz.h>
2020
#include <util/strencodings.h>
2121

22+
#include <array>
2223
#include <cassert>
2324
#include <cstdint>
2425
#include <numeric>
@@ -305,4 +306,25 @@ FUZZ_TARGET_INIT(key, initialize_key)
305306
assert(key == loaded_key);
306307
}
307308
}
309+
310+
{
311+
std::array<uint8_t, 32> rnd32;
312+
memcpy(rnd32.data(), &random_uint256, 32);
313+
assert(pubkey.EllSqEncode(rnd32)->size() == ELLSQ_ENCODED_SIZE);
314+
}
315+
}
316+
317+
FUZZ_TARGET_INIT(ellsq, initialize_key)
318+
{
319+
if(buffer.size() < 64) {
320+
return;
321+
}
322+
323+
auto ellsq_bytes = buffer.first(64);
324+
// Any 64 bytes are a valid elligator squared encoding of a pubkey
325+
EllSqPubKey ellsq_pubkey;
326+
std::copy(ellsq_bytes.begin(), ellsq_bytes.end(), ellsq_pubkey.begin());
327+
CPubKey pubkey{ellsq_pubkey};
328+
329+
assert(pubkey.IsFullyValid());
308330
}

0 commit comments

Comments
 (0)