The oracle fails to compound APR (Annual Percentage Rate) correctly over time, resulting in values that do not accurately reflect the cumulative growth intended
Game
What happens if the oracle reports incorrect values at the wrong moments?
// SPDX-License-Identifier: MIT// Open me in VSCode and really think before opening the hints!// Add @audit tags wherever suspicious// Go to the solidity docs to complete missing knowledge of what's happening here// Solve by drafting a fix!pragmasolidity ^0.8.0;interface IPriceOracle {functiongetPrice() externalviewreturns (uint256);}contract CompoundingMechanismGame { IPriceOracle public oracle;uint256public totalValue;uint256public interestRate =5; // 5% annual interestconstructor(address_oracle,uint256_initialValue) { oracle =IPriceOracle(_oracle); totalValue = _initialValue; }// Compound the value based on oracle pricefunctioncompound() public {uint256 price = oracle.getPrice();uint256 interest = (totalValue * interestRate * price) / (100*1e18); // Compounding logic totalValue += interest; }}
If an attacker can manipulate the oracle, how might they inflate or deflate the calculated interest in the compound function?
Consider how to validate the oracle’s data to prevent reliance on potentially manipulated values.