From eefa78a2997cd8df72e3443620c4b9b918509be0 Mon Sep 17 00:00:00 2001 From: homura Date: Fri, 2 Aug 2024 18:49:00 +0900 Subject: [PATCH] Comment for magick number --- src/segwit_addr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/segwit_addr.c b/src/segwit_addr.c index a04f2a7..a532abe 100644 --- a/src/segwit_addr.c +++ b/src/segwit_addr.c @@ -54,7 +54,16 @@ int bech32_encode(char *const output, const size_t out_len, const char *const hr chk = bech32_polymod_step(chk) ^ (hrp[i] >> 5); ++i; } - if (i + 7 + data_len > 1023) + // An CKB address is encoded from a CKB script, + // which consists of three fields: + // code_hash (32 bytes), hash_type (1 byte), and args (variable). + // It is often longer than a Bitcoin address. + // Since a bech32 character can represent 5-bits of data, + // the original limit of 107 has been changed to 1023 + // to increase the script limit to approximately 640 bytes (1023 * 5 / 8 ≈ 1023) + // allowing support for ultra-long addresses. + int max_data_len = 1023; + if (i + 7 + data_len > max_data_len) return 0; chk = bech32_polymod_step(chk); }