Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

CS - BaseVault out-of-date provider #192

Closed 0xdcota closed 1 year ago

0xdcota commented 1 year ago

Where: https://github.com/Fujicracy/fuji-v2/blob/ab02d2308797577973ac358af8c7aadf973bcec7/packages/protocol/src/abstracts/BaseVault.sol#L487

Description: The BaseVault has the setActiveProvider functions, callable by rebalancer, that allows to change the current provider. The function is called during rebalancing. It is crucial to call this function within one transaction to make the rebalancing process an atomic process. Otherwise, the vault might be used by users after the provider is changed and before the funds are moved, which would result in transactions being reverted (e.g. borrowing from a new provider before it gets collateral).

Recommendation: Make the function internal and call it during the rebalancing process.

0xdcota commented 1 year ago

Notes regarding this vulnerability.

Challenges:

Assumptions:

Facts:

0xdcota commented 1 year ago

With the notes from my previous post I suggest the safest, simplest solution is to change that function setActiveProvider() can only be called by the timelock.

Why this is good:

  1. In case of setting an active provider that has no liquidity, the users will have an open window of time to withdraw (in production).
  2. We can still set and change provider in our test environment.
  3. We keep have the possibility, in production and via timelock, to hard set the active provider in case some future exploit happens with the current provider.

@brozorec @pedrovalido please share your thoughts on this.

brozorec commented 1 year ago

What to do with L82 of RebalancerManager?