USDMPegRecovery.provide() Will Fail If There Is An Excess Of usdm Tokens
The provide function calculates the liquidity to add based only on the usdm balance, ignoring the pool3 balance. If the truncated usdm amount exceeds the available pool3 tokens, the function reverts, preventing guardians from providing liquidity even when sufficient tokens exist.
Submitted by leastwood
The provide function does not take a _steps argument and will instead calculate addingLiquidity by truncating amounts under step. As a result, if there is an excess of usdm such that the truncated amount exceeds the contract’s pool3 truncated balance, then the function will revert due to insufficient pool3 collateral.
This will prevent guardians from effectively providing liquidity whenever tokens are available. Consider the following example:
- The contract has
500000e18usdmtokens and250000e18pool3tokens. addingLiquiditywill be calculated as500000e18 / 250000e18 * 250000e18.- The function will attempt to add
500000e18usdmandpool3tokens in which there are insufficientpool3tokens in the contract. As a result, it will revert even though there is an abundance of tokens that satisfy thestepamount.
Proof of Concept
function provide(uint256 _minimumLP) external onlyGuardian {
require(usdm.balanceOf(address(this)) >= totalLiquidity.usdm, "<liquidity");
// truncate amounts under step
uint256 addingLiquidity = (usdm.balanceOf(address(this)) / step) * step;
// match usdm : pool3 = 1 : 1
uint256[2] memory amounts = [addingLiquidity, addingLiquidity];
usdm.approve(address(usdm3crv), addingLiquidity);
pool3.approve(address(usdm3crv), addingLiquidity);
usdm3crv.add_liquidity(amounts, _minimumLP);
}
Tools Used
Manual code review. Discussions with Taek.
Recommended Mitigation Steps
Consider modifying the provide function such that a _steps argument can be supplied. This will allow guardians to maximise the amount of liquidity provided to the Curve pool.
Alex the Entreprenerd (judge) commented:
The warden identified a logical fallacy that would prevent the code from providing liquidity.
This is because the code is only accounting for one token, ignoring the other token’s amount.
Given the information I have, I agree with validity and severity of the finding. Mitigation could be achieved by following the warden’s advice or by also using the balance of the
pool3token to calculate the LP amounts.
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 provide function calculates the amount of liquidity to add using only the usdm balance, without considering the pool3 balance, leading to a mismatch when pool3 is insufficient.
Impact
Guardians are unable to provide liquidity when there is an excess of usdm tokens, potentially disrupting the peg recovery mechanism.
What the attacker needed
Guardian role; excess usdm tokens; insufficient pool3 tokens
The fix
The provide function should be modified to accept a _steps argument or to also use the pool3 balance when calculating the liquidity amounts.
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 bug where a function tries to add two tokens to a liquidity pool but only checks the balance of one token. If the other token's balance is too low, the whole operation fails, even though there are enough tokens overall. This stops the guardians (trusted users) from doing their job of providing liquidity.
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.