Skip to content

Commit f2ec582

Browse files
committed
primitives: introduce FieldVec type
This will allow `Polynomial` to work without an allocator (at least for "small" checksums. Here a "small" checksum is one of length at most 6 (which covers bech32 and bech32m). The descriptor checksum (8 characters), codex32 (13 characters) and "long codex32" (15 characters) will not work with no-alloc. I would like to fix this but it results in large types, especially a large InvalidResidueError type (see last commit of this PR), so probably it will need to be feature-gated or something. For now we just punt on it. This PR introduces the `primitives::correction` module but only puts a single constant into it for now.
1 parent 86a5bdc commit f2ec582

File tree

3 files changed

+403
-0
lines changed

3 files changed

+403
-0
lines changed

src/primitives/correction.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
//! Error Correction
4+
//!
5+
//! Implements the Berlekamp-Massey algorithm to locate errors, with Forney's
6+
//! equation to identify the error values, in a BCH-encoded string.
7+
//!
8+
9+
/// **One more than** the maximum length (in characters) of a checksum which
10+
/// can be error-corrected without an allocator.
11+
///
12+
/// When the **alloc** feature is enabled, this constant is practically irrelevant.
13+
/// When the feature is disabled, it represents a length beyond which this library
14+
/// does not support error correction.
15+
///
16+
/// If you need this value to be increased, please file an issue describing your
17+
/// usecase. Bear in mind that an increased value will increase memory usage for
18+
/// all users, and the focus of this library is the Bitcoin ecosystem, so we may
19+
/// not be able to accept your request.
20+
// This constant is also used when comparing bech32 residues against the
21+
// bech32/bech32m targets, which should work with no-alloc. Therefore this
22+
// constant must be > 6 (the length of the bech32(m) checksum).
23+
//
24+
// Otherwise it basically represents a tradeoff between stack usage and the
25+
// size of error types, vs functionality in a no-alloc setting. The value
26+
// of 7 covers bech32 and bech32m. To get the descriptor checksum we need a
27+
// value and the descriptor checksum. To also get codex32 it should be >13,
28+
// and for "long codex32" >15 ... but consider that no-alloc contexts are
29+
// likely to be underpowered and will struggle to do correction on these
30+
// big codes anyway.
31+
//
32+
// Perhaps we will want to add a feature gate, off by default, that boosts
33+
// this to 16, or maybe even higher. But we will wait for implementors who
34+
// complain.
35+
pub const NO_ALLOC_MAX_LENGTH: usize = 7;

0 commit comments

Comments
 (0)