In the distributePoints
function, pointsPerToken
is calculated incorrectly. The code performs division before multiplication, which can cause rounding errors and result in different values instead of the correct value.
The distributePoints
function in the Solidity contract is designed to check whether an epoch has completed and then update the pointsPerToken
state variable based on the number of epochs that have passed (weeksPending
), the pointsPerEpoch
value, and the total number of tokens staked (totalStaked
).
In this calculation, the multiplication by weeksPending
is performed after the division of pointsPerEpoch
by totalStaked
. This sequence can lead to significant precision loss, which can negatively impact the accuracy of the pointsPerToken
calculation.
Assume the following values:
pointsPerEpoch = 100 * 10^18
PRECISION_18 = 10^18
totalStaked = (100 * 10^18) * 10^18 + 1
FjordTokens
weeksPending = 2
Given the current implementation, the calculation proceeds as follows:
Division First:
Which results in:
Since Solidity rounds down the result in integer division, this calculation results in 0
.
Multiplication by weeksPending
:
The final result is 0
, which is clearly incorrect in this context.
To avoid this issue, the multiplication by weeksPending
should occur before the division:
Multiplication First:
Which results in:
Division After:
Which results in:
The impact is directly proportional to the weeksPending
value. Due to this rounding issue, the pointsPerToken
calculation results in an incorrect value.
Manual Review
add the following code
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.