Skip to content
Business logic Audit finding Intermediate

A stake that has just been locked gets full reward multiplier

The rewards multiplier for stakers in Union Finance is calculated based solely on whether a stake is locked, not on how long it has been locked. An attacker can lock a stake, vouch for another member, have that member borrow, then withdraw rewards with the full multiplier and repay the loan in the same transaction, gaining extra rewards without risking funds.

Bahurum Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/142

Found by

Bahurum

Summary

A staker gets rewarded with full multiplier even if its stake has just been locked. Multiplier calculation should take into account the duration of the lock.

Vulnerability Detail

  1. A staker stakes an amount of tokens.
  2. The staker waits for some time
  3. The staker has control of another member (bribe, ...)
  4. The staker vouches this other member
  5. The member borrows
  6. The staker calls Comptroller:withdrawRewards and gets an amount of rewards with a multiplier corresponding to a locked stake
  7. The member repays the loan

Note that steps 4 to 7 can be made in one tx, so no interest is paid at step 7.

The result is that the staker can always get the full multiplier for rewards, without ever putting any funds at risk, nor any interest being paid. This is done at the expense of other honest stakers, who get proprotionally less of the rewards dripped into the comptroller.

For a coded PoC replace the test "staker with locked balance gets more rewards" in staking.ts with the following

TypeScript
        it("PoC: staker with locked balance gets more rewards even when just locked", async () => {
            const trustAmount = parseUnits("2000");
            const borrowAmount = parseUnits("1800");
            const [account, staker, borrower] = members;

            const [accountStaked, borrowerStaked, stakerStaked] = await helpers.getStakedAmounts(
                account,
                staker,
                borrower
            );

            expect(accountStaked).eq(borrowerStaked);
            expect(borrowerStaked).eq(stakerStaked);

            await helpers.updateTrust(staker, borrower, trustAmount);
            
            await roll(10);
            await helpers.borrow(borrower, borrowAmount); // borrows just after withdrawing
            
            const [accountMultiplier, stakerMultiplier] = await helpers.getRewardsMultipliers(account, staker);
            console.log("accountMultiplier: ", accountMultiplier);
            console.log("StakerMultiplier: ", stakerMultiplier);
            expect(accountMultiplier).lt(stakerMultiplier);  // the multiplier is larger even if just locked
        });

Impact

A staker can get larger rewards designed for locked stakes by locking and unlocking in the same tx.

Code Snippet

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/token/Comptroller.sol#L166-L173

Solidity
    function getRewardsMultiplier(address account, address token) external view override returns (uint256) {
        IUserManager userManagerContract = _getUserManager(token);
        uint256 stakingAmount = userManagerContract.getStakerBalance(account);
        uint256 lockedStake = userManagerContract.getTotalLockedStake(account);
        (uint256 totalFrozen, ) = userManagerContract.getFrozenInfo(account, block.number);
        bool isMember = userManagerContract.checkIsMember(account);
        return _getRewardsMultiplier(stakingAmount, lockedStake, totalFrozen, isMember);
    }

Tool used

Manual Review

Recommendation

Should introduce the accounting of the duration of a lock into the rewards calculation, so that full multiplier is given only to a lock that is as old as the stake itself.

Discussion

kingjacob

probably a medium because no one is losing funds, just some people might get more UNION votes.

The original report as published on Sherlock, by Bahurum. 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 rewards multiplier calculation ignores the duration of the lock, so any lock, even a momentary one, qualifies for the full multiplier.

What the attacker needed

Control of another member (e.g., via bribe); ability to stake tokens; ability to call withdrawRewards

The fix

The rewards calculation should account for the duration of the lock, giving the full multiplier only to locks that are as old as the stake itself.

How it was found

  1. A staker stakes an amount of tokens.
  2. The staker waits for some time.
  3. The staker gains control of another member (e.g., via bribe).
  4. The staker vouches for this other member.
  5. The member borrows.
  6. The staker calls withdrawRewards and gets rewards with a multiplier for a locked stake, then the member repays the loan.

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 this system, people who lock their tokens for a period are supposed to get extra rewards. But the code only checks if tokens are locked, not how long they have been locked. So someone can lock tokens for just a moment, collect the full bonus, and unlock them right away, taking rewards that should go to honest long-term stakers.

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 Bahurum

View all

10 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.