# Division Before Multiplication Can Lead To Zero Rounding Of Return Amount

In Illuminate's lend() Swivel path, premium/principal division before multiplication rounds returned to zero, losing user funds sent to yield.

- Payout: Contest reward
- Severity: high
- Program: Illuminate
- Credited: kirk-baird
- Disclosed: 2022-08-23
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-06-illuminate-findings/issues/48
- Library page: https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-02
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:precision-loss

**Target:** Lender.sol lend() Swivel order handling
**Root cause:** Integer division `order.premium / order.principal` is performed before multiplying by `(a[i] - fee)`, so when premium < principal the ratio truncates to zero and `returned` becomes zero.
**Steps:**
1. Call `lend()` with a Swivel order where `order.premium < order.principal`
2. Observe `returned += (a[i] - fee) * (order.premium / order.principal)` evaluates `premium/principal` to 0
3. Underlying tokens are transferred in via `Safe.transferFrom` and `ISwivel.initiate` fills orders
4. `yield(u, y, returned, address(this))` is called with returned=0, so no tokens reach yield
**How found:** Code review of the lend() arithmetic; noticed division of premium by principal precedes multiplication, causing truncation when premium < principal.
**Exploitation:** User submits a lend with a Swivel order whose premium is smaller than principal; the truncated ratio zeroes the returned amount, so the underlying transferred in is not forwarded to yield, effectively losing the user's funds.
**Insight:** In Solidity fixed-point math, always multiply before dividing; check ratio computations where the numerator can be smaller than the denominator, since integer truncation silently zeroes downstream amounts.
