Submitted by Lirios, also found by ladboy233, hansfriese, KIntern_NA, csanuragjain, and thecatking
The vault owner has an option to change the adapter for the vault.
The normal mechanism to change adapter is that the change should first be proposed by the owner via proposeAdapter and after a quitPeriod, it can be set via a call to changeAdapter.
After an owner has changed an adapter, any user is still able to call the changeAdapter function again. This will change the adapter to the same adapter, as proposedAdapter variable still has the same value as set by the owner.
This extra call will redeem all funds from the adapter, and deposit again to the same adapter.
When this adapter charges any fees, this will result in a direct loss of assets.
For example Beefy finance has a default withdrawal fee of 0.1%.
When the adapter has been set to a new BeefyAdapter, calling changeAdapter, will do a _protocolWithdraw and _protocolDeposit to deposit/withdraw all assets on the beefyvault. This results in a net loss of 0.1% of those assets, which will go to the beefyVault.
Repeatedly calling changeAdapter can cause a significant direct loss of user funds.
note:
calling changeAdapter before an owner has called proposeAdapter fails because adapter.deposit will revert when adapter is address(0). But it is still recommended to check if proposeAdapter has been called when changeAdapter is executed.
To test the scenario, I have created a new Mock contract to simulate an adapter that charges fees.
test\utils\mocks\MockERC4626WithFees.sol
First, need to add the imports to .\test\vault\Vault.t.sol
and change the test__changeAdapter test in .\test\vault\Vault.t.sol to test the impact of 10 calls to changeAdapter:
Runing this test, results in the vault/adapter assets to have decreased by about 1% (10 times 0.1%).
The output:
Forge
Implement better checks for changeAdapter. It is possible to add an onlyOwner modifier to this function. Other option is to check if proposedAdapterTime is set, and set proposedAdapterTime to 0 after changeAdapter has been called. This will allow only 1 call to changeAdapter for every proposeAdapter call.
RedVeil (Popcorn) confirmed, but disagreed with severity 
LSDan (judge) decreased severity to Medium 
