Root + Impact
Description
-
There is a function called "_convertToShares" in briVault.sol that duplicates functionality of the function "_convertToShares" in ERC4626
-
Intead of duplicating functionality the "_convertToShares" from ERC4626, it can be used with proper params.Risk
Likelihood:
Impact:
Proof of Concept
Byte code size changes after optimization (run with forge build --sizes)
BEFORE:
╭--------------+------------------+-------------------+--------------------+---------------------╮
| Contract | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
+================================================================================================+
| BriVault | 16,502 | 18,754 | 8,074 | 30,398 |
AFTER:
╭--------------+------------------+-------------------+--------------------+---------------------╮
| Contract | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
+================================================================================================+
| BriVault | 16,312 | 18,564 | 8,264 | 30,588 |
Recommended Mitigation
- function _convertToShares(
- uint256 assets
- ) internal view returns (uint256 shares) {
- uint256 balanceOfVault = IERC20(asset()).balanceOf(address(this));
- uint256 totalShares = totalSupply(); // total minted BTT shares so far
-
-
- if (totalShares == 0 || balanceOfVault == 0) {
- // First depositor: 1:1 ratio
- return assets;
- }
-
-
- shares = Math.mulDiv(assets, totalShares, balanceOfVault);
- }
-
- uint256 participantShares = _convertToShares(stakeAsset);
+ uint256 participantShares = _convertToAssets(stakeAsset, Math.Rounding.Floor);