`VaultPoolLib::reserve()` will store the `Pa` not attributed to user withdrawals incorrectly and leave in untracked once it expires again
The reserve function records the PA amount attributed to user withdrawals in the stagnated balance field instead of the amount attributed to the AMM, and the PA attributed to the AMM is never handled afterwards. As a result, that PA becomes stuck in the vault and is never rationed again at the next expiry.
0x73696d616f Follow with 0xNirix, dimulski and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-cork-protocol-judging/issues/191
The protocol has acknowledged this issue.
Found by
0x73696d616f, 0xNirix, dimulski, sakshamguruji
Summary
VaultPoolLib::reserve() stores the Pa attributed to withdrawals in self.withdrawalPool.stagnatedPaBalance instead of storing the amount attributedToAmm. Additionally, this amount of Pa, the one attributed to the Amm is never dealt with and leads to stuck PA.
The comment in the code mentions
// FIXME : this is only temporary, for now
// we trate PA the same as RA, thus we also separate PA
// the difference is the PA here isn't being used as anything
// and for now will just sit there until rationed again at next expiry.
But it is incorrect as it is never rationed again, just forgotten. The VaultPoolLib::rationedToAmm() function only uses the Ra balance, not the Pa, which is effectively left untracked.
Root Cause
In VaultPoolLib:170, the leftover non attributed Pa is not dealt with.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
VaultPoolLib::reserve()is called when liquidating the lp position of theVaultviaVaultLib::_liquidatedLP(), triggered by users when redeeming expired liquidity vault shares or on the admin trigerring a new issuance.
Impact
The Pa in the Vault is stuck.
PoC
VaultPoolLib::rationedToAmm() does not deal with the Pa.
function rationedToAmm(VaultPool storage self, uint256 ratio) internal view returns (uint256 ra, uint256 ct) {
uint256 amount = self.ammLiquidityPool.balance;
(ra, ct) = MathHelper.calculateProvideLiquidityAmountBasedOnCtPrice(amount, ratio);
}
Mitigation
Distributed the Pa to users based on their LV shares or redeem the Pa for Ra and add liquidity to the new issued Ds or similar.
Discussion
ziankork
valid. will fix
ziankork
This is originally has a feature planned for that, but we're still working on it and the feature still needs some time for us to solidify all aspect of it. that's why we won't fix this. Since the feature are considered non-trivial
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 reserve function stores the withdrawal-attributed PA in the stagnated balance instead of the AMM-attributed amount, and the rationing function only reads the RA balance, so the AMM-attributed PA is never tracked or redistributed.
Impact
The PA held in the vault is stuck and cannot be recovered or redistributed to users.
What the attacker needed
None
The fix
The PA should be distributed to users according to their LV shares, or redeemed for RA and added as liquidity to the newly issued DS.
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 keeps track of two kinds of tokens, and when liquidity is liquidated it splits the amounts between users and an automated market maker. The code saves the wrong portion in a bookkeeping field, so one portion of tokens is never counted or handed out again. Those tokens sit in the contract permanently, and nobody can claim them.
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.