Skip to content
DoS Audit finding Intermediate

Denial-of-Service in the liquidation flow results in the collateral NTF will be stuck in the contract

If an offer's loan-to-value ratio is extremely high, the liquidation price calculation can revert due to division by zero or arithmetic overflow, preventing liquidation. The collateral NFT then remains stuck in the contract permanently.

Inspex Follow with jekapi

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-kairos-judging/issues/76

Found by

Inspex, jekapi

Summary

If the loanTovalue value of the offer is extremely high, the liquidation flow will be reverted, causing the collateral NTF to persist in the contract forever.

Vulnerability Detail

The platform allows users to sign offers and provide funds to those who need to borrow assets.

In the first scenario, the lender provided an offer that the loanTovalue as high as the result of the shareMatched is 0. For example, if the borrowed amount was 1e40 and the offer had a loanTovalue equal to 1e68, the share would be 0.

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/BorrowLogic/BorrowHandlers.sol#L47

As a result, an arithmetic error (Division or modulo by 0) will occur in the price() function at line 50 during the liquidation process.

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/AuctionFacet.sol#L34-L55

In the second scenario, if the lender's share exceeds 0, but the offer's loanToValue is extremely high, the price() function at line 54 may encounter an arithmetic error(Arithmetic over/underflow) during the estimatedValue calculation.

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/AuctionFacet.sol#L54

Poof of Concept

kairos-contracts/test/BorrowBorrow.t.sol

Solidity
function testBorrowOverflow() public {
    uint256 borrowAmount = 1e40;
    BorrowArg[] memory borrowArgs = new BorrowArg[](1);
    (, ,uint256 loanId , ) = kairos.getParameters();
    loanId += 1;

    Offer memory offer = Offer({
            assetToLend: money,
            loanToValue: 1e61,
            duration: 1,
            expirationDate: block.timestamp + 2 hours,
            tranche: 0,
            collateral: getNft()
        });
    uint256 currentTokenId;

    getFlooz(signer, money, getOfferArg(offer).amount);

    {
        OfferArg[] memory offerArgs = new OfferArg[](1);
        currentTokenId = getJpeg(BORROWER, nft);
        offer.collateral.id = currentTokenId;
        offerArgs[0] = OfferArg({
            signature: getSignature(offer),
            amount: borrowAmount,
            offer: offer
        });
        borrowArgs[0] = BorrowArg({nft: NFToken({id: currentTokenId, implem: nft}), args: offerArgs});
    }

    vm.prank(BORROWER);
    kairos.borrow(borrowArgs);

    assertEq(nft.balanceOf(BORROWER), 0);
    assertEq(money.balanceOf(BORROWER), borrowAmount);
    assertEq(nft.balanceOf(address(kairos)), 1);

    vm.warp(block.timestamp + 1);
    Loan memory loan = kairos.getLoan(loanId);
    console.log("price of loanId", kairos.price(loanId));
}

Impact

The loan position will not be liquidated, which will result in the collateral NTF being permanently frozen in the contract.

Code Snippet

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/BorrowLogic/BorrowHandlers.sol#L47

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/AuctionFacet.sol#L50

https://github.com/sherlock-audit/2023-02-kairos/blob/main/kairos-contracts/src/AuctionFacet.sol#L54

Tool used

Manual Review

Recommendation

We recommend adding the mechanism during the borrowing process to restrict the maximum loanToValue limit and ensure that the lender's share is always greater than zero. This will prevent arithmetic errors.

Discussion

npasquie

similar to #34

npasquie

fixed here https://github.com/kairos-loan/kairos-contracts/pull/52

IAm0x52

Fix looks good. Shares lent are now required to be above a minimum threshold. In conjunction with the change limiting users to only 1 loan offer this eliminates the potential for lender's shares being 0.

The original report as published on Sherlock, by Inspex. 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 contract does not validate that the loan-to-value ratio is within safe bounds, so extreme values cause division by zero or arithmetic overflow during price calculation.

Impact

The loan cannot be liquidated, so the collateral NFT is permanently frozen in the contract.

What the attacker needed

A signed offer with extremely high loan-to-value; borrower accepts the offer and deposits NFT

The fix

The borrowing process should restrict the maximum loan-to-value ratio and ensure the lender's share is always greater than zero; the report states this was fixed by requiring shares above a minimum threshold.

How it was found

  1. Create an offer with an extremely high loan-to-value ratio.
  2. Borrow assets using the offer, depositing an NFT as collateral.
  3. Wait until the loan is due for liquidation.
  4. Attempt to liquidate the loan; the price calculation reverts due to a maths 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.

A smart contract lets people borrow assets by putting up an NFT as collateral. If the loan terms include an extremely high loan-to-value ratio, the code that calculates the liquidation price can crash with a maths error. Because liquidation is blocked, the NFT collateral can never be recovered and stays locked in the contract.

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 Inspex

View all

2 more disclosed reports, best first.

More from Kairos Loan

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.