BkdLocker#depositFees() can be front run to steal the newly added rewardToken
The depositFees function adds rewards to a pool without a time-based vesting, so an attacker can front-run the deposit by locking a large amount of tokens, then immediately claim a disproportionate share of the new rewards. This allows the attacker to steal a significant portion of the newly added reward tokens that were intended for existing stakeholders.
Submitted by WatchPug
Every time the BkdLocker#depositFees() gets called, there will be a surge of rewards per locked token for the existing stakeholders.
This enables a well-known attack vector, in which the attacker will take a large portion of the shares before the surge, then claim the rewards and exit immediately.
While the _WITHDRAW_DELAY can be set longer to mitigate this issue in the current implementation, it is possible for the admin to configure it to a very short period of time or even 0.
In which case, the attack will be very practical and effectively steal the major part of the newly added rewards.
function depositFees(uint256 amount) external override {
require(amount > 0, Error.INVALID_AMOUNT);
require(totalLockedBoosted > 0, Error.NOT_ENOUGH_FUNDS);
IERC20(rewardToken).safeTransferFrom(msg.sender, address(this), amount);
RewardTokenData storage curRewardTokenData = rewardTokenData[rewardToken];
curRewardTokenData.feeIntegral += amount.scaledDiv(totalLockedBoosted);
curRewardTokenData.feeBalance += amount;
emit FeesDeposited(amount);
}
Proof of Concept
Given:
- Current
totalLockedBoosted()is100,000 govToken; - Pending distribution fees amount is
1,000 rewardToken; depositFees()is called to add1,000 rewardToken;- The attacker frontrun the 1st transaction with a
lock()transaction to deposit100,000 govToken, taking 50% of the pool; - After the transaction in step 1 is mined, the attacker calls
claimFees()and received500 rewardToken.
As a result, the attacker has stolen half of the pending fees which belong to the old users.
Recommendation
Consider switching the reward to a rewardRate-based gradual release model, such as Synthetix’s StakingRewards contract.
See: https://github.com/Synthetixio/synthetix/blob/develop/contracts/StakingRewards.sol#L113-L132
chase-manning (Backd) disputed and commented:
The withdrawal delay prevents this attack.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
Given the need for:
- Withdrawal delay set to 0 or small
- Need for front-running which causes leak of value
I believe High Severity to be out of the question.
That said, because the rewards are given out at the time of
depositFees, and they are not linearly vested, I do believe that a front-run MEV attack can be executed, being able to immediately claim the reward tokens, at the cost / risk of having to lock the tokens.The shorter the withdrawal delay, the lower the risk for the attack..
Because this is contingent on configuration, and at best it’s a loss of yield for the lockers, I believe Medium Severity to be more appropriat.
As an additional note, please consider the fact that if the potential value gained is high enough, an attacker could just hedge the risk of locking by shorting the tokens, effectively being delta neutral while using the rewards for profit.
This means that if your token becomes liquid enough (a goal for any protocol), you would expect the withdrawal delay to become ineffective as hedging options become available.
Forcing the rewards to linearly vest will prevent the front-run from being effective and will reward long term lockers.
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 reward distribution is based on the instantaneous share of locked tokens at the time of deposit, without any time-based vesting or delay, allowing a front-running attack.
Impact
The attacker could steal a major part of the newly added rewards, but the attack is only practical if the withdrawal delay is set to a very short period or zero; otherwise the delay mitigates it.
What the attacker needed
Withdrawal delay set to 0 or very short; attacker can front-run the depositFees transaction; attacker has enough tokens to lock a large share
The fix
The rewards should be distributed using a rewardRate-based gradual release model, such as Synthetix’s StakingRewards contract, to prevent front-running.
How it was found
- The attacker sees a pending depositFees transaction that will add rewards.
- The attacker front-runs it by locking a large amount of govToken, taking a large share of the pool.
- After the depositFees transaction is mined, the attacker calls claimFees and receives a large portion of the new 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 reward pool gives out new tokens to people who have locked their tokens in it. The amount each person gets is based on how many tokens they have locked at the moment the new rewards are added. An attacker can see a reward deposit coming, quickly lock a huge amount of tokens just before it happens, and then claim a large share of the new rewards, leaving less for the people who were already there.
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.