# Funding fee will be zero because of precision loss

Integer division in Velar Artha's utilization/funding-fee math rounds to zero, so funding fees are undercharged and LPs lose ~1% of expected fees.

- Payout: Audit contest
- Severity: medium
- Program: Velar Artha
- Found by: aslanbek
- Disclosed: 2024-08-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-velar-artha-judging/issues/72
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-velar-artha%3AM-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:fee-bypass vuln:precision-loss

**Target:** Vyper perp-DEX fee accounting (params.vy calc_fees)
**Root cause:** long_utilization = base_interest / (base_reserve / 100) and similar divisions round down to 0 when reserve/100 exceeds interest, and the min-fee clamp (10) is applied to borrow fee but funding_fee = borrow_fee * (util_long - util_short) / 100 still collapses to 0.
**Steps:**
1. Configure pool with base_reserve=1000e8, quote_reserve=1_000_000e6, MAX_FEE=100, MIN_FEE=1.
2. Open a long position with min collateral 5e6 at 2x leverage, price 50000.
3. Compute long_utilization = 0.0002e8 / (1000e8/100) = 2e4/1e9 = 0.00002 (rounds down to 0).
4. borrow_long_fee clamps to min 10; funding_fee_long = 10 * (0 - 0)/100 = 0.
5. Mine 1000 blocks; calc_fees(1) returns funding_paid == 0 while borrowing_paid = 50.
**How found:** Reading the fee formula in params.vy and noticing integer division by (reserve/100) truncates to zero for small interest relative to reserve; verified with a pytest PoC asserting funding_paid == 0.
**Exploitation:** Trader opens leveraged positions and holds them; because utilization rounds to zero, funding fees are never charged (or undercharged ~1% at larger scales), so the trader pays less than owed and LPs receive less fee revenue.
**Insight:** In fixed-point fee math, dividing interest by (reserve/100) before multiplying by max_fee loses all precision when interest < reserve/100; check every division's ordering and whether a min-clamp is applied before or after the truncating subtraction.

## Proof of concept (copied exactly from the original report)

**PoC test asserting funding_paid is zero**

```
def test_precision_loss(setup, open,VEL, STX, long, positions, pools):
    setup()
    open(VEL, STX, True, d(5), 10, price=d(50000), sender=long)
    chain.mine(1000)
    fee = positions.calc_fees(1)
    assert fee.funding_paid == 0
```

