aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjosibake <josibake@protonmail.com>2024-08-06 10:58:04 +0200
committerjosibake <josibake@protonmail.com>2024-08-06 11:03:31 +0200
commit59c0ece0a785ce9e22fbfefce9ca228d85e5d43d (patch)
treedc8841c23ae493baac723f27f4dc105b9692cee1 /src
parent949b67347255c0f2494055cbcdbb729a6476ded7 (diff)
downloadbitcoin-59c0ece0a785ce9e22fbfefce9ca228d85e5d43d.tar.xz
fuzz: replace hardcoded numbers for bech32 limits
Use bech32::CharLimit::BECH32 and bech32::CHECKSUM_SIZE instead of hardcoded values. This is a follow-up fix for #34007 (where this file was missed)
Diffstat (limited to 'src')
-rw-r--r--src/bech32.cpp3
-rw-r--r--src/bech32.h3
-rw-r--r--src/test/fuzz/bech32.cpp5
3 files changed, 6 insertions, 5 deletions
diff --git a/src/bech32.cpp b/src/bech32.cpp
index d8d31a415c..5694ad54c8 100644
--- a/src/bech32.cpp
+++ b/src/bech32.cpp
@@ -19,9 +19,6 @@ namespace
typedef std::vector<uint8_t> data;
-/** The Bech32 and Bech32m checksum size */
-constexpr size_t CHECKSUM_SIZE = 6;
-
/** The Bech32 and Bech32m character set for encoding. */
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
diff --git a/src/bech32.h b/src/bech32.h
index fe2a276ae0..33d1ca1935 100644
--- a/src/bech32.h
+++ b/src/bech32.h
@@ -21,6 +21,9 @@
namespace bech32
{
+/** The Bech32 and Bech32m checksum size */
+constexpr size_t CHECKSUM_SIZE = 6;
+
enum class Encoding {
INVALID, //!< Failed decoding
diff --git a/src/test/fuzz/bech32.cpp b/src/test/fuzz/bech32.cpp
index ffc5ba518f..daa6e24404 100644
--- a/src/test/fuzz/bech32.cpp
+++ b/src/test/fuzz/bech32.cpp
@@ -29,8 +29,9 @@ FUZZ_TARGET(bech32)
std::vector<unsigned char> input;
ConvertBits<8, 5, true>([&](unsigned char c) { input.push_back(c); }, buffer.begin(), buffer.end());
- if (input.size() + 3 + 6 <= 90) {
- // If it's possible to encode input in Bech32(m) without exceeding the 90-character limit:
+ // Input data part + 3 characters for the HRP and separator (bc1) + the checksum characters
+ if (input.size() + 3 + bech32::CHECKSUM_SIZE <= bech32::CharLimit::BECH32) {
+ // If it's possible to encode input in Bech32(m) without exceeding the bech32-character limit:
for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {
const std::string encoded = bech32::Encode(encoding, "bc", input);
assert(!encoded.empty());