Skip to content
Smart contracts Audit finding Intermediate

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.

rotcivegaf Follow

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

Exchange.sol#L212-L227

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 Exchange contract send the dust(Exchange balance) back to the contract
  • This one for any reason reject the call
  • The dust stay in the Exchange contract
  • In the next call of bulkExecute or execute the balance of the Exchange contract(including the old dust) 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.


The original report as published on Code4rena, by rotcivegaf. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. A contract uses bulkExecute
  2. One of the executions fails
  3. The Exchange contract sends the dust back to the contract
  4. The contract rejects the call
  5. The dust stays in the Exchange contract
  6. 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.

More by rotcivegaf

View all

4 more disclosed reports, best first.

More from Blur Exchange contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.