Skip to content

[tests] crypto suites (bigint/rsa/crypto) not executable: stale unsafe:/-> void syntax #1053

Closed

Description

@eas4ai

Summary

Zero executable coverage of lib/std/crypto/bigint.w (and the same staleness in tests/test_rsa.w, tests/test_crypto.w) at 450733e: with test tests/test_bigint.w fails on syntax drift — unsafe: statement prefix rejected at every call site ("requires a newline and indented block") and -> void ("unknown type 'void'"). The module's arithmetic values spot-check correct against python3 oracles, so this is a coverage gap, not a wrong-code report — but it means neither #1051 nor the fixed-buffer defect above has any executable backstop in-repo.

Notes

Pre-existing drift since 613be15, not caused by the crypto module. Fix is mechanical (current unsafe { } block syntax, removal of -> void), plus promotion of the #1051 vectors (610-bit modpow boundary, oracle-computed) into the suite.

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Established: the three crypto test files do not compile, so lib/std/crypto/bigint.w has no executable coverage. Both reported drift errors reproduce. Two corrections, both making the situation worse than reported: the "fix is mechanical" characterization is incomplete, and there are more blockers than the two named. After fixing unsafe: and -> void, the tests still fail because (a) their extern fn int_to_string/with_eprintln shadow prelude functions, and (b) every i31_* function is module-private, so a separate file that use std.crypto.bigint cannot call them at all. On top of that, the tests/ directory is wired into no test target, so even a compiling file would never run. This is a coverage gap, not a wrong-code report, as the report says.

    Tested.

    Source main @ 5809ac1 (2026-09-14); the three files and bigint.w's private visibility are unchanged since the reported revision 450733e (all date to 613be15)
    Compiler with v0.15.2.1 built from 5809ac1 in a staging worktree
    Platform macOS Darwin 25.6.0 arm64

    Reproductions (with check):

    • tests/test_bigint.w:55: error: unsafe: requires a newline and indented block; use unsafe { ... } or unsafe *ptr (16 unsafe: sites in this file; 5 each in test_rsa.w/test_crypto.w).
    • tests/test_crypto.w:12: error: unknown type 'void'; With uses Unit for no value and c_void for C void pointers (one -> void per file, on extern fn with_eprintln).

    Both match the report. Then, mechanically rewriting test_bigint.w (unsafe: X → unsafe { X }, -> void → -> Unit) and re-checking surfaces the further blockers:

    • error: extern fn 'int_to_string' shadows prelude function 'int_to_string' (and with_eprintln is likewise now a prelude name) — additional drift the report does not mention.
    • After removing those externs: error: symbol 'i31_word_count' is private to module '<embedded-std>/std/crypto/bigint.w' (and the same for every other i31_* call).

    Source facts.

    • All 13 i31_* functions in lib/std/crypto/bigint.w are declared unsafe fn ..., none pub. Per spec §18.3, cross-module access to a non-pub symbol is a compile error, so a file in tests/ that use std.crypto.bigint cannot reach them regardless of syntax. The test was written when it lived alongside the module or before visibility was enforced.
    • The repo's test suite globs live under test/ (singular): test/behavior/*.w, test/spec/*.w, etc. (build.w:2497 onward). No .Test target globs tests/ (plural), where these three files live. The only tests/ references in the build are unrelated glob-tests fixtures written into a temp dir by build/selfhost.w. So these files are not part of with build :test.

    Root cause. Test rot since 613be15 (the BearSSL bigint/RSA port): the tests were never updated for the current unsafe { } block syntax, Unit return type, prelude int_to_string/eprintln, or the module-privacy of i31_*, and were placed in a directory the suite does not scan. No compiler defect. Direct source/check evidence; no debugger needed.

    Why it matters. As the report notes, this is why the serious crypto defects #1051 (mlen>=20 wrongness) and #1052 (mlen>=80 overflow) have no in-repo executable backstop, and why both are green in CI. That is the real cost of the gap.

    Related. #1051, #1052 (the defects this coverage would catch). No open PR.

    Recommendation — champion, but the fix is larger than "mechanical." To get a working, running crypto test:

    1. Give bigint.w a test-visible surface: either mark the needed i31_* entry points pub (they are already unsafe, so callers stay explicit), or add a thin pub test-only API, or co-locate the tests inside the module. Privacy is the load-bearing blocker; syntax is the easy part.
    2. Modernize syntax: unsafe { ... } blocks, -> Unit, and drop the int_to_string/with_eprintln externs in favor of prelude .to_string() / eprintln.
    3. Wire the files into the suite: move them under test/behavior/ (or add a tests/*.w target), so with build :test runs them.
    4. Add the [crypto] i31_from_monty silently wrong for moduli >= 590 bits via #1049 ([u32;80] temp only 20 words zeroed) #1051 vector: a 610-bit modpow (mlen 20, the first failing size) against a python-oracle-computed result, plus a 3072-bit case for [crypto] bigint i31_from_monty fixed [u32;80] temps overflow for moduli above 2449 bits (RSA-3072/4096 admitted by callers) #1052, so both defects gain a regression backstop.

    Acceptance criteria: with build :test compiles and runs a crypto suite that includes an oracle-checked modpow above 576 bits; a red result appears if #1051 or #1052 regresses.

    Not tested. I did not attempt to run the fully-repaired suite end to end (it needs the privacy change to compile at all); I established each blocker by incremental check. Linux/Windows not exercised.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced; none of the three crypto test files compiles.

    $ with test tests/test_bigint.w
    error: unsafe: requires a newline and indented block; use unsafe { ... } or unsafe *ptr
     --> tests/test_bigint.w:55:13
    $ with test tests/test_rsa.w
    error: unsafe: requires a newline and indented block; use unsafe { ... } or unsafe *ptr
     --> tests/test_rsa.w:51:21
    $ with test tests/test_crypto.w
    error: unknown type 'void'; With uses Unit for no value and c_void for C void pointers
     --> tests/test_crypto.w:12:36
    

    post-release: test coverage, and the earlier review found the repair is more than mechanical.

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions