getUserInfo() returns incorrect values for locked and stakedAmount
The getUserInfo() function in UnionLens.sol returns the locked and stakedAmount values swapped because it destructures the Staker struct in the wrong order. Any user or front end calling this function receives incorrect staking information, which could lead to wrong decisions.
Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/80
Found by
obront
Summary
The getUserInfo() function mixes up the values for locked and stakedAmount, so the value for each of these is returned for the other.
Vulnerability Detail
In UnionLens.sol, the getUserInfo() function is used to retrieve information about a given user.
In order to pull the user's staking information, the following function is called:
(bool isMember, uint96 locked, uint96 stakedAmount) = userManager.stakers(user);
This function is intended to return these three values from the UserManager.sol contract. However, in that contract, the function being called returns a Staker struct, which has the following values:
struct Staker {
bool isMember;
uint96 stakedAmount;
uint96 locked;
}
Because both locked and stakedAmount have the type uint96, the function does not revert, and simply returns the incorrect values to the caller.
Impact
Any user or front end calling the getUserInfo() function will be given incorrect values, which could lead to wrong decisions.
Code Snippet
Tool used
Manual Review
Recommendation
Reverse the order of return values in the getUserInfo() function, so that it reads:
(bool isMember, uint96 stakedAmount, uint96 locked) = userManager.stakers(user);
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 destructuring assignment lists the struct fields in the wrong order, so the second returned value is assigned to locked and the third to stakedAmount.
Impact
Any user or front end calling getUserInfo() receives incorrect values, which could lead to wrong decisions.
What the attacker needed
None
The fix
The order of return values in getUserInfo() should be reversed to match the Staker struct fields.
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 that reads user staking data returns two numbers in the wrong order. Because both numbers are the same type, the code does not crash and silently gives back swapped values. Anyone relying on this function, such as a front end, sees incorrect information.
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.