Skip to content
Business logic Audit finding Beginner

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.

obront Follow

Originally disclosed on Sherlock

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:

Solidity
(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:

Solidity
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

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/UnionLens.sol#L62

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L37-L41

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/user/UserManager.sol#L117-L120

Tool used

Manual Review

Recommendation

Reverse the order of return values in the getUserInfo() function, so that it reads:

Solidity
(bool isMember, uint96 stakedAmount, uint96 locked) = userManager.stakers(user);

The original report as published on Sherlock, by obront. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by obront

View all

46 more disclosed reports, best first.

More from Union Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.