Skip to content
Business logic Audit finding Intermediate

Inability to offboard term twice in a 7-day period may lead to bad debt to the market

The offboarding contract prevents proposing a new offboarding poll for the same lending term within 7 days, even if the previous offboarding completed and the term was re-onboarded. An attacker could exploit this by re-onboarding a risky term quickly, preventing GUILD voters from offboarding it again, potentially leading to bad debt.

santipu_ Follow

Originally disclosed on Code4rena

Submitted by santipu_

In Ethereum Credit Guild, when a LendingTerm is considered too risky, its GUILD voters are incentivized to offboard that term via the LendingTermOffboarding contract. This mechanism is designed to be a fast and secure way to remove a LendingTerm from a market before it accrues bad debt.

Each time that GUILD voters want to offboard a term, someone will have to call proposeOffboard() in order to start a poll. The other voters will have the ability to support this poll by calling supportOffboard(). As soon as the votes reach to a quorum, the offboard() function will have to be called to remove that term from the market and allow all loans from that term to be called.

The poll for offboarding a term has a max duration of 7 days, this restriction is enforced on proposeOffboard():

    require(
        block.number > lastPollBlock[term] + POLL_DURATION_BLOCKS,
        "LendingTermOffboarding: poll active"
    );

This check will enforce that nobody can propose the offboarding of a LendingTerm twice in a 7-day period.

Given that the system allows for re-onboarding terms, it’s possible that a LendingTerm can be offboarded and re-onboarded in less than 7 days. In such case, if market conditions turn adverse, the GUILD voters won’t be able to offboard the same term for a second time; therefore, allowing for bad debt to be created and impact all the market.

It’s not unfeasible to assume this situation can occur in a future given that the protocol aims for supporting thousands of terms in a market, as it’s stated in the docs:

Major lending pools today support at most a few dozen unique loan terms, the Credit Guild is intended to support thousands […]

Impact

GUILD voters won’t be able to offboard the same term twice in a 7-day window period and that will lead to bad debt that will impact all the market and its voters. In the scenario where loans start to default, all voters for that term will be slashed and the CREDIT token of that market will experience losses.

Proof of Concept

The following coded POC can be pasted in LendingTermOffboarding.t.sol. The test can be run with the command: forge test --match-test testCannotOffboardTwiceIn7Days:

function testCannotOffboardTwiceIn7Days() public {
    // Offboard term
    guild.mint(bob, _QUORUM);
    vm.startPrank(bob);
    guild.delegate(bob);
    uint256 snapshotBlock = block.number;
    offboarder.proposeOffboard(address(term));
    vm.roll(block.number + 1);
    vm.warp(block.timestamp + 13);
    offboarder.supportOffboard(snapshotBlock, address(term));
    offboarder.offboard(address(term));

    // Get enough CREDIT to pack back interests
    vm.stopPrank();
    vm.roll(block.number + 1);
    vm.warp(block.timestamp + 13);
    uint256 debt = term.getLoanDebt(aliceLoanId);
    credit.mint(alice, debt - aliceLoanSize);

    // Close loans and cleanup
    vm.startPrank(alice);
    credit.approve(address(term), debt);
    term.repay(aliceLoanId);
    vm.stopPrank();
    offboarder.cleanup(address(term));

    // After ~5 days @ 13s/block...
    vm.roll(block.number + 33230);
    vm.warp(block.timestamp + 5 days);

    // Re-onboard
    guild.addGauge(1, address(term));

    // After ~1 day...
    vm.roll(block.number + 6646);
    vm.warp(block.timestamp + 1 days);

    // It's not possible to offboard a second time
    vm.expectRevert("LendingTermOffboarding: poll active");
    offboarder.proposeOffboard(address(term));
}

Recommended Mitigation Steps

It’s recommended to modify the check in proposeOffboard() in order to allow a second offboarding of a term if the previous offboarding is already complete.

As a potential solution, consider adding a mapping isPollCompleted[term] that marks true when the quorum is reached for a certain poll on supportOffboard(). This could be the new check on proposeOffboard() to mitigate this issue:

    require(
-       block.number > lastPollBlock[term] + POLL_DURATION_BLOCKS,
+       block.number > lastPollBlock[term] + POLL_DURATION_BLOCKS || isPollCompleted[term],
        "LendingTermOffboarding: poll active"
    );

Assessed type

Timing

eswak (Ethereum Credit Guild) confirmed, but disagreed with severity and commented:

Confirming this is an issue, I think it is more fit for medium severity given the unlikeliness of the whole situation, but technically the code allows this path. I disagree with the proposed fix (that would allow proposing the offboarding without limits after a term has been offboarded once), but we can reset the lastPollBlock[term] storage variable upon successful offboarding.

TrungOre (judge) decreased severity to Medium


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

Root cause

The proposeOffboard function checks only the time since the last poll, not whether the previous poll has completed, so a completed offboarding still blocks a new proposal for 7 days.

Impact

GUILD voters cannot offboard the same term twice within 7 days, which could lead to bad debt and losses for the market and its voters.

What the attacker needed

GUILD voters offboard a term; Term is re-onboarded within 7 days; Market conditions turn adverse

The fix

The check in proposeOffboard should be modified to allow a new offboarding if the previous poll is completed, for example by resetting lastPollBlock upon successful offboarding.

How it was found

  1. Offboard a term by proposing, supporting, and executing offboard.
  2. Repay all loans and call cleanup to allow re-onboarding.
  3. After about 5 days, re-onboard the term by adding a gauge.
  4. After about 1 day, attempt to propose offboarding again.
  5. The transaction reverts with 'LendingTermOffboarding: poll active'.

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.

In this lending system, a group of voters can vote to remove a risky loan term. But the code only allows starting a removal vote once every 7 days for each term. If a term is removed and then quickly added back, the voters cannot start another removal vote for 7 days, even if the term becomes risky again. This could cause losses if loans default during that time.

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 santipu_

View all

13 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.