sherlock-audit / 2024-05-sophon-judging

7 stars 6 forks source link

Incorrect natspec for `accPointsPerShare` in `SophonFarmingState` PoolInfo struct #231

Closed sherlock-admin3 closed 4 months ago

sherlock-admin3 commented 4 months ago

Incorrect natspec for accPointsPerShare in SophonFarmingState PoolInfo struct

Low/Info issue submitted by 4b

Summary

Incorrect natspec in SophonFarmingState PoolInfo struct

Vulnerability Detail

The natspec states that accPointsPerShare = Accumulated points per share, times 1e18.

But in SophonFarming updatePool function at line 430, we can observe that the accPointsPerShare being calculated is not multiplied by 1e18 like other parts of the code.

Therefore violating the invariant stated in the natspec

Impact

Incorrect natspec

Code Snippet

    function updatePool(uint256 _pid) public {
        PoolInfo storage pool = poolInfo[_pid];
        if (getBlockNumber() <= pool.lastRewardBlock) {
            return;
        }
        uint256 lpSupply = pool.amount;
        uint256 _pointsPerBlock = pointsPerBlock;
        uint256 _allocPoint = pool.allocPoint;
        if (lpSupply == 0 || _pointsPerBlock == 0 || _allocPoint == 0) {
            pool.lastRewardBlock = getBlockNumber();
            return;
        }
        uint256 blockMultiplier = _getBlockMultiplier(pool.lastRewardBlock, getBlockNumber());
        uint256 pointReward =
            blockMultiplier *
            _pointsPerBlock *
            _allocPoint /
            totalAllocPoint;

        pool.accPointsPerShare = pointReward /
            lpSupply +
            pool.accPointsPerShare;

        pool.lastRewardBlock = getBlockNumber();
    }

Tool used

Manual Review

Recommendation

Natspec should be corrected