From 74ec75fb4f85599b006969bc916a577556230387 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sat, 21 Sep 2024 19:35:44 +0000 Subject: [PATCH] bech32: use correct generator exponents There are two parameterizations of the bech32 checksum (see the "roots" unit test in src/primitives/polynomial.rs for what they are). In #203 we mixed them up, using the generator from one but the exponents from the other. We made the same mistake with codex32 apparently. When we implement error correction this will cause failures. Fix it. --- src/lib.rs | 2 +- src/primitives/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 64969b4d..4def6ece 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,7 @@ //! type MidstateRepr = u128; //! type CorrectionField = bech32::primitives::gf32_ext::Fe32Ext<2>; //! const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::_9, Fe32::_9]); -//! const ROOT_EXPONENTS: core::ops::RangeInclusive = 77..=84; +//! const ROOT_EXPONENTS: core::ops::RangeInclusive = 9..=16; //! //! const CHECKSUM_LENGTH: usize = 13; //! const CODE_LENGTH: usize = 93; diff --git a/src/primitives/mod.rs b/src/primitives/mod.rs index a4d803fa..ae308ba3 100644 --- a/src/primitives/mod.rs +++ b/src/primitives/mod.rs @@ -60,7 +60,7 @@ impl Checksum for Bech32 { type CorrectionField = Fe1024; const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::P, Fe32::X]); - const ROOT_EXPONENTS: core::ops::RangeInclusive = 997..=999; + const ROOT_EXPONENTS: core::ops::RangeInclusive = 24..=26; const CODE_LENGTH: usize = 1023; const CHECKSUM_LENGTH: usize = 6; @@ -73,7 +73,7 @@ impl Checksum for Bech32m { type CorrectionField = Fe1024; const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::P, Fe32::X]); - const ROOT_EXPONENTS: core::ops::RangeInclusive = 997..=999; + const ROOT_EXPONENTS: core::ops::RangeInclusive = 24..=26; const CODE_LENGTH: usize = 1023; const CHECKSUM_LENGTH: usize = 6;