Skip to content

fix(rust): canonicalize bigint argument keys - #280

Draft
lan17 wants to merge 2 commits into
mainfrom
fix/rust-canonical-bigint-keys
Draft

lan17 wants to merge 2 commits into
mainfrom
fix/rust-canonical-bigint-keys

Conversation

@lan17

@lan17 lan17 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Problem

Cross-port testing found that Rust accepted decimal BigInt text such as 0001, -0001, -0 and 000 but used that text unchanged in cache keys. TypeScript, Go and Python use 1, -1, 0 and 0 for the same numeric values.

This violates W02 and the canonical scalar equality confirmed in issue 14. It is separate from the malformed TypeScript ID validation tracked in issue 97.

Change

Type: Bug fix. No design record is needed: this restores the existing contract without changing the public API or accepted input syntax.

  • Normalize BigInt decimal text at the existing scalar conversion boundary: remove leading zeros and spell every zero as 0.
  • Keep every significant digit without parsing into a fixed-width integer. Keep ordinary string arguments, entity IDs and malformed-input rejection unchanged.
  • Add direct Rust API regressions, including 2,000-digit magnitudes, and two fixed shared vectors. Update only the affected Go and Python corpus counts.

The existing Quint normalizedIntegersRetainExactMagnitude invariant requires canonical signs and digits; signedBigintsPreserveEveryDecimalDigitTest and its generated vectors already cover the numeric rule. No new model or generator change is needed for this Rust decimal-text binding: the new shared vectors supply its alternate spellings to every port.

Rolling upgrade and rollback: only noncanonical BigInt argument keys change. They can miss old entries or reuse the existing canonical entry; request/local cache identity, coalescing and cohort selection follow the canonical key. Old padded entries can remain until expiry. Entity watermark keys exclude arguments and remain unchanged. Literal strings and already-canonical BigInts keep their keys.

Ports

Port Status
TypeScript No implementation change; shared vectors pass.
Go No implementation change; shared vectors pass with the updated inventory count.
Rust Normalization fixed; native checks and shared vectors pass.
Python No implementation change; shared vectors pass with the updated inventory count.

Validation

Head: dd2ff4f5c25583fe6237ecf5f6ed2c6af6499cf0

  • Before the fix, cargo test --locked --all-features --test protocol_keys from rust/ at 84b8b11c85738ad505d49519f7114e7fa1fc5033 failed both new API regressions and both new shared vectors.

  • make check-rust: passed on the head inputs, including formatting, clippy, native tests and conformance.

  • corepack pnpm --dir typescript exec vitest run test/formal-protocol-vectors.test.ts --coverage.enabled=false: passed, 1,538 tests.

  • make check-go: passed, including vet, formatting and native tests with race detection.

  • python -m pytest python/tests/test_protocol_vectors.py: passed, 1,537 tests.

  • python -m ruff check python: passed.

  • make audit: passed.

  • The initial hosted Go job stopped at formatting because the updated vector-count line lost its indentation. The base file passed formatting. This head restores that indentation; no Go implementation change was needed.

  • Hosted PR CI passed on this head: CI, Formal smoke, documentation, title and CodeQL.

  • Formal Mutations run 43386609323 on dd2ff4f5c25583fe6237ecf5f6ed2c6af6499cf0: passed in mutations mode. Corpus generation, all four port replay lanes, symbolic checks, all 25 mutation shards (6 TypeScript, 15 Go, 4 Rust), their report merges and the formal-full aggregate passed.

Not run: model checks, the model-fault campaign and optional fresh-seed exploration. These are not required for this port-only bug fix. Every lane required by the Mutations tier passed.

Follow-ups

None.

@codecov-commenter

codecov-commenter commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.77%. Comparing base (22c1f50) to head (dd2ff4f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #280      +/-   ##
==========================================
+ Coverage   94.76%   94.77%   +0.01%     
==========================================
  Files          84       84              
  Lines       13168    13176       +8     
  Branches      805      805              
==========================================
+ Hits        12479    12488       +9     
+ Misses        623      622       -1     
  Partials       66       66              
Flag Coverage Δ
go 93.90% <ø> (+0.04%) ⬆️
python 93.60% <ø> (ø)
rust 94.78% <100.00%> (+<0.01%) ⬆️
typescript 97.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Remove decimal padding and normalize signed zero before key construction. Keep validation and literal string handling unchanged.
@lan17
lan17 force-pushed the fix/rust-canonical-bigint-keys branch from a86f254 to dd2ff4f Compare November 13, 2026 07:26

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.

2 participants