code-423n4 / 2022-02-concur-findings

2 stars 0 forks source link

`USDMPegRecovery.provide()` Will Fail If There Is An Excess Of `usdm` Tokens #94

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L73-L82

Vulnerability details

Impact

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:

Proof of Concept

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L73-L82

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.

GalloDaSballo commented 2 years ago

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 advice or by also using the balance of the pool3 token to calculate the LP amounts