code-423n4 / 2023-07-tapioca-findings

12 stars 9 forks source link

BigBang Contract: The repay function can be DoSed #64

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/bigBang/BigBang.sol#L728

Vulnerability details

Impact

Users can get DoSed from repaying their debt, which can be very damaging during volatile scenarios.

The same issue is present in the SGLLendingCommon.sol contract _repay function

Proof of Concept

During the _repay function the following code is executed:

userBorrowPart[to] -= part;

It reduces the borrow part of a given user to. The issue arises because the function does not handle the case where part > userBorrowPart[to]; instead, it will fail due to underflow. In volatile scenarios, it is rational to think that users will try to repay all their debt or a big part of it. But, due to the incorrect state handling, an attacker may prevent any user's repayment. For example:

Severity Rationale

Tools Used

Manual Review

Recommended Mitigation Steps

Rewrite the _repay function as:

function _repay(
        address from,
        address to,
        uint256 part
    ) internal returns (uint256 amount) {
        // @audit NOTE: FIX
        if(part > userBorrowPart[to]) {
            part = userBorrowPart[to];
        }

        (totalBorrow, amount) = totalBorrow.sub(part, true);

        userBorrowPart[to] -= part;

        uint256 toWithdraw = (amount - part); //acrrued
        uint256 toBurn = amount - toWithdraw;
        yieldBox.withdraw(assetId, from, address(this), amount, 0);
        //burn USDO
        if (toBurn > 0) {
            IUSDOBase(address(asset)).burn(address(this), toBurn);
        }

        emit LogRepay(from, to, amount, part);
    }

Assessed type

DoS

c4-pre-sort commented 1 year ago

minhquanym marked the issue as low quality report

minhquanym commented 1 year ago

Consider QA

c4-pre-sort commented 1 year ago

minhquanym marked the issue as primary issue

c4-pre-sort commented 1 year ago

minhquanym marked the issue as remove high or low quality report

c4-sponsor commented 1 year ago

0xRektora marked the issue as sponsor confirmed

c4-judge commented 11 months ago

dmvt marked the issue as selected for report