# LPs cannot specify min amount received in burn function, causing loss of fund for them

Velar Artha burn() lacks min-amount slippage params, so an LP's withdrawal can be front-run by a profitable position close, cutting payout ~$2500.

- Payout: Audit contest
- Severity: medium
- Program: Velar Artha
- Found by: PASCAL
- Disclosed: 2024-08-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-velar-artha-judging/issues/74
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-velar-artha%3AM-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:race-window vuln:business-logic

**Target:** LP burn function in api.vy / pools.vy (Vyper DEX)
**Root cause:** burn() computes payout as lp_amt * pool_reserve / total_supply with no user-supplied min_base/min_quote, and pool_reserve shrinks when profitable positions close before the burn tx lands.
**Steps:**
1. LP mints 20,000e6 LP with base_reserve=10,000e6, quote_reserve=10,000e6
2. Alice opens long: collateral 1000 STX, LEV 5, price 1
3. Price rises to $2
4. Bob calls `calc_burn(1, 10000e6, 20000e6)` at price 2 -> base 3750 VEL, quote 7500 STX
5. Bob submits `burn(VEL, STX, LP, 10000e6, price=2)`
6. Alice's `close` executes first, reducing pool reserves
7. Bob's burn executes: receives 3875 VEL + 4750 STX (~$12,500) instead of ~$15,000
**How found:** Researcher noted burn payout derives from live pool_reserve/total_supply and that closing profitable positions decreases reserves, so any tx ordering between calc_burn and burn changes the payout; confirmed with a coded PoC in tests/test_positions.py.
**Exploitation:** Attacker/MEV searcher observes a pending LP burn and front-runs it with a profitable position close, shrinking pool_reserve so the victim's burn payout drops; no capital beyond an open position needed.
**Insight:** For AMM/LP withdrawal functions, check whether payout depends on mutable pool state (reserves) without a user-supplied min-out; if calc and execute are separate txs, ordering by other users' closes/opens is a free slippage vector.

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

**Coded PoC test showing LP loss on burn**

```
def test_lost_assets(setup, VEL, STX, lp_provider, LP, pools, math, open, long, close, burn):
    setup()
    #Alice opens position
    open(VEL, STX, True, d(1000), 5, price=d(1), sender=long)
    
    reserve = pools.total_reserves(1)
    assert reserve.base == 10000e6
    assert reserve.quote == 10000e6
    #Bob calls calc_burn, Bob's assets in term of dollar is $15,000
    amts = pools.calc_burn(1, d(10000)  , d(20000), ctx(d(2)))
    
    assert amts.base == 3752500000
    assert amts.quote == 7495000000

    #Alice closes her position
    bef = VEL.balanceOf(long)
    close(VEL, STX, 1, price=d(2), sender=long)
    after = VEL.balanceOf(long)

    vel_bef = VEL.balanceOf(lp_provider)
    stx_bef = STX.balanceOf(lp_provider)

    amts = pools.calc_burn(1, d(10000)  , d(20000), ctx(d(2)))
    assert amts.base == 3877375030
    assert amts.quote == 4747749964
    #Bob's tx will be executed
    burn(VEL, STX, LP, d(10000), price=d(2), sender=lp_provider)

    vel_after = VEL.balanceOf(lp_provider)
    stx_after = STX.balanceOf(lp_provider)


    print("vel_diff:", (vel_after - vel_bef) / 1e6)#3877.37503 VEL
    print("stx_diff:", (stx_after - stx_bef) / 1e6)#4747.749964 STX
```

