Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Japy69 - Anyone can block any borrowing #27

Closed
sherlock-admin opened this issue Oct 23, 2023 · 1 comment
Closed

Japy69 - Anyone can block any borrowing #27

sherlock-admin opened this issue Oct 23, 2023 · 1 comment
Assignees
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Oct 23, 2023

Japy69

high

Anyone can block any borrowing

Summary

The LiquidityBorrowingManager.sol smart contract in the Real Wagmi project has a vulnerability that can lead to a situation where no one can borrow a specific ERC20 token. It works with any ERC20 token.

Vulnerability Detail

In the LiquidityBorrowingManager.sol smart contract, specifically in the borrow function, there is a check on borrowingCollateral . The relevant code snippet is as follows:

uint256 borrowingCollateral = cache.borrowedAmount - cache.holdTokenBalance;
(borrowingCollateral > params.maxCollateral).revertError(ErrLib.ErrorCode.TOO_BIG_COLLATERAL);

The borrowingCollateral variable is calculated as the difference between the borrowed amount and cache.holdTokenBalance. cache.holdTokenBalance is equivalent to the balance of the params.holdToken token held by the contract. In a normal world, this is equivalent to the tokens the contract just received by the position used here. Since anyone can send ERC20 tokens to this contract, an attacker can manipulate cache.holdTokenBalance by sending an amount of the params.holdToken token to the contract directly. This manipulation can result in cache.holdTokenBalance being larger than cache.borrowedAmount, causing the transaction and all the next one to revert.

To PoC this vulnerability, in the test file WagmiLeverageTests.ts, we just need to modify this line

[owner.address, alice.address, bob.address, aggregatorMock.address],

by

[owner.address, alice.address, bob.address, aggregatorMock.address, borrowingManager.address],

By this modification, we also send tokens to the smart contract. Then all the tests (run npx hardhat test) when someone borrows (and logically then other actions after borrowing) fail.

Impact

The impact of this vulnerability is significant. An attacker can effectively prevent anyone from borrowing the specific params.holdToken token. Moreover, the cost is not high since borrowingCollateral is normally not very high (in some cases it is equal to 1).

Code Snippet

The vulnerability comes from this line: https://github.com/sherlock-audit/2023-10-real-wagmi/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L869-L872

Tool used

Manual Review

Recommendation

  1. Call the balanceOf function of the token at the beginning of the borrow function. When computing cache.holdTokenBalance, compare it to the previous balance.
  2. Add a function allowing to withdraw ERC20 tokens of this contract (and not in the vault!). Because the balance should be empty, in case of receipt, someone should be able to withdraw it.

Duplicate of #86

@fann95 fann95 self-assigned this Oct 24, 2023
@fann95 fann95 added the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Oct 24, 2023
@fann95
Copy link

fann95 commented Oct 24, 2023

this is a duplicate of this one #72

@github-actions github-actions bot added the Medium A valid Medium severity issue label Oct 26, 2023
@Evert0x Evert0x added High A valid High severity issue and removed Medium A valid Medium severity issue labels Oct 30, 2023
@sherlock-admin sherlock-admin changed the title Itchy Canvas Cricket - Anyone can block any borrowing Japy69 - Anyone can block any borrowing Oct 30, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Oct 30, 2023
@Evert0x Evert0x added Medium A valid Medium severity issue and removed High A valid High severity issue labels Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

3 participants