Skip to content
DoS Audit finding Intermediate

Low TVL and high Leverage Supply will DoS the redeem of Leverage tokens

The redeem function for Leverage tokens can revert due to an underflow when the asset supply is high relative to the total value locked (TVL). An attacker could exploit this to prevent users from redeeming their Leverage tokens.

0xc0ffEE Follow with 0xe4669da, CL001 and 6 others

Originally disclosed on Sherlock

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

Found by

0xc0ffEE, 0xe4669da, CL001, Goran, KupiaSec, dobrevaleri, elvin.a.block, future, zxriptor

Summary

Low TVL and high Leverage Supply might lead to DoS of the Leverage tokens redemption, due to underflow.

Root Cause

In getRedeemAmount, there is multiplication after division, which might lead to underflow. (ref).

This can happen when the assetSupply is higher than the tvl * PRESICION.

Internal Pre-conditions

  1. There should be high Leverage Supply
  2. The Bond supply and the TVL should be just enough, so that the collateral level is above 1.2.

External Pre-conditions

No response

Attack Path

  1. User redeem any number of Leverage Tokens.

Impact

User will be unable to redeem his Leverage tokens.

PoC

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {Test, console} from "forge-std/Test.sol";

import {Pool} from "src/Pool.sol";
import {Token} from "test/mocks/Token.sol";
import {Utils} from "src/lib/Utils.sol";
import {Auction} from "src/Auction.sol";
import {BondToken} from "src/BondToken.sol";
import {PoolFactory} from "src/PoolFactory.sol";
import {Distributor} from "src/Distributor.sol";
import {OracleFeeds} from "src/OracleFeeds.sol";
import {LeverageToken} from "src/LeverageToken.sol";
import {Deployer} from "src/utils/Deployer.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {UpgradeableBeacon} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {MockPriceFeed} from "test/mocks/MockPriceFeed.sol";

contract PoolPoC is Test {
    error ZeroLeverageSupply();

    Pool pool;
    Token reserve;
    BondToken bond;
    LeverageToken lev;

    address governance = address(0x1);
    address user = address(0x2);

    uint256 constant RESERVE_AMOUNT = 13 ether;

    uint256 private constant CHAINLINK_DECIMAL_PRECISION = 10 ** 8;
    uint8 private constant CHAINLINK_DECIMAL = 8;

    function setUp() public {
        vm.startPrank(governance);
        address deployer = address(new Deployer());
        address oracleFeeds = address(new OracleFeeds());

        address poolBeacon = address(new UpgradeableBeacon(address(new Pool()), governance));
        address bondBeacon = address(new UpgradeableBeacon(address(new BondToken()), governance));
        address levBeacon = address(new UpgradeableBeacon(address(new LeverageToken()), governance));
        address distributorBeacon = address(new UpgradeableBeacon(address(new Distributor()), governance));

        reserve = new Token("Balancer Pool Token", "balancerPoolToken", false);
        Token coupon = new Token("Coupon Token", "couponToken", false);

        // Deploy a mock price feed for the reserve token
        MockPriceFeed mockPriceFeed = new MockPriceFeed();
        mockPriceFeed.setMockPrice(100 * int256(CHAINLINK_DECIMAL_PRECISION), uint8(CHAINLINK_DECIMAL));

        // Set the price feed for the reserve token
        OracleFeeds(oracleFeeds).setPriceFeed(address(reserve), address(0), address(mockPriceFeed), 1 days);

        // Deploy the pool factory
        PoolFactory poolFactory = PoolFactory(
            Utils.deploy(
                address(new PoolFactory()),
                abi.encodeCall(
                    PoolFactory.initialize,
                    (governance, deployer, oracleFeeds, poolBeacon, bondBeacon, levBeacon, distributorBeacon)
                )
            )
        );

        // Prepare the pool parameters
        PoolFactory.PoolParams memory params;
        params.fee = 0;
        params.reserveToken = address(reserve);
        params.sharesPerToken = 2500000;
        params.distributionPeriod = 90 days;
        params.couponToken = address(coupon);

        poolFactory.grantRole(poolFactory.GOV_ROLE(), governance);
        poolFactory.grantRole(poolFactory.POOL_ROLE(), governance);

        // Mint enough tokens for the pool deployment
        reserve.mint(governance, RESERVE_AMOUNT);
        reserve.approve(address(poolFactory), RESERVE_AMOUNT);

        pool = Pool(
            poolFactory.createPool(
                params,
                RESERVE_AMOUNT,
                10 * 10 ** 18,
                1000 * 10 ** 18,
                "Bond ETH",
                "bondETH",
                "Leverage ETH",
                "levETH",
                false
            )
        );

        bond = pool.bondToken();
        lev = pool.lToken();

        vm.stopPrank();
    }
    function testLowTvlAndLowBondTokenSupplyWillBlockLevTokenRedemption() public {
        // The Bond and Leverage tokens are minted to the governance, because the pool is deployed by this address
        // Using governance we bypass the need to have PreDeposit contract, which deploys the pool
        // The tokens from governance are sent to the user, simulating the PreDeposit claim functionality
        console.log("Governance lev balance: ", lev.balanceOf(governance));

        vm.startPrank(governance);
        lev.transfer(user, lev.balanceOf(governance));
        vm.stopPrank();

        console.log("User lev balance: ", lev.balanceOf(user));
        console.log("Governance lev balance: ", lev.balanceOf(governance));

        vm.startPrank(user);
        uint256 amountLev = lev.balanceOf(user);
        vm.expectRevert(Pool.ZeroAmount.selector);
        pool.redeem(Pool.TokenType.LEVERAGE, amountLev, 0);
        console.log("User lev balance after redeem: ", lev.balanceOf(user));
        console.log("Pool reserve tokens: ", reserve.balanceOf(address(pool)));

        vm.stopPrank();
    }
}

Logs:

LOGS
 Governance lev balance:  1000000000000000000000
 User lev balance:  1000000000000000000000
 Governance lev balance:  0
 User lev balance after redeem:  1000000000000000000000
  Pool reserve tokens:  13000000000000000000

Mitigation

Diff
if (collateralLevel <= COLLATERAL_THRESHOLD) {
      redeemRate = ((tvl * multiplier) / assetSupply);
    } else if (tokenType == TokenType.LEVERAGE) {
-      redeemRate = ((tvl - (bondSupply * BOND_TARGET_PRICE)) / assetSupply) * PRECISION;
+  redeemRate = ((tvl - (bondSupply * BOND_TARGET_PRICE)) * PRECISION / assetSupply) ;
    } else {
      redeemRate = BOND_TARGET_PRICE * PRECISION;
    }

    if (marketRate != 0 && marketRate < redeemRate) {
      redeemRate = marketRate;
    }

Discussion

sherlock-admin2

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

The original report as published on Sherlock, by 0xc0ffEE. 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

The redeem rate calculation performs division before multiplication, leading to precision loss and underflow when assetSupply exceeds tvl * PRECISION.

Impact

Users are unable to redeem their Leverage tokens, resulting in a denial of service.

What the attacker needed

High Leverage Supply; TVL and Bond supply such that collateral level > 1.2

The fix

The protocol team fixed this issue by changing the order of operations to multiply before dividing.

How it was found

  1. Deploy the pool with specific parameters and a mock price feed.
  2. Transfer Leverage tokens from governance to a user.
  3. User attempts to redeem all Leverage tokens.
  4. The transaction reverts with a ZeroAmount error.

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.

In a smart contract, a calculation for redeeming tokens does division before multiplication, which can cause the result to round down to zero. If the result is zero, the contract may reject the redemption, effectively locking users out of their funds.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xc0ffEE

View all

27 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.