Funding#requestWithdraw uses incorrect withdraw address
The requestWithdraw function incorrectly uses msg.sender instead of the from address when queuing a withdrawal, so withdrawals initiated on behalf of another user are recorded against the caller. This breaks integrations that rely on initiating withdrawals for other users, potentially stranding funds.
Source: https://github.com/sherlock-audit/2023-12-jojo-exchange-update-judging/issues/53
Found by
0x52, FastTiger, OrderSol, Varun_05, bughuntoor, dany.armstrong90
Summary
When requesting a withdraw, msg.sender is used in place of the from address. This means that withdraws cannot be initiated on behalf of other users. This will break integrations that depend on this functionality leading to irretrievable funds.
Vulnerability Detail
function requestWithdraw(
Types.State storage state,
address from,
uint256 primaryAmount,
uint256 secondaryAmount
)
external
{
require(isWithdrawValid(state, msg.sender, from, primaryAmount, secondaryAmount), Errors.WITHDRAW_INVALID);
state.pendingPrimaryWithdraw[msg.sender] = primaryAmount;
state.pendingSecondaryWithdraw[msg.sender] = secondaryAmount;
state.withdrawExecutionTimestamp[msg.sender] = block.timestamp + state.withdrawTimeLock;
emit RequestWithdraw(msg.sender, primaryAmount, secondaryAmount, state.withdrawExecutionTimestamp[msg.sender]);
}
As shown above the withdraw is accidentally queue to msg.sender NOT the from address. This means that all withdraws started on behalf of another user will actually trigger a withdraw from the operator. The result is that withdraw cannot be initiated on behalf of other users, even if the allowance is set properly, leading to irretrievable funds
Impact
Requesting withdraws for other users is broken and strands funds
Code Snippet
Tool used
Manual Review
Recommendation
Change all occurrences of msg.sender in stage changes to from instead.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid because { This is valid and a dupp of 082 with minimal impact}
detectiveking123
@nevillehuang do you believe this has enough impact to be considered valid?
JoscelynFarr
Fixed PR: https://github.com/JOJOexchange/smart-contract-EVM/commit/82b5c85c9999ace00265382e7d1bc83036685069
IAm0x52
Fix looks good. Now uses from instead of msg.sender
nevillehuang
@detectiveking123 @JoscelynFarr https://github.com/sherlock-audit/2023-12-jojo-exchange-update-judging/issues/30#issuecomment-1927840325
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 code uses msg.sender instead of the from parameter when updating withdrawal state, so withdrawals are always attributed to the caller.
Impact
Withdrawals on behalf of other users cannot be initiated, which breaks integrations and may strand funds.
What the attacker needed
Allowance set for operator; integration calls requestWithdraw for another user
The fix
The code was fixed to use the from address instead of msg.sender when recording withdrawal requests.
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.
In a smart contract, when someone asks to withdraw funds on behalf of another user, the contract should record the request for that other user. Here, it mistakenly records it for the person making the request, so the intended user's withdrawal never happens and their funds can get stuck.
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.