Skip to content
Business logic Audit finding Intermediate

Users are susceptible to back-running when depositing ETH to TridenRouter

The router's deposit functions accept ETH but do not use the actual amount deposited, so users must pre-calculate and send extra ETH. If the exchange rate changes before execution, leftover ETH remains in the router and anyone can back-run to claim it via refundETH.

broccoli Follow

Originally disclosed on Code4rena

Submitted by broccoli

Impact

The _depositToBentoBox and _depositFromUserToBentoBox allow users to provide ETH to the router, which is later deposited to the bento contract for swapping other assets or providing liquidity. However, in these two functions, the input parameter does not represent the actual amount of ETH to deposit, and users have to calculate the actual amount and send it to the router, causing a back-run vulnerability if there are ETH left after the operation.

Proof of Concept

  1. A user wants to swap ETH to DAI. He calls exactInputSingleWithNativeToken on the router with the corresponding parameters and params.amountIn being 10. Before calling the function, he calculates bento.toAmount(wETH, 10, true) = 15 and thus send 15 ETH to the router.
  2. However, at the time when his transaction is executed, bento.toAmount(wETH, amount, true) becomes to 14, which could happen if someone calls harvest on bento to update the elastic value of the wETH token.
  3. As a result, only 14 ETH is transferred to the pool, and 1 ETH is left in the router. Anyone could back-run the user’s transaction to retrieve the remaining 1 ETH from the router by calling the refundETH function.

Referenced code: TridentRouter.sol#L318-L351

Recommended Mitigation Steps

Directly push the remaining ETH to the sender to prevent any ETH left in the router.

maxsam4 (Sushi) confirmed:

I think it’s low risk because it’s basically arbitrage and we have protection for the user in terms of “minOutputAmount”. I will be reworking ETH handling to avoid this issue completely.

alcueca (judge) commented:

It’s a loss of funds, not arbitrage. It should be prevented or documented. Sustained.

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 deposit functions do not use the actual ETH amount received and do not refund excess ETH to the sender, leaving funds in the router.

Impact

Users could lose the excess ETH they sent, which an attacker could take; the report notes this is a loss of funds, not arbitrage.

What the attacker needed

User sends extra ETH to the router; exchange rate changes before execution; attacker can back-run the transaction

The fix

The remaining ETH should be directly pushed to the sender to prevent any ETH left in the router.

How it was found

  1. User calculates the required ETH amount using bento.toAmount and sends that amount to the router.
  2. Before the user's transaction executes, the exchange rate changes (e.g., due to a harvest call), so less ETH is needed.
  3. The router deposits only the needed ETH, leaving the excess in the contract.
  4. An attacker back-runs the user's transaction and calls refundETH to take the leftover ETH.

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 you send cryptocurrency to a smart contract, you often have to send a bit extra to cover fees or price changes. Here, the contract doesn't automatically return the extra, so it sits in the contract. An attacker can watch for such leftovers and quickly take them for themselves.

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.