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 May 26, 2023. It is now read-only.
github-actionsbot opened this issue
Mar 1, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
If shareAmount in withdrawLend is set to type(uint256).max then it is reassigned to the maximum value that can be withdrawn from Compound. Although the token transfers all work the updating of pos.underlyingAmount may have an overflow, resulting in a failed tx.
shareAmount is set to pos.underlyingVaultShare in the max case.
Suppose a user opens a new position and some time later would like to close it and withdraw all the lend tokens. When opening a position the lend function will pos.underlyingVaultShare to lendAmount / exchangeRate where lendAmount is given by the user and exchangeRate is the ratio that Compound gives.
When the user wants to close their whole position they set shareAmount = type(uint256).max which is then set to pos.underlyingVaultShare = lendAmount / exchangeRate
The correct SoftVault tokens are sent to the SoftVault and the correct amount of cTokens are sent to Compound. Compound then sends back amount * exchangeRateNew of lend tokens to the SoftVault which passes them on to the bank.
The updates pos.underlyingVaultShare using the following forumla: pos.underlyingVaultShare -= amount * exchangeRateNew which can be expanded to pos.underlyingVaultShare -= lendAmount / exchangeRate * exchangeRateNew. If exchangeRateNew > exchangeRate then lendAmount / exchangeRate * exchangeRateNew > lendAmount / exchangeRate = pos.underlyingVaultShare which will cause an overflow.
Impact
Any smart contract that is dependent on the max assumption (setting shareAmount = type(uint256).max means all lend tokens will be returned) may end up getting stuck if the exchange rate increases on Compound.
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` labelHighA valid High severity issueRewardA payout will be made for this issue
stent
medium
Max value for withdrawLend is not correct
Summary
If
shareAmount
inwithdrawLend
is set totype(uint256).max
then it is reassigned to the maximum value that can be withdrawn from Compound. Although the token transfers all work the updating ofpos.underlyingAmount
may have an overflow, resulting in a failed tx.Vulnerability Detail
This is the code in question in BlueBerryBank:
shareAmount
is set topos.underlyingVaultShare
in the max case.lend
function willpos.underlyingVaultShare
tolendAmount / exchangeRate
wherelendAmount
is given by the user andexchangeRate
is the ratio that Compound gives.shareAmount = type(uint256).max
which is then set topos.underlyingVaultShare = lendAmount / exchangeRate
amount * exchangeRateNew
of lend tokens to the SoftVault which passes them on to the bank.pos.underlyingVaultShare
using the following forumla:pos.underlyingVaultShare -= amount * exchangeRateNew
which can be expanded topos.underlyingVaultShare -= lendAmount / exchangeRate * exchangeRateNew
. IfexchangeRateNew > exchangeRate
thenlendAmount / exchangeRate * exchangeRateNew > lendAmount / exchangeRate = pos.underlyingVaultShare
which will cause an overflow.Impact
Any smart contract that is dependent on the max assumption (setting
shareAmount = type(uint256).max
means all lend tokens will be returned) may end up getting stuck if the exchange rate increases on Compound.Code Snippet
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L679
Tool used
Manual Review
Recommendation
Duplicate of #109
The text was updated successfully, but these errors were encountered: