Skip to content
Business logic Audit finding Intermediate

LendingTerm debtCeiling function uses creditMinterBuffer incorrectly

The debtCeiling function incorrectly uses the creditMinterBuffer as a cap on total debt rather than on additional borrowing, causing the ceiling to be lower than it should be. This can prevent guild voters and surplus stakers from removing their votes or stakes from a gauge, even when the true debt ceiling would allow it.

niroh Follow with EV_om, carrotsmuggler and 3 others

Originally disclosed on Code4rena

Submitted by niroh, also found by EV_om, carrotsmuggler, EllipticPoint, rvierdiiev, and kaden

Lines of code

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/LendingTerm.sol#L291

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/LendingTerm.sol#L303

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/LendingTerm.sol#L317

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/LendingTerm.sol#L324

Description

The debtCeiling function uses the minimum of hardCap and credit minter remaining buffer (creditMinterBuffer) as a hard limit on the term’s debtCeiling in two places:

Line 298:

if (totalBorrowedCredit == 0 && gaugeWeight != 0) {
            // first-ever CREDIT mint on a non-zero gauge weight term
            // does not check the relative debt ceilings
            // returns min(hardCap, creditMinterBuffer)
            return
                _hardCap < creditMinterBuffer ? _hardCap : creditMinterBuffer;
        }

Line 324:

 if (creditMinterBuffer < _debtCeiling) {
            return creditMinterBuffer;
        }

However, unlike hardCap, the creditMinterBuffer-induced limit should be issuance + creditMinterBuffer instead. This is because the buffer is a limit on additional borrows, not on the total of current issuance and additional borrows. This error triggers a revert in GuildToken::_decrementGaugeWeight whenever a gauge’s current issuance exceeds the remaining buffer. This occurs even if the post-decrement true debtCeiling is above the issuance.

Consequently, guild voters and surplusGuildMinder stakers are unjustifiably prevented from removing their votes/stakes from a gauge. This situation is likely to occur naturally when borrowing demand is high, or as a DOS attack where a malicious actor borrows the sum needed to keep a term’s issuance above the remaining buffer, blocking voters and surplus stakers from exiing their positions.

Impact

Preventing guild voters/surplus stakers from removing votes/stakes from gauges they see as unsafe breaks the main system mechanism, through which term quality is maintained and risk is reduced. In addition, voters/surplus stakers who are unable to exit their positions from term they consider too risky may later have those votes slashed when the term incurs a loss, causing them considerable financial damage.

Proof of Concept

This POC shows how a single term with a single voter can not remove 2% of the votes because the term’s issuance is above the current buffer.

Note: there is another issue with debtCeiling() (see my other submission on the matter) that would prevent removing more than 16.666% of the votes of a single-term market; however, removing 2% should have succeeded in spite of the other issue.

To run:

Add the code below to the test file integrationTestBadDebtFlows.sol. Forge test --match-test 'testRemoveVotesSingleTerm' --fork-url $ETH_RPC_URL -vvv:

function testDebtCeilingBufferError() public {
    //causes this contract to vote on term
    testAllocateGaugeToSDAI();

    //borrow 51% of the credit buffer to simulate issuance being above
    //remaining buffer
    uint256 borrowAmount = rateLimitedCreditMinter.buffer() * 51 / 100;
    uint128 supplyAmount = uint128(borrowAmount);
    bytes32 loanId = _supplyCollateralUserOne(borrowAmount, supplyAmount);

    //try to remove 2%  of the vote
    uint256 decrementAmount = guild.balanceOf(address(this)) * 2 / 100;
    vm.expectRevert("GuildToken: debt ceiling used");
    guild.decrementGauge(address(term), decrementAmount);

    //Reverts due to finding error. Decrementing 2% should succeed in the case
    //of a single term but fails because current issuance is above the remaining buffer.
}

Tools Used

Foundry

Recommended Mitigation Steps

In debtCeiling() use issuance + creditMinterBuffer instead of creditMinterBuffer.

TrungOre (judge) commented:

I believe this issue should be treated as a separate medium issue, with the root cause being that: the use of creditMinterBuffer causes debtCeiling to be lower than it should. Medium severity is fit for its impact. Additionally, the sponsor confirmed that creditMinterBuffer should be removed from the debt ceiling calculation instead of applying the recommended mitigation.

eswak (Ethereum Credit Guild) confirmed


The original report as published on Code4rena, by niroh. 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

Guild voters and surplus stakers are unjustifiably prevented from removing their votes or stakes from a gauge, which can lead to financial damage if the term later incurs a loss.

What the attacker needed

A gauge with votes; borrowing demand high enough to exceed buffer

The fix

The sponsor confirmed that creditMinterBuffer should be removed from the debt ceiling calculation instead of applying the recommended mitigation.

How it was found

  1. Allocate a gauge to a term so the contract can vote.
  2. Borrow 51% of the credit buffer to make issuance exceed the remaining buffer.
  3. Attempt to remove 2% of the vote from the gauge.
  4. The transaction reverts with 'GuildToken: debt ceiling used'.

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 calculates how much can be borrowed from a lending pool. It mistakenly treats a limit on new borrowing as a limit on total borrowing, so it sometimes blocks people from withdrawing their votes or stakes from that pool. This can trap their funds and expose them to losses.

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 niroh

View all

28 more disclosed reports, 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.