Closed code423n4 closed 2 years ago
Duplicate of #66
We are aware that the contract allows users to use latent funds, although we disagree on it being an issue as no funds (ERC20 or native) should ever lay in the contract. To make sure that no value is ever kept by the diamond, we now provide refunds for outstanding user value (after bridges/swaps).
Lines of code
https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/Swapper.sol#L12 https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibSwap.sol#L33
Vulnerability details
Impact
LibSwap.swap
only transfers non-native tokens from msg.sender when balance of said token is lesser than requested fromAmont, thus if there are any remaining tokens in the contract, attacker can easily utilize those tokens for swapping and in turn claim ownership of thoseProof of Concept
The following exploit is demonstrated using GenericSwapFacet. But the vulnerability can be triggered from almost every faucet that uses
_executeSwaps
.GenericSwapFacet.swapTokensGeneric
and_lifiData.receivingAssetId
is set to native asset (can be set to any asset except WETH)https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/GenericSwapFacet.sol#L22
LibAsset.getOwnBalance(fromAssetId) < fromAmount
, no WETH will be collected from Alicehttps://github.com/code-423n4/2022-03-lifinance/blob/main/src/Libraries/LibSwap.sol#L42
Tools Used
Manual code review.
Recommended Mitigation Steps
Before doing
_executeSwaps
. the contract should track the preBalance.And use
prebalance - LibAsset.getOwnBalance(fromAssetId) < fromAmount
instead of
LibAsset.getOwnBalance(fromAssetId) < fromAmount