Skip to content
Business logic Audit finding Intermediate

function lockFunds in TopUpActionLibrary can cause serious fund lose. fee and Capped bypass. It’s not calling stakerVault.increaseActionLockedBalance when transfers stakes.

The lockFunds function in TopUpActionLibrary transfers staked tokens from a user but fails to update the user's action-locked balance in StakerVault. This causes stakedAndActionLockedBalanceOf to return zero, allowing an attacker to bypass deposit caps and fee penalties, and causing users to lose rewards.

unforgiven Follow

Originally disclosed on Code4rena

Submitted by unforgiven

TopUpAction.sol#L57-L65

In function TopUpActionLibrary.lockFunds when transfers stakes from payer it doesn’t call stakerVault.increaseActionLockedBalance for that payer so stakerVault.actionLockedBalances[payer] is not get updated for payer and stakerVault.stakedAndActionLockedBalanceOf(payer) is going to show wrong value and any calculation based on this function is gonna be wrong which will cause fund lose and theft and some restriction bypasses.

Proof of Concept

When user wants to create a TopUpAction. so he deposit his funds to Pool and get LP token. then stake the LP token in StakerVault and use that stakes to create a TopUp position with function TopUpAction.register. This function transfer user stakes (locks user staks) and create his position.

For transferring and locking user stakes it uses TopUpActionLibrary.lockFunds. function lockFunds transfers user stakes but don’t call stakerVault.increaseActionLockedBalance for the payer which cause that stakerVault.actionLockedBalances[payer] to get different values(not equal to position.depositTokenBalance).

Function StakerVault.stakedAndActionLockedBalanceOf(account) uses stakerVault.actionLockedBalances[account] so it will return wrong value and any where in code that uses stakedAndActionLockedBalanceOf() is going to cause problems.

three part of the codes uses stakerVault.stakedAndActionLockedBalanceOf():

  1. LiqudityPool.depositFor() for checking user total deposits to be less than depositCap.
  2. LiqudityPool._updateUserFeesOnDeposit() for updating user fee on new deposits.
  3. userCheckpoint() for calculating user rewards. attacker can use #1 and #2 to bypass high fee payment and max depositCap and #3 will cause users to lose rewards.

The detail steps: 1- user deposit fund to Pool and get LP token. 2- user stakes LP token in StakerVault. 3- user approve TopUpAction address to transfer his staks in StakerVault. 3- user use all his stakes to create a position with TopUpAction.register() function. 3.1- register() will call lockFunds to transfer and lock user stakes. 3.2- lockFunds() will transfer user stakes with stakerVault.transferFrom() but don’t call stakerVault.increaseActionLockedBalance() so StakerVault.actionLockedBalances[user] will be zero. 3.3- StakerVault.balance[useer] will be zero too because his stakes get transfers in 3.2 4- StakerVault.stakedAndActionLockedBalanceOf(user) will return zero (user has some locked stakes in TopUpAction but because of the bug calculation get out of sync)

In this moment user will lose all the rewards that are minted in LpGauge. because userCheckpoint() use stakerVault.stakedAndActionLockedBalanceOf(user) for calculating rewards which is zero and new rewards will be zero too.

Attacker can use this process to bypass “max deposit Cap” and deposit any amount of assets he wants. because LiqudityPool.depositFor(address,uint256,uint256) uses stakedAndActionLockedBalanceOf to check user deposits which is zero so Attacker can deposit & stake & register to make his balance zero and repeat this and in the end reset his TopUp positions to get back his large stakes which are multiple time bigger than “max deposit Cap”

Attacker can also use this process to bypass fee penalties for early withdraw. because LiqudityPool._updateUserFeesOnDeposit() to get user current balance use stakedAndActionLockedBalanceOf() which is zero. so the value of shareExisting variable become zero and newFeeRatio will be calculated based on feeOnDeposit which can be minFee if asset is already in wallet for some time.

Tools Used

VIM

Recommended Mitigation Steps

Add this line to TopUpActionLibrary.lockFunds() after stakerVault.transferFrom():

stakerVault.increaseActionLockedBalance(payer, amountLeft);

chase-manning (Backd) confirmed and resolved


The original report as published on Code4rena, by unforgiven. 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 lockFunds function omits a call to stakerVault.increaseActionLockedBalance after transferring stakes, leaving the action-locked balance out of sync.

Impact

An attacker could bypass the maximum deposit cap and fee penalties, and users could lose rewards due to incorrect balance calculations.

What the attacker needed

User has staked LP tokens; user approves TopUpAction to transfer stakes

The fix

The lockFunds function should call stakerVault.increaseActionLockedBalance(payer, amountLeft) after transferring stakes.

How it was found

  1. User deposits funds to the Pool and receives LP tokens.
  2. User stakes LP tokens in StakerVault.
  3. User approves TopUpAction to transfer their stakes.
  4. User calls TopUpAction.register() to create a position using all stakes.
  5. register() calls lockFunds, which transfers stakes but does not update actionLockedBalances.
  6. stakedAndActionLockedBalanceOf(user) returns zero, causing incorrect calculations.

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 stake tokens, the system tracks how many are locked for actions. A bug meant that after locking tokens for a top-up action, the system forgot to record that they were locked, so it thought you had zero locked tokens. This let someone repeatedly deposit and lock tokens to exceed the maximum deposit limit and avoid fees, and also caused users to lose rewards.

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 unforgiven

View all

50 more disclosed reports, best first.

More from Backd Tokenomics 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.