Skip to content
Business logic Audit finding Intermediate

JUSDBank users can bypass individual collateral borrow limits

The JUSDBank contract enforces individual collateral borrow caps only during borrow operations, but not during withdrawals. An attacker can use a flash loan to temporarily deposit extra collateral, borrow beyond the cap, then withdraw the extra collateral to repay the flash loan, leaving an over-cap borrow.

0x52 Follow with Ace-30, GalloDaSballo and 3 others

Originally disclosed on Sherlock

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

Found by

0x52, Ace-30, GalloDaSballo, J4de, carrotsmuggler, peakbolt

Summary

JUSDBank imposes individual borrow caps on each collateral. The issue is that this can be bypassed due to the fact that withdraw and borrow use different methods to determine if an account is safe.

Vulnerability Detail

https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/JUSDBank.sol#L105-L117

    function borrow(
        uint256 amount,
        address to,
        bool isDepositToJOJO
    ) external override nonReentrant nonFlashLoanReentrant{
        //     t0BorrowedAmount = borrowedAmount /  getT0Rate
        DataTypes.UserInfo storage user = userInfo[msg.sender];
        _borrow(user, isDepositToJOJO, to, amount, msg.sender);
        require(
            _isAccountSafeAfterBorrow(user, getTRate()),
            JUSDErrors.AFTER_BORROW_ACCOUNT_IS_NOT_SAFE
        );
    }

When borrowing the contract calls _isAccountSafeAfterBorrow. This imposes a max borrow on each collateral type that guarantees that the user cannot borrow more than the max for each collateral type. The issues is that withdraw doesn't impose this cap. This allows a user to bypass this cap as shown in the example below.

Example: Assume WETH and WBTC both have a cap of 10,000 borrow. The user deposits $30,000 WETH and takes a flashloand for $30,000 WBTC. Now they deposit both and borrow 20,000 JUSD. They then withdraw all their WBTC to repay the flashloan and now they have borrowed 20,000 against $30000 in WETH

Impact

Deposit caps can be easily surpassed creating systematic risk for the system

Code Snippet

https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/JUSDBank.sol#L105-L117

Tool used

Manual Review

Recommendation

Always use _isAccountSafeAfterBorrow

Discussion

JoscelynFarr

fix link: https://github.com/JOJOexchange/JUSDV1/commit/611ce809ab1c3c300d888053bea6960ed69ec3c3 https://github.com/JOJOexchange/JUSDV1/commit/0ba5d98aac0e8109f38ebf2382bf84391a7c846b

IAm0x52

Fixes look good. Borrow specific functions have been replaced with the generic checks, preventing this issue

The original report as published on Sherlock, by 0x52. 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 withdraw function does not call the same safety check (_isAccountSafeAfterBorrow) that enforces per-collateral borrow caps, allowing users to bypass the cap by manipulating collateral balances.

Impact

Deposit caps can be easily surpassed, creating systematic risk for the system.

What the attacker needed

Ability to take a flash loan; Sufficient collateral to initiate borrow

The fix

The withdraw function should use the same safety check (_isAccountSafeAfterBorrow) as the borrow function to enforce per-collateral caps.

How it was found

  1. Deposit $30,000 worth of WETH as collateral.
  2. Take a flash loan of $30,000 worth of WBTC.
  3. Deposit the borrowed WBTC as additional collateral.
  4. Borrow 20,000 JUSD, which exceeds the individual collateral cap because the WBTC is temporarily present.
  5. Withdraw all WBTC collateral to repay the flash loan.
  6. Now the user has borrowed 20,000 JUSD against only $30,000 WETH, bypassing the cap.

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 bank lets you borrow money against collateral, but limits how much you can borrow against each type of collateral. The bank checks this limit when you borrow, but not when you withdraw your collateral. So you can temporarily add extra collateral, borrow more than allowed, then remove the extra collateral, leaving you with a loan that exceeds the limit.

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 0x52

View all

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