F-2024-0004·precision-loss

Potential rounding-down precision loss when median averages two values

Acknowledgedoracleprice-feeddata-streamsgithub.com/redstone-finance/redstone-oracles-monorepo
TL;DR

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.

Severity
INFO
Impact
LOW
Likelihood
LOW
Method
MManual review
CAT.
Complexity
LOW
Exploitability
LOW
02Section · Description

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:

solidity
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.

03Section · Impact

Impact

By default, RedStone feeds use eight decimals, where the expected precision loss is around 0.0000005%, which is considered negligible.

04Section · Recommendation

Recommendation

Ensure awareness of this rounding behaviour to maintain appropriate precision in price calculations.

05Section · Resolution

Resolution

RedStone: Acknowledged.

F-2024-0004

oog
zealynx

Smart Contract Security Digest

Monthly exploit breakdowns, audit checklists, and DeFi security research — straight to your inbox

© 2026 Zealynx