Skip to content
Business logic Audit finding Advanced

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.

broccoli Follow

Originally disclosed on Code4rena

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

  1. The HybridPool accounts for the reserve and balance of the pool using the bento.toAmount function, which represents the actual amount of assets that the pool owns instead of the relative share. The value of toAmount could increase or decrease if the bento.harvest function is called (by anyone), depending on whether the strategy contract earns or loses money.
  2. Supposing that the DAI strategy contract of Bento has a profit not accounted for yet. To account for the profit, anyone could call harvest on Bento with the corresponding parameters, which, as a result, increases the elastic of the DAI token.
  3. Now, an attacker wants to utilize the unrealized profit to steal funds from a DAI-WETH hybrid pool. He calls flashSwap to initiate a flash swap from WETH to DAI. First, the pool transfers the corresponding amount of DAI to him, calls the tridentSwapCallback function on the attacker’s contract, and expects that enough DAI is received at the end.
  4. During the tridentSwapCallback function, the attacker calls bento.harvest to realize the profit of DAI. As a result, the pool’s bento.toAmount increases, 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:

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).

maxsam4 (Sushi) confirmed:

Stableswap needs to use toAmount balances 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.

The original report as published on Code4rena, by broccoli. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Ensure the Bento strategy contract for the input token has unrealised profit.
  2. Call flashSwap on the HybridPool to borrow the output token.
  3. In the tridentSwapCallback, call bento.harvest to realise the profit and increase toAmount.
  4. 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.

More by broccoli

View all

16 more disclosed reports, best first.

More from Sushi Trident contest phase 1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.