GlobalVariables::oftOrCollateralReceiveFromOtherChains() always charges twice the collateral on COLLATERAL_TRANSFER, which is not needed
Summary
GlobalVariables::oftOrCollateralReceiveFromOtherChains() frequently occurs losses by forwarding too much ETH as it assumes collateral transfer always happen for the 2 tokens + eth, which is not true as it can just be ETH and it skips collateral transfers when the amount is null. This will happen on liquidations for example as the collateral my just be ETH and it needs to fetch ETH from the other chain, so the other chain will only send ETH and the 2 other collateral transfers can be skipped. However, they will still be payed here, taking the user the loss.
Root Cause
In GlobalVariables.sol:290/300, collateral transfers are always charged even if amounts to send are null.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- Borrower is liquidated and had deposited ETH.
- Chain does not have enough ETH and requests from other chain. It pays for 2 extra collateral transfers.
- Other chain sends ETH and will have leftover native.
Impact
Losses keep being accrued as it overcharges fees.
PoC
See links above.
Mitigation
Check if the amount is null and only charge fees for both collateral tokens if the amount is non null.