Skip to content
Business logic Audit finding Intermediate

Staking#changeStakeTime and changeStakeAmount are problematic given current staking design

The staking contract stores a time-based bonus at stake time, so later changes to the bonus parameters create a permanent voting-power advantage or disadvantage for existing stakers. An attacker could exploit this by staking before a bonus decrease to gain a lasting advantage over new stakers.

0x52 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-frankendao-judging/issues/31

Found by

0x52

Summary

Staking#changeStakeTime and changeStakeAmount allow the locking bonus to be modified. Any change to this value will cause voting imbalance in the system. If changes result in a higher total bonus then existing stakers will be given a permanent advantage over new stakers. If the bonus is increased then existing stakers will be at a disadvantage because they will be locked and unable to realize the new staking bonus.

Vulnerability Detail

function _stakeToken(uint _tokenId, uint _unlockTime) internal returns (uint) {
  if (_unlockTime > 0) {
    unlockTime[_tokenId] = _unlockTime;
    uint fullStakedTimeBonus = ((_unlockTime - block.timestamp) * stakingSettings.maxStakeBonusAmount) / stakingSettings.maxStakeBonusTime;
    stakedTimeBonus[_tokenId] = _tokenId < 10000 ? fullStakedTimeBonus : fullStakedTimeBonus / 2;
  }

When a token is staked their stakeTimeBonus is stored. This means that any changes to stakingSettings.maxStakeBonusAmount or stakingSettings.maxStakeBonusTime won't affect tokens that are already stored. Storing the value is essential to prevent changes to the values causing major damage to the voting, but it leads to other more subtle issue when it is changed that will put either existing or new stakers at a disadvantage.

Example: User A stake when maxStakeBonusAmount = 10 and stake long enough to get the entire bonus. Now maxStakeBonusAmount is changed to 20. User A is unable to unstake their token right away because it is locked. They are now at a disadvantage because other users can now stake and get a bonus of 20 while they are stuck with only a bonus of 10. Now maxStakeBonusAmount is changed to 5. User A now has an advantage because other users can now only stake for a bonus of 5. If User A never unstakes then they will forever have that advantage over new users.

Impact

Voting power becomes skewed for users when Staking#changeStakeTime and changeStakeAmount are used

Code Snippet

https://github.com/sherlock-audit/2022-11-frankendao/blob/main/src/Staking.sol#L389-L415

Tool used

Manual Review

Recommendation

I recommend implementing a poke function that can be called by any user on any user. This function should loop through all tokens (or the tokens specified) and recalculate their voting power based on current multipliers, allowing all users to be normalized to prevent any abuse.

Discussion

zobront

This is the intended behavior. Staking windows will be relatively short (~1 month) and bonuses will change only by governance vote. We accept that there may be short periods where a user is locked in a suboptimal spot, but they can unstake and restake when the period is over.

0x00052

Escalate for 1 USDC

I think this should be considered valid. It won't just be for a small amount of time if the staking amount is lowered. In this case, all users who staked beforehand will have a permanent advantage over other users. Due to the permanent imbalance lowering it would cause in the voting power of users, I think that medium is appropriate.

sherlock-admin

Escalate for 1 USDC

I think this should be considered valid. It won't just be for a small amount of time if the staking amount is lowered. In this case, all users who staked beforehand will have a permanent advantage over other users. Due to the permanent imbalance lowering it would cause in the voting power of users, I think that medium is appropriate.

You've created a valid escalation for 1 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

zobront

I can see the argument here. We don't want to change it and believe it's fine as is, but it may be a valid Medium.

Evert0x

Escalation accepted

sherlock-admin

Escalation accepted

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

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

Likely the design stores the staking bonus at stake time and allows governance to change the bonus parameters without recalculating existing stakes, creating a permanent imbalance.

Impact

Voting power becomes skewed for users when the staking bonus parameters are changed, potentially giving some users a permanent advantage or disadvantage.

What the attacker needed

Governance changes staking bonus parameters; user stakes before parameter change

The fix

The report recommends implementing a poke function that recalculates voting power for all tokens based on current multipliers, but the project team stated this is intended behaviour and did not fix it.

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 gives you extra voting power based on how long you lock them. That extra power is fixed at the moment you stake. If the rules for extra power change later, people who staked earlier can end up with more or less power than new stakers, which is unfair.

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 0x52

View all

211 more disclosed reports, best first.

More from FrankenDAO

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.