sherlock-audit / 2024-05-sophon-judging

1 stars 1 forks source link

nikhil840096 - Precision loss in `SophonFarming.sol:_pendingPoints`. #204

Closed sherlock-admin2 closed 1 month ago

sherlock-admin2 commented 1 month ago

nikhil840096

medium

Precision loss in SophonFarming.sol:_pendingPoints.

Summary

In this function multiplication is done after the division which can lead to the precision loss

Vulnerability Detail

pointReward is calculated by multiplying (blockMultiplier *pointsPerBlock *pool.allocPoint ) and then dividing by totalAllocPoint. Then after division it is getting multipled by 1e18 and divided by (lpSupply + accPointsPerShare) and accPointsPerShare has 1e18 decimal place. This can lead to a precision loss.

Impact

depositors may get less reward due to precision loss.

Code Snippet

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

Tool used

Manual Review

Recommendation

Use best practice to save from precision loss.

sherlock-admin2 commented 1 month ago

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

0xmystery commented:

invalid because no division before multiplication is found