Yul call return value not checked
The Yul call return value in _returnDust was not checked, so if a contract rejected the refund, the dust stayed in the Exchange and could be sent to a later caller. An attacker could cause another user's refund to be lost and later claim those funds.
Originally disclosed on Code4rena
Submitted by rotcivegaf, also found by 0x4non, 0xDecorativePineapple, 9svR6w, adriro, ajtra, aviggiano, brgltd, carlitox477, chaduke, codexploder, corerouter, joestakey, ladboy233, s3cunda, saian, Trust, V_B, and wait
The Yul call return value on function _returnDust is not checked, which could leads to the sender lose funds
Proof of Concept
The caller of the functions bulkExecute and execute could be a contract who may not implement the fallback or receive functions or reject the call, when a call to it with value sent in the function _returnDust, it will revert, thus it would fail to receive the dust ether
Proof:
- A contract use
bulkExecute - One of the executions fails
- The
Exchangecontract send thedust(Exchange balance) back to the contract - This one for any reason reject the call
- The
duststay in theExchangecontract - In the next call of
bulkExecuteorexecutethe balance of theExchangecontract(including the olddust) will send to the new caller - The second sender will get the funds of the first contract
Recommended Mitigation Steps
+ error ReturnDustFail();
+
function _returnDust() private {
uint256 _remainingETH = remainingETH;
+ bool success;
assembly {
if gt(_remainingETH, 0) {
- let callStatus := call(
+ success := call(
gas(),
caller(),
selfbalance(),
0,
0,
0,
0
)
}
}
+ if (!success) revert ReturnDustFail();
}
nonfungible47 (Blur) confirmed and commented:
Mitigation to check call status and revert if unsuccessful was implemented.
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
Likely the contract used a low-level Yul call to return dust without checking its success status, so a failed refund left funds in the contract.
Impact
A contract that rejects the refund could lose its dust ether, which may later be sent to another caller.
What the attacker needed
Caller is a contract that rejects ether; uses bulkExecute or execute
The fix
The mitigation was implemented to check the call status and revert if unsuccessful.
How it was found
- A contract uses bulkExecute
- One of the executions fails
- The Exchange contract sends the dust back to the contract
- The contract rejects the call
- The dust stays in the Exchange contract
- In the next call, the Exchange balance including the old dust is sent to the new caller
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 a smart contract sends ether to another contract, the receiving contract can refuse the payment. If the sender does not check whether the payment succeeded, the ether stays in the sender's account. Later, someone else might receive that leftover ether by mistake.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.