Skip to content
Business logic Audit finding Intermediate

burst() does not return eth when action fails

When a batched call in Magnetar.burst() is allowed to fail and carries an ETH value, the failed action's ETH is not refunded and stays in the contract. A malicious user could then spend that stranded ETH through another action that forwards value, effectively stealing it.

bin2chen Follow with ronnyx2017 and rvierdiiev

Originally disclosed on Code4rena

Submitted by bin2chen, also found by ronnyx2017, rvierdiiev, and deadrxsezzz (1, 2)

When executing Magnetar.burst(), the user can specify allowFailure = true. If it fails, it ignores the current _action and execute another _action.

burst() -> _executeCall(_allowFailure).

    function _executeCall(address _target, bytes calldata _actionCalldata, uint256 _actionValue, bool _allowFailure)
        private
    {
        bool success;
        bytes memory returnData;

        if (_actionValue > 0) {
            (success, returnData) = _target.call{value: _actionValue}(_actionCalldata);
        } else {
            (success, returnData) = _target.call(_actionCalldata);
        }

@>      if (!success && !_allowFailure) {
            _getRevertMsg(returnData);
        }
    }

But with the current implementation, if the user also passes _action.value> 0 and _action.allowFailure = true, if the action fails, the _action.value is not returned to the user, it stays in the contract.

Although the owner can retrieve the eth left in the contract via rescueEth(), the eth is not returned to the user until the owner executes rescueEth(). However, before the owner executes rescueEth(), a malicious user can use the contract’s eth directly to execute an action .

For example, by using MagnetarAssetModule.depositRepayAndRemoveCollateralFromMarket() -> _withdrawToChain() -> _lzWithdraw() -> sendPacket{value:??} () to use up eth.

Impact

If the action fails, the eth left in the contract can be stolen by malicious people.

Recommended Mitigation

Recommends the final return of all eth:

    function burst(MagnetarCall[] calldata calls) external payable {
        uint256 valAccumulator;

        uint256 length = calls.length;

        for (uint256 i; i < length; i++) {
.....

        if (msg.value != valAccumulator) revert Magnetar_ValueMismatch(msg.value, valAccumulator);
+       if(address(this).balance>0){
+         msg.sender.call{value:address(this).balance}(""); // return all eth
+       }
      }

Assessed type

Context

cryptotechmaker (Tapioca) confirmed and commented:

PR here.


The original report as published on Code4rena, by bin2chen. 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 failure path in _executeCall skips the revert but never refunds the value attached to the failed call, leaving it in the contract balance.

Impact

ETH from failed actions remains in the contract and could be taken by a malicious user before the owner rescues it.

What the attacker needed

Caller sends ETH with an action; action is marked allowFailure; the action fails

The fix

The burst function should return any remaining ETH balance to the caller after the loop, and the project confirmed a fix was made.

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.

A contract lets a user send several actions in one transaction, each with some ETH attached. If one action is marked as allowed to fail, the code skips the error but also forgets to send that action's ETH back, so the money sits in the contract. Anyone who can make the contract send ETH out could then use that leftover money.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Tapioca Invitational

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.