USDMPegRecovery.sol#withdraw() withdraw may often fail
The withdraw function transfers tokens directly from the contract's balance, but after the guardian moves most funds into a Curve pool, the contract lacks sufficient tokens, causing withdrawals to fail. An attacker could not exploit this for gain, but users may be unable to withdraw their deposits.
Submitted by WatchPug
Per the doc:
USDM deposits are locked based on the KPI’s from carrot.eth.
3Crv deposits are not locked.
function withdraw(Liquidity calldata _withdrawal) external {
Liquidity memory total = totalLiquidity;
Liquidity memory user = userLiquidity[msg.sender];
if(_withdrawal.usdm > 0) {
require(unlockable, "!unlock usdm");
usdm.safeTransfer(msg.sender, uint256(_withdrawal.usdm));
total.usdm -= _withdrawal.usdm;
user.usdm -= _withdrawal.usdm;
}
if(_withdrawal.pool3 > 0) {
pool3.safeTransfer(msg.sender, uint256(_withdrawal.pool3));
total.pool3 -= _withdrawal.pool3;
user.pool3 -= _withdrawal.pool3;
}
totalLiquidity = total;
userLiquidity[msg.sender] = user;
emit Withdraw(msg.sender, _withdrawal);
}
However, because the withdraw() function takes funds from the balance of the contract, once the majority of the funds are added to the curve pool via provide(). The withdraw() may often fail due to insufficient funds in the balance.
Proof of Concept
- Alice deposits
4MUSDM and4Mpool3 tokens; - Guardian calls
provide()and all theusdmandpool3tousdm3crv; - Alice calls
withdraw(), the tx will fail, due to insufficient balance.
Recommended Mitigation Steps
Consider calling usdm3crv.remove_liquidity_one_coin() when the balance is insufficient for the user’s withdrawal.
Alex the Entreprenerd (judge) commented:
The warden has identified a specific scenario in which user funds would not be withdrawable
Because the code uses internal storage for accounting rather than “value” this scenario can happen fairly reliably.
I believe mitigation requires further thought than just withdrawing and ideally it would be best to setup a system similar to Vault Shares so that a withdrawal could be triggered either by available liquidity or via a withdrawal from the pool.
I think Medium severity is 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
The withdraw function assumes the contract holds enough tokens, but provide() moves most tokens into an external pool, leaving insufficient balance for withdrawals.
Impact
Users may be unable to withdraw their funds when the contract's balance is insufficient, causing a denial of service for withdrawals.
What the attacker needed
User has deposited funds; Guardian has called provide() to move funds to pool
The fix
The withdraw function should call usdm3crv.remove_liquidity_one_coin() when the contract's balance is insufficient, or use a vault-shares model to handle withdrawals from the pool.
How it was found
- Alice deposits 4M USDM and 4M pool3 tokens.
- Guardian calls provide() and moves all usdm and pool3 to usdm3crv.
- Alice calls withdraw(), and the transaction fails due to insufficient balance.
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 holds user deposits. When users withdraw, it sends tokens from its own balance. But if most tokens have been moved into another pool for earning interest, the contract may not have enough tokens on hand, so the withdrawal fails. This is a denial-of-service issue for users, not a way to steal funds.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.