sherlock-audit / 2024-06-magicsea-judging

2 stars 0 forks source link

Tricky Pebble Dachshund - Owner can by mistake rollover to a new voting period while previous period is active, users could loose bribe rewards due to deprived participation #696

Closed sherlock-admin2 closed 2 months ago

sherlock-admin2 commented 2 months ago

Tricky Pebble Dachshund

Low/Info

Owner can by mistake rollover to a new voting period while previous period is active, users could loose bribe rewards due to deprived participation

Summary

The owner can roll over the voting session unintentionally by clicking on startNewVotingPeriod() function. This will replace the context of _currentVotingPeriodId, then it will not create enough opportunity for all eligible users to participate in the voting.

Vulnerability Detail

Current Voting period is the context when votes are casted and bribes are accounted. If the current voting period is amended before it expires replacing it with a new voting period, then users who did not vote yet will be deprived of the opportunity to earn bribe rewards.

In summary, there is a possibility that the voter contract is not honouring the voting period time window. This is unfair to those who assumed the time window for voting was 14 days.

While owner is responsible, the problem exists because there is no way for owner to correct this error.

Impact

Code Snippet

https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/Voter.sol#L107-L115

Tool used

Manual Review

Recommendation

The startNewVotingPeriod function should have a validation criteria to ensure that there is no active voting period before creating a new one.

   function startNewVotingPeriod() public onlyOwner {
   ==>    if(!_votingEnded()){
   ==>        revert IVoter_VotingPeriodInProgress()
   ==>    }

        _currentVotingPeriodId++;

        VotingPeriod storage period = _startTimes[_currentVotingPeriodId];
        period.startTime = block.timestamp;
        period.endTime = block.timestamp + _periodDuration;

        emit VotingPeriodStarted();
    }