-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improper handling of cases when withdrawable assets = 0 #180
Comments
asselstine marked the issue as sponsor confirmed |
Picodes changed the severity to 2 (Med Risk) |
There is definitely a bug here, but I don't see why it should be high severity. "This case has a profound impact since a lot of vault logic is based on the vault's collateralized status" is a bit light to pass the burden or proof. At first sight, as they are no funds in the vault anymore there is no loss of funds. Then there is the case where assets are readded to the vault for some reason, but this would be a Medium severity scenario considering it's very unlikely and not described by the report. |
Picodes marked the issue as satisfactory |
Hi @Picodes, thank you for your response! Sorry I didn't make it clearer. As you can see in the report, the affected function is
function maxDeposit(address) public view virtual override returns (uint256) {
return _isVaultCollateralized() ? type(uint96).max : 0;
} if the Vault is under-collateralized, user can't deposit since
To conclude, I agree that this will not lead to direct loss of funds for the vault, but will greatly impact user, making them send tokens to the vault (through liquidate or deposit) when it's not collateralized and will potentially suffer economically. I think it should be marked as High severity. |
@ktg9 I still think that the original reports perfectly fit with the definition of Med severity: "leak value with a hypothetical attack path with stated assumptions, but external requirements". The described scenarios require that we are in a situation with |
This issue has been fixed and the exchange rate between the Vault and YieldVault is now 1 to 1. If the Vault is collateralized, meaning the amount of withdrawable assets from the YieldVault is greater than the amount of underlying assets supplied to the YieldVault, then users can only withdraw the amount they deposited. |
Fixed in GenerationSoftware/pt-v5-vault#18 |
Lines of code
https://github.com/GenerationSoftware/pt-v5-vault/blob/b1deb5d494c25f885c34c83f014c8a855c5e2749/src/Vault.sol#L1182-#L1186
Vulnerability details
Impact
Proof of Concept
The function
_currentExchangeRate
and_isVaultCollateralized
ofVault
are implemented as follows:The function
Calculate exchange rate between the amount of assets withdrawable from the YieldVault and the amount of shares minted by this Vault.
However, if
_withdrawableAssets
is 0, then the function returns_assetUnit
(which means 1-1 ratio). This means that even when thevault
has no withdrawable assets from_yieldVault
, it's still consideredcollateralized
.To illustrate the oddity of this special case, consider when
_withdrawableAssets
= 1 and_totalSupplyAmount
> 0; in this scenario,_currentExchangeRate
returns 0 and the vault is considered under-collateralized (since 1 <_assetUnit
). However, if_withdrawableAssets
= 0, the vault is considered collateralized.This case has profound impact since a lot of vault logic is based on the vault's collateralized status.
Below is a POC for the above example, for ease of testing, let's place these 2 test cases
in file
vault/test/unit/Vault/Deposit.t.sol
under contractVaultDepositTest
,then test them using commands:
forge test --match-path test/unit/Vault/Deposit.t.sol --match-test testOneWithdrawableAmount -vvvv
forge test --match-path test/unit/Vault/Deposit.t.sol --match-test testZeroWithdrawableAmount -vvvv
testOneWithdrawableAmount
is to demonstrate when_withdrawableAssets
= 1 and the vault is considered not collateralized,testZeroWithdrawableAmount
is to demonstrate when_withdrawableAssets
= 0 and the vault is considered collateralized.Tools Used
Manual review
Recommended Mitigation Steps
Since
_withdrawableAssets
is the dividend, there seems to be no harm in removing the check if_withdrawableAssets
= 0. Therefore, I recommend removing it from the condition.Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: