# updateIRMParams does not call applyInterestForToken before updating irmParams which leads to incorrect calculation of interest rate for subsequent trades.

Predy's updateIRMParams overwrites IRM params without accruing interest first, retroactively applying new rates to the elapsed period and mispricing fees.

- Payout: Audit contest
- Severity: medium
- Program: Predy
- Found by: WinSec
- Disclosed: 2024-07-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-predy-findings/issues/134
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-predy%3AM-02
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** PredyPool AddPairLogic interest rate model params
**Root cause:** updateIRMParams (and updateFeeRatio) overwrite irmParams/feeRatio without calling applyInterestForToken, so the elapsed period since lastUpdateTimestamp is accrued using the new params instead of the old ones.
**Steps:**
1. Observe AddPairLogic.updateIRMParams sets _pairStatus.quotePool.irmParams and basePool.irmParams directly after validateIRMParams, without accruing interest.
2. Note applyInterestForPoolStatus computes interestRate = calculateInterestRate(poolStatus.irmParams, utilizationRatio) * (block.timestamp - lastUpdateTimestamp) / 365 days.
3. Admin calls updateIRMParams raising slope1/slope2.
4. Next trade triggers applyInterestForToken, which accrues the whole elapsed window at the new higher params, inflating interestRate and totalProtocolFee.
5. Same flaw applies to updateFeeRatio.
**How found:** Code reading of the interest accrual path: noticed applyInterestForPoolStatus multiplies by (block.timestamp - lastUpdateTimestamp) using current irmParams, so any param change without prior accrual retroactively reprices the elapsed window.
**Insight:** In any time-weighted accrual (interest, fees, rewards), check every admin setter that mutates the rate/param: if it doesn't checkpoint accrual first, the new value is applied retroactively to the whole elapsed window.

