sherlock-audit / 2023-04-blueberry-judging

8 stars 5 forks source link

J4de - `BalancePairOracal.sol#computeFairReserves` function does not consider the decimals #68

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

J4de

medium

BalancePairOracal.sol#computeFairReserves function does not consider the decimals

Summary

BalancePairOracal.sol#computeFairReserves function does not consider the decimals.

Vulnerability Detail

File: oracle/BalancerPairOracle.sol
 53         uint256 r0 = resA / resB;
 54         uint256 r1 = (wA * pxB) / (wB * pxA);

Lines 53 and 54 do not consider decimals, this can lead to very large calculation errors. For example, the decimals of token A is 8 and the decimals of token B is 18, then r0 is almost always 0.

Impact

The computeFairReserves function is used to calculate prices, which can lead to very large price errors.

Code Snippet

https://github.com/sherlock-audit/2023-04-blueberry/blob/main/blueberry-core/contracts/oracle/BalancerPairOracle.sol#L53-L54

Tool used

Manual Review

Recommendation

It is recommended to consider the decimal places of token and price.