DeFiFoundry
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Divide before multiply in FjordPoints.sol

Summary

The FjordPoints contract contains a mathematical vulnerability in the distributePoints function, where division is performed before multiplication, which may lead to precision loss. This vulnerability occurs when computing variables such as weeksPending, pointsPerToken, totalPoints, and lastDistribution.

Vulnerability Details

Location

  1. src/FjordPoints.sol#251

uint256 weeksPending = (block.timestamp - lastDistribution) / EPOCH_DURATION;

Kopier kode

  1. src/FjordPoints.sol#252-253

pointsPerToken = pointsPerToken.add(weeksPending * (pointsPerEpoch.mul(PRECISION_18).div(totalStaked)));

Kopier kode

  1. src/FjordPoints.sol#254

totalPoints = totalPoints.add(pointsPerEpoch * weeksPending);

Kopier kode

  1. src/FjordPoints.sol#255

lastDistribution = lastDistribution + (weeksPending * 604800); // 604800 is EPOCH_DURATION

When performing integer division before multiplication, Solidity truncates the division result, potentially leading to precision loss. For instance, the weeksPending variable might result in 0 if the calculated duration between block.timestamp and lastDistribution is less than EPOCH_DURATION, causing subsequent calculations to incorrectly evaluate to 0.

For example:

uint256 weeksPending = (block.timestamp - lastDistribution) / EPOCH_DURATION;

If block.timestamp - lastDistribution is less than EPOCH_DURATION, weeksPending will be zero, causing further calculations that depend on weeksPending to also be zero.

Impact

  • Precision Loss: The calculated number of weeks pending, total points distributed, and points per token can be significantly lower than expected due to truncated results.

  • Incorrect Distribution: Users may not receive the correct number of points for their staked tokens, leading to unfair point distribution.

  • Potential Exploitation: An attacker may manipulate the timings to minimize weeksPending and thus reduce points distribution

Tools Used

  • Manual code review

Recommendations

Rearrange the arithmetic operations to perform multiplication before division to retain precision.

Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Division before multiplication

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.