Skip to content
Smart contracts Audit finding Intermediate

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.

zzzitron Follow with pontifex

Originally disclosed on Code4rena

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:

  1. A malicious user deposits, for example, two times the value of type(uint96).max underlying assets into the Vault; calling the function Vault.deposit() two times. They can’t deposit more in a single transaction because type(uint96).max is the maximum value to deposit.
  2. Then, the malicious user calls Vault.withdraw() with a higher value of assets to withdraw more than type(uint96).max. For example, they withdraw (2 * type(uint96).max), which is the total amount of assets they deposited before.
  3. Now what happens, is the Vault.sol contract only burns type(uint96).max shares for the user, but transfers 2 * type(uint96).max underlying assets to the malicious user, which is the total amount they deposited before.
  4. This happens because Vault._burn() only burns uint96(shares) shares of the malicious users - see Vault.sol line 1155.
  5. Now, the malicious user has still vault shares left but they withdrew the total amount of their deposited assets.
  6. 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.
  7. 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.
  8. Or, if the malicious user is not the first depositor, they use a flashLoan or flashMint to deposit multiple times type(uint96).max assets into the vault. Then, they can withdraw their deposit, pay back the flashLoan or flashMint and 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

PoolTogether mitigated:

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.


The original report as published on Code4rena, by zzzitron. 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.

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

  1. Deposit an amount of underlying assets equal to twice type(uint96).max by calling deposit twice.
  2. Call withdraw with an asset amount greater than type(uint96).max, for example twice type(uint96).max.
  3. The contract burns only type(uint96).max shares but transfers the full requested assets.
  4. 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.

More by zzzitron

View all

21 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.