Vault can be DoS
mediumLines of code
Vulnerability details
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.
solidityfunction 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.
solidityfunction 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
solidityfunction _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
difffunction 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++; } } }
Assessed type
DoS
