Skip to content
Business logic Audit finding Advanced

Can steal gOhm by calling Clearinghouse.claimDefaulted on loans not made by Clearinghouse

The Clearinghouse contract's claimDefaulted function did not verify that the loans passed to it were originated by the Clearinghouse itself. An attacker could mix in self-created loans with tiny collateral to inflate the keeper reward calculation and steal gOhm from the contract.

detectiveking Follow with jkoppel and mert_eren

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-08-cooler-judging/issues/28

Found by

detectiveking, jkoppel, mert_eren

Clearinghouse.claimDefaulted assumes that all loans passed in were originated by the Clearinghouse. However, nothing guarantees that. An attacker can wreak havoc by calling it with a mixture of Clearinghouse-originated and external loans. In particular, they can inflate the computed totalCollateral recovered to steal excess gOhm from defaulted loans.

Vulnerability Detail

  1. Alice creates a Cooler. 9 times, she calls requestLoan (not through the Clearinghouse) to request a loan of 0.000001 DAI collateralized by 2 gOhm. For each loan, she then calls clearLoan and loans the 0.000001 DAI to herself.
  2. One week later, Bob calls Clearinghouse.lendToCooler and takes a loan for 3000 DAI collateralized by 1 gOHM
  3. Alice defaults on the loans she made to herself and waits 7 days
  4. Bob defaults on his loan
  5. Alice calls Clearinghouse.claimDefaulted, passing in both her loans to herself and Bob's loan from the Clearinghouse. Clearinghouse.claimDefaulted calls Cooler.claimDefaulted on each, returning 18 gOhm to Alice and 1 gOhm to the Clearinghouse.
  6. For each of Alice's loan, the keeper reward is incremented by the max award of 0.1 gOhm. For Bob's loan, the keeper reward is incremented by somewhere between 0 and 0.05 gOhm, depending on how much time has elapsed since Bob's loan defaulted.
  7. The keeper reward is transferred to Alice. Alice's reward will be between 0.9 and 0.95 gOhm, but it should be between 0 and 0.05 gOhm. The contract should recover between 0.95 and 1 gOhm, but it only recovers between 0.05 and 0.1 gOhm. Alice has effectively stolen 0.9 gOhm from the contract

The attack as stated above can steal at most 5% of the collateral. Note that Alice can get this even without waiting 7 days from loan expiry time. It further requires the Clearinghouse have some extra gOhm around, as it will burn totalCollateral - keeperRewards. This can happen if the treasury or someone sends it some gOhm for some reason, or by calling claimDefault as in #3 .

However, #5 extends this attack so that Alice can steal 100% of the collateral, even if the Clearinghouse has no extra gOhm lying around.

For added fun, note that, when setting up her loans to herself, Alice can set the loan duration to 0 seconds. So this only requires setting up 1 block in advance.

Impact

Anyone can steal collateral from defaulted loans.

Code Snippet

https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Clearinghouse.sol#L191

Notice the lack of any checks that the loan's lender is the Clearingouse

Solidity
    function claimDefaulted(address[] calldata coolers_, uint256[] calldata loans_) external {
        uint256 loans = loans_.length;
        if (loans != coolers_.length) revert LengthDiscrepancy();

        uint256 totalDebt;
        uint256 totalInterest;
        uint256 totalCollateral;
        uint256 keeperRewards;
        for (uint256 i=0; i < loans;) {
            // Validate that cooler was deployed by the trusted factory.
            if (!factory.created(coolers_[i])) revert OnlyFromFactory();
            
            // Claim defaults and update cached metrics.
            (uint256 debt, uint256 collateral, uint256 elapsed) = Cooler(coolers_[i]).claimDefaulted(loans_[i]);

keeperRewards is incremented for every loan.

Solidity
            // Cap rewards to 5% of the collateral to avoid OHM holder's dillution.
            uint256 maxAuctionReward = collateral * 5e16 / 1e18;
            // Cap rewards to avoid exorbitant amounts.
            uint256 maxReward = (maxAuctionReward < MAX_REWARD)
                ? maxAuctionReward
                : MAX_REWARD;
            // Calculate rewards based on the elapsed time since default.
            keeperRewards = (elapsed < 7 days)
                ? keeperRewards + maxReward * elapsed / 7 days
                : keeperRewards + maxReward;
        }

https://github.com/sherlock-audit/2023-08-cooler/blob/main/Cooler/src/Cooler.sol#L318

Cooler.claimDefaulted can be called by anyone.

Solidity
 function claimDefaulted(uint256 loanID_) external returns (uint256, uint256, uint256) {
        Loan memory loan = loans[loanID_];
        delete loans[loanID_];

       // Hey look, no checks on sender
}

Tool used

Manual Review

Recommendation

Check that the Clearinghouse is the originator of all loans passed to claimDefaulted

Discussion

0xRusowsky

jkoppel

Note on this:

The link to #3 is meant to be a link to #46

The link to #5 is meant to be a link to #115

In the past, when I linked to issues in my private judging repository, Sherlock would properly update them upon submission. Now it just links them to whatever issue in the public judging repo has the same number.

jkoppel

Fix confirmed.

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

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

Likely the claimDefaulted function lacked a check that each loan's lender was the Clearinghouse, so keeper rewards were summed across arbitrary loans.

Impact

An attacker could steal collateral from defaulted loans, though the basic attack is limited to about 5% of collateral and requires the Clearinghouse to hold extra gOhm; a related issue reportedly extends this to 100%.

What the attacker needed

Ability to create a Cooler and self-loans; a defaulted Clearinghouse loan exists; Clearinghouse holds extra gOhm (for basic attack)

The fix

The fix was to check that the Clearinghouse is the originator of all loans passed to claimDefaulted, and the fix was confirmed.

How it was found

  1. Alice creates a Cooler and makes several tiny self-loans not through the Clearinghouse, then clears them.
  2. Bob borrows through the Clearinghouse with real collateral.
  3. Alice defaults on her self-loans and waits, then Bob's loan defaults.
  4. Alice calls claimDefaulted passing both her loans and Bob's loan.
  5. The keeper reward is inflated by her loans and paid to Alice, exceeding what she should receive.

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 lets people lend and borrow tokens. When a borrower fails to repay, anyone can trigger a default-claiming function and earn a small reward for doing so. The bug was that this function trusted the caller to only pass in loans the contract itself had created, so an attacker could sneak in their own fake loans to inflate the reward and take more tokens than they should.

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 detectiveking

View all

1 more disclosed report, best first.

More from Cooler Update

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.