fix: resolve 14 audit findings (L-1, M-5, M-16, L-3/4/6/7/10/11/18/23/30/34/36)#52
Open
fix: resolve 14 audit findings (L-1, M-5, M-16, L-3/4/6/7/10/11/18/23/30/34/36)#52
Conversation
…ad-debt (L-1) The old `asserts!` pattern abused the error branch to execute the slash-total-staked-lp-tokens call. Replace with an explicit `if`/`try!` conditional for clarity and proper error propagation.
Prevents potential underflow when the liquidation discount times collateral LTV exceeds the scaling factor.
Compute staked-part as the remainder (interest - lp - protocol) instead of a third independent division, so rounding dust doesn't leak.
The old formula divided by one-12 twice, losing precision. Simplified to a single division by seconds-in-year since rate is already 12-fixed.
The 6th-degree Taylor expansion of e^x diverges for large inputs. Cap rt at MAX-TAYLOR-INPUT (2x in 12-fixed) and return an explicit error instead of silently producing wrong results.
Prevents potential underflow when slashing staked LP tokens if rounding causes active-staked-lp-tokens-to-slash to exceed the total.
…ps (L-11) get-time-now now returns (response uint uint) with ERR-BLOCK-INFO instead of panicking. All callers updated to propagate via try!.
Compute staked-part as remainder (interest - lp - protocol) in both execute-liquidation and socialize-bad-debt paths, matching the L-4 fix in borrower-v1.
Guard against underflow when time-now <= last-updated-at by returning elapsed=0 instead of subtracting.
Prevent third-party callers from claiming rewards on behalf of another user. Only the user themselves can claim (or caller == user when on-behalf-of is none).
The half-up rounding in mul() compounds through 6 taylor terms, systematically inflating the result. Switch to truncation to match standard fixed-point convention.
Prevent same-block borrow-then-liquidate attacks by enforcing a minimum 6-block gap (~1 minute) between a user's borrow and any liquidation attempt on their position.
The 0.5% buffer was too tight for multi-collateral positions where rounding across multiple collateral types could push the post-liquidation health ratio above the threshold, causing the assert to revert.
Cap ir-slope-1, ir-slope-2, and base-ir at MAX-IR-PARAM to prevent governance from setting values that would cause arithmetic overflow in the interest rate calculation, bricking accrual.
b76b776 to
4f9d422
Compare
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.
Summary
Resolves 14 audit findings from the 2026-03-10 security audit across 6 contract files.
MEDIUM
LOW
Files changed
contracts/liquidator-v1.clar— M-5, L-1, L-3, L-18, L-36contracts/modules/linear-kinked-ir-v1.clar— M-16, L-6, L-7, L-34contracts/modules/withdrawal-caps-v1.clar— L-11, L-23contracts/borrower-v1.clar— L-4contracts/staking-v1.clar— L-10contracts/lp-incentives-v2.clar— L-30Test plan
clarinet checkpasses (36 contracts)npm testpasses (211 tests, 15 suites)