You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
sherlock-admin opened this issue
Oct 23, 2023
· 1 comment
Assignees
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
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:
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
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).
Call the balanceOf function of the token at the beginning of the borrow function. When computing cache.holdTokenBalance, compare it to the previous balance.
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.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
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:The
borrowingCollateral
variable is calculated as the difference between the borrowed amount andcache.holdTokenBalance
.cache.holdTokenBalance
is equivalent to the balance of theparams.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 manipulatecache.holdTokenBalance
by sending an amount of theparams.holdToken
token to the contract directly. This manipulation can result incache.holdTokenBalance
being larger thancache.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
by
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 sinceborrowingCollateral
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
balanceOf
function of the token at the beginning of the borrow function. When computingcache.holdTokenBalance
, compare it to the previous balance.Duplicate of #86
The text was updated successfully, but these errors were encountered: