Open code423n4 opened 2 years ago
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).
Duplicate of #130
Warden highlighted the vulnerability in AnyswapFacet
which would allow attacker to grant approval to arbitrary contract.
There can be fund leftover in the contract under normal operation, for example this tx. In fact, ~$300 worth of token is left in the LI.Fi smart contract on ETH mainnet 0x5a9fd7c39a6c488e715437d7b1f3c823d5596ed1 as of block 14597316. I don't think this is High Risk because the max amount lost is no more than allowed slippage, which can be loss to MEV too.
Lines of code
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/AnyswapFacet.sol#L131-L157
Vulnerability details
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Facets/AnyswapFacet.sol#L131-L157
https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Libraries/LibAsset.sol#L59-L70
In the
AnyswapFacet.sol
,_anyswapData.router
is from the caller's calldata, which can really be any contract, including a fake Anyswap router contract, as long as it complies to the interfaces used.And in
_startBridge
, it will grant infinite approval for the_anyswapData.token
to the_anyswapData.router
.This makes it possible for a attacker to steal all the funds from the contract.
Which we explained in [WP-H6], the diamond contract may be holding some funds for various of reasons.
PoC
Given:
startBridgeTokensViaAnyswap()
with a FAKE_anyswapData.router
.transferFrom()
and take all the funds, including the 100 USDC in the contract anytime.Recommendation
_anyswapData.router
rather than trusting user's inputs;approve()
for the amount that required for the current transaction instead of infinite approval.