Skip to content

fix(moid): reduce the check character's sum as it goes - #2

Merged
adammharris merged 1 commit into
masterfrom
agent/backlog-check-char-overflows-a-32-bit-sum
Oct 29, 2026
Merged

adammharris merged 1 commit into
masterfrom
agent/backlog-check-char-overflows-a-32-bit-sum

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

Alphabet::check_char (moid/src/alphabet.rs) now takes the remainder by the radix at every step, of the position as well as of the running sum, instead of summing ordinal × position in a usize and reducing once at the end. Every term now stays under radix², so the sum can't overflow on any target. This is the same reduction moid-ts's checkChar already does.

Why

The sum grew with the square of the body's length. On wasm32, where usize is 32 bits, a body of about 17,500 of noid_xdigit's last symbol passed u32::MAX. A debug build panicked, and a release build gave a check character that a 64-bit build and moid-ts disagree with ('w' instead of 'f' at 20,000 symbols). The change gives the same result for every body that did not overflow.

Closes docs/tasks/check-char-overflows-a-32-bit-sum.md. Its status is now done, and it names this fix.

How it was verified

  • Wrote the test first: check_char_of_a_body_past_a_32_bit_sum pins the 20,000-symbol body to 'f' and the 17,000-symbol body to '8'. Before the fix it panicked with an overflow on wasm32-wasip1 (run under Node's node:wasi as the cargo runner). After the fix, all moid lib tests pass on wasm32-wasip1 in both debug and release.
  • Ran every CI job locally:
    • cargo fmt --all --check
    • cargo clippy --workspace --all-targets --all-features -- -D warnings
    • cargo test with default features, --no-default-features and --all-features
    • the moid-ts check, test (49 pass) and build
    • the parity job: regenerated vectors.json and ts-minted.tsv with no drift, then cargo test -p moid-parity
    • the MSRV job: cargo +1.70 check -p moid with default features, --no-default-features and --features js

Alphabet::check_char summed ordinal × position in a usize and reduced
once at the end. On wasm32 that overflowed at about 17,500 symbols of
noid_xdigit: a panic in a debug build, and in a release build a check
character that a 64-bit build and moid-ts disagree with. It now takes
the remainder at every step, as moid-ts does, so the result is unchanged
for every body that did not overflow.

Closes docs/tasks/check-char-overflows-a-32-bit-sum.md.

Behavioural-change: on 32-bit targets, check_char, verify_check and Minter::validate no longer panic (debug) or answer a wrapped check character (release) for bodies whose sum passed u32::MAX; they give what 64-bit builds and moid-ts give.
@adammharris
adammharris merged commit 4f482bd into master Oct 29, 2026
7 checks passed
@adammharris
adammharris deleted the agent/backlog-check-char-overflows-a-32-bit-sum branch October 30, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant