BaseVaultAdaptor assumes sharePrice is always in underlying decimals
The shared BaseVaultAdaptor contract calculates vault shares assuming the vault share price and the underlying token use the same number of decimals. If a token or price with a different precision is integrated, the calculation would produce too many shares and could cause losses.
Submitted by cmichel
The two BaseVaultAdaptor.calculateShare functions compute share = amount.mul(uint256(10)**decimals).div(sharePrice)
uint256 sharePrice = _getVaultSharePrice();
// amount is in "token" decimals, share should be in "vault" decimals
share = amount.mul(uint256(10)**decimals).div(sharePrice);
This assumes that the sharePrice is always in token decimals and that token decimals is the same as vault decimals.
Both these assumptions happen to be correct for Yearn vaults, but that will not necessarily be the case for other protocols. As this functionality is in the BaseVaultAdaptor, and not in the specific VaultAdaptorYearnV2_032, consider generalizing the conversion.
Integrating a token where the token or price is reported in a different precision will lead to potential losses as more shares are computed.
Because the conversion seems highly protocol-specific, it is recommended that calculateShare should be an abstract function (like _getVaultSharePrice) that is implemented in the specific adaptors.
- kristian-gro (Gro) confirmed
Confirmed and shares have been removed from release version.
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
Likely the shared adaptor hard-codes a decimal conversion that assumes the vault share price and the underlying token share the same precision, rather than letting each protocol-specific adaptor define it.
Impact
For tokens or prices with a different precision, more shares than intended could be computed, leading to potential losses; the text notes the assumptions happen to hold for Yearn vaults.
What the attacker needed
Integration of a token with different decimals
The fix
The report recommends making calculateShare an abstract function implemented in each specific adaptor, and the project confirmed shares were removed from the release version.
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 contract that holds tokens for users and gives them 'shares' representing their portion. Converting a token amount into shares needs the right number of decimal places, like converting pence to pounds. The code assumed both sides always use the same number of decimals, which is true for one vault type but not guaranteed for others, so the maths could go wrong.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.