Skip to content

Commit 74ec75f

Browse files
committed
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.
1 parent 3f98190 commit 74ec75f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
//! type MidstateRepr = u128;
106106
//! type CorrectionField = bech32::primitives::gf32_ext::Fe32Ext<2>;
107107
//! const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::_9, Fe32::_9]);
108-
//! const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 77..=84;
108+
//! const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 9..=16;
109109
//!
110110
//! const CHECKSUM_LENGTH: usize = 13;
111111
//! const CODE_LENGTH: usize = 93;

src/primitives/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Checksum for Bech32 {
6060

6161
type CorrectionField = Fe1024;
6262
const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::P, Fe32::X]);
63-
const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 997..=999;
63+
const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 24..=26;
6464

6565
const CODE_LENGTH: usize = 1023;
6666
const CHECKSUM_LENGTH: usize = 6;
@@ -73,7 +73,7 @@ impl Checksum for Bech32m {
7373

7474
type CorrectionField = Fe1024;
7575
const ROOT_GENERATOR: Self::CorrectionField = Fe1024::new([Fe32::P, Fe32::X]);
76-
const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 997..=999;
76+
const ROOT_EXPONENTS: core::ops::RangeInclusive<usize> = 24..=26;
7777

7878
const CODE_LENGTH: usize = 1023;
7979
const CHECKSUM_LENGTH: usize = 6;

0 commit comments

Comments
 (0)