Skip to content
Business logic Audit finding Intermediate

GeneralRepay#repayJUSD returns excess USDC to `to` address rather than msg.sender

The GeneralRepay#repayJUSD function sends any excess USDC to the 'to' address (the repayment recipient) instead of the caller (msg.sender). When repaying on behalf of another user, the caller's excess funds are incorrectly transferred to that user.

0x52 Follow

Originally disclosed on Sherlock

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

Found by

0x52

Summary

When using GeneralRepay#repayJUSD to repay a position on JUSDBank, any excess tokens are sent to the to address. While this is fine for users that are repaying their own debt this is not good when repaying for another user. Additionally, specifying an excess to repay is basically a requirement when attempting to pay off the entire balance of an account. This combination of factors will make it very likely that funds will be refunded incorrectly.

Vulnerability Detail

https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/flashloanImpl/GeneralRepay.sol#L65-L69

        IERC20(USDC).approve(jusdExchange, borrowBalance);
        IJUSDExchange(jusdExchange).buyJUSD(borrowBalance, address(this));
        IERC20(USDC).safeTransfer(to, USDCAmount - borrowBalance);
        JUSDAmount = borrowBalance;
    }

As seen above, when there is an excess amount of USDC, it is transferred to the to address which is the recipient of the repay. When to != msg.sender all excess will be sent to the recipient of the repay rather than being refunded to the caller.

Impact

Refund is sent to the wrong address if to != msg.sender

Code Snippet

https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/flashloanImpl/GeneralRepay.sol#L32-L73

Tool used

Manual Review

Recommendation

Either send the excess back to the caller or allow them to specify where the refund goes

Discussion

JoscelynFarr

fix link: https://github.com/JOJOexchange/JUSDV1/commit/7382ce40dd54f0a396fb5d3f13ab3cfede0493e2

IAm0x52

Fix looks good. Excess USDC is now refunded to msg.sender

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 function transfers excess USDC to the 'to' address instead of refunding the caller (msg.sender).

Impact

If the caller repays on behalf of another user and sends more than the outstanding debt, the excess USDC is sent to the other user rather than refunded to the caller.

What the attacker needed

Caller repays on behalf of another user; caller sends more USDC than needed

The fix

The excess USDC is now refunded to msg.sender.

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.

When you repay a debt for someone else, you might send more money than needed to cover the exact amount. The extra money should go back to you, but in this case it goes to the person whose debt you are paying. This means you could accidentally give your extra funds to someone else.

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.