Lucene search

K
code423n4Code4renaCODE423N4:2023-05-BASE-FINDINGS-ISSUES-38
HistoryJun 02, 2023 - 12:00 a.m.

If no funds are deposited at the beginning, L1-L2 cannot be transferred out

2023-06-0200:00:00
Code4rena
github.com
9
ethereum
vulnerability
mitigation
token transfer
deposits
loss
smart contract

Lines of code

Vulnerability details

Impact

If user transfer tokenA-tokenB from L1 to L2, and the L2 deposits[tokenB][tokenA] is zero at the beginning.It will cause user lossing his funds.

Proof of Concept

First, user transfer TokenA, and it will send Message to L2 and L2 will call finalizeBridgeERC20

    function _initiateBridgeERC20(
        address _localToken,
        address _remoteToken,
        address _from,
        address _to,
        uint256 _amount,
        uint32 _minGasLimit,
        bytes memory _extraData
    ) internal {
        if (_isOptimismMintableERC20(_localToken)) {
            require(
                _isCorrectTokenPair(_localToken, _remoteToken),
                "StandardBridge: wrong remote token for Optimism Mintable ERC20 local token"
            );

            OptimismMintableERC20(_localToken).burn(_from, _amount);
        } else {
            IERC20(_localToken).safeTransferFrom(_from, address(this), _amount);
            deposits[_localToken][_remoteToken] = deposits[_localToken][_remoteToken] + _amount;
        }

        // Emit the correct events. By default this will be ERC20BridgeInitiated, but child
        // contracts may override this function in order to emit legacy events as well.
        _emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData);

        MESSENGER.sendMessage(
            address(OTHER_BRIDGE),
            abi.encodeWithSelector(
                this.finalizeBridgeERC20.selector,
                // Because this call will be executed on the remote chain, we reverse the order of
                // the remote and local token addresses relative to their order in the
                // finalizeBridgeERC20 function.
                _remoteToken,
                _localToken,
                _from,
                _to,
                _amount,
                _extraData
            ),
            _minGasLimit
        );
    }

As we can see, finalizeBridgeERC20() will directly reduce the deposits, but the deposits is zero at the beginning.It will cause user lossing his funds.

function finalizeBridgeERC20(
        address _localToken,
        address _remoteToken,
        address _from,
        address _to,
        uint256 _amount,
        bytes calldata _extraData
    ) public onlyOtherBridge {
        if (_isOptimismMintableERC20(_localToken)) {
            require(
                _isCorrectTokenPair(_localToken, _remoteToken),
                "StandardBridge: wrong remote token for Optimism Mintable ERC20 local token"
            );

            OptimismMintableERC20(_localToken).mint(_to, _amount);
        } else {
            deposits[_localToken][_remoteToken] = deposits[_localToken][_remoteToken] - _amount;//@audit
            IERC20(_localToken).safeTransfer(_to, _amount);
        }

        // Emit the correct events. By default this will be ERC20BridgeFinalized, but child
        // contracts may override this function in order to emit legacy events as well.
        _emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
    }

Tools Used

vs code

Recommended Mitigation Steps

We should check the deposits and add function to add sum of deposits

Assessed type

ETH-Transfer


The text was updated successfully, but these errors were encountered:

All reactions