Skip to content

id(web): TS shell-contract checker rejects valid u64 values above 2^53-1 that the Rust checker accepts (seed, sequence, offset) #1441

Closed

Description

@dezren39

Summary

The TypeScript port of the shell contract checker (pkgs/id/web/src/shell-contract.ts) caps every u64 field at Number.MAX_SAFE_INTEGER (2^53−1), while the Rust original (pkgs/id/src/shell_contract.rs) caps u64 at u64::MAX and the contract document (pkgs/id/contract/shell-contract.v1.json) puts no max on most u64 fields. The TS checker therefore reports false violations for contract-valid frames — e.g. an install_begin whose seed is 2^53 or larger, a value class the system itself produces (rand::rng().random::<u64>(), src/world_session/mod.rs:1162).

Evidence (verified on main 95cd41f0, 2026-10-27)

Verbatim shell-contract.ts (sha256 02baac39…, identical both sides) plus the real shell-contract.v1.json, driven under Bun on the laptop (log: goal hidden_files/probe-2026-10-27-laneB-u64/out.log):

client install_begin seed=42:              {"ok":true}
client install_begin seed=9007199254740991 (2^53−1): {"ok":true}
client install_begin seed=9007199254740992 (2^53):   {"ok":false,"error":"`install_begin.seed` must be in 0..=9007199254740991, got 9007199254740992"}
client install_begin seed=u64::MAX (from wire JSON): {"ok":false,"error":"`install_begin.seed` must be in 0..=9007199254740991, got 18446744073709552000"}
server view sequence=u64::MAX (from wire JSON):     {"ok":false,"error":"`view.sequence` must be in 0..=9007199254740991, got 18446744073709552000"}
server view sequence=7: {"ok":true}

Code facts:

  • TS: INTEGER_MAX in shell-contract.ts maps u64 to Number.MAX_SAFE_INTEGER, and checkValue clamps every integer field to min(field.max ?? typeMax, typeMax).
  • Rust: check_value in shell_contract.rs maps FieldType::U64 to u64::MAX; only an explicit contract max narrows it.
  • Contract fields with u64 and no explicit max include install_begin.seed (required), install_chunk.offset, view.sequence, program_changed.sequence, records.sequence, module_info.current_sequence, participant_id, and the optional expires_at / expires_in_secs fields.
  • The one u64 field with an explicit max (install_begin.total_bytes, ≤ 16777216) is unaffected — the cap only bites where the contract leaves the range open, which is exactly where the Rust checker allows the full range.

Why it matters

The contract's stated purpose (module docs, both ports) is that "a new shell proves conformance by running a check instead of reading host code." A shell (or a transcript checker — the Rust side ships check_transcript, the TS side Conformance) built on the TS port will fail frames the Rust host accepts, and its error message asserts a range (0..=9007199254740991) that appears nowhere in the contract — a conformance proof that disagrees with the contract is worse than none, because the failure looks like the frame's fault.

Scope honesty: no production web code imports the TS checker today (only world-contract.test.ts); this is a correctness/parity defect in the conformance library before it gains consumers, not a live user-facing outage — hence priority/low.

Note on precision: a JS consumer parsing wire JSON already loses integer precision above 2^53 (the probe shows u64::MAX arriving as 18446744073709552000). The fix is therefore not "validate the exact value" — it is "do not reject values the contract allows": for u64, a non-negative integer number at or above the safe range cannot be proven out of range in JS and must be accepted (explicit field min/max bounds that lie within the safe range can still be enforced exactly).

Acceptance criteria

  • checkClientFrame accepts install_begin with seed = 2^53 and with the JSON-parsed form of u64::MAX; checkServerFrame likewise accepts a view/records frame whose sequence is at/above 2^53. (Parity with the Rust checker's verdicts on the same frames.)
  • Bounds that are exactly enforceable in JS still are: negative and non-integer values are still rejected for all integer kinds; u16/u32 caps unchanged; explicit contract max values within the safe range (e.g. total_bytes ≤ 16777216) still reject above-max values, including for u64 fields.
  • Error messages for u64 fields no longer cite 9007199254740991 as a contract bound.
  • Regression tests in world-contract.test.ts pin the parity cases above, and a comment at the cap explains the JS precision constraint (mirroring how the Rust side documents its bound).
  • Rust checker and the contract JSON are unchanged.

Activity

  1. developing-today commented on Oct 27, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 27, 2026
  3. dezren39 commented on Oct 27, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

    • Agent: new-issue-creator-code-b
    • Session / ID: new-issue-creator-code-b cron run, 2026-10-27 ~10:34 CDT
    • Found via: filed this run
    • Task: TS shell-contract port (pkgs/id/web/src/shell-contract.ts) caps u64 at Number.MAX_SAFE_INTEGER while the Rust original (pkgs/id/src/shell_contract.rs) caps at u64::MAX and the contract leaves most u64 fields unbounded — verified with verbatim shell-contract.ts + the real contract JSON under Bun on the laptop: install_begin seed=2^53 and seed=u64::MAX (wire-parsed) are rejected with a fabricated 0..=9007199254740991 range; server view sequence=u64::MAX likewise. Probe log: goal hidden_files/probe-2026-10-27-laneB-u64/out.log.
    • Expectation: triage (effort/s, priority/low — conformance-library parity defect, no production consumer yet) — accept JS-unprovable u64 magnitudes, keep exactly-enforceable bounds, pin parity tests in world-contract.test.ts.
    • Links: issue id(web): TS shell-contract checker rejects valid u64 values above 2^53-1 that the Rust checker accepts (seed, sequence, offset) #1441
  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 28, 2026
  5. 49 remaining items

  6. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    work/assignedQueue worker lifecycle state
    effort/sSmall: expected under 2 hours of work
    on Oct 31, 2026
  7. added 2 commits that reference this issue on Oct 31, 2026
  8. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions