Inflation attack in VotiumStrategy
The VotiumStrategy contract lacked a minimum output check when minting shares, allowing an attacker to front-run a user's deposit and inflate the share price so the victim receives zero shares. The attacker could then withdraw the victim's deposited tokens.
Submitted by adriro, also found by MiloTruck
The VotiumStrategy contract is susceptible to the Inflation Attack, in which the first depositor can be front-runned by an attacker to steal their deposit.
Impact
Both AfEth and VotiumStrategy acts as vaults: accounts deposit some tokens and get back another token (share) that represents their participation in the vault.
These types of contracts are potentially vulnerable to the inflation attack: an attacker can front-run the initial deposit to the vault to inflate the value of a share and render the front-runned deposit worthless.
In AfEth, this is successfully mitigated by the slippage control. Any attack that inflates the value of a share to decrease the number of minted shares is rejected due to the validation of minimum output:
https://github.com/code-423n4/2023-09-asymmetry/blob/main/contracts/AfEth.sol#L166-L167
166: uint256 amountToMint = totalValue / priceBeforeDeposit;
167: if (amountToMint < _minout) revert BelowMinOut();
However, this is not the case of VotiumStrategy. In this contract, no validation is done in the number of minted tokens. This means that an attacker can execute the attack by front-running the initial deposit, which may be from AfEth or from any other account that interacts with the contract. See Proof of Concept for a detailed walkthrough of the issue.
39: function deposit() public payable override returns (uint256 mintAmount) {
40: uint256 priceBefore = cvxPerVotium();
41: uint256 cvxAmount = buyCvx(msg.value);
42: IERC20(CVX_ADDRESS).approve(VLCVX_ADDRESS, cvxAmount);
43: ILockedCvx(VLCVX_ADDRESS).lock(address(this), cvxAmount, 0);
44: mintAmount = ((cvxAmount * 1e18) / priceBefore);
45: _mint(msg.sender, mintAmount);
46: }
Proof of Concept
Let’s say a user wants to deposit in VotiumStrategy and calls deposit() sending an ETH amount such as it is expected to buy X tokens of CVX. Attacker will front-run the transaction and execute the following:
- Initial state is empty contract,
assets = 0andsupply = 0. - Attacker calls deposit with an amount of ETH such as to buy
1e18CVX tokens, this makesassets = 1e18andsupply = 1e18. - Attacker calls
requestWithdraw(1e18 - 1)so thatsupply = 1, assume also1e18 - 1CVX tokens are withdrawn so thatcvxUnlockObligations = 1e18 - 1. - Attacker transfers (donates) X amount of CVX to VotiumStrategy contract.
- At this point,
priceBefore = cvxPerVotium() = (totalCvx - cvxUnlockObligations) * 1e18 / supply = (X + 1e18 - (1e18 - 1)) * 1e18 / 1 = (X + 1) * 1e18 - User transaction gets through and
deposit()buys X amount of CVX. Minted tokens will bemintAmount = X * 1e18 / priceBefore = X * 1e18 / (X + 1) * 1e18 = X / (X + 1) = 0. - User is then minted zero VotiumStrategy tokens.
- Attacker calls
requestWithdraw()again to queue withdrawal to remove all CVX balance from the contract, including the tokens deposited by the user.
Recommendation
There are multiple ways of solving the issue:
- Similar to AfEth, add a minimum output check to ensure the amount of minted shares.
- Track asset balances internally so an attacker cannot donate assets to inflate shares.
- Mint an initial number of “dead shares”, similar to how UniswapV2 does.
A very good discussion of these can be found here.
0xleastwood (Judge) decreased severity to Medium and commented:
Downgrading this to medium severity because the
_minOutparameter should actually prevent this attack as long as it’s non-zero, but I agree this is of concern if users do not set this parameter. This is a stated assumption.Upon further investigation,
AfEth.deposit()is not vulnerable to the deposit front-running. This is only an issue if we are interacting with the votium strategy contract directly which is atypical behaviour. However, funds are still at risk even with these stated assumptions so I believe medium severity to be more correct.
@0xleastwood - Apologies for commenting after post-judging QA, but isn’t the inflation attack still a problem even if users only interact with the
AfEthcontract?
AfEth.deposit()calls VotiumStrategy’sdeposit()function, so if a user callsAfEth.deposit()after VotiumStrategy’s state has been manipulated,vMintedwill be 0, causing him to lose the portion of his ETH that was deposited into VotiumStrategy.Unless I’m missing something here…
0xleastwood (Judge) commented:
@MiloTruck - Ultimately, I do believe
_minOutto be sufficient in detecting such an attack.
Track balances instead of using
balanceOf.
Status: Mitigation confirmed. Full details in reports from adriro and m_Rassska.
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 calculates shares based on the current balance without a minimum output check, allowing an attacker to donate tokens and inflate the share price.
Impact
An attacker could steal a user's deposit by front-running and inflating the share price, though the judge noted that the `_minOut` parameter in AfEth should prevent the attack if set to a non-zero value.
What the attacker needed
Attacker can front-run the victim's deposit; Victim deposits directly into VotiumStrategy or via AfEth…
The fix
The issue was mitigated by tracking balances internally instead of using `balanceOf`.
How it was found
- Attacker deposits enough ETH to buy 1e18 CVX tokens, receiving 1e18 shares.
- Attacker requests withdrawal of 1e18 - 1 shares, leaving 1 share and creating unlock obligations.
- Attacker transfers (donates) X amount of CVX directly to the contract.
- Victim's deposit transaction executes, buying X CVX, but mints zero shares due to inflated price.
- Attacker requests withdrawal again to remove all CVX, including the victim's deposit.
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.
When you put money into a shared pot, you get a receipt showing your share. If someone can make each share look very valuable just before you join, your money might buy zero shares. This report shows how an attacker could do that to steal a deposit.
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.