sendParam.minAmountLD slippage setting is too strict
mediumLines of code
Vulnerability details
Impact
sendParam.minAmountLD slippage setting is too strict
Proof of Concept
Across the codebase,
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);
}
}
}
the minAmonutLD and amountLD is set to equal value
However, minAmonutLD served as a slippage control on layerzero v2 side,
and 0% slippage is not always possible, then the cross-chain transaction will always reverted in too strict slippage contract and block asset transfer
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);
}
}
Tools Used
Manual Review
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