Reentrancy may allow an admin to steal funds
The withdrawAdmin function in VTVLVesting.sol checks the contract's token balance before transferring tokens, allowing a reentrant token to call the function again before the balance updates. An admin could exploit this to drain tokens reserved for active vestings.
Submitted by Czar102, also found by 0xSmartContract, csanuragjain, hansfriese, Lambda, Respx, and sashik_eth
If the token is reentrant, an admin can steal all tokens locked in the VTVLVesting contract while having active locks.
In other words, due to this exploit possibility, the contract may be insolvent with respect to active vestings. Note that revoking claim doesn’t break this invariant since the vesting is closed in that case.
Proof of Concept
The reentrancy in the vested token can be used by an admin if the execution can be hijacked before the balance change occurs.
/**
@notice Admin withdrawal of the unallocated tokens.
@param _amountRequested - the amount that we want to withdraw
*/
function withdrawAdmin(uint112 _amountRequested) public onlyAdmin {
// Allow the owner to withdraw any balance not currently tied up in contracts.
uint256 amountRemaining = tokenAddress.balanceOf(address(this)) - numTokensReservedForVesting;
require(amountRemaining >= _amountRequested, "INSUFFICIENT_BALANCE");
// Actually withdraw the tokens
// Reentrancy note - this operation doesn't touch any of the internal vars, simply transfers
// Also following Checks-effects-interactions pattern
tokenAddress.safeTransfer(_msgSender(), _amountRequested);
// Let the withdrawal known to everyone
emit AdminWithdrawn(_msgSender(), _amountRequested);
}
Let’s consider function withdrawAdmin. Firstly, the balance is checked and then if there is enough token surplus to withdraw, the withdrawal is allowed. The surplus is based on two values: numTokensReservedForVesting which isn’t changed by this function and the balance of the contract.
If the owner hijacks the execution before the balance change in the token transfer (which is possible in, for example, ERC777), an admin can call this function again and it will allow for an invocation of another transfer since the token balance hasn’t changed yet.
For example, if there is $1m in vestings in the contract, an admin can send $100k to it in tokens and recursively invoke withdrawalAdmin with the amount of $100k eleven times so that the whole contract balance will be drained.
Recommended Mitigation Steps
Add ReentrancyGuard’s nonReentrant to the withdrawAdmin function.
This would require a number of assumptions to be the case including a malicious admin which the sponsors called out of scope. Because it is obviously not intended functionality, I am going to leave as Medium pending sponsor review. I think the non-reentrant modifier is worth adding.
lawrencehui (VTVL) acknowledged and commented:
Will consider adding ReentrancyGuard as suggested.
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 withdrawAdmin function performs a balance check before the token transfer, and if the token is reentrant, the balance is not updated until after the external call, allowing repeated withdrawals.
Impact
An admin could steal all tokens locked in active vestings, making the contract insolvent, but this requires a malicious admin and a reentrant token.
What the attacker needed
Malicious admin; reentrant token (e.g., ERC777)
The fix
Add a reentrancy guard (nonReentrant modifier) to the withdrawAdmin function.
How it was found
- Admin sends a small amount of tokens to the contract to create a surplus.
- Admin calls withdrawAdmin with an amount equal to the surplus.
- During the token transfer, the reentrant token calls back into withdrawAdmin before the balance is updated.
- The callback sees the same surplus and allows another withdrawal.
- Repeat the callback to drain the contract's balance.
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 reentrant token is a token that can run code when it is transferred, which can call back into the contract before the first transfer finishes. The withdrawAdmin function checks how many tokens are available before sending them, but if the token calls back before the balance changes, the check can pass again. This lets an admin take out more tokens than they should, potentially taking tokens meant for other users.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.