The function viewWhitelistedCurrencies in the CurrencyManager contract allows users to retrieve a paginated list of whitelisted currencies based on the cursor and size parameters. However, if the cursor provided by the user is greater than the total number of whitelisted currencies, an underflow will occur, causing the function to revert unexpectedly.
In the viewWhitelistedCurrencies function, the length of the paginated response is calculated by checking if the requested size exceeds the available whitelisted currencies starting from the given cursor. If cursor is greater than or equal to _whitelistedCurrencies.length(), then _whitelistedCurrencies.length() - cursor results in an underflow, causing a revert.
This occurs because the subtraction is unsigned and cannot handle values where cursor > _whitelistedCurrencies.length(). Users providing a high cursor value, either accidentally or maliciously, will encounter unexpected reverts when attempting to call this function.
This vulnerability can disrupt the user experience and potentially impact front-end interfaces that rely on this function to fetch paginated data. An attacker could also use this to intentionally trigger reverts, disrupting the UI or causing denial-of-service for users attempting to view whitelisted currencies.
User calls the viewWhitelistedCurrencies function with a cursor value greater than by mistake this will cause the function to revert due to underflow.
Due to this underflow, the function will revert and the user will not be able to retrieve the paginated list of whitelisted currencies.
Create a BugTest.t.sol contract in the test folder.
Add the following code to the BugTest.t.sol file:
Run the test using the command forge test --mt test_FortisAudits_Underflow -vvvv.
To mitigate this, add a check at the beginning of the function to ensure that cursor is within bounds:
This check prevents cursor from exceeding the length of _whitelistedCurrencies, avoiding the underflow and ensuring consistent and safe function execution.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.