Skip to content
Business logic Audit finding Intermediate

Incorrect implementation of the onDropMessage function in the L1ReverseCustomGateway contract

The onDropMessage function in the L1ReverseCustomGateway contract attempts to refund tokens by transferring them, but since tokens are burned on deposit, the contract lacks the tokens to transfer. This prevents users from recovering their tokens after a failed deposit.

0xRajkumar Follow with mstpr-brainbot and sammy

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/66

Found by

0xRajkumar, mstpr-brainbot, sammy

Summary and Vulnerability Detail

In the L1ReverseCustomGateway, tokens are burned during deposit and minted during the finalizeWithdrawERC20 process.

For failed deposits, we have the onDropMessage function to allow the user to retrieve their tokens.

Solidity
    function onDropMessage(bytes calldata _message) external payable virtual onlyInDropContext nonReentrant {
        // _message should start with 0x8431f5c1  =>  finalizeDepositERC20(address,address,address,address,uint256,bytes)
        require(bytes4(_message[0:4]) == IL2ERC20Gateway.finalizeDepositERC20.selector, "invalid selector");

        // decode (token, receiver, amount)
        (address _token, , address _receiver, , uint256 _amount, ) = abi.decode(
            _message[4:],
            (address, address, address, address, uint256, bytes)
        );

        // do dome check for each custom gateway
        _beforeDropMessage(_token, _receiver, _amount);

        IERC20Upgradeable(_token).safeTransfer(_receiver, _amount);

        emit RefundERC20(_token, _receiver, _amount);
    }

It will not work now because instead of using safeTransfer we should mint the tokens to _receiver.

Impact

The impact is high because the dropMessage functionality will never work, preventing the user from recovering their tokens.

Tool used

Manual Review

Recommendation

My recommendation is to use IMorphERC20Upgradeable(_token).mint(_receiver, _amount) instead of transferring the tokens.

References

https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/gateways/L1ReverseCustomGateway.sol

https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/gateways/L1ERC20Gateway.sol#L74-L90

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/morph-l2/morph/pull/562

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

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 onDropMessage function uses safeTransfer to refund tokens, but the tokens were burned during deposit, so the contract does not hold them; it should mint new tokens instead.

Impact

The dropMessage functionality will never work, preventing the user from recovering their tokens.

What the attacker needed

A failed deposit; the onDropMessage function is called

The fix

The fix is to use IMorphERC20Upgradeable(_token).mint(_receiver, _amount) instead of transferring the tokens.

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 deposit tokens, they are destroyed on one chain and recreated on another. If the deposit fails, a special function is supposed to give your tokens back. But this function tries to send you tokens that no longer exist, so it fails and you cannot get your tokens back.

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 0xRajkumar

View all

6 more disclosed reports, best first.

More from MorphL2

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.