Skip to content

Fixes 3 accrual-ordering and finalization findings in staking-v1.clar#49

Merged
hackercf merged 2 commits intomasterfrom
v1.5
Mar 11, 2026
Merged

Fixes 3 accrual-ordering and finalization findings in staking-v1.clar#49
hackercf merged 2 commits intomasterfrom
v1.5

Conversation

@hackercf
Copy link
Contributor

  • stake() — moved accrue-interest before convert-to-staked-lp-tokens so new stakers use a fresh exchange rate instead of a stale one.
  • initiate-unstake() — moved accrue-interest before convert-to-lp-tokens / convert-to-withdrawal-shares so unstakers get the correct LP token amount.
  • finalize-unstake() — removed check-staking-enabled gate so users with pending withdrawals can always finalize, even when staking is disabled or wiped out. Added staking-wiped-out guard to skip unfinalized-withdrawals subtraction when the slash has already zeroed the counters (prevents arithmetic underflow)

Phase 1 security fixes from v2 audit (2026-03-10):

pyth-adapter-v1:
- Reject zero/negative prices before to-uint conversion (H-1, H-9, M-15)
- Bound exponent to [-18, 18] to prevent pow overflow (M-3)
- Cap future timestamps to 60s tolerance (M-2)
- Enforce time-delta range [60s, 7200s] (M-1)
- Remove dead zero-price branch in check-confidence
- Add named constants MAXIMUM_TIME_DELTA, FUTURE_TIMESTAMP_TOLERANCE

linear-kinked-ir-v1:
- Guard utilization-calc division by zero on total-assets (H-2)
- Guard elapsed-block-time underflow with saturation to u0 (H-10)

linear-kinked-ir-utility:
- Same division-by-zero and elapsed-time underflow guards (L-32)

liquidator-v1:
- Unconditionally reject zero repay amount (H-1 defense-in-depth)

tests:
- Add pyth-adapter oracle hardening tests (price, exponent, timestamp, time-delta)
- Add utilization zero-total-assets test
- Fix pyth test helpers to use simnet-aligned timestamps
- Update all test files for time-delta max of 7200
- Add price refreshes for long-running test scenarios

207/207 tests pass. No state-v1 modifications.
…H-4, H-5)

H-3: Move accrue-interest before convert-to-staked-lp-tokens in stake()
so new stakers use a fresh exchange rate.

H-4: Move accrue-interest before convert-to-lp-tokens in initiate-unstake()
so unstakers get the correct LP token amount.

H-5: Remove check-staking-enabled from finalize-unstake() so users with
pending withdrawals can finalize even when staking is disabled or wiped out.
Add staking-wiped-out guard to skip unfinalized-withdrawals subtraction
when the slash has already zeroed the counters (prevents arithmetic underflow).
@hackercf hackercf requested a review from talhasch March 11, 2026 14:14
Copy link
Contributor

@talhasch talhasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hackercf hackercf merged commit 66067ce into master Mar 11, 2026
4 checks passed
@hackercf hackercf deleted the v1.5 branch March 11, 2026 16:50
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.

2 participants