Users can claim more fees than expected if governance migrates current rewardToken again by fault.
The migrate function lacks a check that the new reward token differs from the current one, so if governance migrates to the same token, the token is added twice to the replaced list. When users claim fees, their shares are counted twice for that token, allowing them to receive more fees than they should.
Originally disclosed on Code4rena
Submitted by hansfriese, also found by csanuragjain and unforgiven
https://github.com/code-423n4/2022-05-backd/tree/main/protocol/contracts/BkdLocker.sol#L70-L75
https://github.com/code-423n4/2022-05-backd/tree/main/protocol/contracts/BkdLocker.sol#L302-L322
Impact
Users can claim more fees than expected if governance migrates current rewardToken again by fault.
Proof of Concept
In the migrate() function, there is no requirement newRewardToken != rewardToken. If this function is called with the same “rewardToken” parameter, ”_replacedRewardTokens” will contain the current “rewardToken” also. Then when the user claims fees, “userShares” will be added two times for the same token at L302-L305, L314-L317.
It’s because “curRewardTokenData.userFeeIntegrals[user]” is updated at L332 after the “userShares” calculation for past rewardTokens. So the user can get paid more fees than he should.
Tools Used
Solidity Visual Developer of VSCode
Recommended Mitigation Steps
You need to add this require() at L71.
require(newRewardToken != rewardToken, Error.SAMEASCURRENT);
Alex the Entreprenerd (judge) commented:
The warden has identified how a governance migration from and to the same token can cause the rewards to be double-counted.
Because the exploit is contingent on:
- Admin Privilege
- Would cause issues with Yield
I believe Medium Severity to be appropriate.
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 migrate function does not require the new reward token to be different from the current one, so migrating to the same token causes duplicate entries in the replaced tokens list and double-counting of user shares.
What the attacker needed
Governance calls migrate with same token
The fix
The migrate function should be fixed by adding a require that the new reward token is not the same as the current one.
How it was found
- Governance calls migrate() with the same rewardToken as the current one.
- The current rewardToken is added to _replacedRewardTokens.
- A user calls claim and their userShares are calculated twice for the same token.
- The user receives more fees than they should.
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 smart contract lets users claim fees based on their share of a reward token. If the contract's admin accidentally 'migrates' to the same token, the contract records that token twice, so when a user claims, their share is counted twice and they get extra fees. This only happens if the admin makes that mistake.
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.