# Sandwich attack on loan fulfillment will temporarily prevent users from accessing their borrowed funds

Size checks Aave liquidity but never reserves it, so an attacker can sandwich a loan by pulling liquidity and block the borrower's withdrawal.

- Payout: Audit contest
- Severity: medium
- Program: Size
- Found by: gesha17
- Disclosed: 2024-09-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-06-size-findings/issues/152
- Library page: https://bugbountylibrary.com/r/c4%3A2024-06-size%3AM-08
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:business-logic vuln:dos

**Target:** Size.sol sellCreditMarket / Aave variable pool liquidity check
**Root cause:** sellCreditMarket only validates that the Aave variable pool holds enough underlying balance via validateVariablePoolHasEnoughLiquidity() but never removes/reserves that liquidity; the borrower receives borrowAToken and must withdraw in a separate tx.
**Steps:**
1. Attacker frontruns: supplies liquidity to the Aave variable pool so the pool balance exceeds the loan amount.
2. Victim calls `sellCreditMarket()`; `validateVariablePoolHasEnoughLiquidity(amount)` passes because balance >= amount, but no liquidity is reserved.
3. Attacker backruns: withdraws the supplied liquidity, dropping pool balance below the amount.
4. Victim's later `borrowAToken` withdrawal reverts until pool liquidity is restored.
**How found:** Code reading: noticed sellCreditMarket calls validateVariablePoolHasEnoughLiquidity after execution and only reads balanceOf(variablePool) rather than transferring/removing liquidity, and that borrowAToken (not underlying) is transferred to the borrower, implying a separate withdrawal step.
**Exploitation:** Attacker deposits liquidity before the victim's loan tx and removes it immediately after, leaving the pool under-collateralized relative to the loan; victim cannot redeem borrowed funds until external liquidity returns.
**Insight:** When a protocol gates an action on an external pool's balanceOf instead of pulling/reserving funds atomically, the check is sandwichable: look for validate-then-defer patterns where the actual liquidity transfer happens in a later user transaction.

