Skip to content
Business logic Audit finding Intermediate

Missing transaction expiration check result in reward tokens selling at a lower price

The protocol's swap function sets the Uniswap deadline to the current block timestamp, effectively disabling the transaction expiration check. This allows a sandwich attack to sell reward tokens at an outdated, lower price, reducing yield for users.

Bauer Follow with Jeiwan and PRAISE

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/323

Found by

Bauer, Jeiwan, PRAISE

Summary

Selling of reward tokens misses the transaction expiration check, which may lead to reward tokens being sold at a price that's lower than the market price at the moment of a swap. Gamers and depositors may receive less yield than expected.

Vulnerability Detail

The protocol integrates with third-party vaults (e.g. Aave, Compound, Yearn, etc.), in which it deposits user funds to generate yield. Some of the third-party vaults (at the moment, only Compound) reward their users with protocol tokens (COMP, in the case of Compound). These tokens can be claimed and sold for the underlying token of the vaults (e.g. USDC):

  1. during rebalancing;
  2. at any moment by calling claimTokens.

The Swap.swapTokensMulti function, which is responsible for selling tokens on Uniswap, sets the deadline argument of the exactInput call to block.timestamp–this basically disables the transaction expiration check because the deadline will be set to whatever timestamp the block including the transaction is minted at.

Transaction expiration check (implemented in Uniswap via the deadline argument) allows users of Uniswap to protect from selling tokens at an outdated price that's lower than the current price. Consider this scenario:

  1. The Vault.rebalance function is called on the Ethereum mainnet.
  2. Before the transaction is mined, there's a rapid increase of gas cost. The transaction remains in the mempool for some time since the gas cost paid by the transaction is lower than the current gas price.
  3. While the transaction is in the mempool, the price of the reward token increases.
  4. After a while, gas cost drops and the transaction is mined. Since the value of amountOutMinimum was calculated based on an outdated reward token price which is now lower than the current price, the swapping is sandwiched by a MEV bot. The bot decreases the price of the reward token in a Uniswap pool so than the minimum output amount check still holds and earns a profit from the swapping happing at a lower price.
  5. As a result of the sandwich attack, reward tokens are swapped at an outdated price, which is now lower than the current price of the tokens. The protocol (and thus gamers and depositors) earn less yield than they could've received by selling the tokens at the current price.

Impact

Claiming and selling reward tokens can be exploited by a sandwich attack. Gamers and depositors may receive less yield than expected due to reward tokens have been sold at an outdated price.

Code Snippet

  1. ClaimTokens sells the reward token for the underlying token:

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Vault.sol#L404

  1. ClaimToken is called during rebalancing:

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Vault.sol#L141

  1. The proceedings from selling reward tokens increase the total number of underlying tokens during rebalancing:

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Vault.sol#L158-L164

  1. When Swap.swapTokensMulti calls Uniswap's exactInput, it sets deadline to block.timestamp, which disables the transaction expiration protection:

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/libraries/Swap.sol#L88

Tool used

Manual Review

Recommendation

Consider a reasonable value to the deadline argument. For example, Uniswap sets it to 30 minutes on the Etehreum mainnet and to 5 minutes on L2 networks. Also consider letting the guardian and/or the DAO change the value when on-chain conditions change and may require a different value.

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

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

Impact

Reward tokens can be sold at an outdated, lower price via a sandwich attack, so gamers and depositors may receive less yield than expected.

What the attacker needed

Protocol uses Uniswap for swaps; reward tokens are sold via swaps; transaction delayed in mempool

The fix

The deadline argument should be set to a reasonable value, such as 30 minutes on Ethereum mainnet and 5 minutes on L2 networks, and possibly made adjustable by the guardian or DAO.

How it was found

  1. The Vault.rebalance function is called on Ethereum mainnet.
  2. Gas costs rise, so the transaction stays in the mempool.
  3. The price of the reward token increases while the transaction waits.
  4. Gas costs drop and the transaction is mined; a MEV bot sandwiches it, profiting from the outdated price.

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 swap tokens on a decentralized exchange, you can set a deadline to prevent your trade from executing if it's delayed. Here, the deadline was set to the current time, so the protection was effectively turned off. This let an attacker manipulate the price and buy the tokens cheaply, meaning users got less money than they should have.

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 Bauer

View all

17 more disclosed reports, best first.

More from Derby

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.