Changing VoteWeighting contract can result in lost staking incentives
The Dispenser contract allows the owner to change the VoteWeighting contract, but the new contract does not carry over the last claimed staking epoch for existing nominees. An attacker can re-register a nominee on the new contract, resetting its last claimed epoch to the current one and causing the nominee to lose staking incentives for previous epochs.
Submitted by 0xSwahili
The Dispenser contract provides functionality for the owner to update manager accounts at any time, including changing the VoteWeighting contract.
function changeManagers(address _tokenomics, address _treasury, address _voteWeighting) external {
// Check for the contract ownership
if (msg.sender != owner) {
revert OwnerOnly(msg.sender, owner);
}
// Change Tokenomics contract address
if (_tokenomics != address(0)) {
tokenomics = _tokenomics;
emit TokenomicsUpdated(_tokenomics);
}
// Change Treasury contract address
if (_treasury != address(0)) {
treasury = _treasury;
emit TreasuryUpdated(_treasury);
}
// Change Vote Weighting contract address
if (_voteWeighting != address(0)) {
voteWeighting = _voteWeighting;
emit VoteWeightingUpdated(_voteWeighting);
}
}
Changing the VoteWeighting contract mid-flight can lead to lost staking incentives due to mapLastClaimedStakingEpochs state reset to the current epoch.
Proof of Concept
Consider the following scenario:
- Dispenser owner decides to swap the current VoteWeighting contract for some reason, e.g., a critical vulnerability has been found with the VoteWeighting contract.
- The new VoteWeighting contract does not have Nominee X, a popular staking program that has earned huge rewards since the protocol was deployed. Nominee X has not yet claimed staking rewards for 3 epochs.
- Bob notices that a new VoteWeighting contract has been set, and decides to disrupt the party by registering staking program X again by calling
VoteWeighting::addNominee(X, chainId). Since the Dispenser contract does not check if Nominee X has already been set, this results in a reset to the current epoch.
mapLastClaimedStakingEpochs[X] = ITokenomics(tokenomics).epochCounter().
Now, when claimStakingIncentives is called for Nominee X, staking incentives for 2 epochs will have been lost.
For a coded POC:
- Add these lines to
Tokenomics/test/Dispenser.t.sol::Ln 24:
MockVoteWeighting internal vw;
MockVoteWeighting internal vw2;
- Add these lines to
Tokenomics/test/Dispenser.t.sol::Ln 64:
vw = new MockVoteWeighting(address(dispenser));
vw2 = new MockVoteWeighting(address(dispenser));
- Add this test to
Tokenomics/test/Dispenser.t.sol::DispenserTest Ln 100:
function testChangeVoteWeightLostIncenctives() public{
dispenser.setPauseState(Pause.Unpaused);
address deal = makeAddr("deal");
vw.addNominee(deal,1);
uint256 epoch = dispenser.mapLastClaimedStakingEpochs(keccak256(abi.encode(Nominee(bytes32(uint256(uint160(deal))),1))));
assertEq(tokenomics.epochCounter(),epoch);
// Move at least epochLen seconds in time
vm.warp(block.timestamp + epochLen + 10);
// Mine a next block to avoid a flash loan attack condition
vm.roll(block.number + 1);
// Start new epoch and calculate tokenomics parameters and rewards
tokenomics.checkpoint();
assertGt(tokenomics.epochCounter(),epoch);
// Get the last settled epoch counter
dispenser.changeManagers(address(0), address(0), address(vw2));
vw2.addNominee(deal,1);
uint256 epoch2 = dispenser.mapLastClaimedStakingEpochs(keccak256(abi.encode(Nominee(bytes32(uint256(uint160(deal))),1))));
assertGt(epoch2,epoch);
// Move at least epochLen seconds in time
}
Recommended Mitigation Steps
Add code to Dispenser::changeManagers to check that no Nominee exists when changing the VoteWeighting contract to a new one.
Assessed type
Invalid Validation
kupermind (Olas) disputed and commented:
VoteWeighting is a very sensitive contract, and it’s almost impossible that no nominee exists when VoteWeighting is changed.
It is an absolute responsibility of the DAO to take steps in order to minimize the inflation loss (which is still possible to recover by adjusting the inflation schedule in the years ahead).
Here are the possible steps:
- Pause the dispenser and wait for all the targets to claim incentives.
- Re-create VoteWeighting storage
- Create a wrapper for VoteWeighting, as we have done for veOLAS when wrapping it under wveOLAS contract.
- Manually process some of the queued requests by the DAO-controlled
processDataMaintenance()function.There are several mitigation steps. However, note that the incentives are not minted unless claimed; thus, pausing the staking incentives mechanism is sufficient to take care of all the mess around VoteWeighting re-deployment and re-setting the inflation where needed.
0xA5DF (judge) decreased severity to Medium and commented:
Regarding severity - given that this happens only under certain conditions and the loss is limited, this isn’t more than medium.
It’s true that this issue can be addressed by doing the change in a certain way (and therefore, a change to the code isn’t necessarily required), but I’m not convinced that this is the trivial path that would be taken if this issue hadn’t been reported.
Therefore, the issue/concern that’s raised here seems valid and qualifies as medium severity.
Disagree here. Tracking for the zero amount of nominees as suggested is impossible, yet very expensive - need to literally remove all the nominees by the DAO.
A very easy fix that does not cost any staking inflation loss:
- Initiate all the nominees claim of incentives, as those are ownerless;
- Pause staking incentives;
- Change VoteWeighting contract;
- Unpause staking incentives.
As the epoch lasts for a long period of time, and staking incentives are distributed only by the last week of epoch values, there’s a lot of time to re-shape VoteWeighting by the given scenario.
Your comment seems to address whether the mitigation is a good idea or the best way to address the issue. But as for judging the question is whether the issue raised here is valid or not.
In other words, in a world where this issue wasn’t reported, could this issue occur? Correct me if I’m wrong, but it seems to me that the answer is yes.
kupermind (Olas) acknowledged and commented:
Ok, this is possible then.
Olas mitigated:
Added this to the deployment procedure.
There’s no fix to this issue. Best is that the admin takes right actions before changing the voteWeighting contract.
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 new VoteWeighting contract starts with empty state for `mapLastClaimedStakingEpochs`, and the Dispenser does not prevent re-adding an existing nominee, so the last claimed epoch is reset to the current epoch.
Impact
Staking incentives for previous epochs could be lost for affected nominees, but the loss is limited and only occurs under specific conditions when the VoteWeighting contract is changed.
What the attacker needed
Dispenser owner changes VoteWeighting contract; Attacker can call addNominee on new contract; Nominee has unclaimed incentives
The fix
The issue was mitigated by adding a step to the deployment procedure to handle claims before changing the VoteWeighting contract.
How it was found
- The Dispenser owner changes the VoteWeighting contract to a new one.
- The new VoteWeighting contract does not have Nominee X registered.
- Bob calls VoteWeighting::addNominee(X, chainId) to register Nominee X again.
- The last claimed staking epoch for Nominee X is reset to the current epoch.
- When claimStakingIncentives is called for Nominee X, staking incentives for previous epochs are lost.
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 staking system lets people earn rewards over time. When the contract that tracks rewards is swapped for a new one, the record of when each person last claimed is lost. If someone re-registers a nominee on the new contract, the system thinks they have never claimed, so they lose the rewards they were owed for past periods.
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.