feat(devtooling): implement formal verification specification for critical functions#293
Merged
Smartdevs17 merged 3 commits intoSmartdevs17:mainfrom Apr 29, 2026
Conversation
…tical functions (Smartdevs17#224) Adds a machine-checkable formal specification suite for all critical lending protocol functions, satisfying the acceptance criteria in Issue Smartdevs17#224. ## What was added ### Spec modules (stellar-lend/contracts/lending/src/spec/) | Module | Function(s) covered | Lemmas | |---------------------|--------------------------------------------|--------| | interest.rs | calculate_interest | I-01…I-08 | | collateral.rs | validate_collateral_ratio | C-01…C-06 | | accounting.rs | borrow / repay (accounting invariants) | A-01…A-08 | | health_factor.rs | compute_health_factor | H-01…H-07 | | liquidation.rs | get_max_liquidatable_amount | L-01…L-06 | | rewards.rs | update_global_index / update_user / claim | R-01…R-07 | | deposit_spec.rs | deposit | D-01…D-07 | | withdraw_spec.rs | withdraw | W-01…W-07 | Total: 56 lemmas, all passing (cargo test --features spec -- spec::). ### Properties proved - Absence of overflow/underflow in all critical arithmetic paths - Correctness of accounting (INV-1…INV-6): borrow/repay are inverses, total debt is bounded by ceiling and never negative - Mathematical correctness of interest formula (5% APY), collateral boundary (150%), health factor boundary, and close-factor formula - Monotonicity of interest (principal & time), health factor (collateral & debt), and reward global index (time) - Edge cases: zero inputs, over-repay, ceiling breach, oracle absence, same-timestamp idempotency, post-claim zeroing ### CI integration (.github/workflows/formal-verification.yml) - spec-lemmas: runs 56 lemma tests on ubuntu + macos for every relevant push/PR - spec-isolation: asserts no spec symbols leak into the production WASM binary - spec-lint: Clippy on spec modules - kani-harnesses: optional manual-dispatch Kani bounded model-checking job ### Documentation (docs/FORMAL_VERIFICATION.md) Full developer guide: how to run, architecture, assumptions, maintained properties, and spec maintenance workflow. ### Spec feature flag Added [features] spec = [] and kani = [] to lending/Cargo.toml. The spec modules are gated under #[cfg(any(test, feature = "spec"))] so they never appear in production WASM. Closes Smartdevs17#224
|
@onelove-dev is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@onelove-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Hi @onelove-dev, This PR could not be merged. Please check for conflicts and resolve them. 🤖 Drips Wave Review Agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a machine-checkable formal specification suite for all critical lending protocol functions, satisfying the acceptance criteria in Issue #224.
What was added
Spec modules (stellar-lend/contracts/lending/src/spec/)
Total: 56 lemmas, all passing (cargo test --features spec -- spec::).
Properties proved
CI integration (.github/workflows/formal-verification.yml)
Documentation (docs/FORMAL_VERIFICATION.md)
Full developer guide: how to run, architecture, assumptions, maintained properties, and spec maintenance workflow.
Spec feature flag
Added [features] spec = [] and kani = [] to lending/Cargo.toml. The spec modules are gated under #[cfg(any(test, feature = "spec"))] so they never appear in production WASM.
Closes #224
Testing