# TimeswapConvenience.sol#borrowGivenDebt() Attacker can increase state.y to an extremely large value with a dust amount of assetOut

borrowGivenDebt() in TimeswapConvenience lets an attacker inflate pool.state.y with dust assetOut, overflowing core math and stealing lender funds via inflated interest.

- Payout: Audit contest
- Severity: high
- Program: Timeswap
- Found by: WatchPug
- Disclosed: 2022-03-03
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2022-01-timeswap-findings/issues/169
- Library page: https://bugbountylibrary.com/r/c4%3A2022-01-timeswap%3AH-02
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:precision-loss

**Target:** TimeswapConvenience.sol borrowGivenDebt / BorrowMath
**Root cause:** borrowGivenDebt() lets the caller specify arbitrary interest, so a dust assetOut with huge interest inflates state.y without bounds; state.y is used in unchecked arithmetic in LendMath.check and BorrowMath.check.
**Steps:**
1. Call `borrowGivenDebt()` on TimeswapConvenience with a dust `assetOut` and an extremely large interest parameter.
2. Observe `pool.state.y` becomes near-overflow large.
3. Call `lend()` with a small amount of asset tokens to mint a large amount of Bond (interest) tokens.
4. Redeem/withdraw to extract value from other lenders and LPs.
**How found:** Code review of BorrowMath.sol borrowGivenDebt; noticed caller-controlled interest and unbounded state.y, linked to two prior state.y manipulation findings on TimeswapPair.
**Exploitation:** Attacker inflates state.y via dust borrowGivenDebt, then lends a small amount to receive outsized Bond tokens representing interest, draining lenders/LPs.
**Escalation:** Near-overflow state.y also breaks LendMath.check and BorrowMath.check arithmetic, disabling core protocol features.
**Insight:** When a convenience/helper contract exposes a math function that writes shared pool state, check whether caller-supplied parameters (like interest) are bounded—helper contracts bypass onlyConvenience guards on core.
