USDMPegRecovery Risk of fund locked, due to discrepancy between curveLP token value against internal contract math
The contract tracks user deposits in storage but uses real token balances when providing liquidity to Curve, so after any swap the real balances diverge from the stored ones. Users then cannot withdraw the exact amounts they deposited, and funds can become locked.
Originally disclosed on Code4rena
Submitted by Alex the Entreprenerd, also found by gzeon, IllIllI, and leastwood
USDMPegRecovery.sol#L90 USDMPegRecovery.sol#L110 USDMPegRecovery.sol#L73 USDMPegRecovery.sol#L84
In USDMPegRecovery deposit and withdraw allow for direct deposits of a specific token (3crv or usdm).
The balances are directly changed and tracked in storage.
provide seems to be using the real balances (not the ones store) to provide liquidity.
Because of how curve works, you’ll be able (first deposit) to provide exactly matching liquidity.
But after (even just 1 or) multiple swaps, the pool will be slightly imbalanced, adding or removing liquidity at that point will drastically change the balances in the contract from the ones tracked in storage.
Eventually users won’t be able to withdraw the exact amounts they deposited.
This will culminate with real balances not matching user deposits, sometimes to user advantage and other times to user disadvantage, ultimately to the protocol dismay.
Proof of Concept
Deposit equal usdm and 3crv LP Do one trade on CRV Withdraw the LP
The real balances are not matching the balances in storage.
User tries to withdraw all their balances, inevitable revert.
Recommended Mitigation Steps
Either find a way to price the user contribution based on the LP tokens (use virtual_price) Or simply have people deposit the LP token directly (avoiding the IL math which is a massive headache)
Alex the Entreprenerd (judge) commented:
I’m forfeitting winnings as I am judging the contest.
The sponsor confirmed.
I believe the closest findings are #191 and #94 these both focus on the provide aspect. However, this finding shows how the Curve LP Math will cause the internal balances to break after just one LP provision.
Because this breaks accounting of the protocol and will cause funds to be stuck I believe High Severity to be appropriate.
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 contract uses the pool's real token balances for liquidity operations instead of the internally tracked deposit balances, causing a mismatch after any swap.
Impact
Users may be unable to withdraw their full deposited amounts, and funds could become locked in the contract.
What the attacker needed
Users deposit into the contract; At least one swap occurs on the Curve pool
The fix
The contract should price user contributions based on LP tokens (using virtual_price) or have users deposit LP tokens directly.
How it was found
- Deposit equal amounts of usdm and 3crv to get LP tokens.
- Perform one trade on the Curve pool.
- Attempt to withdraw the LP tokens.
- The real balances no longer match the stored balances, so the withdrawal reverts.
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.
This is a smart contract that lets people deposit two types of tokens and then puts them into a trading pool. The contract remembers how much each person put in, but when it adds or removes tokens from the pool it uses the pool's actual current amounts, which change whenever someone trades. So after a trade, the remembered amounts no longer match reality, and people may be unable to take out what they put in.
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.