QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

MultiHopOracle::_getData Function Does Not Check If Oracle Returns Zero Data

Summary

In the MultiHopOracle::_getData function, the contract does not check whether the data returned from the Oracle is zero. This could result in division by zero errors or unexpected results when performing mathematical operations on the returned data. Specifically, when the Oracle returns zero data, the contract fails to perform a valid check and handle this situation, potentially leading to unpredictable behavior.

Vulnerability Details

The MultiHopOracle::_getData function attempts to gather data from a series of Oracles and performs a sequence of transformations to calculate the final data value. However, the function does not check if the data returned from each Oracle is zero. Specifically, the following areas could lead to issues:

  1. If the data returned by any Oracle is zero, the subsequent mathematical operations will lead to division by zero errors or inaccurate results. This could result in:

    • If the data is zero and not handled, it could cause the contract state to become inconsistent or return incorrect computed results.

    • If a division by zero occurs, it may throw exceptions or cause the computation to fail, interrupting the contract's normal functionality.

  2. If any Oracle returns zero data and it is not addressed, the final calculated result may be inaccurate, leading to incorrect state updates or erroneous decision-making.

Impact

This vulnerability could lead to the following problems:

  1. Division by Zero Error: If an Oracle returns zero and participates in subsequent calculations, it will lead to a division by zero error, causing the contract to fail or halt execution.

  2. Inaccurate Calculation Results: If Oracle data is zero and not properly handled, the final computed value will be inaccurate, which could lead to incorrect transactions or undermine the functionality of the contract.

  3. Contract Failures: Inaccurate calculations or errors could cause the contract's functionality to break, leading to loss of user funds or the inability to execute operations.

  4. Potential Attacks: Malicious actors may exploit the lack of checks for zero data from Oracles, causing abnormal contract behavior and potentially jeopardizing the pool's funds.

Tools Used

Manual code audit

Recommendations

It is recommended to add checks to verify if the data from each Oracle is zero before performing any mathematical operations. If zero data is detected, the contract should either revert the operation or handle it appropriately. For example:

function _getData() internal view override returns (int216 data, uint40 timestamp) {
HopConfig memory firstOracle = oracles[0];
(data, timestamp) = firstOracle.oracle.getData();
// Check if data is zero
+ require(data != 0, "Oracle returned zero data");
if (firstOracle.invert) {
data = 10 ** 36 / data; // 10^36 (i.e., 1 with 18 decimals * 10^18) to get the inverse with 18 decimals.
}
uint256 oracleLength = oracles.length;
for (uint i = 1; i < oracleLength; ) {
HopConfig memory oracleConfig = oracles[i];
(int216 oracleRes, uint40 oracleTimestamp) = oracleConfig.oracle.getData();
// Check if each Oracle's data is zero
+ require(oracleRes != 0, "Oracle returned zero data");
if (oracleTimestamp < timestamp) {
timestamp = oracleTimestamp; // Return minimum timestamp
}
// Update data based on whether inversion is required
if (oracleConfig.invert) {
data = (data * 10 ** 18) / oracleRes;
} else {
data = (data * oracleRes) / 10 ** 18;
}
unchecked {
++i;
}
}
}

By adding these checks, the contract can ensure that the Oracle data is valid before performing any mathematical operations, preventing division by zero errors or inaccurate results, and ensuring the contract operates as expected.

Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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