Verify Number with Verus - #774
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Verus specification/proof infrastructure around Number (and related f64/BigInt assumptions) while keeping ordinary (non-verification) builds compiling by introducing a no-op verus-shim proc-macro crate. This fits Regorus’ security-critical goal of strengthening numeric correctness guarantees without changing runtime semantics.
Changes:
- Introduces
regorus-verus-shim(proc-macro) to strip#[verus_verify]/#[verus_spec]and eraseproof!blocks whenfeature = "verus"is disabled. - Adds
src/verify/modules with Verus specs/axioms/lemmas forNumber,f64, primitive numeric APIs, andnum_bigint::BigInt, plus a small executablef64test. - Wires verification module into the crate (cfg-gated) and bumps the Verus toolchain/vstd pins (including lockfile updates).
Reviewed changes
Copilot reviewed 16 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| verus-shim/src/lib.rs | No-op proc-macros for Verus attributes and proof!/proof_decl!. |
| verus-shim/Cargo.toml | Declares the shim proc-macro crate (license metadata needs alignment). |
| src/verify/utils.rs | Verus assumptions/specs to support anyhow!/formatting and str::to_ascii_uppercase. |
| src/verify/number_specs.rs | Defines NumberView model and specs (e.g., add_ensures, div_ensures). |
| src/verify/number_proofs.rs | Lemmas bridging Rust division/remainder behavior to Verus models. |
| src/verify/num_assumptions.rs | Assumptions/specs for primitive numeric operations used in proofs. |
| src/verify/mod.rs | Module wiring for verification components (cfg-gated). |
| src/verify/f64_tests.rs | Runtime test justifying a key f64 casting axiom. |
| src/verify/f64_assumptions.rs | Axioms/assumptions for IEEE-like f64 behavior used by Number proofs. |
| src/verify/bigint_proofs.rs | Proof helper for BigInt::bits-related reasoning. |
| src/verify/bigint_assumptions.rs | Large set of assumptions/specs for num_bigint::BigInt. |
| src/number.rs | Annotates Number implementation with Verus specs/proofs; adds a few runtime tests. |
| src/lib.rs | Adjusts crate-level attributes/cfg for verification-only unstable features and lints. |
| Cargo.toml | Adds shim crate dependency; updates pinned vstd version. |
| Cargo.lock | Updates lockfile for new shim crate and updated Verus-related deps. |
| bindings/wasm/Cargo.lock | Lockfile update to include shim + updated Verus deps. |
| bindings/python/Cargo.lock | Lockfile update to include shim + updated Verus deps. |
| bindings/java/Cargo.lock | Lockfile update to include shim + updated Verus deps. |
| bindings/ffi/Cargo.lock | Lockfile update to include shim + updated Verus deps. |
| .gitignore | Ignores Emacs backup files. |
| .github/workflows/verus.yml | Updates Verus release artifact URL/SHA. |
| .github/skills/verus-verification/SKILL.md | Adds guidance doc for Verus verification work in this repo. |
Comments suppressed due to low confidence (1)
src/number.rs:196
- This
proof! { ... }invocation is used as a standalone statement but is missing a trailing semicolon, which can cause a Rust parse error in non-Verus builds (the shim expands to empty, but the parser still requires statement termination).
proof! { axiom_f64_ops_deterministic(); }
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jay Lorch <jaylorch@gmail.com>
Ah, good point. Before we do this, I should talk with Anand Krishnamoorthi (@anakrish) about alternatives, such as taking a dependency on the |
|
Automated Verus proof audit — summary and traceability concern Source: automated formal-analysis review performed by GitHub Copilot. This comment is not authored by Anand Krishnamoorthi (@anakrish). The audit found substantial real proof value: 57 bodies are verified for arithmetic safety; integer However, the PR does not make the proof boundary discoverable. Please add a short proof map covering: method → plain-English theorem → body-proved/external/trusted status → axioms relied upon → relevant lemma. Also mark opaque clauses as |
|
Automated formal-review finding — High: Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). In This is specifically the representation-leaking existential anti-pattern described by the repository's Verus guidance. Please relate BigInt |
|
Automated formal-review finding — High: float-to-integer contracts certify saturated wrong answers Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). The contracts at
Because |
|
Automated formal-review finding — High: Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). At The contracts also expose an |
|
Automated formal-review finding — High: several float specifications only rename opaque behavior Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). In As a result, contracts for |
|
Automated formal-review finding — Medium: totality contracts omit resource failure Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). The contracts for Please state the allocation assumption explicitly, avoid executing the extreme allocation in a unit test, and consider enforcing a shift/exponent resource bound consistent with the repository's resource-limit invariant. |
|
Automated formal-review finding — Medium: bitwise contracts are uninterpreted Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish).
Please give these operations falsifiable semantics, at minimum by proving agreement with primitive signed/unsigned bitwise operations over representable ranges and documenting the extension to arbitrary BigInts. |
|
Automated formal-review finding — Medium: the trusted axiom set has no consistency/vacuity guard Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). The verification relies on 22 axioms and 121 Please document the justification and dependents of each axiom, split broad axioms to the facts actually required, remove unused assumptions, and add an expected-failure consistency probe that calls the trusted axioms and verifies that |
|
Automated formal-review finding — Medium: eight functions are silently outside verification Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish). Verification is opt-in, leaving Please annotate each intentionally unverified function explicitly as external with a reason, and list it in the proposed proof index. This prevents future reviewers from mistaking absence of annotations for verified coverage. |
|
Automated formal-review finding — Medium/Low: trait-level guarantees are disabled without explanation Source: automated GitHub Copilot proof audit; not authored by Anand Krishnamoorthi (@anakrish).
Please explain each disabled trait contract and state in the proof map that these guarantees apply only to statically resolved |
This PR is just an intermediate step in the verification of the project. It is not intended to be the end of the verification process. Soon, we'll be verifying higher-level functions, whose correctness depends on the functions in So I suggest deferring the job of marking the trust boundary until proof work is further along. It will certainly move. |
Even before verification the function had the name |
It's not clear whether the behavior you observe is a bug or not. I agree that if you convert |
Thanks! I didn't realize that I don't understand the point you're making about an |
This is a good idea, which should probably wait for this outstanding Verus PR. Alternatively, I'm starting to wonder if it's a good idea to support floats at all(!) None of the supported operations require floats, and would work fine on rationals. Rational numbers would give us perfect precision. |
Ah, good point. I've removed the unit test that allocates lots of memory. As for limiting the allocation by enforcing a resource bound, that's a design decision I leave to Anand Krishnamoorthi (@anakrish). |
Good idea. Done! |
This can be revisited later in subsequent PRs to see if possible. |
This PR adds specifications for
Numberfunctions and proves that the implementation satisfies them. Some of these specs are self-contained, but most of them refer to specifications described inverify/number_specs.rs. In these specs, aNumberis abstracted as aNumberView, which has two variants: Integer and Float.This PR adds needed assumptions about libraries it depends on, notably
BigNumassumptions inverify/bignum_assumptions.rs,f64assumptions inverify/f64_assumptions.rs, and assumptions about numeric types inverify/num_assumptions.rs.Most of this code was written by AI (GPT 5.6 Sol, Claude Opus 4.8, and Claude Opus 5), with Jay Lorch (@jaylorch) auditing (and occasionally rewriting) the specifications.
This PR doesn't involve any changes to executable code. However, in the course of generating these proofs, AI found four bugs that necessitated changing the code. Those fixes have already been committed to the Regorus repo:
To avoid having a dependency on the
vstdlibrary in non-verification builds, this PR adds averus-shimcrate with procedural macros. These simple procedural macros simply ignore any#[verus_verify]and#[verus_spec]attributes and expandproof!andproof_decl!blocks into nothing.