Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERC777 can break the term and cause every lender to get liquidated #184

Closed
c4-bot-3 opened this issue Dec 19, 2023 · 14 comments
Closed

ERC777 can break the term and cause every lender to get liquidated #184

c4-bot-3 opened this issue Dec 19, 2023 · 14 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working primary issue Highest quality submission among a set of duplicates sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-3
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/main/src/loan/LendingTerm.sol#L804-L817

Vulnerability details

Impact

One of the attack vectors that the developers want us to check is malicious collateral. One such vector could be ERC777, as its use as collateral could result in every liquidation causing bad debt.

Proof of Concept

After borrowers miss their partial payments, anyone can call them and start an auction. When a user thinks they will profit from the liquidation, they can bid on the auction. In this process, they pay the bad debt for some collateral, and the remaining collateral is returned to the borrower.

if (collateralToBorrower != 0) {
   IERC20(params.collateralToken).safeTransfer(loans[loanId].borrower, collateralToBorrower);
}

if (collateralToBidder != 0) {
   IERC20(params.collateralToken).safeTransfer(bidder, collateralToBidder);
}

However, this can be dangerous, as borrowers can revert the transaction when they receive the collateral. This way, they can prevent any bid below the mid-point, and after the mid-point, bids can cause bad debt.

Example:

  • ERC777 is used as collateral.
  1. A competitor of ECG wants to harm its reputation, so he borrows the minimum allowed amount.

  2. He leaves the loan open and intentionally misses his first payment.

  3. Alice tries to liquidate this borrower, however, every transaction before the mid-point is reverted by the borrower's smart contract.

  4. The mid-point passes, and the borrower no longer receives collateral, preventing them from reverting the transaction.

  5. Alice successfully liquidates the borrower after the mid-point, but this causes the gauge to be slashed as a very small amount of bad debt accrues.

Note that the borrower can borrow the maximum allowed loan token for their collateral. If the minimum ratio is worth 100 USD, and maxDebtPerCollateralToken is 80%, the borrower can borrow 80 USD, effectively causing the gauge to be slashed for only 20 USD.

Tools Used

Manual review.

Recommended Mitigation Steps

Implement push instead of pull. This way, borrowers will not be able to cause unnecessary damage to the protocol.

Assessed type

ERC20

@c4-bot-3 c4-bot-3 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 19, 2023
c4-bot-3 added a commit that referenced this issue Dec 19, 2023
@c4-pre-sort
Copy link

0xSorryNotSorry marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Jan 4, 2024
@c4-pre-sort
Copy link

0xSorryNotSorry marked the issue as duplicate of #685

@c4-judge
Copy link
Contributor

Trumpero changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 27, 2024
@c4-judge
Copy link
Contributor

Trumpero marked the issue as grade-b

@c4-judge c4-judge reopened this Jan 31, 2024
@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Jan 31, 2024
@c4-judge
Copy link
Contributor

This previously downgraded issue has been upgraded by Trumpero

@c4-judge
Copy link
Contributor

Trumpero marked the issue as not a duplicate

@c4-judge
Copy link
Contributor

Trumpero marked the issue as primary issue

@Trumpero
Copy link

I consider this issue to be distinct from issue #685, as a borrower can just use ERC777's hook to prevent bidding and create losses for lending terms. Since the contest docs didn't exclude ERC777, I believe this should be a medium.

@c4-judge
Copy link
Contributor

Trumpero marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 31, 2024
@c4-judge
Copy link
Contributor

Trumpero marked the issue as selected for report

@c4-judge c4-judge added the selected for report This submission will be included/highlighted in the audit report label Jan 31, 2024
@c4-sponsor
Copy link

eswak (sponsor) acknowledged

@c4-sponsor c4-sponsor added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Feb 1, 2024
@serial-coder
Copy link
Member

Hi @Trumpero,

The sponsor confirmed to us in Discord that ERC-777 is not supported.

Screenshot 2567-02-03 at 02 14 44

@Trumpero
Copy link

Trumpero commented Feb 3, 2024

@serial-coder Thanks for providing information. Based on the sponsor's statement in the public channel, this issue should be marked as OOS.

@c4-judge
Copy link
Contributor

c4-judge commented Feb 3, 2024

Trumpero marked the issue as unsatisfactory:
Out of scope

@c4-judge c4-judge closed this as completed Feb 3, 2024
@c4-judge c4-judge added unsatisfactory does not satisfy C4 submission criteria; not eligible for awards and removed satisfactory satisfies C4 submission criteria; eligible for awards selected for report This submission will be included/highlighted in the audit report labels Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working primary issue Highest quality submission among a set of duplicates sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

7 participants