Skip to content
Business logic Audit finding Intermediate

JUSD borrow fee rate is less than it should be

The borrow fee rate calculation in JUSD is incorrect, causing the protocol to charge less than the intended fee. An attacker could borrow JUSD at a lower cost than expected.

BenRai Follow with RaymondFam, Ruhum and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-04-jojo-judging/issues/73

Found by

BenRai, RaymondFam, Ruhum, carrotsmuggler, y1cunhui

Summary

The borrow fee rate calculation is wrong causing the protocol to take less fees than it should.

Vulnerability Detail

The borrowFeeRate is calculated through getTRate():

SOL
    function getTRate() public view returns (uint256) {
        uint256 timeDifference = block.timestamp - uint256(lastUpdateTimestamp);
        return
            t0Rate +
            (borrowFeeRate * timeDifference) /
            JOJOConstant.SECONDS_PER_YEAR;
    }

t0Rate is initialized as 1e18 in the test contracts:

SOL
    constructor(
        uint256 _maxReservesNum,
        address _insurance,
        address _JUSD,
        address _JOJODealer,
        uint256 _maxPerAccountBorrowAmount,
        uint256 _maxTotalBorrowAmount,
        uint256 _borrowFeeRate,
        address _primaryAsset
    ) {
        // ...
        t0Rate = JOJOConstant.ONE;
    }

SECONDS_PER_YEAR is equal to 365 days which is 60 * 60 * 24 * 365 = 31536000:

SOL
library JOJOConstant {
    uint256 public constant SECONDS_PER_YEAR = 365 days;
}

As time passes, getTRate() value will increase. When a user borrows JUSD the contract doesn't save the actual amount of JUSD they borrow, tAmount. Instead, it saves the current "value" of it, t0Amount:

SOL
    function _borrow(
        DataTypes.UserInfo storage user,
        bool isDepositToJOJO,
        address to,
        uint256 tAmount,
        address from
    ) internal {
        uint256 tRate = getTRate();
        //        tAmount % tRate ? tAmount / tRate + 1 : tAmount % tRate
        uint256 t0Amount = tAmount.decimalRemainder(tRate)
            ? tAmount.decimalDiv(tRate)
            : tAmount.decimalDiv(tRate) + 1;
        user.t0BorrowBalance += t0Amount;

When you repay the JUSD, the same calculation is done again to decrease the borrowed amount. Meaning, as time passes, you have to repay more JUSD.

Let's say that JUSDBank was live for a year with a borrowing fee rate of 10% (1e17). getTRate() would then return: $1e18 + 1e17 * 31536000 / 31536000 = 1.1e18$

If the user now borrows 1 JUSD we get: $1e6 * 1e18 / 1.1e18 ~= 909091$ for t0Amount. That's not the expected 10% decrease. Instead, it's about 9.1%.

Impact

Users are able to borrow JUSD for cheaper than expected

Code Snippet

https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/JUSDBank.sol#L274-L286 https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/lib/JOJOConstant.sol#L7 https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/JUSDBank.sol#L37

Tool used

Manual Review

Recommendation

Change formula to: t0Amount = tAmount - tAmount.decimalMul(tRate) where t0Rate is initialized with 0 instead of 1e18.

Discussion

JoscelynFarr

fix link: https://github.com/JOJOexchange/JUSDV1/commit/334fb691eea57a96fb7220e67e31517638725a80

IAm0x52

Fix looks good. Interest is now accumulated with each state update rather than only when the rate is changed.

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

Impact

Users are able to borrow JUSD for cheaper than expected.

What the attacker needed

None

The fix

The formula should be changed to subtract the fee from the borrowed amount, and the initial rate should be set to zero.

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.

The protocol charges a fee for borrowing its stablecoin, but the formula used to calculate the fee is flawed. Instead of charging the full intended percentage, it charges a smaller amount, so borrowers pay less than they should.

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 BenRai

View all

13 more disclosed reports, best first.

More from JOJO Exchange

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.