Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

KupiaSec - When the startBlock is reset, the lastRewardBlocks of the pools are not updated accordingly #90

Closed
sherlock-admin2 opened this issue May 24, 2024 · 2 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented May 24, 2024

KupiaSec

high

When the startBlock is reset, the lastRewardBlocks of the pools are not updated accordingly

Summary

The SophonFarming.setStartBlock() function resets the startBlock value, but does not update the lastRewardBlocks of the pools.

Vulnerability Detail

When the setStartBlock() function is called, it only updates the startBlock value, but does not reset the lastRewardBlocks of the pools.

In the normal situation, the lastRewardBlocks of the pools are initialized to the startBlock value in the add() function. However, if the owner later resets the startBlock to a value smaller than the original one, the lastRewardBlocks will remain set to the previous, higher startBlock value.

As a result, when the first update of the pools is performed, the rewards will be miscalculated. The system will assume the point distribution started from the old, higher startBlock value, instead of the new, lower startBlock value. This is because the blockMultiplier is calculated based on the lastRewardBlock.

This mismatch in startBlock and lastRewardBlock values leads to an incorrect rewards calculation, resulting in a loss of points for the users.

Impact

If the owner resets the startBlock to a value smaller than the previous one, users will lose a portion of their accumulated reward points.

Code Snippet

https://github.com/sherlock-audit/2024-05-sophon/blob/main/farming-contracts/contracts/farm/SophonFarming.sol#L272-L280

Tool used

Manual Review

Recommendation

When the setStartBlock() function is called, the lastRewardBlocks of the pools should also be reset, in addition to the startBlock.

Duplicate of #108

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels May 28, 2024
@sherlock-admin4
Copy link
Contributor

1 comment(s) were left on this issue during the judging contest.

0xmystery commented:

valid because lastRewardBlock for each pool should indeed sync with the latest startBlock

@sherlock-admin3 sherlock-admin3 added the Sponsor Disputed The sponsor disputed this issue's validity label May 29, 2024
@mystery0x
Copy link
Collaborator

This report should be valid as it described scenario 2 of #108.

@sherlock-admin3 sherlock-admin3 changed the title Nutty Bronze Rat - When the startBlock is reset, the lastRewardBlocks of the pools are not updated accordingly KupiaSec - When the startBlock is reset, the lastRewardBlocks of the pools are not updated accordingly Jun 1, 2024
@sherlock-admin3 sherlock-admin3 added the Reward A payout will be made for this issue label Jun 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Disputed The sponsor disputed this issue's validity
Projects
None yet
Development

No branches or pull requests

4 participants