UniswapPriceAdaptor fails after updating impact
The updateImpact function accepts a uint32 parameter, but the impact variable is used in a calculation that can produce values larger than uint32, causing getMarkPrice to revert. An attacker could not directly exploit this, but the adaptor would malfunction and fail to return the price from Uniswap Oracle.
Source: https://github.com/sherlock-audit/2023-04-jojo-judging/issues/364
Found by
ast3ros
Summary
The impact variable can have a maximum value of uint32 (=4.294.967.295) after updating. This is too low and will cause the UniswapPriceAdaptor#getMarkPrice() function to revert.
Vulnerability Detail
When initialized, the impact variable is a uint256. However, in the updateImpact function, the newImpact is a uint32.
function updateImpact(uint32 newImpact) external onlyOwner {
emit UpdateImpact(impact, newImpact);
impact = newImpact;
}
The new impact variable will be too small because in the getMarkPrice() function, we need diff * 1e18 / JOJOPriceFeed <= impact:
require(diff * 1e18 / JOJOPriceFeed <= impact, "deviation is too big");
The result of diff * 1e18 / JOJOPriceFeed <= impact is a number with e18 power. It is very likely that it is larger than the impact variable which is a uint32. The function getMarkPrice() will revert.
Impact
The UniswapPriceAdaptor will malfunction and not return the price from Uniswap Oracle.
Code Snippet
https://github.com/sherlock-audit/2023-04-jojo/blob/main/smart-contract-EVM/contracts/adaptor/uniswapPriceAdaptor.sol#L52 https://github.com/sherlock-audit/2023-04-jojo/blob/main/smart-contract-EVM/contracts/adaptor/uniswapPriceAdaptor.sol#L61-L64
Tool used
Manual Review
Recommendation
Change the newImpact argument from uint32 to uint256.
- function updateImpact(uint32 newImpact) external onlyOwner {
+ function updateImpact(uint256 newImpact) external onlyOwner {
emit UpdateImpact(impact, newImpact);
impact = newImpact;
}
Discussion
JoscelynFarr
fix link: https://github.com/JOJOexchange/smart-contract-EVM/commit/6138d912bdfe7e644b74a182749ab79bb5dc6028 https://github.com/JOJOexchange/JUSDV1/commit/cc6c7518719406923e4678478b7ea0eebfa0b079
JoscelynFarr
And we also think this is a low issues to update uint32 to uint256
thangtranth
Escalate for 10 USDC.
The impact of this issue is that “The UniswapPriceAdaptor will malfunction and not return the price from Uniswap Oracle”. This breaks the functionality of the protocol as explained above and therefore it definitely qualifies as a medium issue. The simplicity of the fix does not imply a low severity issue.
sherlock-admin
Escalate for 10 USDC.
The impact of this issue is that “The UniswapPriceAdaptor will malfunction and not return the price from Uniswap Oracle”. This breaks the functionality of the protocol as explained above and therefore it definitely qualifies as a medium issue. The simplicity of the fix does not imply a low severity issue.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
JoscelynFarr
Ok
hrishibhat
Result: Medium Unique This is a valid medium issue as pointed out by the escalation
sherlock-admin
Escalations have been resolved successfully!
Escalation status:
- thangtranth: accepted
IAm0x52
Fix looks good. Type of newImpact changed from uint32 to uint256
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 updateImpact function takes a uint32 parameter, but the impact variable is compared against a value scaled by 1e18, which can easily exceed uint32, causing the require statement to revert.
What the attacker needed
Owner calls updateImpact with a value that is too small
The fix
The fix changes the newImpact parameter from uint32 to uint256, as confirmed by the fix link and the comment that the fix looks good.
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.
This is a smart contract bug where a number type is too small. The impact variable is used in a calculation that can produce very large numbers, but it is stored as a 32-bit unsigned integer (uint32), which can only hold up to about 4.3 billion. When the calculated value exceeds that, the function that checks the deviation will fail and revert, breaking the price feed.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.