A malicious user can steal other user’s deposits from Vault.sol
The Vault contract's withdraw function burns only a truncated uint96 amount of shares while transferring the full requested assets, allowing a malicious user to withdraw more assets than their shares should permit and later steal other users' deposits.
Submitted by zzzitron, also found by pontifex
Lines of code
https://github.com/GenerationSoftware/pt-v5-vault/blob/b1deb5d494c25f885c34c83f014c8a855c5e2749/src/Vault.sol#L509-L521 https://github.com/GenerationSoftware/pt-v5-vault/blob/b1deb5d494c25f885c34c83f014c8a855c5e2749/src/Vault.sol#L407-L415
Impact
When the Vault.withdraw() function is called, a maximum of type(uint96).max shares are burnt subsequently: Vault.withdraw()-> Vault._withdraw()-> Vault._burn burns uint96(_shares), see Vault.sol line 1139.
A malicious user can exploit this in the following way:
- A malicious user deposits, for example, two times the value of
type(uint96).maxunderlying assets into the Vault; calling the functionVault.deposit()two times. They can’t deposit more in a single transaction becausetype(uint96).maxis the maximum value to deposit. - Then, the malicious user calls
Vault.withdraw()with a higher value of assets to withdraw more thantype(uint96).max. For example, they withdraw (2 * type(uint96).max), which is the total amount of assets they deposited before. - Now what happens, is the Vault.sol contract only burns
type(uint96).maxshares for the user, but transfers2 * type(uint96).maxunderlying assets to the malicious user, which is the total amount they deposited before. - This happens because
Vault._burn()only burnsuint96(shares)shares of the malicious users - see Vault.sol line 1155. - Now, the malicious user has still vault shares left but they withdrew the total amount of their deposited assets.
- Now, the vault transferred the total amount of the malicious user’s assets back to them and the malicious user still has shares left to withdraw; with even more assets that are now being stolen from assets deposited by other users.
- Or, if the malicious user was the first depositor, they wait until another user deposits and the malicious user can now withdraw the other users deposited assets since the malicious user still has Vault shares left.
- Or, if the malicious user is not the first depositor, they use a
flashLoanorflashMintto deposit multiple timestype(uint96).maxassets into the vault. Then, they can withdraw their deposit, pay back theflashLoanorflashMintand they will still have enough vault shares left to steal all other users assets by withdrawing them.
In this way, other user’s deposited assets can be stolen, as explained above.
Proof of Concept
Here is a POC, where the problem is illustrated:
https://gist.github.com/zzzitron/397790302ca95aa3fbf05694ae1497ab
Recommended Mitigation Steps
Consider adjusting the Vault._burn function to not convert from uint256 to uint96 when burning shares.
Assessed type
Math
asselstine (PoolTogether) confirmed
Added SafeCast PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/9
Status: Mitigation confirmed. Full details in reports from dirk_y, rvierdiiev and 0xStalin.
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 Vault._burn function converts the share amount from uint256 to uint96 without checking, so large withdrawals burn fewer shares than intended.
Impact
A malicious user could steal other users' deposited assets by exploiting the share burning bug, potentially draining the vault.
What the attacker needed
Attacker has enough assets to deposit; or uses flash loan to fund deposit
The fix
The Vault._burn function was fixed by adding SafeCast to prevent unsafe uint256 to uint96 conversion when burning shares.
How it was found
- Deposit an amount of underlying assets equal to twice type(uint96).max by calling deposit twice.
- Call withdraw with an asset amount greater than type(uint96).max, for example twice type(uint96).max.
- The contract burns only type(uint96).max shares but transfers the full requested assets.
- The attacker retains leftover shares and can later withdraw assets deposited by other users.
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 like a shared savings account where you get shares for depositing money. When you withdraw, the contract is supposed to destroy the right number of shares, but a bug causes it to destroy fewer shares than it should. This lets an attacker take out more money than they put in, leaving other users' money at risk.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.