Vault.balance() mixes normalized and standard amounts
The Vault.balance function adds a normalised balance (scaled to 18 decimals) to a non-normalised balance from the controller, causing the total to be under-reported. This leads to incorrect share calculations when depositing or redeeming tokens.
Submitted by cmichel
The Vault.balance function uses the balanceOfThis function which scales (“normalizes”) all balances to 18 decimals.
for (uint8 i; i < _tokens.length; i++) {
address _token = _tokens[i];
// everything is padded to 18 decimals
_balance = _balance.add(_normalizeDecimals(_token, IERC20(_token).balanceOf(address(this))));
}
Note that balance()’s second term IController(manager.controllers(address(this))).balanceOf() is not normalized. The code is adding a non-normalized amount (for example 6 decimals only for USDC) to a normalized (18 decimals).
Impact
The result is that the balance() will be under-reported. This leads to receiving wrong shares when depositing tokens, and a wrong amount when redeeming tokens.
Recommended Mitigation Steps
The second term IController(manager.controllers(address(this))).balanceOf() must also be normalized before adding it. IController(manager.controllers(address(this))).balanceOf() uses _vaultDetails[msg.sender].balance which directly uses the raw token amounts which are not normalized.
GainsGoblin (yAxis) acknowledged
GalloDaSballo (judge) commented:
balanceandbalanceOfThismixes the usage of decimals by alternatingly using_normalizeDecimalsThis can break accounting as well as create opportunities for abuse A consistent usage of_normalizeDecimalswould mitigate
BobbyYaxis (yAxis) noted:
Mitigated in PR 114: https://github.com/yaxis-project/metavault/pull/114/commits/b3c0405640719aa7d43560f4b4b910b7ba88170b
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 second term in the balance calculation is not normalised to 18 decimals before being added to the normalised first term.
Impact
The vault under-reports its total balance, which could lead to users receiving incorrect shares on deposit and incorrect amounts on redemption.
What the attacker needed
None
The fix
The second term should also be normalised before being added, and the project mitigated this in a pull request.
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 contract tracks how many tokens it holds. It converts some token amounts to a common 18-decimal scale, but forgets to do so for one part of the total. Adding numbers with different decimal scales gives a wrong total, so users get the wrong number of shares when they deposit or withdraw.