# Interest compounding and frequency dependence

Interest math that depends on how often it is applied, or resets that discard remainders

_Area: DeFi accounting and math bugs. Seen in 9 disclosed reports; latest 2026-07-11. Updated 2026-10-23._

## How it works
Interest should depend on elapsed time and rate, not on how often the code touches the balance. The assumption that breaks is "accrual is idempotent over time." When interest is applied per checkpoint, per update, or per call, the result scales with call frequency. A second break: when a period is floored for computation but the stored start time is reset to `now`, the leftover fraction of the interval is silently discarded. Both make the recorded debt drift from the true economic value.

## Where it shows up
- A compounding index updated on every call, alongside a pool or supply side that accrues linearly [E1](https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-10.md)[E3](https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10.md).
- A discrete per-checkpoint compounding formula whose output changes with checkpoint count [E2](https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-1.md).
- A view function and a state-mutating accrual computing the same rate with different formulas [E4](https://bugbountylibrary.com/r/sherlock%3A2023-12-jojo-exchange-update%3AM-1.md).
- Partial repayment folding accrued interest into principal, so future interest compounds [E5](https://bugbountylibrary.com/r/c4%3A2023-01-astaria%3AM-31.md).
- Recursive per-tick loops whose termination predicate is off by one boundary [E6](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.9.md).
- `startTime = block.timestamp` after flooring elapsed intervals [E7](https://bugbountylibrary.com/r/c4%3A2022-12-gogopool%3AM-06.md).
- Two functions computing the same slope/quantity, one missing a denominator or expiry term [E8](https://bugbountylibrary.com/r/sherlock%3A2022-10-astaria%3AM-8.md).

## How to review
Identify every place interest is written and confirm the invariant: total accrued interest over a window equals the formula applied once over that window, independent of how many updates occur. Check that index updates are additive over elapsed time, not multiplicative per call. Diff view vs stored accrual line by line [E4](https://bugbountylibrary.com/r/sherlock%3A2023-12-jojo-exchange-update%3AM-1.md)[E8](https://bugbountylibrary.com/r/sherlock%3A2022-10-astaria%3AM-8.md). For any `start = now` reset, verify the new start is `oldStart + intervals*period`, preserving the remainder [E7](https://bugbountylibrary.com/r/c4%3A2022-12-gogopool%3AM-06.md). Confirm supply and borrow sides use the same accrual model, or that a skim path exists for the delta [E3](https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10.md).

## Variants seen
- Compound debt vs simple pool interest, causing underflow on withdrawal [E1](https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-10.md).
- Frequency-dependent compounding amplifiable by user-triggered checkpoints [E2](https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-1.md).
- Compound borrow vs linear supply leaving unclaimable surplus [E3](https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10.md).
- View/state formula mismatch biasing safety checks [E4](https://bugbountylibrary.com/r/sherlock%3A2023-12-jojo-exchange-update%3AM-1.md).
- Interest folded into principal on partial repay [E5](https://bugbountylibrary.com/r/c4%3A2023-01-astaria%3AM-31.md).
- Off-by-one in recursive compounding loop [E6](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.9.md).
- Interval-start reset burning remainder [E7](https://bugbountylibrary.com/r/c4%3A2022-12-gogopool%3AM-06.md).
- Missing denominator in slope recalculation [E8](https://bugbountylibrary.com/r/sherlock%3A2022-10-astaria%3AM-8.md).

## Impact and severity
Borrowers overpay or the protocol loses interest (up to 71% inflation or 42% loss [E2](https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-1.md)); pools become insolvent or withdrawals revert [E1](https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-10.md)[E8](https://bugbountylibrary.com/r/sherlock%3A2022-10-astaria%3AM-8.md); surplus funds lock permanently [E3](https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10.md). Severity rises when a user can trigger checkpoints at will [E2](https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-1.md) or when the drift feeds safety checks [E4](https://bugbountylibrary.com/r/sherlock%3A2023-12-jojo-exchange-update%3AM-1.md).

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AH-10.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-1.md
- E3: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-10.md
- E4: https://bugbountylibrary.com/r/sherlock%3A2023-12-jojo-exchange-update%3AM-1.md
- E5: https://bugbountylibrary.com/r/c4%3A2023-01-astaria%3AM-31.md
- E6: https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.9.md
- E7: https://bugbountylibrary.com/r/c4%3A2022-12-gogopool%3AM-06.md
- E8: https://bugbountylibrary.com/r/sherlock%3A2022-10-astaria%3AM-8.md
