Victim's fund can be stolen due to rounding error and exchange rate manipulation
The vault's share calculation is vulnerable to a rounding error and exchange rate manipulation, allowing an attacker to steal a victim's deposit. By front-running the victim's deposit with a tiny deposit and a direct transfer to inflate the share price, the attacker can cause the victim to receive almost no shares and then redeem a disproportionate amount of the pooled assets.
Bandit Follow with LTDingZhen, cawfree and 3 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-01-napier-judging/issues/94
The protocol has acknowledged this issue.
Found by
Bandit, LTDingZhen, cawfree, jennifer37, xAlismx, xiaoming90
Summary
Victim's funds can be stolen by malicious users by exploiting the rounding error and through exchange rate manipulation.
Vulnerability Detail
The LST Adaptor attempts to guard against the well-known vault inflation attack by reverting the TX when the amount of shares minted is rounded down to zero in Line 78 below.
File: BaseLSTAdapter.sol
71: function prefundedDeposit() external nonReentrant returns (uint256, uint256) {
72: uint256 bufferEthCache = bufferEth; // cache storage reads
73: uint256 queueEthCache = withdrawalQueueEth; // cache storage reads
74: uint256 assets = IWETH9(WETH).balanceOf(address(this)) - bufferEthCache; // amount of WETH deposited at this time
75: uint256 shares = previewDeposit(assets);
76:
77: if (assets == 0) return (0, 0);
78: if (shares == 0) revert ZeroShares();
However, this control alone is not sufficient to guard against vault inflation attacks.
Let's assume the following scenario (ignoring fee for simplicity's sake):
- The victim initiates a transaction that deposits 10 ETH as the underlying asset when there are no issued estETH shares.
- The attacker observes the victim’s transaction and deposits 1 wei of ETH (issuing 1 wei of estETH share) before the victim’s transaction. 1 wei of estETH share worth of PT and TY will be minted to the attacker.
- Then, the attacker executes a transaction to directly transfer 5 stETH to the adaptor. The exchange rate at this point is
1 wei / (5 ETH + 1 wei). Note that thetotalAssetsfunction uses thebalanceOffunction to compute the total underlying assets owned by the adaptor. Thus, this direct transfer will increase the total assets amount. - When the victim’s transaction is executed, the number of estETH shares issued is calculated as
10 ETH * 1 wei / (5 ETH + 1 wei), resulting in 1 wei being issued due to round-down. - The attacker will combine the PT + YT obtained earlier to redeem 1 wei of estETH share from the adaptor.
- The attacker, holding 50% of the issued estETH shares (indirectly via the PT+YT he owned), receives
(15 ETH + 1 wei) / 2as the underlying asset. - The attacker seizes 25% of the underlying asset (2.5 ETH) deposited by the victim.
This scenario demonstrates that even when a revert is triggered due to the number of issued estETH share being 0, it does not prevent the attacker from capturing the user’s funds through exchange rate manipulation.
Impact
Loss of assets for the victim.
Code Snippet
Tool used
Manual Review
Recommendation
Following are some of the measures that could help to prevent such an attack:
- Mint a certain amount of shares to zero address (dead address) during contract deployment (similar to what has been implemented in Uniswap V2)
- Avoid using the
balanceOfso that malicious users cannot transfer directly to the contract to increase the assets per share. Track the total assets internally via a variable.
Discussion
massun-onibakuchi
Openzeppelin's ERC4626 with a decimalsOffset=0 in the virtual share mitigates the issue, but it is recognized that it does not completely resolve it. We plan to deposit a small amount of tokens after deployment.
ydspa
Escalate This finding is not high. This attack would be success only if the protocol team doesn't provide and keep any initial liquidity for the vault. However, in practical, we merely find protocol teams don't provide any fund to bootstrap projects. The likelihood of this attack is very low.
sherlock-admin2
Escalate This finding is not high. This attack would be success only if the protocol team doesn't provide and keep any initial liquidity for the vault. However, in practical, we merely find protocol teams don't provide any fund to bootstrap projects. The likelihood of this attack is very low.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
massun-onibakuchi
Escalate This finding is not high. This attack would be success only if the protocol team doesn't provide and keep any initial liquidity for the vault. However, in practical, we merely find protocol teams don't provide any fund to bootstrap projects. The likelihood of this attack is very low.
Agree. This kind of inflation attack is not listed as a finding in the Mixbytes audit, which is still unpublished.
MehdiKarimi81
If the protocol team doesn't provide initial liquidity it would be high, since it's not listed as a known issue and the protocol team didn't clear that they plan to provide initial liquidity, it can be considered as a high severity.
xiaoming9090
The mitigation of minting some shares in advance to prevent this issue was not documented in the contest’s README. Thus, the issue remains valid and as it is, as mitigation cannot be applied retrospectively after the contest. Otherwise, it would be unfair to the Watsons to raise an issue that only gets invalid by a mitigation shared after the contest/audit.
cvetanovv
I disagree with the escalation and this report should remain a valid High. Nowhere in the Readme or Documentation is it described that the protocol knows and can prevent this attack.
Czar102
Uncommunicated plans for issue mitigation don't constitute a reason for invalidation. I believe this was correctly judged – planning to reject the escalation and leave the issue as is.
Czar102
Result: High Has duplicates
sherlock-admin3
Escalations have been resolved successfully!
Escalation status:
- ydspa: rejected
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
Impact
The attacker could steal a significant portion of the victim's deposit, leading to loss of assets for the victim.
What the attacker needed
No initial liquidity in the vault; Attacker can front-run victim's deposit
The fix
The protocol should mint a small amount of shares to a dead address during deployment and avoid using balanceOf by tracking total assets internally.
How it was found
- The victim initiates a deposit of 10 ETH when no shares exist.
- The attacker deposits 1 wei of ETH before the victim, receiving 1 wei of shares.
- The attacker directly transfers 5 stETH to the adaptor, inflating the total assets.
- The victim's deposit is processed, but due to rounding, they receive only 1 wei of shares.
- The attacker redeems their shares, which now represent 50% of the pool, and receives about 7.5 ETH, stealing 2.5 ETH from the victim.
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.
This is a 'vault inflation' attack on a smart contract that pools deposits. An attacker manipulates the exchange rate between deposited assets and shares by making a tiny deposit and then directly sending assets to the vault, so that when a victim deposits, they get almost no shares. The attacker then redeems their shares for more than they put in, taking the victim's money.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.