code-423n4 / 2022-03-lifinance-findings

6 stars 4 forks source link

QA Report #126

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

QA

  1. QA
    1. Coin whitelist for planned improvement
      1. Impact
      2. Proof of Concept
      3. Recommended Mitigation Steps
    2. ExecuteSwap and PostSwapBalance check wrong input
      1. Impact
      2. Recommended Mitigation Steps
    3. Project does not follow clean code style and lack of organization

Coin whitelist for planned improvement

Low Severity

Planned improvement with function signature whitelist is not enough to prevent malicious call through LibSwap.sol and Swapper.sol.

Impact

Attacker can use LiFi contract as call function outside of whitelist function. But without caller msg.sender as LiFi, the fund is safe.

Yet it is possible to create reentrancy attack through this contract token transfer or approval before it call to LibSwap.swap().

Proof of Concept

Without msg.sender as Li.Fi, there is not much to do here except reentrancy back to Li.Fi.

Recommended Mitigation Steps

Add token whitelist as well along with function whitelist.

It would be safe to consider reentrancy guard at the cost of more 40000 gas for each facet.

ExecuteSwap and PostSwapBalance check wrong input

Rating: Low Severity

All Facets are implemented follow these swap token pattern.

function doSomething(
  LiFiData memory _lifiData, // for event
  LibSwap.SwapData[] calldata _swapData, // the swap data
  FacetData memory inputSpecialData
){
  tokenFromInput = inputSpecialData.token;
  // balance token before swap
  uint256 _fromTokenBalance = LibAsset.getOwnBalance(tokenFromInput);
  // Swap.
  _executeSwaps(_lifiData, _swapData);
  // Check balance to see if we have new token that was swapped and return it to user.
  uint256 _postSwapBalance = LibAsset.getOwnBalance(tokenFromInput) - _fromTokenBalance;
  require(_postSwapBalance > 0, "ERR_INVALID_AMOUNT");
  // give token back to user or bridge it over another chain
  // ....
}

The expected behavior is user use UI and the input data would be the same as FacetData made for each facet. But what happen is, attacker can use this to tell swap token unrelated to current facet. Which the same as call anything they want with whitelist address

Impact

This allow attack angle if _executeSwaps does not work correctly (it didn't check swap and balance correctly).

Recommended Mitigation Steps

I assume the expected behavior is user only send token to contract and contract swap that token only. Hence checking tokenFromInput, postswapbalance.

Split this into atomic function to do one thing and use multicall into these function is much better approach to this.

Project does not follow clean code style and lack of organization

Rating: NonCritical

This project break lots of software development practices and design principles which should translated well into security practice.

H3xept commented 2 years ago

Re Coin whitelist for planned improvement

Duplicate of #108

H3xept commented 2 years ago

Re ExecuteSwap and PostSwapBalance check wrong input

Duplicate of #76