-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
🤖_primaryAI based primary recommendationAI based primary recommendationQA (Quality Assurance)Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntaxAssets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntaxbugSomething isn't workingSomething isn't workingdowngraded by judgeJudge downgraded the risk level of this issueJudge downgraded the risk level of this issuegrade-aprimary issueHighest quality submission among a set of duplicatesHighest quality submission among a set of duplicatessponsor confirmedSponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Description
Lines of code
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/Vault.sol#L153-L158
Vulnerability details
Description
The Vault::rebalance() function rounds-down the sharesToMint against the protocol's favour. It ought to be rounded-up to avoid loss of funds for the protocol.
uint256 feeInEthScaled = uint256(balanceChange) *
settings().getPerformanceFee();
uint256 sharesToMint = (feeInEthScaled * totalSupply()) /
_totalAssets(maxPriceAge) /
PERCENTAGE_PRECISION;
_mint(settings().getFeeReceiver(), sharesToMint);Impact
Loss of funds for the protocol.
Tools Used
Manual review
Recommended Mitigation Steps
Round up in favour of the protocol. A library like solmate can be used which has mulDivUp:
- uint256 sharesToMint = (feeInEthScaled * totalSupply()) /
- _totalAssets(maxPriceAge) /
- PERCENTAGE_PRECISION;
+ uint256 sharesToMint = feeInEthScaled.mulDivUp(totalSupply(), _totalAssets(maxPriceAge) * PERCENTAGE_PRECISION);Assessed type
Math
Metadata
Metadata
Assignees
Labels
🤖_primaryAI based primary recommendationAI based primary recommendationQA (Quality Assurance)Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntaxAssets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntaxbugSomething isn't workingSomething isn't workingdowngraded by judgeJudge downgraded the risk level of this issueJudge downgraded the risk level of this issuegrade-aprimary issueHighest quality submission among a set of duplicatesHighest quality submission among a set of duplicatessponsor confirmedSponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")