uint(-1) index for not found
The smart contract functions that look up token configurations by symbol hash, cToken, or underlying asset check whether the returned index equals the maximum unsigned integer to indicate 'not found'. However, an uninitialised unsigned integer defaults to zero, so the sentinel value can never be returned; instead, zero is returned for non-existent configurations, which is also a valid index for the first configuration. This could cause callers to treat a missing configuration as the first valid one.
Based Loans
Originally disclosed on Code4rena
Functions getTokenConfigBySymbolHash, getTokenConfigByCToken and getTokenConfigByUnderlying check returned index against max uint: index != uint(-1)
-1 should indicate that the index is not found, however, a default value for an uninitialized uint is 0, so it is impossible to get -1. What is even weirder is that 0 will be returned for non-existing configs but 0 is a valid index for the 1st config.
One of the solutions would be to reserve 0 for a not found index and use it when searching in mappings. Then normal indexes should start from 1. Another solution would be to introduce a new mapping with a boolean value that indicates if this index is initialized or not but this may be a more gas costly way.
ghoul-sol (Based Loans) confirmed:
UniswapConfighas been refactored. Index 0 is considered a non-existent config and all comparison are against that value.
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
Likely the code uses an impossible sentinel value (max uint) to indicate 'not found' for an unsigned integer index, but uninitialised values default to 0, so the sentinel is never returned and 0 is ambiguous with a valid index.
Impact
Callers may incorrectly treat a non-existent token configuration as the first valid configuration, potentially leading to wrong behaviour or unintended actions.
What the attacker needed
None
The fix
The contract was refactored so that index 0 is reserved to mean 'non-existent configuration' and all comparisons use that value.
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.
In programming, a function sometimes needs to say 'I couldn't find what you asked for'. Here, the code tried to say that by returning a special number (the largest possible unsigned integer, which looks like -1). But in this language, numbers can't be negative, and a variable that hasn't been set starts at 0. So the 'not found' signal never happens; instead, the function returns 0, which is also the index of the first real configuration. That means a caller might think a missing configuration is actually the first one.
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.