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

When an attacker lends to a loan, the attacker can trigger DoS that any lenders can not buyout it #89

Open
code423n4 opened this issue Apr 7, 2022 · 7 comments · Fixed by with-backed/backed-protocol#69
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 disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-04-backed/blob/main/contracts/NFTLoanFacilitator.sol#L205-L208
https://github.com/code-423n4/2022-04-backed/blob/main/contracts/NFTLoanFacilitator.sol#L215-L218

Vulnerability details

Impact

If an attacker (lender) lends to a loan, the attacker can always revert transactions when any lenders try to buyout, making anyone can not buyout the loan of the attacker.

Proof of Concept

  1. A victim calls lend(), trying to buyout the loan of the attacker.
  2. In lend(), it always call ERC20(loanAssetContractAddress).safeTransfer to send accumulatedInterest + previousLoanAmount to currentLoanOwner (attacker).
  3. If the transfer of loanAssetContractAddress is ERC777, it will call _callTokensReceived that the attacker can manipulate and always revert it.
  4. Because NFTLoanFacilitator uses safeTransfer and safeTransferFrom to check return value, the transaction of the victim will also be reverted. It makes anyone can not buyout the loan of the attacker.

In _callTokensReceived, the attacker just wants to revert the buyout transaction, but keep repayAndCloseLoan successful. The attacker can call loanInfoStruct(uint256 loanId) in _callTokensReceived to check if the value of loanInfo is changed or not to decide to revert it.

Tools Used

vim

Recommended Mitigation Steps

Don't transfer ERC20(loanAssetContractAddress) to currentLoanOwner in lend(), use a global mapping to record redemption of lenders and add an external function redeem for lenders to transfer ERC20(loanAssetContractAddress).

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Apr 7, 2022
code423n4 added a commit that referenced this issue Apr 7, 2022
@wilsoncusack wilsoncusack added disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons labels Apr 7, 2022
@wilsoncusack
Copy link
Collaborator

I think this is just part of perils of working with certain assets and I am not sure we will mitigate

@wilsoncusack wilsoncusack added sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") and removed sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons labels Apr 13, 2022
@wilsoncusack
Copy link
Collaborator

Sorry I lost track of this one/labeled incorrectly. This is indeed an issue we intend to address: we will block erc777 tokens.

The worse implication here is that a lender could prevent a borrower from repaying and could seize the NFT.

@wilsoncusack
Copy link
Collaborator

Still not sure if this should be high or medium. But there are legit ERC777 tokens that a borrower might selecting unknowingly, so probably is high?

@gzeoneth
Copy link
Member

I suggest this as Med Risk as no fund is loss by preventing buyout.

@gzeoneth gzeoneth added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Apr 15, 2022
@gzeoneth gzeoneth reopened this Apr 15, 2022
@wilsoncusack wilsoncusack added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Apr 15, 2022
@wilsoncusack
Copy link
Collaborator

I suggest this as Med Risk as no fund is loss by preventing buyout.

But as I said above the bigger issue is they could block repayment, guaranteeing default and seizure of collateral?

@gzeoneth
Copy link
Member

I suggest this as Med Risk as no fund is loss by preventing buyout.

But as I said above the bigger issue is they could block repayment, guaranteeing default and seizure of collateral?

I think you are correct as there is a similar call in L241. However both warden failed to describe such attack path and I am inclined to keep this as Med Risk.

@wilsoncusack
Copy link
Collaborator

resolved with with-backed/backed-protocol#69

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 disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants