code-423n4 / 2022-04-abranft-findings

0 stars 0 forks source link

QA Report #195

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas optimizations:

1. Unnecessary loan parameter comparison in _lend when used in through requestAndBorrow or takeCollateralAndLend

QA Report: Recommandation (No bug found)

I highly recommend the team to remove the ability to do arbitrary function calls on behalf of the NFTPair contract. Use of arbitrary contract call is a very dangerous pattern, it should be avoided unless there's a very strong motive to support it.

Things that can go wrong with it:

  1. user's wallet can be drained if they accidentally approve the NFTPair contract to use their asset. (it should have been approving BentoBox) This can be achieved by calling asset.transferFrom(user, attacker).
  2. potential airdrops or any token will become public for anyone to withdraw.
  3. it's possible that the collateral suffer the same vulnerability as the tUSD bug and could have lead to huge hack in Compound. The exact bug caused by having 2 entry points to a single contract is unlikely to happen with well-known ERC20s again, but there might be more potential issue similar to this one, and the process of adding collateral will need to be better reviewed, potentially the team should not accept any upgradable contracts.
  4. Same thing happen to BentoBoxV1 contract, if the team decide to launch this code base on BentoBoxV1 it should be safe, but if the newer version is upgrdable then this mechanism cannot be trusted, because it's possible that user use different entry points to mess up BentoBox's accounting.

Solution:

If the team added this feature to support token farming or trapped tokens, it would make sense to add onlyOwner sweep function to do that; If it was mainly for interacting with other protocols, I suggest add a custom interface as a middle layer: So only allow the NFTPair contract to call ICallee(callee).ourSpecialCall(data), and for each cool feature you want to support you add a new callee contract which works as a security proxy.

IMO arbitrary calls lead to a huge space of potential vulnerabilities (some of them might still be unknown), so i would suggest to completely remove the possibility of volnerability by replacing it with one of the solution above.

cryptolyndon commented 2 years ago

Seen, thanks