Potential loss of token0, token1 in the MoneyBrinter contract
The compound function in the MoneyBrinter contract does not handle leftover token0 and token1 returned by the Zapper after a multi-token zap-in. Those unused tokens can become stuck in the contract or lose value through extra swaps before being added to the liquidity pool.
- Disclosed after under an hour
#41895 [SC-Medium] Potential loss of token0, token1 in the MoneyBrinter contract
Submitted on Mar 19th 2025 at 08:46:59 UTC by @trtrth for Audit Comp | Yeet
- Report ID: #41895
- Report Type: Smart Contract
- Report severity: Medium
- Target: https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/contracts/MoneyBrinter.sol
- Impacts:
- Permanent freezing of funds
Description
Brief/Intro
The function MoneyBrinter::compound() is expected to be called by manager to compound rewards by swapping harvested tokens, staking in Kodiak vault and depositing into Beradrome farm. However, the unused token0, token1 held by the contract is not handled
Vulnerability Details
The function MoneyBrinter::compound() calls Zapper::zapInWithMultipleTokens() to handle zapping in with multiple input tokens.
It is expected behavior that the Zapper contract returns the unused token0, token1 to the vault in the flow of compounding. However, that unused tokens returned to vault contract are not explicitly handled. Besides, if the manager is about to use these tokens for the next compounding, there can be 2 scenarios:
- Token0 and token1 are supposed to directly added to the liquidity pool ==> This is not supported by the function
Zapper::zapInWithMultipleTokens()because all input tokens are swapped to token0 and token1 - The manager resolves the scenario (1) by swap token0 to token1 and token1 to token0. This case, the swaps will have to suffer slippage/price impacts. ==> The amounts of token0, token1 after swap can be lower than the original amounts ==> The actual amounts to be added into liquidity pool is lower than expected
// Zapper contract
function zapInWithMultipleTokens(
MultiSwapParams calldata swapParams,
KodiakVaultStakingParams calldata stakingParams,
VaultDepositParams calldata vaultParams
) public nonReentrant onlyWhitelistedKodiakVaults(stakingParams.kodiakVault) returns (uint256, uint256) {
IERC20 token0 = IKodiakVaultV1(stakingParams.kodiakVault).token0();
IERC20 token1 = IKodiakVaultV1(stakingParams.kodiakVault).token1();
// loop and swap Input tokens with corresponding swapData
(uint256 _token0Debt, uint256 token1Debt) = _performMultiSwaps(token0, token1, swapParams);
return _yeetIn(token0, token1, _token0Debt, token1Debt, stakingParams, vaultParams);
function _performMultiSwaps(IERC20 token0, IERC20 token1, MultiSwapParams calldata params)
internal
returns (uint256 token0Debt, uint256 token1Debt)
{
require(
params.inputTokens.length == params.swapToToken0.length + params.swapToToken1.length,
"Zapper: Swap Array disparity"
);
for (uint256 i = 0; i < params.swapToToken0.length; i++) {
// fetch user token
IERC20(params.inputTokens[i]).safeTransferFrom(
_msgSender(), address(this), params.swapToToken0[i].inputAmount
);
// @> input tokens are swapped even when the input token is token0 or token1
token0Debt +=
_verifyTokenAndSwap(params.swapToToken0[i], params.inputTokens[i], address(token0), address(this));
}
for (uint256 i = params.swapToToken0.length; i < params.inputTokens.length; i++) {
// fetch user token
IERC20(params.inputTokens[i]).safeTransferFrom(
_msgSender(), address(this), params.swapToToken1[i - params.swapToToken0.length].inputAmount
);
// @> input tokens are swapped even when the input token is token0 or token1
token1Debt += _verifyTokenAndSwap(
params.swapToToken1[i - params.swapToToken0.length],
params.inputTokens[i],
address(token1),
address(this)
);
}
}
}
Impact Details
- Token0, token1 held by MoneyBrinter contract can be either stuck or suffer swapping's slippage/price impacts before being added into liquidity pool
References
Proof of Concept
Proof of Concept
- Rewards are harvested
- The manager calls
compound()with all holding rewards - There are unused token0, token1 in the process of zapping in, let's say
xandyare unsued amount of token0 and token1 - The manager can not directly add
xtoken0 andytoken1 into liquidity pool OR
if the manager tries to swapxtoken0 to token1 andytoken1 to token1, then the resulted amounts arex'token0 andy'token1. Most of the cases,x' < xandy' < yhappens => Loss ofx - x'token0 andy - y'token1 for adding liquidity
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 compound flow does not explicitly handle the unused token0 and token1 that the Zapper returns to the vault after a multi-token zap-in.
Impact
Leftover token0 and token1 could be permanently stuck in the contract or lose value to slippage and price impact before being added to the pool.
What the attacker needed
Manager role calls compound(); zap-in leaves unused token0/token1
How it was found
- Rewards are harvested into the contract.
- The manager calls compound() with all held rewards.
- The zap-in leaves unused amounts of token0 and token1 in the contract.
- The manager cannot add those leftovers directly to the pool, and swapping them first can return less than the original 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 smart contract can hold two kinds of tokens, called token0 and token1, that it puts into a liquidity pool to earn rewards. When it swaps several reward tokens at once, some of those two tokens are left over, and the code never deals with them. So those leftovers may sit unused forever or be swapped again at a worse rate, which loses money.
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.