Skip to content
Business logic Audit finding Intermediate

`Staking.unstake()` doesn't decrease the original voting power that was used in `Staking.stake()`

The staking contract recalculates a token's voting power at unstake time using current admin-set parameters, rather than the value recorded at stake time. If the admin changes a multiplier between staking and unstaking, the recalculated value can exceed the stored voting power, causing an underflow revert and preventing the user from unstaking.

hansfriese Follow with 0x52 and Haruxe

Originally disclosed on Sherlock

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

Found by

hansfriese, 0x52, Haruxe

Summary

Staking.unstake() doesn't decrease the original voting power that was used in Staking.stake().

Vulnerability Detail

When users stake/unstake the underlying NFTs, it calculates the token voting power using getTokenVotingPower() and increases/decreases their voting power accordingly.

Solidity
    function getTokenVotingPower(uint _tokenId) public override view returns (uint) {
      if (ownerOf(_tokenId) == address(0)) revert NonExistentToken();

      // If tokenId < 10000, it's a FrankenPunk, so 100/100 = a multiplier of 1
      uint multiplier = _tokenId < 10_000 ? PERCENT : monsterMultiplier;
      
      // evilBonus will return 0 for all FrankenMonsters, as they are not eligible for the evil bonus
      return ((baseVotes * multiplier) / PERCENT) + stakedTimeBonus[_tokenId] + evilBonus(_tokenId);
    }

But getTokenVotingPower() uses some parameters like monsterMultiplier and baseVotes and the output would be changed for the same tokenId after the admin changed these settings.

Currently, _stake() and _unstake() calculates the token voting power independently and the below scenario would be possible.

  • At the first time, baseVotes = 20, monsterMultiplier = 50.
  • A user staked a FrankenMonsters and his voting power = 10 here.
  • After that, the admin changed monsterMultiplier = 60.
  • When a user tries to unstake the NFT, the token voting power will be 20 * 60 / 100 = 12 here.
  • So it will revert with uint underflow here.
  • After all, he can't unstake the NFT.

Impact

votesFromOwnedTokens might be updated wrongly or users can't unstake for the worst case because it doesn't decrease the same token voting power while unstaking.

Code Snippet

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

Tool used

Manual Review

Recommendation

I think we should add a mapping like tokenVotingPower to save an original token voting power when users stake the token and decrease the same amount when they unstake.

Discussion

zobront

Fixed: https://github.com/Solidity-Guild/FrankenDAO/pull/17

jack-the-pug

Fix confirmed

The original report as published on Sherlock, by hansfriese. 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 contract does not store the voting power at stake time; it recalculates it at unstake time using parameters that can change, so the subtracted amount may exceed the stored value.

Impact

Voting power tracking may become incorrect, and in the worst case users cannot unstake their NFTs.

What the attacker needed

Admin changes a voting power parameter; user has staked an NFT

The fix

The contract was fixed by storing the original voting power at stake time and decreasing that same amount at unstake time.

How it was found

  1. Admin sets baseVotes to 20 and monsterMultiplier to 50.
  2. User stakes a FrankenMonster NFT, receiving voting power of 10.
  3. Admin changes monsterMultiplier to 60.
  4. User attempts to unstake the NFT; the contract recalculates voting power as 12.
  5. The contract tries to subtract 12 from the stored voting power of 10, causing a uint underflow revert.
  6. The user cannot unstake the NFT.

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 an NFT, the contract gives you voting power based on a formula. If the admin later changes a number in that formula, the contract recalculates your voting power when you try to unstake. If the new number is higher, the contract tries to subtract more voting power than you have, which causes an error and blocks you from unstaking.

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 hansfriese

View all

65 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.