Skip to content
Business logic Audit finding Intermediate

WStable Contract Invariant Break in isSaving=true Mode

The WStable contract's mint and burn functions with isSaving=true convert between shares and assets asymmetrically, so when yield accrues between a user's deposit and withdrawal, the user receives fewer vault shares than they deposited. An attacker could exploit this to cause users to permanently lose a portion of their shares proportional to the yield accrued.

8olidity Follow with Berring, DharkArtz and 15 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-08-usg-tangent-judging/issues/293

This issue has been acknowledged by the team but won't be fixed at this time.

Found by

8olidity, Berring, DharkArtz, ExtraCaterpillar, Pro_King, SiddiqX7860, Yaneca_b, ami, befree3x, coin2own, covey0x07, curly, deadmanwalking, glitch-Hunter, itsRavin, jayjoshix, udo, vivekd

Summary

The WStable contract breaks the 1:1 invariant between vault shares and WStable tokens when using the isSaving=true mode. When yield accrues in the underlying ERC4626 vault between mint and burn operations, users permanently lose a portion of their vault shares, with the loss percentage directly proportional to the yield accrual.

Root Cause

The root cause is an asymmetric conversion logic between the mint and burn functions when isSaving=true, specifically when user shares have already accrued yield:

  1. In mint(amountIn, receiver, true):

    • User provides vault shares (amountIn) that have already accrued yield
    • Contract converts these yield-bearing shares to assets using previewMint(amountIn)
    • User receives WStable tokens equal to the asset value(as asset value is more then shares already), capturing the accrued yield
  2. In burn(amount, receiver, true):

    • User provides WStable tokens (amount) representing assets
    • Contract converts assets back to shares using previewWithdraw(amount)
    • User receives vault shares

When additional yield accrues between these operations, the share-to-asset ratio increases further, causing users to receive fewer shares than they initially deposited. This asymmetric conversion creates a permanent loss of shares for users, as the contract fails to account for the fact that the user's original shares already had accrued yield at the time of deposit.

Invariant from README : Users are always able to withdraw 1:1 their deposits NB : This one is not completely true. Because of rounding, it can even be false. The consequence of this is that the last user to withdraw its WStable will not be able to burn everything but everything - numberOfBurnSinceCreation * 1wei. This is mitigated because we'll mint in the WStable few K$ to initiate the associated LP that we'll never remove. So we have a lot of room before this error occurs.

Internal Pre-conditions

  • User must use the isSaving=true mode in both mint and burn functions
  • The user's shares must have already accrued some yield before deposit
  • Additional yield must accrue in the vault between the user's mint and burn operations

External Pre-conditions

.

Attack Path

  1. User has vault shares that have already accrued yield (ratio 1:1.1)

    • Each share is worth 1.1 assets due to previous yield accrual
  2. User deposits these yield-bearing vault shares using mint(shares, user, true)

    • User transfers X vault shares to the contract
    • Contract calculates asset value: assets = vault.previewMint(X) = X * 1.1
    • User receives X * 1.1 amount of WStable tokens
  3. Additional yield accrues in the underlying vault (this happens naturally over time)

    • Share-to-asset ratio increases from 1:1.1 to 1:1.2 (where each share is now worth 1.2 assets)
  4. User burns WStable tokens using burn(assets, user, true)

    • User burns X * 1.1 amount of WStable tokens
    • Contract calculates share value: shares = vault.previewWithdraw(X * 1.1) = (X * 1.1) / 1.2 = X * 0.9167
    • User receives X * 0.9167 amount of vault shares, which is less than the original X
  5. Result: User has permanently lost vault shares (8.33% loss)

Impact

  • Loss of user funds: Users permanently lose a portion of their vault shares proportional to the yield accrual
  • In our test scenario, a user lost 8.33% of their shares when the share-to-asset ratio changed from 1:1.1 to 1:1.2
  • This issue affects all users who use the isSaving=true mode, which is specifically designed for share-based operations

PoC

Place this file at WStables folder of test and run this command to run test forge test --mt "test_InvariantBreak_Scenario" -vv

JavaScript
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "../../contexts/MarketDeploymentContext.sol";


contract wUSDE_InvariantBreak is MarketDeploymentContext {
    IERC20 stable = AddrClassicERC20.USDe;
    IERC4626 saving = AddrERC4626.sUSDe;

  
    function test_InvariantBreak_Scenario() external {
        
        vm.startPrank(address(this));
        deal(address(stable), address(this), 10000 ether);
        stable.approve(address(saving), 10000 ether);
        saving.deposit(10000 ether, address(this)); // Get shares at 1:1 ratio
        vm.stopPrank();

        // Step 2: Accrue yield to create exactly 1 : 1.1 ratio
        uint256 currentShares = saving.totalSupply();
        uint256 targetAssetsFor11 = (currentShares * 11) / 10; // 1.1 ratio
        console.log("currentShares : ", currentShares);
        console.log("targetAsetsFor11 : ", targetAssetsFor11);
        deal(address(stable), address(saving), targetAssetsFor11);
        skip(1 days);

        uint256 ratio11 = saving.previewRedeem(1 ether);
        console.log("After first yield: 1 share = %s assets (exactly 1:1.1 ratio)", ratio11);
        
        // Verify we have approximately 1.1 ratio 
        assertApproxEqRel(ratio11, 1100000000000000000, 1e16, "Ratio should be approximately 1.1");

        // Step 3: Giving user 1000 vault shares (now at 1:1.1 ratio)
        uint256 vaultShares = 1000 ether;
        vm.startPrank(address(this));
        saving.transfer(usr1, vaultShares);
        vm.stopPrank();

        uint256 initialShares = saving.balanceOf(usr1);
        console.log("User gets 1000 vault shares (worth %s assets at 1:1.1 ratio)", saving.previewRedeem(initialShares));

        // Step 4: User deposits 1000 vault shares using WStable contract
        vm.startPrank(usr1);
        saving.approve(address(wUSDE), vaultShares);
        wUSDE.mint(vaultShares, usr1, true);
        vm.stopPrank();

        uint256 wStableReceived = wUSDE.balanceOf(usr1);
        console.log("WStable tokens received: %s", wStableReceived);
        console.log("Expected: 1000 * 1.1 = 1100 (exactly 1100000000000000000000)");
        
        assertApproxEqRel(wStableReceived, 1100000000000000000000, 1e16, "Should receive approximately 1100 WStable tokens");

        // Step 5: Accrue more yield to create 1:1.2 ratio
        uint256 targetAssetsFor12 = (saving.totalSupply() * 12) / 10; // 1.2 ratio
        console.log("targetAssetsFor12: " , targetAssetsFor12);
        deal(address(stable), address(saving), targetAssetsFor12);
        skip(1 days);

        uint256 ratio12 = saving.previewRedeem(1 ether);
        console.log("After second yield: 1 share = %s assets (exactly 1:1.2 ratio)", ratio12);
        
        assertApproxEqRel(ratio12, 1200000000000000000, 1e16, "Ratio should be approximately 1.2");

        // Step 6: User burns WStable tokens using WStable contract
        vm.startPrank(usr1);
        wUSDE.burn(wStableReceived, usr1, true);
        vm.stopPrank();

        uint256 finalShares = saving.balanceOf(usr1);
        uint256 sharesLost = initialShares - finalShares;
        uint256 lossPercentage = (sharesLost * 100) / initialShares;
        
        console.log("Final user vault shares: %s", finalShares);
        console.log("Expected: 1100 / 1.2 = 916.67 (exactly 916666666666666666667)");
        console.log("Shares lost: %s", sharesLost);
        console.log("Loss percentage: %s%%", lossPercentage);
        console.log("Expected loss: 83.33 shares (8.33%%)");
        
        // Verifying we get approximately 916.67 shares back 
        assertApproxEqRel(finalShares, 916666666666666666667, 1e16, "Should receive approximately 916.67 shares");
        assertApproxEqRel(sharesLost, 83333333333333333333, 1e16, "Should lose approximately 83.33 shares");

        // The invariant is broken: user deposited more shares than they got back
        assertLt(finalShares, initialShares, "User should have fewer shares than they started with");
        assertGt(sharesLost, 0, "User should have lost shares due to invariant break");
        assertGt(lossPercentage, 5, "Loss should be significant (>5%) to clearly demonstrate the issue");
        
        console.log("INVARIANT BROKEN: Deposited %s shares, got back %s shares", initialShares, finalShares);
    }
}

Output of test:

JavaScript

Ran 1 test for test/unit/WStables/wUSDE_InvariantBreak.t.sol:wUSDE_InvariantBreak
[PASS] test_InvariantBreak_Scenario() (gas: 731009)
Logs:
  currentShares :  4404337623717191315390233149
  targetAsetsFor11 :  4844771386088910446929256463
  After first yield: 1 share = 1099999999999999999 assets (exactly 1:1.1 ratio)
  User gets 1000 vault shares (worth 1099999999999999999999 assets at 1:1.1 ratio)
  WStable tokens received: 1100000000000000000000
  Expected: 1000 * 1.1 = 1100 (exactly 1100000000000000000000)
  targetAssetsFor12:  5285205148460629578468279778
  After second yield: 1 share = 1199999999999999999 assets (exactly 1:1.2 ratio)
  Final user vault shares: 916666666666666666667
  Expected: 1100 / 1.2 = 916.67 (exactly 916666666666666666667)
  Shares lost: 83333333333333333333
  Loss percentage: 8%
  Expected loss: 83.33 shares (8.33%)
  INVARIANT BROKEN: Deposited 1000000000000000000000 shares, got back 916666666666666666667 shares

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.34s (5.24ms CPU time)

Mitigation

Share-Based Accounting: Track shares instead of assets when isSaving=true

The original report as published on Sherlock, by 8olidity. 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 mint and burn functions use different conversion methods (previewMint vs previewWithdraw) that do not preserve the share amount when yield accrues, breaking the 1:1 invariant.

Impact

Users permanently lose a portion of their vault shares proportional to the yield accrual; in the test scenario, a user lost 8.33% of their shares.

What the attacker needed

User uses isSaving=true mode; Shares have accrued yield before deposit; Additional yield accrues between mint and burn

The fix

The contract should track shares instead of assets when isSaving=true to maintain the 1:1 invariant.

How it was found

  1. User has vault shares that have already accrued yield (ratio 1:1.1).
  2. User deposits these shares using mint(shares, user, true), receiving WStable tokens equal to the asset value.
  3. Additional yield accrues in the vault, changing the ratio to 1:1.2.
  4. User burns WStable tokens using burn(assets, user, true), receiving fewer shares than originally deposited.

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.

This is a smart contract bug where a user deposits vault shares and gets tokens in return, but when they later withdraw, they get back fewer shares because the contract converts values in a way that doesn't account for interest earned in between. The user loses money, and the loss grows with the interest earned.

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 8olidity

View all

9 more disclosed reports, best first.

More from USG - Tangent

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.