Vault can be DoS
When the vault's total supply is zero, an attacker can donate a tiny amount of tokens to make the share calculation always return zero, preventing deposits. This causes a denial of service for the vault.
zhaojie Follow with 0xStalin and rvierdiiev
Originally disclosed on Code4rena
Submitted by zhaojie, also found by 0xStalin and rvierdiiev
Impact
When totalSupply = 0, the attacker donates 1wei token, causing the number of shares to remain 0 at deposit time.
Proof of Concept
The toBase function only determines whether total.elastic(_totalAssets) is 0, not whether totalSupply is 0.
function toBase(Rebase memory total, uint256 elastic,bool roundUp
) internal pure returns (uint256 base) {
@ if (total.elastic == 0) {
base = elastic;
} else {
//total.base = totalSupply ; total.elastic = _totalAssets
base = (elastic * total.base) / total.elastic;
if (roundUp && (base * total.elastic) / total.base < elastic) {
base++;
}
}
}
When totalSupply=0, if _totalAssets > 0, toBase always returns 0.
An attacker can make a donation of _totalAssets > 0, the toBase function will then compute base through a branch in the else statement, since totalSupply=0. base = 0 * elastic / total.elastic = 0,
As a result, the number of deposit shares is always 0, and the protocol will not work.
function deposit(address receiver) ....{
.....
shares = total.toBase(amount, false);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, msg.value, shares);
}
An attacker can send Collateral token to the StrategyAAVEv3(address(this)) contract,
_totalAssets = collateralBalance - debtBalance
function _getMMPosition() internal virtual override view returns ( uint256 collateralBalance, uint256 debtBalance ) {
DataTypes.ReserveData memory wethReserve = (aaveV3().getReserveData(wETHA()));
DataTypes.ReserveData memory colleteralReserve = (aaveV3().getReserveData(ierc20A()));
debtBalance = IERC20(wethReserve.variableDebtTokenAddress).balanceOf(address(this));
collateralBalance = IERC20(colleteralReserve.aTokenAddress).balanceOf(address(this));
}
Tools Used
VSCode, Manual
Recommended Mitigation Steps
function toBase(Rebase memory total, uint256 elastic,bool roundUp
) internal pure returns (uint256 base) {
- if (total.elastic == 0) {
+ if (total.elastic == 0 || total.base == 0) {
base = elastic;
} else {
//total.base = totalSupply ; total.elastic = _totalAssets
base = (elastic * total.base) / total.elastic;
if (roundUp && (base * total.elastic) / total.base < elastic) {
base++;
}
}
}
hvasconcelos (BakerFi) confirmed
0xleastwood (judge) decreased severity to Medium and commented:
Thinking about this more, continuous DoS of vault deployment only lasts until it is fixed and does not seem to have any impact on user funds. Downgrading to
mediumseverity.
Fixed → https://github.com/baker-fi/bakerfi-contracts/pull/44
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 share calculation only checks if total assets are zero, not if total supply is zero, so when supply is zero but assets are positive, the formula returns zero shares.
Impact
The vault becomes unusable for deposits until the issue is fixed, but user funds are not directly at risk.
What the attacker needed
Vault total supply is zero; attacker can send tokens to the vault
The fix
The share calculation should also check if total supply is zero and handle that case by returning the elastic amount as base.
How it was found
- Attacker sends a small amount of collateral tokens directly to the vault contract when total supply is zero.
- This makes total assets greater than zero while total supply remains zero.
- When a user tries to deposit, the share calculation returns zero shares, so the deposit fails to mint shares.
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 holds funds and gives shares in return for deposits. If someone sends a tiny amount of tokens directly to the vault before anyone else deposits, the vault's maths for calculating shares breaks, so new deposits get zero shares and the vault stops working.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.