sherlock-audit / 2024-02-optimism-2024-judging

6 stars 4 forks source link

Potential Precision Loss Due to Division Before Multiplication #236

Closed sherlock-admin2 closed 7 months ago

sherlock-admin2 commented 7 months ago

Potential Precision Loss Due to Division Before Multiplication

Low/Info issue submitted by bigbick123456789000

Summary

see below

Vulnerability Detail

In the provided code snippet, a potential vulnerability arises due to the sequence of operations involving division followed by multiplication. Here's a detailed breakdown:

uint256 a = highGasCharged / baseGasCharged; // Division operation
uint256 lnA = uint256(FixedPointMathLib.lnWad(int256(a * FixedPointMathLib.WAD))); // Multiplication operation

The highGasCharged and baseGasCharged variables represent certain gas-related parameters, and the lnWad function calculates the natural logarithm. However, the vulnerability lies in the fact that the division operation is performed before the multiplication. This sequence of operations can potentially lead to precision loss.

Impact

The impact of this vulnerability is that it can introduce inaccuracies or imprecisions in the calculated value of lnA. Depending on the specific values of highGasCharged and baseGasCharged, as well as the precision handling within the FixedPointMathLib library, the loss of precision could affect the accuracy of subsequent calculations or decisions based on the result.

Code Snippet

FaultDisputeGame.sol#L604-L610

Tool used

Manual Review

Recommendation

The sequence of operations should be adjusted to prioritize multiplication before division.

 uint256 a = (highGasCharged * FixedPointMathLib.WAD) / baseGasCharged; // Multiplication operation followed by division
uint256 lnA = uint256(FixedPointMathLib.lnWad(int256(a))); // Calculate natural logarithm