Skip to content
Business logic Audit finding Intermediate

New vest reset unlockBegin of existing vest without removing vested amount

The vesting contract resets the unlock schedule when new tokens are vested, but does not reset the claimed amount, so a user who has already claimed some tokens can have their claimable balance underflow and revert. This locks their previously vested tokens until the new schedule completes.

gzeon Follow

Originally disclosed on Code4rena

Submitted by gzeon, also found by cccz, TrungOre, minhquanym, cmichel, 0xDjango, and rayn

https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/StakedCitadelVester.sol#L143

https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/StakedCitadelVester.sol#L109

Impact

When vest is called by xCTDL vault, the previous amount will re-lock according to the new vesting timeline. While this is as described in L127, claimableBalance might revert due to underflow if vesting[recipient].claimedAmounts > 0 because the user will need to vest the claimedAmounts again which should not be an expected behavior as it is already vested.

Proof of Concept

https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/StakedCitadelVester.sol#L143

        vesting[recipient].lockedAmounts =
            vesting[recipient].lockedAmounts +
            _amount;
        vesting[recipient].unlockBegin = _unlockBegin;
        vesting[recipient].unlockEnd = _unlockBegin + vestingDuration;

https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/StakedCitadelVester.sol#L109

        uint256 locked = vesting[recipient].lockedAmounts;
        uint256 claimed = vesting[recipient].claimedAmounts;
        if (block.timestamp >= vesting[recipient].unlockEnd) {
            return locked - claimed;
        }
        return
            ((locked * (block.timestamp - vesting[recipient].unlockBegin)) /
                (vesting[recipient].unlockEnd -
                    vesting[recipient].unlockBegin)) - claimed;

Recommended Mitigation Steps

Reset claimedAmounts on new vest

        vesting[recipient].lockedAmounts =
            vesting[recipient].lockedAmounts -
            vesting[recipient].claimedAmounts +
            _amount;
        vesting[recipient].claimedAmounts = 0
        vesting[recipient].unlockBegin = _unlockBegin;
        vesting[recipient].unlockEnd = _unlockBegin + vestingDuration;

shuklaayush (BadgerDAO) confirmed and commented:

I think this is valid and was fixed in https://github.com/Citadel-DAO/citadel-contracts/pull/44

jack-the-pug (judge) decreased severity to Medium and commented:

I’m downgrading this to Medium as there are no funds directly at risk, but a malfunction and leak of value. The user will have to wait for a longer than expected time to claim their vested funds.


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

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

The vest function updates lockedAmounts and the unlock schedule but leaves claimedAmounts unchanged, so the claimable calculation subtracts previously claimed tokens from a newly locked amount that does not include them.

Impact

The user cannot claim their previously vested tokens until the new vesting period ends, causing a delay and a leak of value, but no funds are directly at risk.

What the attacker needed

User has previously claimed some vested tokens; xCTDL vault calls vest again for the same user

The fix

The vest function should subtract the claimed amount from lockedAmounts and reset claimedAmounts to zero when a new vest is started; the report says this was fixed in a later pull request.

How it was found

  1. A user vests some tokens and claims part of them, so claimedAmounts is greater than zero.
  2. The xCTDL vault calls vest again for the same recipient with a new unlockBegin.
  3. The contract adds the new amount to lockedAmounts and resets unlockBegin and unlockEnd, but does not reset claimedAmounts.
  4. When the user calls claimableBalance, the calculation subtracts the old claimedAmounts from the new locked amount, causing an underflow and revert.

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 vesting contract gradually releases tokens over time. When new tokens are added, the contract restarts the release schedule but forgets to reset how many tokens the user has already claimed. This makes the contract think the user has claimed more than is available, so it refuses to release any more tokens until the new schedule finishes.

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 gzeon

View all

46 more disclosed reports, best first.

More from Badger Citadel contest

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.