Skip to content
Business logic Audit finding Beginner

LendingTerm::debtCeiling() can return wrong debt as the min() is evaluated incorrectly

The debtCeiling function in LendingTerm incorrectly computes the minimum of three values, potentially returning a higher debt ceiling than intended. This could allow more debt than the hard cap permits, affecting downstream calculations in GuildToken.

neocrao Follow with thank_you, TheSchnilch and 14 others

Originally disclosed on Code4rena

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:

// return min(creditMinterBuffer, hardCap, debtCeiling)
if (creditMinterBuffer < _debtCeiling) {
    return creditMinterBuffer;
}
if (_hardCap < _debtCeiling) {
    return _hardCap;
}
return _debtCeiling;

However, the above minimum logic is flawed, as it does not always return the minimum of the 3 values.

Impact

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.

Proof of concept

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.

Recommended Mitigation Steps

Update the min() logic to be correct:

-   if (creditMinterBuffer < _debtCeiling) {
-      return creditMinterBuffer;
-   }
-   if (_hardCap < _debtCeiling) {
-      return _hardCap;
-   }
-   return _debtCeiling;
+   if (creditMinterBuffer < _debtCeiling && creditMinterBuffer < _hardCap) {
+       return creditMinterBuffer;
+   } else if (_debtCeiling < _hardCap) {
+       return _debtCeiling;
+   } else {
+       return _hardCap;
+   }

eswak (Ethereum Credit Guild) confirmed


The original report as published on Code4rena, by neocrao. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Impact

The function may return a higher debt ceiling than the actual minimum, potentially allowing more debt than the hard cap permits and causing incorrect behaviour in GuildToken.

What the attacker needed

None

The fix

The min() logic should be corrected to properly compare all three values, as shown in the recommended mitigation.

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.

A smart contract function is supposed to pick the smallest of three numbers, but its comparison logic is wrong. This means it might pick a larger number instead, which could let more borrowing happen than allowed.

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.

More by neocrao

View all

1 more disclosed report, best first.

More from Ethereum Credit Guild

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.