Skip to content
Business logic Audit finding Intermediate

Variable balance token causing fund lock and loss

The vesting contract checks its token balance only when a claim is created, but some ERC20 tokens can change balance over time. If the balance falls below the reserved amount, withdrawals revert and users' funds are locked; the protocol may need to top up the contract, causing a loss.

__141345__ Follow

Originally disclosed on Code4rena

Submitted by 141345, also found by 0xDecorativePineapple, CertoraInc, djxploit, hyh, IllIllI, JohnSmith, MiloTruck, rbserver, and zzzitron

VTVLVesting.sol#L295 VTVLVesting.sol#L388

Some ERC20 token’s balance could change, one example is stETH. The balance could become insufficient at the time of withdraw(). User’s fund will be locked due to DoS. The way to take the fund out is to send more token into the contract, causing fund loss to the protocol. And there is no guarantee that until the end time the balance would stay above the needed amount, the lock and loss issue persist.

Proof of Concept

For stETH like tokens, the balanceOf() value might go up or down, even without transfer.

// stETH
    function balanceOf(address who) external override view returns (uint256) {
        return _shareBalances[who].div(_sharesPerToken);
    }

In VTVLVesting, the require check for the spot balanceOf() value will pass, but it is possible that as time goes on, the value become smaller and fail the transfer. As a result, the withdraw() call will revert, causing DoS, and lock user’s fund.

// contracts/VTVLVesting.sol
    function _createClaimUnchecked() private  hasNoClaim(_recipient) {
        // ...
        require(tokenAddress.balanceOf(address(this)) >= numTokensReservedForVesting + allocatedAmount, "INSUFFICIENT_BALANCE");
        // ...
    }

    function withdraw() hasActiveClaim(_msgSender()) external {
        // ...
        tokenAddress.safeTransfer(_msgSender(), amountRemaining);
        // ...
    }

Reference

https://etherscan.io/address/0x312ca0592a39a5fa5c87bb4f1da7b77544a91b87#code

Recommended Mitigation Steps

Disallow such kind of variable balance token.

0xean (judge) decreased severity to Medium and commented:

stETH only rebases up, not down. So that is a poor example.

The sponsor’s README does say they will support any ERC20 token, so that could include Fee on Transfer or downward rebasing tokens which could lead to less tokens in the contract than expected and transfers to revert due to balances being lower than expected.

Downgrading to Medium as the external requirement is using these contracts on tokens that are known to have variable supply.

lawrencehui (VTVL) confirmed and commented:

Thanks for reporting this and I will add this as a feature enhancement to cater / avoid for tokens with rebasing supplies.

Question: Is there a straight forward way to detect rebasing tokens? Or on the flip side, restricting erc20 tokens that do not exhibit rebasing behaviour?

0xean (judge) commented:

@lawrencehui - Great question. There isn’t a great way to detect this functionality in any generic manner unfortunately.

Most contracts that want to handle FOT tokens will do something like (in pseudocode)

uint256 balBefore = ERC20.balanceOf(address(this));
ERC20.transferFrom(...);
uint256 balAfter= ERC20.balanceOf(address(this));
uint256 actualBalChange = balAfter - balBefore;

Rebasing tokens are different again, and the easiest way to handle them is to create shares to track the internal math. The shares track the % ownership of the entire balance of the contract. Probably more than I can explain here, but would be happy to work with you if this is something you are interested in.


The original report as published on Code4rena, by __141345__. 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

Likely the contract assumes a static token balance and does not account for tokens whose balance can decrease over time.

Impact

Withdrawals could revert, locking user funds; the protocol may need to send more tokens to unlock them, causing a loss. The judge noted the example token only rebases up, so the issue depends on using downward-rebasing or fee-on-transfer tokens.

What the attacker needed

Contract uses a variable-balance ERC20 token; token balance decreases below reserved amount

The fix

The contract should either disallow variable-balance tokens or track shares of the contract's balance instead of absolute amounts.

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 holds tokens for users and pays them out over time. It checks it has enough tokens when it sets up a claim, but some tokens (like rebasing tokens) can change how many tokens the contract holds without any transfer. If the balance drops later, the payout fails and the user cannot get their tokens.

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 __141345__

View all

18 more disclosed reports, best first.

More from VTVL 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.