Submitted by neocrao, also found by thank_you, TheSchnilch, nonseodion, Varun_05, Aymen0909, Chinmay, mojito_auditor, 0xStalin, twcctop (1, 2), rbserver, The-Seraphs, santipu_, kaden, ether_sky, Byteblockers, Timenov, and mussucal
The LendingTerm::debtCeiling() function calculates the min of creditMinterBuffer, _debtCeiling and _hardCap as shown below:
However, the above minimum logic is flawed, as it does not always return the minimum of the 3 values.
As the min() calculation is not correct, the LendingTerm::debtCeiling() might return the incorrect value, and so might return a higher debt ceiling rather than the actual debt ceiling as the function should be returning.
LendingTerm::debtCeiling() is used in GuildToken::_decrementGaugeWeight(), which will will make this function incorrect as well.
If creditMinterBuffer was 3, _debtCeiling was 5, and _hardCap was 1, then the min of the 3 values should be _hardCap which is 1.
But instead, this condition becomes true creditMinterBuffer < _debtCeiling, which then returns creditMinterBuffer, which is incorrect.
Update the min() logic to be correct:
eswak (Ethereum Credit Guild) confirmed
