Muscular Ceramic Dragonfly
Medium
The missing check in getExchangeRate
will cause a complete loss of funds for users as an attacker can exploit the lack of registered oracles to obtain incorrect exchange rates.
In getExchangeRate
function, there is no validation to ensure that the oracles for the specified tokens are registered. This oversight allows an attacker to manipulate the exchange rates by calling the function with unregistered oracles, potentially leading to financial losses.
No response
No response
- An attacker calls
getExchangeRate(tokenIn, tokenOut)
without registering the required oracles. - The function retrieves zero or incorrect values for the exchange rates.
- The attacker utilizes these manipulated rates to execute trades, resulting in financial losses for users.
No response
contract TestVulnerability {
VulnerableExchange exchange;
function setUp() public {
exchange = new VulnerableExchange();
}
function testInvalidExchangeRate() public {
IERC20 tokenIn = IERC20(address(0)); // Using a dummy token
IERC20 tokenOut = IERC20(address(0)); // Using a dummy token
// Not registering oracles to test the vulnerability
// exchange.registerOracle(tokenIn, oracle); // Commented out to demonstrate vulnerability
// Attempting to get exchange rate should lead to division by zero
uint256 rate = exchange.getExchangeRate(tokenIn, tokenOut); // Expecting error or incorrect value
}
}
No response