Skip to content

clazel-js-number: array-backed FixedBig, with Kani harnesses - #288

Open
atiernan wants to merge 2 commits into
claude/js-number-kanifrom
claude/js-number-array-big
Open

atiernan wants to merge 2 commits into
claude/js-number-kanifrom
claude/js-number-array-big

Conversation

@atiernan

Copy link
Copy Markdown
Member

Stacked on #274 (claude/js-number-kani): this branch contains its commit (7e7bfa5) plus two more. Merge #274 first, then retarget to main.

What changed

  • FixedBig<N>: an array-backed big integer (fixed.rs) for the exact Number paths (StringToNumber's exact fallback, the formatters, the power tables). Overflowing operations drop limbs and set lost, so every operation is total at every N.
  • StringToNumber now runs on bytes (string_to_number_bytes), since the &str version crashed the Kani compiler in char decoding. tests/trim.rs compares the new trimmer with trim_matches on every Unicode scalar value.
  • Kani harnesses for FixedBig and StringToNumber; proofs header corrected.

What each new harness proves (symbolic inputs, not sampled)

FixedBig at N = 1..3 (unwind 5): the representation invariant holds after every operation, and:

  • from_u128, low_u128, bit_len, bit equal u128 (N=2); cmp_big is u128 order.
  • add_small, add_assign equal u128 addition, with lost exactly on carry out; sub_assign equals saturating u128 subtraction.
  • mul_small: one limb times a word equals the u128 product; total on any 3 limbs times any word.
  • div_small: total on any 3 limbs and any word including zero, remainder below the divisor.
  • shl (any shift of a u64, equals u128 shift below 64), shr (any shift of a u128, sticky bit); both total on any 3 limbs.
  • string_to_number_bytes::<2> (unwind 6) with a table having no Eisel-Lemire entry: total on every byte string of up to 3 bytes over a 12-byte alphabet. A 3-byte literal never reaches the exact path, so that path is not covered.
  • From clazel-js-number: more Kani harnesses for Big, corrected proofs header #274: four Big two-limb harnesses.

Kani found one real bug: add_small with a carry out of the top limb left a zero top limb; fixed by trimming.

Not proven (stated in the proofs header)

FixedBig::divrem, mul_pow10, mul_pow5, div_pow5, to_decimal, decimal_exact, tables(), and the formatters did not finish in CBMC within 7-12 minutes at small bounds; those harnesses were dropped, not weakened. None produced a counterexample. They are covered by tests/fixed.rs and the differential tests only. That N = 2/3 results hold at N = 64 is an argument (all limb access via get/take/zip), not a Kani result. The crate stays at tier 0.

Command results (local, nothing run on CI yet)

  • cargo xtask verify --part crate clazel-js-number --metrics <tmp>: CRATE PART PASSED; Kani: 33 successfully verified harnesses, 0 failures. (Tier 0, so no mutations or conformance run.)
  • cargo test -p clazel-js-number: all pass (differential tests against Rust f64 parsing and Display included; slowest binary 40 s).
  • cargo clippy -p clazel-js-number --all-targets -- -D warnings: clean. cargo fmt --check: clean.
  • cargo xtask check: STATIC CHECKS PASSED.
  • cargo +nightly-2026-08-21 miri test -p clazel-js-number: all pass; slowest test binary 284 s (under 300 s).

CI's full verification has not run on this PR and proof jobs need a full-verification approval.

🤖 Generated with Claude Code

atiernan and others added 2 commits November 22, 2026 08:58
Replaces the Vec-backed Big in StringToNumber's fallback, the formatters and
the power tables with FixedBig<N> (64 limbs for parsing, 32 otherwise; measured
at most 57 and 28). BigInt keeps the unbounded Vec-backed Big, trimmed to the
operations it uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ytes

Byte-level trim and digit helpers replace the str/char calls that crashed the
Kani compiler. Kani found add_small leaving a zero top limb on carry-out; fixed.
The proofs header lists what is proven, at which bounds, and what is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan

Copy link
Copy Markdown
Member Author

Included in #286, which verifies all open phase 7 pull requests together; this merges with it.

This branch has not been deployed

No deployments
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