Add full-precision mulDiv512 stdlib helpers#1802
Conversation
|
Latest update ( Local validation:
|
|
Latest update adds full-precision ceil/floor exactness lemmas:
These mirror the existing 256-bit Validation after this update:
|
|
Docs/API-reference follow-up after reviewing the
Validation passed locally:
|
|
Full local validation after the docs-site API reference update also passed:
|
|
Latest update (
This gives the new 512-bit proof helpers the same one-step ceil/floor shape already available for the existing 256-bit Local validation passed:
|
|
Latest update (
This brings the new Local validation passed:
|
|
Latest update (
This fills the corresponding 512-bit proof API gap next to the existing numerator monotonicity lemmas and mirrors the divisor-antitone shape already available for the 256-bit Local validation passed:
|
|
Latest update (
These avoid re-proving the shared quotient-fit boundary when downstream proofs move between Local validation passed:
|
|
Follow-up (
Validation after this fix passed locally:
|
|
Latest update (
This closes the remaining API parity gap with the existing 256-bit Local validation passed:
|
|
Latest update (
These prove the new Local validation passed:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0863e03. Configure here.
|
Latest update (
These pin the opposite boundary from the existing wide-product fitting regressions: a 512-bit product may exceed 256 bits, but the helper still rejects when the final floor/ceil quotient is above Local validation passed:
|
|
Follow-up (
Validation after this fix passed locally:
|
|
Latest update (
These mirror the existing 256-bit Local validation passed:
|
# Conflicts: # PrintAxioms.lean

Summary
Partially addresses #1761.
Adds proof-facing full-precision multiply-divide helpers for modeling Solidity
Math.mulDiv/FullMath.mulDivsemantics without requiring the intermediate product to fit inuint256:mulDiv512Down? a b cmulDiv512Up? a b cBoth helpers compute
a * bin unbounded natural-number precision and returnnoneonly when the divisor is zero or the final floor/ceil quotient exceedsMAX_UINT256.This intentionally does not add a compiled Yul builtin yet. The docs call out that first-class compiler lowering through a 512-bit division algorithm remains the next #1761 step.
Follow-up hardening adds explicit proof regressions for
MAX_UINT256 * 2 / 2, covering the core #1761 failure mode where the intermediate product exceeds 256 bits but the final quotient fits.Latest update adds
isSome/isNoneiff lemmas for both floor and ceil helpers, so downstream proofs can discharge fit and rejection conditions directly instead of unpackingOptionresults by hand.Validation
lake build Verity.Stdlib.Math Verity.Proofs.Stdlib.Mathlake build Verity.Proofs.Stdlib.Mathlake buildpython3 scripts/generate_print_axioms.pypython3 scripts/generate_print_axioms.py --checkgit diff --checkmake checkNote
Low Risk
Adds new
Stdlib.Mathhelper functions plus accompanying proof/automation lemmas; it does not change existing compiled arithmetic behavior, so risk is mainly API surface/lemma soundness.Overview
Adds new
Stdlib.MathAPIsmulDiv512Down?andmulDiv512Up?that computea*b/cin unboundedNatprecision and returnnoneonly on division-by-zero or when the final floor/ceil quotient exceedsMAX_UINT256.Extends
Verity/Proofs/Stdlib/Math.leanwith a large lemma suite (fit/reject iff characterizations, sandwich bounds, monotonicity/antitonicity, cancellation/zero cases, ceil-vs-floor relationships, and regression proofs for wide intermediate products) and adds automation-friendly mirrors inVerity/Proofs/Stdlib/Automation.lean.Updates generated
PrintAxioms.leancounts and refreshes docs (edsl-api-reference, arithmetic profile, interpreter matrix, roadmap) to document the new full-precision modeling helpers and clarify they are not yet a compiled 512-bit Yul primitive.Reviewed by Cursor Bugbot for commit 0f9480e. Bugbot is set up for automated code reviews on this repo. Configure here.
Additional proof coverage:
mulDiv512Up?_isSome_iff/mulDiv512Up?_isNone_iffmulDiv512Down?_mul_lemulDiv512Down?_lt_succ_mulmulDiv512Up?_mul_gemulDiv512Up?_mul_le_add_predAdditional proof API parity:
mulDiv512Down?_comm/mulDiv512Up?_commValidation after latest update:
lake build Verity.Stdlib.Math Verity.Proofs.Stdlib.Mathlake buildpython3 scripts/generate_print_axioms.py --checkgit diff --check