Skip to content

Challenge 30: verify integer logarithms with modular Kani proofs - #788

Draft
adarmaori wants to merge 1 commit into
model-checking:mainfrom
adarmaori:verify-integer-logarithms
Draft

adarmaori wants to merge 1 commit into
model-checking:mainfrom
adarmaori:verify-integer-logarithms

Conversation

@adarmaori

Copy link
Copy Markdown

Implements a candidate solution for Challenge 30: prove exact integer logarithms and safety for all required primitive and unsigned NonZero types, including invalid-input behavior.

Proof structure

  • Add exact input/result contracts for all six decimal helpers and eleven wrappers; verified stubs check helper domains and the wrappers’ unsafe result bounds.
  • Check public decimal APIs through those wrapper contracts. Check binary API bodies directly against the highest-set-bit characterization, including nonzero intrinsic requirements and arithmetic safety.
  • Prove every invalid input reaches the shared panic helper, and independently check the actual no-argument helper panics. This avoids treating an existential symbolic should_panic result as a universal proof.
  • Cover all required signed/unsigned widths and unsigned NonZero variants. Pointer-sized APIs run on 64-bit targets; the documented same-width conversion argument and verified fixed-width wrappers cover the challenge’s 16/32-bit obligations.
  • Keep runtime algorithms unchanged. Document specifications, dependencies, coverage, and reproduction commands in the challenge chapter.

Automation and validation

The existing partitioned Kani checks discover all harnesses. An added step reuses partition 1’s built verifier on each OS to run the complete logarithm suite with invalid-value checks enabled and sharding disabled.

Locally on aarch64 macOS, with the repository-pinned Kani 0.68.0 and CBMC 6.11.0:

./scripts/run-kani.sh --kani-args --harness num::imp::int_log
./scripts/run-kani.sh --kani-args --harness num::imp::int_log -Z valid-value-checks

Both configurations: 79 successfully verified harnesses, zero failures. Formatting and whitespace checks pass; workflow YAML parsing and a source coverage audit pass. Full Rust regression tests and Linux execution have not been run locally and remain for CI.

Review context

This is an independently developed learning exercise and an alternative candidate to the earlier open submissions #749 and #750. Those submissions have review priority under the challenge rules. This draft does not claim acceptance, resolution, or reward priority; the challenge remains marked open.

The contribution is submitted under this repository’s MIT and Apache-2.0 licensing terms.

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