Skip to content
Business logic Audit finding Intermediate

Rebases can be frontrun with very little token downtime even when warmUpPeriod > 0

A user can stake just before an epoch ends, bypassing the forced rebase in the stake function, then immediately unstake in the next block to collect the rebase rewards without staying staked. This allows the user to get in, collect the rebase, and get out with minimal token downtime.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52, also found by elprofesor

Rebases can be frontrun with very little token downtime even when warmUpPeriod > 0.

Proof of Concept

https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/Staking.sol#L415-L417

https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/Staking.sol#L703

A user can call stake the block before epoch.endTime <= block.timestamp, allowing the user to bypass the forced rebase called in L416 of the the stake function. If warmUpPeriod > 0 then the user will receive a “warmUpInfo” with the value of their deposit. The very next block, the user can then call instantUnstakeCurve.

https://github.com/code-423n4/2022-06-yieldy/blob/524f3b83522125fb7d4677fa7a7e5ba5a2c0fe67/src/contracts/Staking.sol#L600-L627

This will call rebase again in L633 and this time epoch.endTime <= block.timestamp will be true and it will trigger an actual rebase, distributing the pending rewards. _retrieveBalanceFromUser (L617) will then allows the user to unstake all the funds locked in warm up. The issue is that when unstaking it uses userWarmInfo.credits meaning that any rebalance rewards are kept. This allows the user to get in, collect the rebase, then immediately get out.

Recommended Mitigation Steps

Being able to unstake tokens even when in the warm up period is a useful feature but tokens unstaked during that period should not be allowed to accumulate any rebases or it can lead to situations like this. L537-L539 should be changed to: warmUpBalance = userWarmInfo.amount.

toshiSat (Yieldy) acknowledged


The original report as published on Code4rena, by 0x52. 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 unstaking logic uses the warm-up credits amount, which includes pending rebase rewards, instead of the original deposited amount, allowing rewards to be collected without proper warm-up.

What the attacker needed

WarmUpPeriod > 0; ability to stake and unstake

The fix

The warm-up balance should be set to the original deposited amount, not the credits amount, so that tokens unstaked during warm-up do not accumulate rebases.

How it was found

  1. Call stake in the block before epoch.endTime <= block.timestamp, bypassing the forced rebase.
  2. Receive a warmUpInfo with the deposit amount if warmUpPeriod > 0.
  3. In the next block, call instantUnstakeCurve, which triggers a rebase and distributes pending rewards.
  4. Unstake all funds locked in warm up, keeping the rebase rewards.

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 rebase is a reward distribution that increases token balances. The staking contract normally forces a rebase when you stake, but by timing the stake just before the epoch ends, the user avoids that forced rebase. Then, in the next block, they unstake and trigger the rebase, keeping the rewards even though they were only staked briefly.

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 0x52

View all

211 more disclosed reports, best first.

More from Yieldy contest

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.