https://github.com/OpenEdenHQ/openeden.usdoexpress.audit/tree/f3f31d2ac15e3253cba342229f9d05495f95d6fd
UsycRedemption.getprice() is used to determine the price of usdc to redemption token and vice versa.
function getPrice(address _oracle) public view returns (uint256) {
(uint80 roundId, int256 price, , uint256 updatedAt, uint80 answeredInRound) = IPriceFeed(_oracle)
.latestRoundData();
// Check if the price data is not older than 3 days
if (block.timestamp - updatedAt > MAX_PRICE_AGE) {
revert StalePrice(updatedAt, MAX_PRICE_AGE);
}
// Check for incomplete round data
if (answeredInRound < roundId) {
revert StalePrice(updatedAt, MAX_PRICE_AGE);
}
@> if (uint256(price) < minPrice) revert InvalidPrice(price);
return uint256(price);
}
The issue is that casting a negative int256 price to uint256 will wrap to a huge positive number, bypassing the minPrice check. This results in flawed stale price prevention mechanism. As all chainlink compliance implementation checks for negative price.
stale prices would be use to determine price of assets leading to inflated redemption.
Simulation of a negative price with chisel as it would require an oracle node to provide a stale price.
Enter chisel then:
Welcome to Chisel! Type `!help` to show available commands.
➜ uint256 minPrice = 1e18;
➜ int256 price = -5;
➜ uint256 converted = uint256(price);
➜ minPrice
Type: uint256
├ Hex: 0xde0b6b3a7640000
├ Hex (full word): 0x0000000000000000000000000000000000000000000000000de0b6b3a7640000
└ Decimal: 1000000000000000000
➜ price
Type: int256
├ Hex: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
├ Hex (full word): 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
└ Decimal: -5
➜ converted
Type: uint256
├ Hex: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
├ Hex (full word): 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
└ Decimal: 115792089237316195423570985008687907853269984665640564039457584007913129639931
➜ converted < minPrice
Type: bool//@audit the if condition would not execute
└ Value: false
➜
use this check instead
+ if (price <= 0 || uint256(price) < minPrice) revert InvalidPrice(price);
whenever there's a stale price the protocol ingests it due to implicit wrapping bypassing all constraints.
Attachments are hidden
This information is not publicly available.
Comments are hidden
This information is not publicly available.