Skip to content
Business logic Audit finding Intermediate

sendParam.minAmountLD slippage setting is too strict

The contract sets the minimum amount for a cross-chain transfer equal to the exact amount, leaving no slippage tolerance. An attacker could not exploit this directly, but legitimate transfers may revert when the received amount is slightly lower, blocking asset movement.

ladboy233 Follow

Originally disclosed on Code4rena

Submitted by ladboy233

Across the codebase, the minAmonutLD and amountLD is set to equal value:

 if (data.collateralAmount > 0) {
            address collateralWithdrawReceiver = data.withdrawCollateralParams.withdraw ? address(this) : data.user;
            uint256 collateralShare = _yieldBox.toShare(_market.collateralId(), data.collateralAmount, false);

            (Module[] memory modules, bytes[] memory calls) = IMarketHelper(data.marketHelper).removeCollateral(
                data.user, collateralWithdrawReceiver, collateralShare
            );
            _market.execute(modules, calls, true);

            //withdraw
            if (data.withdrawCollateralParams.withdraw) {
                uint256 collateralId = _market.collateralId();
                if (data.withdrawCollateralParams.assetId != collateralId) revert Magnetar_WithdrawParamsMismatch();

                // @dev re-calculate amount
                if (collateralShare > 0) {
                    uint256 computedCollateral = _yieldBox.toAmount(collateralId, collateralShare, false);
                    if (computedCollateral == 0) revert Magnetar_WithdrawParamsMismatch();

                    data.withdrawCollateralParams.lzSendParams.sendParam.amountLD = computedCollateral;
                    data.withdrawCollateralParams.lzSendParams.sendParam.minAmountLD = computedCollateral;
                    _withdrawToChain(data.withdrawCollateralParams);
                }
            }
        }

However, minAmonutLD served as a slippage control on layerzero v2 side, and 0% slippage is not always possible. The cross-chain transaction will always reverted in too strict slippage contract and block asset transfer.

https://github.com/LayerZero-Labs/LayerZero-v2/blob/142846c3d6d51e3c2a0852c41b4c2b63fcda5a0a/oapp/contracts/oft/OFTCore.sol#L345

 function _debitView(
        uint256 _amountLD,
        uint256 _minAmountLD,
        uint32 /*_dstEid*/
    ) internal view virtual returns (uint256 amountSentLD, uint256 amountReceivedLD) {
        // @dev Remove the dust so nothing is lost on the conversion between chains with different decimals for the token.
        amountSentLD = _removeDust(_amountLD);
        // @dev The amount to send is the same as amount received in the default implementation.
        amountReceivedLD = amountSentLD;

        // @dev Check for slippage.
        if (amountReceivedLD < _minAmountLD) {
            revert SlippageExceeded(amountReceivedLD, _minAmountLD);
        }
    }

Recommended Mitigation Steps

Let user input a percentage and compute minAmountLD based on a percentage of slippage user is willing to take risk of.

Assessed type

Token-Transfer

cryptotechmaker (Tapioca) confirmed, but disagreed with severity and commented:

Slippage is only for EVM to Non-EVM transfers. We’re good for now.


The original report as published on Code4rena, by ladboy233. 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

The code sets the minimum received amount equal to the computed amount, providing zero slippage tolerance.

Impact

Cross-chain transfers could always revert when the received amount is even slightly less than the sent amount, blocking asset transfers; the project noted this only affects EVM to non-EVM transfers.

What the attacker needed

Cross-chain transfer to non-EVM chain

The fix

The code should let the user specify a slippage percentage and compute the minimum amount from that percentage.

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 sending tokens across blockchains, the amount that arrives can be slightly less than what was sent due to fees or rounding. A 'slippage' setting lets you accept a small difference. Here the code required the exact same amount, so any tiny difference caused the transfer to fail.

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 ladboy233

View all

47 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.