Missing Return Statement in _getReserves Function in MagicLpAggregator Contract
The _getReserves function in the MagicLpAggregator contract did not return the reserve values fetched from the pair contract, causing latestAnswer to always return zero. This could lead dependent systems to receive incorrect price data, potentially causing financial loss or system failure.
0xAadi Follow with bareli, 0x11singh99 and 1 other
Originally disclosed on Code4rena
Submitted by 0xAadi, also found by bareli, 0x11singh99, and hihen
The MagicLpAggregator contract contains a flaw within the _getReserves function where it fails to return the reserve values fetched from the pair contract. This oversight results in the latestAnswer function always returning zero, which can have severe implications for any systems that depend on this contract for accurate liquidity pool pricing data.
Impact
The missing return statement in the _getReserves function leads to the latestAnswer function always returning zero. This affects any dependent systems or contracts that rely on accurate price data from the MagicLpAggregator contract, as they will receive incorrect information, potentially leading to financial loss or system failure.
Proof of Concept
The _getReserves function in the provided code snippet does not return the fetched reserves:
33: function _getReserves() internal view virtual returns (uint256, uint256) {
34: (uint256 baseReserve, uint256 quoteReserve) = pair.getReserves();
35: }
Due to the missing return statement, the latestAnswer function uses uninitialized variables for baseReserve and quoteReserve, which default to zero:
function latestAnswer() public view override returns (int256) {
// ...
(uint256 baseReserve, uint256 quoteReserve) = _getReserves();
baseReserve = baseReserve * (10 ** (WAD - baseDecimals)); // baseReserve defaults to 0
quoteReserve = quoteReserve * (10 ** (WAD - quoteDecimals)); // quoteReserve defaults to 0
// ...
}
Recommended Mitigation Steps
Update _getReserves()
- function _getReserves() internal view virtual returns (uint256, uint256) {
+ function _getReserves() internal view virtual returns (uint256 baseReserve, uint256 quoteReserve) {
- (uint256 baseReserve, uint256 quoteReserve) = pair.getReserves();
+ (baseReserve, quoteReserve) = pair.getReserves();
}
0xCalibur (Abracadabra) confirmed and commented:
Fixed in main during the audit:
https://github.com/Abracadabra-money/abracadabra-money-contracts
Note: For full discussion, see here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The _getReserves function declared return values but did not return them, so the caller received default zero values.
Impact
The latestAnswer function always returns zero, so any dependent systems or contracts relying on accurate price data receive incorrect information, potentially leading to financial loss or system failure.
What the attacker needed
None
The fix
The function should be updated to return the fetched reserves, and the text states it was fixed in main during the audit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract function was supposed to fetch two numbers (reserves) from another contract and pass them back, but it forgot to actually return them. So whenever the price function asked for those numbers, it got zero instead. Any system relying on that price would see a price of zero, which could cause serious problems.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.