The guardian may not be able to blacklist a protocol
The blacklistProtocol function can revert when the protocol's current balance exceeds the cached total underlying, preventing the guardian from blacklisting a malicious protocol. The protocol continues to receive funds during rebalancing.
Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/320
Found by
Jeiwan
Summary
An attempt to blacklist a protocol may revert in some situations, not making it possible for the guardian to remove a malicious or a hacked protocol from the system. The protocol will keep receiving funds during rebalancing.
Vulnerability Detail
The Vault.blacklistProtocol function allows the guardian to blacklist a protocol: a blacklisted protocol will be excluded from receiving funds during rebalancing. When a protocol is blacklisted, vault funds need to be removed from it and updated the cached amount of funds in the protocol. However, the latter can cause a revert when balanceUnderlying(_protocolNum) is greater than savedTotalUnderlying, and this can realistically happen in any protocol.
savedTotalUnderlying is set at a final step of rebalancing–in the Vault.rebalance function: its value is the sum of all funds deposited to underlying protocols. When a protocol is blacklisted, its underlying balance is re-calculated and subtracted from savedTotalUnderlying. In situations when the blacklisted protocol is the only protocol that has allocations (allocations are chosen by gamers based on the performance of different protocols, thus one, the most profitable, protocol can be the only protocol of a vault), it's current underlying balance will be greater than the cached one (savedTotalUnderlying) because the protocol will accrue interest between the moment savedTotalUnderlying was calculated and the moment it's being blacklisted. Thus, the balanceProtocol variable in the blacklistProtocol function can be greater than savedTotalUnderlying, which will case a revert. The function will keep reverting until there's another protocol with allocations or until there are no allocations in the vault at all (which solely depends on gamers, not the guardian).
Impact
The guardian may not be able to blacklist a malicious or a hacked protocol, and the protocol will keep receiving funds during rebalancing.
Code Snippet
Tool used
Manual Review
Recommendation
In the Vault.blacklistProtocol function, consider checking if savedTotalUnderlying is greater or equal to balanceProtocol: if it's not so, consider setting its value to 0, instead of subtracting balanceProtocol from it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the subtraction of the protocol's balance from the cached total underlying underflows when the balance is greater than the cached total.
Impact
The guardian may not be able to blacklist a malicious or hacked protocol, and it will keep receiving funds during rebalancing.
What the attacker needed
Guardian role; protocol has accrued interest; protocol is the only one with allocations
The fix
The function should check if savedTotalUnderlying is greater than or equal to balanceProtocol; if not, set savedTotalUnderlying to 0 instead of subtracting.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A guardian tries to block a bad protocol, but the blocking action can fail because the numbers don't match up. The protocol keeps getting money from the vault.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.