Skip to content
Business logic Audit finding Intermediate

users still forced to follow previously set cooldownDuration even when cooldown is off (set to zero) before unstaking

Users who started a cooldown before the contract's cooldown duration was set to zero remain unable to unstake their assets from the silo until the original 90-day period ends, even though new withdrawals are immediate. This causes a temporary lock of funds for those users.

adeolu Follow with jasonxiale, Madalad and 5 others

Originally disclosed on Code4rena

Submitted by adeolu, also found by jasonxiale, Madalad, Mike_Bello90, peanuts, josephdara, Eeyore, and Shubham

The StakedUSDeV2 contract can enforces coolDown periods for users before they are able to unstake/ take out their funds from the silo contract if coolDown is on. Based on the presence of the modifiers ensureCooldownOff and ensureCooldownOn, it is known that the coolDown state of the StakedUSDeV2 contract can be toggled on or off. In a scenario where coolDown is on (always turned on by default) and Alice and Bob deposits, two days after Alice wants to withdraw/redeem. Alice is forced to wait for 90 days before completing withdrawal/getting her tokens from the silo contract because Alice must call coolDownAsset()/coolDownShares() fcns respectively. Bob decides to wait an extra day.

On the third day, Bob decides to withdraw/redeem. Contract admin also toggles the coolDown off (sets cooldownDuration to 0), meaning there is no longer a coolDown period and all withdrawals should be sent to the users immediately. Bob now calls calls the redeem()/withdraw() fcn to withdraw instantly to his address instead of the silo address since there is no coolDown.

Alice sees Bob has gotten his tokens but Alice cant use the redeem()/withdraw() because her StakedUSDeV2 were already burned and her underlying assets were sent to the silo contract for storage. Alice cannot sucessfully call unstake() because her userCooldown.cooldownEnd value set to ~ 90 days. Now Alice has to unfairly wait out the 90 days even though coolDowns have been turned off and everyone else has unrestricted access to their assets. Alice only crime is trying to withdraw earlier than Bob. This is a loss to Alice as Alice has no StakedUSDE or the underlying asset for the no longer necessary 90 days as if the assset is volatile, it may lose some fiat value during the unfair and no longer necessary wait period.

If cooldown is turned off, it should affect all contract processes and as such, withdrawals should become immediate to users. Tokens previously stored in the USDeSilo contract should become accessible to users when the cooldown state is off. Previous withdrawal requests that had a cooldown should no longer be restricted by a coolDown period since coolDown now off and the coolDownDuration of the contract is now 0.

Proof of Concept

  • Since StakedUSDeV2 is ERC4626, user calls deposit() to deposit the underlying token asset and get minted shares that signify the user’s position size in the vault.

  • The coolDown duration is set to 90 days on deployment of the StakedUSDeV2 contract, meaning coolDown is toggled on by default.

  • User cannot redeem/withdraw his funds via withdraw() and redeem() because coolDown is on. Both functions have the ensureCooldownOff modifier which reverts if the coolDownDuration value is not 0.

  • User tried to exit position, to withdraw when coolDown is on, user must call coolDownAsset()/coolDownShares(). This will cause :

    • For the user’s underlyingAmount and cooldownEnd timestamp values to be set in the mapping cooldowns. cooldownEnd timestamp values is set to 90 days from the present.
    • For the user’s StakedUSDeV2 ERC4626 position shares to be burnt and the positon underlying asset value to be sent to the USDeSilo contract.
        /// @notice redeem assets and starts a cooldown to claim the converted underlying asset
        /// @param assets assets to redeem
        /// @param owner address to redeem and start cooldown, owner must allowed caller to perform this action
        function cooldownAssets(uint256 assets, address owner) external ensureCooldownOn returns (uint256) {
         if (assets > maxWithdraw(owner)) revert ExcessiveWithdrawAmount();

         uint256 shares = previewWithdraw(assets);

         cooldowns[owner].cooldownEnd = uint104(block.timestamp) + cooldownDuration;
         cooldowns[owner].underlyingAmount += assets;

         _withdraw(_msgSender(), address(silo), owner, assets, shares);

         return shares;
        }

        /// @notice redeem shares into assets and starts a cooldown to claim the converted underlying asset
        /// @param shares shares to redeem
        /// @param owner address to redeem and start cooldown, owner must allowed caller to perform this action
        function cooldownShares(uint256 shares, address owner) external ensureCooldownOn returns (uint256) {
         if (shares > maxRedeem(owner)) revert ExcessiveRedeemAmount();

         uint256 assets = previewRedeem(shares);

         cooldowns[owner].cooldownEnd = uint104(block.timestamp) + cooldownDuration;
         cooldowns[owner].underlyingAmount += assets;

         _withdraw(_msgSender(), address(silo), owner, assets, shares);

         return assets;
        }
  • User can only use unstake() to get the assets from the silo contract. unstake enforces that the block.timestamp (present time) is more than the 90 days cooldown period set during the execution of cooldownAssets() and cooldownShares() and reverts if 90 days time has not been reached yet.
      function unstake(address receiver) external {
        UserCooldown storage userCooldown = cooldowns[msg.sender];
        uint256 assets = userCooldown.underlyingAmount;

        if (block.timestamp >= userCooldown.cooldownEnd) {
          userCooldown.cooldownEnd = 0;
          userCooldown.underlyingAmount = 0;

          silo.withdraw(receiver, assets);
        } else {
          revert InvalidCooldown();
        }
      }
  • If contract admin decides to turn the coolDown period off, by setting the cooldownDuration to 0 via setCooldownDuration(), user who has his assets under the coolDown in the silo still wont be able to withdraw via unstake() because the logic in unstake() doesnt allow for the user’s coolDownEnd value which was set under the previous coolDown duration state to be bypassed as coolDowns are now turned off and the StakedUSDeV2 behavior is supposed to be changed to follow ERC4626 standard and allow for the user assets to get to them immediately with no coolDown period still enforced on withdrawals as seen in the comment here.
  • User who initiated withdrawal when the coolDown was toggled on will still continue to be restricted from his tokens/funds even after coolDown is toggled off. This should not be because restrictions are removed, all previous pending withdrawals should be allowed to be completed without wait for 90 days since the coolDownDuration of the contract is now 0.

Coded Proof of Concept

Run with forge test --mt test_UnstakeUnallowedAfterCooldownIsTurnedOff.

    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8;

    /* solhint-disable private-vars-leading-underscore  */
    /* solhint-disable var-name-mixedcase  */
    /* solhint-disable func-name-mixedcase  */

    import "forge-std/console.sol";
    import "forge-std/Test.sol";
    import {SigUtils} from "forge-std/SigUtils.sol";

    import "../../../contracts/USDe.sol";
    import "../../../contracts/StakedUSDeV2.sol";
    import "../../../contracts/interfaces/IUSDe.sol";
    import "../../../contracts/interfaces/IERC20Events.sol";

    contract StakedUSDeV2CooldownTest is Test, IERC20Events {
      USDe public usdeToken;
      StakedUSDeV2 public stakedUSDeV2;
      SigUtils public sigUtilsUSDe;
      SigUtils public sigUtilsStakedUSDe;
      uint256 public _amount = 100 ether;

      address public owner;
      address public alice;
      address public bob;
      address public greg;

      bytes32 SOFT_RESTRICTED_STAKER_ROLE;
      bytes32 FULL_RESTRICTED_STAKER_ROLE;
      bytes32 DEFAULT_ADMIN_ROLE;
      bytes32 BLACKLIST_MANAGER_ROLE;
      bytes32 REWARDER_ROLE;

      event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
      event Withdraw(
        address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares
      );
      event LockedAmountRedistributed(address indexed from, address indexed to, uint256 amountToDistribute);

      function setUp() public virtual {
        usdeToken = new USDe(address(this));

        alice = makeAddr("alice");
        bob = makeAddr("bob");
        greg = makeAddr("greg");
        owner = makeAddr("owner");

        usdeToken.setMinter(address(this));

        vm.startPrank(owner);
        stakedUSDeV2 = new StakedUSDeV2(IUSDe(address(usdeToken)), makeAddr('rewarder'), owner);
        vm.stopPrank();

        FULL_RESTRICTED_STAKER_ROLE = keccak256("FULL_RESTRICTED_STAKER_ROLE");
        SOFT_RESTRICTED_STAKER_ROLE = keccak256("SOFT_RESTRICTED_STAKER_ROLE");
        DEFAULT_ADMIN_ROLE = 0x00;
        BLACKLIST_MANAGER_ROLE = keccak256("BLACKLIST_MANAGER_ROLE");
        REWARDER_ROLE = keccak256("REWARDER_ROLE");
      }

      function test_UnstakeUnallowedAfterCooldownIsTurnedOff () public {
        address staker = address(20);
        uint usdeTokenAmountToMint = 10000*1e18;

        usdeToken.mint(staker, usdeTokenAmountToMint);

        //at the deposit coolDownDuration is set to 90 days
        assert(stakedUSDeV2.cooldownDuration() == 90 days);

        vm.startPrank(staker);
        usdeToken.approve(address(stakedUSDeV2), usdeTokenAmountToMint);

        stakedUSDeV2.deposit(usdeTokenAmountToMint / 2, staker);

        vm.roll(block.number + 1);
        uint assets  = stakedUSDeV2.maxWithdraw(staker);
        stakedUSDeV2.cooldownAssets(assets , staker);

        vm.stopPrank();

        //assert that cooldown for the staker is now set to 90 days from now
        ( uint104 cooldownEnd, ) = stakedUSDeV2.cooldowns(staker);
        assert(cooldownEnd == uint104( block.timestamp + 90 days));

        vm.prank(owner);
        //toggle coolDown off in the contract
        stakedUSDeV2.setCooldownDuration(0);

        //now try to unstake,
        /** since cooldown duration is now 0 and contract is cooldown state is turned off.
        it should allow unstake immediately but instead it will revert **/
        vm.expectRevert(IStakedUSDeCooldown.InvalidCooldown.selector);
        vm.prank(staker);
        stakedUSDeV2.unstake(staker);
      }
    }

Tools Used

Manual review, Foundry

Recommended Mitigation Steps

Modify the code in unstake() fcn to allow for withdrawals from the silo contract when the contract’s coolDownDuration has become 0.

Assessed type

Error

kayinnnn (Ethena) confirmed and commented:

Acknowledge the issue, but revise to low severity finding as it causes minor inconvenience in the rare time we change cooldown period. However, it is still fixed - existing per user cooldown is ignored if the global cooldown is 0.


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

The unstake function checks only the user's stored cooldown end time and does not consider that the global cooldown duration may have been set to zero.

Impact

Users who initiated a cooldown before it was disabled may have their funds locked for up to the original 90-day period, causing a temporary loss of access and potential financial loss if the asset's value changes.

What the attacker needed

User has initiated a cooldown; admin sets cooldown duration to zero

The fix

The unstake function should be modified to allow withdrawal from the silo when the global cooldown duration is zero, ignoring the user's stored cooldown end time.

How it was found

  1. Deploy the contract with a 90-day cooldown duration.
  2. A user deposits tokens and later calls cooldownAssets to start the cooldown, which burns their shares and moves the underlying assets to the silo contract.
  3. The admin sets the cooldown duration to zero, turning off the cooldown.
  4. The user tries to call unstake to retrieve their assets from the silo, but the transaction reverts because their stored cooldown end time is still in the future.

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 staking contract had a rule that made people wait 90 days before taking their money out. The admin could turn this waiting period off, but people who had already started waiting were still stuck until their original 90 days finished, even though the rule was gone for everyone else.

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 adeolu

View all

16 more disclosed reports, best first.

More from Ethena Labs

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.