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