Unused funds are not returned and not counted in GeVault
When users deposit funds into GeVault, some tokens may not be deposited into Uniswap pools and are left in the contract. These unused tokens are not returned to the depositor and are not counted in the total value locked (TVL), so depositors can lose part of their funds.
Jeiwan Follow with Jeiwan, LokiThe5th and 3 others
Originally disclosed on Code4rena
Submitted by Jeiwan, also found by Jeiwan, LokiThe5th, osmanozdemir1, said, and HChang26
Users can lose a portion of their deposited funds if some of their funds haven’t been deposited to the underlying Uniswap pools. There’s always a chance of such event since Uniswap pools take balanced token amounts when liquidity is added but GeVault doesn’t pre-compute balanced amounts. As a result, depositing and withdrawing can result in a partial loss of funds.
Proof of Concept
The GeVault.deposit() function is used by users to deposits funds into ticks and underlying Uniswap pools. The function takes funds from the caller and calls rebalance() to distribute the funds among the ticks. The GeVault.rebalance() function first removes liquidity from all ticks and then deposits the removed assets plus the user assets back in to the ticks:
function rebalance() public {
require(poolMatchesOracle(), "GEV: Oracle Error");
removeFromAllTicks();
if (isEnabled) deployAssets();
}
The GeVault.deployAssets() function calls the GeVault.depositAndStash() function, which actually deposits tokens into a TokenisableRange contract by calling the TokenisableRange.deposit(). The function deposits tokens into a Uniswap V3 pool and returns unspent tokens to the caller:
(uint128 newLiquidity, uint256 added0, uint256 added1) = POS_MGR.increaseLiquidity(
...
);
...
_mint(msg.sender, lpAmt);
TOKEN0.token.safeTransfer( msg.sender, n0 - added0);
TOKEN1.token.safeTransfer( msg.sender, n1 - added1);
However, the GeVault.depositAndStash() function doesn’t handle the returned unspent tokens. Since Uniswap V3 pools take balanced token amounts (respective to the current pool price) and since the funds deposited into ticks are not balanced (deployAssets() splits token amounts in halves), there’s always a chance that the TokenisableRange.deposit() function won’t consume all specified tokens and will return some of them to the GeVault contract. However, GeVault won’t return the unused tokens to the depositor.
Moreover, the contract won’t include them in the TVL calculation:
- The GeVault.getTVL() function computes the total LP token balance of the contract (
getTickBalance(k)) and the price of each LP token (t.latestAnswer()), to compute the total value of the vault. - The GeVault.getTickBalance() function won’t count the unused tokens because it only returns the amount of LP tokens deposited into the lending pool. I.e. only the liquidity deposited to Uniswap pools is counted.
- The TokenisableRange.latestAnswer() function computes the total value (TokenisableRange.sol#L355) of the liquidity deposited into the Uniswap pool (TokenisableRange.sol#L338). Thus, the unused tokens won’t be counted here as well.
- The GeVault.getTVL() function is used to compute the amount of tokens to return to the depositor during withdrawal.
Thus, the unused tokens will be locked in the contract until they’re deposited into ticks. However, rebalancing and depositing of tokens can result in new unused tokens that won’t be counted in the TVL.
Recommended Mitigation Steps
In the GeVault.deposit() function, consider returning unspent tokens to the depositor. Extra testing is needed to guarantee that rebalancing doesn’t result in unspent tokens, or, alternatively, such tokens could be counted in a storage variable and excluded from the balance of unspent tokens during depositing.
Alternatively, consider counting GeVault’s token balances in the getTVL() function. This won’t require returning unspent tokens during depositing and will allow depositors to withdraw their entire funds.
Keref (Good Entry) confirmed and commented:
See update.
Take unused funds into account for TVL. PR: https://github.com/GoodEntry-io/ge/commit/a8ba6492b19154c72596086f5531f6821b4a46a2
Status: Mitigation confirmed. Full details in reports from kutugu, xuwinnie and 3docSec.
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 deposit logic does not return unspent tokens to the depositor and the TVL calculation ignores tokens held directly by the vault.
Impact
Depositors could lose a portion of their funds because unused tokens are locked in the contract and not counted in the TVL, so they cannot be withdrawn.
What the attacker needed
User deposits funds into GeVault; Uniswap pool does not consume all tokens
The fix
The project mitigated the issue by taking unused funds into account for TVL.
How it was found
- User calls GeVault.deposit() with tokens.
- deposit() calls rebalance(), which removes liquidity from all ticks and then deploys assets.
- deployAssets() calls depositAndStash(), which calls TokenisableRange.deposit().
- TokenisableRange.deposit() deposits tokens into a Uniswap V3 pool and returns unspent tokens to GeVault.
- GeVault does not return the unspent tokens to the user and does not count them in getTVL().
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 vault is a smart contract that pools users' money and invests it. When you deposit, the vault tries to put your tokens into a trading pool, but the pool may not accept all of them. The leftover tokens stay in the vault but are not credited to you, so you cannot withdraw them later.
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.