Potential rounding-down precision loss when median averages two values
When the price array length is even, the median is the integer average of the two middle elements. Solidity's lack of decimals means the result rounds down.
Description
The prices for the feeds are calculated as the median of all values. The median requires a sorted array of elements, taking the middle value. However, when the number of elements is even, the median is calculated as the arithmetic average of the two middle elements:
uint256 sum = arr[middleIndex - 1] + arr[middleIndex];return sum / 2;
Since Solidity does not support decimal numbers, some precision may be lost during this operation due to rounding down which could lead to slightly different prices than was expected. This behaviour is likely known to the RedStone protocol, but it is important to note this potential loss in precision to maintain reasonable decimal accuracy for the prices.
Impact
By default, RedStone feeds use eight decimals, where the expected precision loss is around 0.0000005%, which is considered negligible.
Recommendation
Ensure awareness of this rounding behaviour to maintain appropriate precision in price calculations.
Resolution
RedStone: Acknowledged.

