Funds in the pool could be stolen by exploiting flashSwap in HybridPool
The HybridPool contract used the BentoBox toAmount function to track reserves, which can change when anyone calls harvest to realise strategy profits. An attacker could call harvest during a flash swap callback to reduce the amount of tokens they owed, thereby stealing unrealised yield from the pool.
Submitted by broccoli
Impact
An attacker can call the bento.harvest function during the callback function of a flash swap of the HybridPool to reduce the number of input tokens that he has to pay to the pool, as long as there is any unrealized profit in the strategy contract of the underlying asset.
Proof of Concept
- The
HybridPoolaccounts for the reserve and balance of the pool using thebento.toAmountfunction, which represents the actual amount of assets that the pool owns instead of the relative share. The value oftoAmountcould increase or decrease if thebento.harvestfunction is called (by anyone), depending on whether the strategy contract earns or loses money. - Supposing that the DAI strategy contract of
Bentohas a profit not accounted for yet. To account for the profit, anyone could callharvestonBentowith the corresponding parameters, which, as a result, increases theelasticof the DAI token. - Now, an attacker wants to utilize the unrealized profit to steal funds from a DAI-WETH hybrid pool. He calls
flashSwapto initiate a flash swap from WETH to DAI. First, the pool transfers the corresponding amount of DAI to him, calls thetridentSwapCallbackfunction on the attacker’s contract, and expects that enough DAI is received at the end. - During the
tridentSwapCallbackfunction, the attacker callsbento.harvestto realize the profit of DAI. As a result, the pool’sbento.toAmountincreases, and the amount of DAI that the attacker has to pay to the pool is decreased. The attacker could get the same amount of ETH but paying less DAI by exploiting this bug.
Referenced code:
HybridPool.solL218-L220HybridPool.solL249-L250HybridPool.solL272-L285BentoBoxV1Flat.solL1105BentoBoxV1Flat.solL786-L792BentoBoxV1Flat.solL264-L277
Recommended Mitigation Steps
Consider not using bento.toAmount to track the reservers and balances, but use balanceOf instead (as done in the other two pools).
Stableswap needs to use
toAmountbalances rather shares to work. This issue allows skimming yield profits from the pool. There’s no user funds at risk but still an issue.We plan on resolving this by using a fixed toElastic ratio during the whole swap.
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 pool used a mutable share-to-amount conversion (bento.toAmount) to track reserves, which can be changed mid-transaction by calling harvest, instead of using a fixed ratio or balanceOf.
Impact
The attacker could skim unrealised yield profits from the pool, but according to the project no user funds were at risk.
What the attacker needed
Unrealised profit in the strategy contract; attacker can deploy a contract; attacker can call flashSwap
The fix
The project planned to fix it by using a fixed toElastic ratio during the whole swap.
How it was found
- Ensure the Bento strategy contract for the input token has unrealised profit.
- Call flashSwap on the HybridPool to borrow the output token.
- In the tridentSwapCallback, call bento.harvest to realise the profit and increase toAmount.
- Repay less of the input token because the pool's toAmount is now higher, keeping the difference.
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 flash swap is a loan that must be repaid within the same transaction. The pool calculated how much the attacker owed using a value that could be increased by calling a public function (harvest) during the loan. By doing so, the attacker made it look like the pool had more assets, so they had to repay less and kept the difference.
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.