Malicious strategy can lead to loss of funds
A malicious strategy contract could manipulate the adapter's storage because the adapter calls the strategy using delegatecall. This allowed the attacker to change values such as performanceFee and highWaterMark, potentially leading to loss of funds.
Submitted by 7siech, also found by imare and fs0c
A malicious strategy has access to the adapter’s storage and can therefore freely change any values.
Proof of Concept
Because AdapterBase calls the Strategy using delegatecall, the Strategy has access to the calling contract’s storage and can be manipulated directly.
In the following proof of concept, a MaliciousStrategy is paired with the BeefyAdapter and when called will manipulate the performanceFee and highWaterMark values. Of course, any other storage slots of the adapter could also be manipulated or any other calls to external contracts on behalf of the msg.sender could be performed.
MaliciousStrategy implementation showing the exploit -
https://gist.github.com/alpeware/e0b1c9f330419986142711e814bfdc7b#file-beefyadapter-t-sol-L18
Adapter helper used to determine the storage slots -
https://gist.github.com/alpeware/e0b1c9f330419986142711e814bfdc7b#file-beefyadapter-t-sol-L65
BeefyAdapterTest changes made to tests -
Adding the malicious strategy - https://gist.github.com/alpeware/e0b1c9f330419986142711e814bfdc7b#file-beefyadapter-t-sol-L123
Adding new test test__StrategyHarvest() executing harvest() -
https://gist.github.com/alpeware/e0b1c9f330419986142711e814bfdc7b#file-beefyadapter-t-sol-L132
Log output - https://gist.github.com/alpeware/e0b1c9f330419986142711e814bfdc7b#file-log-txt
Tools Used
Foundry
Recommended Mitigation Steps
From chatting with the devs, the goal is to mix and match adapters and strategies. I don’t think delegatecall should be used and adapters and strategies should be treated as separate contracts. Relevant approvals should be given individually instead.
RedVeil (Popcorn) acknowledged
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
The adapter uses delegatecall to execute strategy code, giving the strategy full control over the adapter's storage.
What the attacker needed
A malicious strategy contract; the strategy is used by an adapter
The fix
The use of delegatecall should be avoided; adapters and strategies should be separate contracts with individual approvals.
How it was found
- Create a malicious strategy contract that modifies storage slots of the adapter.
- Pair the malicious strategy with the BeefyAdapter.
- Call harvest() on the adapter, which triggers the delegatecall to the strategy.
- The strategy's code executes in the adapter's context and changes performanceFee and highWaterMark.
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.
When one contract calls another with delegatecall, the called code runs in the caller's context, so it can read and write the caller's storage. Here, a strategy contract could change important settings in the adapter, like fees, which could be abused to steal funds.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.