_requireVaultCollateralized() is called at the beginning of the functions mintYieldFee() and liquidate()
The collateralization check in mintYieldFee() and liquidate() runs before the functions change state, so the vault can end up under-collateralized after they finish. An attacker could mint yield fee shares even when doing so leaves the vault under-collateralized, causing a loss of funds for depositors.
The liquidate() and mintYieldFee() functions could leave the vaults under-collateralized.
Proof of Concept
_requireVaultCollateralized() is called at the beginning of mintYieldFee() and liquidate(). These two functions change the state and the vault could become under-collateralized at the end of the functions.
Keeping High severity as this report shows how shares could be minted; although, the vault is in fact under-collateralized leading to a loss of funds for users.
* @dev - We exclude the amount of yield generated by the YieldVault, so the user can only withdraw their share of deposits.
* Except when the vault is under-collateralized, in this case, any unclaimed yield fee is included in the calculation.
If the Vault ends up being under-collateralized, any yield that has not been claimed will be shared proportionally between depositors. If we use _totalShares instead of _totalSupply, we would account for Vault shares that have not been minted yet, since _yieldFeeTotalSupply keeps track of the accrued yield fee, but needs to be minted as Vault shares by calling mintYieldFee: https://github.com/GenerationSoftware/pt-v5-vault/blob/44a6c6b081db5cc5e2acc4757a3c9dbaa6f60943/src/Vault.sol#L395
@PierrickGT - I do agree with you that the mitigation of this report is incorrect. However, my understanding is that there is still an important issue here; because mintYieldFee could be called even when it would lead to an under-collateralized state.
So we could imagine a scenario where _yieldFeeTotalSupply is 4, assets in the vault are 10, and user shares are 10. Then, a call to mintYieldFee would mint 4 and would lead to a loss of funds for users, as it’d bring the vault into an under-collateralized state.
The original report as published on Code4rena, by RedTiger. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the collateralization check is performed before the state-changing operations in mintYieldFee() and liquidate(), so it does not account for the under-collateralization those operations can cause.
Impact
The vault could become under-collateralized, leading to a loss of funds for users; the judge noted that shares could be minted even when this would happen.
What the attacker needed
Ability to call mintYieldFee or liquidate
The fix
The check should be moved to the end of these functions, or otherwise ensure the vault remains collateralized after the state changes; the project later mitigated with a fix for partial collateralization.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A vault holds money for many users and should always have enough assets to cover everyone's shares. The code checked that the vault was fully backed before doing an action that creates new shares, but not after, so the action itself could leave the vault short. That means some users might not be able to withdraw everything they are owed.
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.