DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: high
Invalid

function does not properly validate the `buyBackAmount` input

Summary

function does not properly validate the buyBackAmount input

Vulnerability Details

The vulnerability in the code between lines 43 to 78 is related to the lack of proper input validation and error handling. The function exitShortWallet allows a user to exit a short position by buying back a certain amount of ERC tokens. However, the function does not properly validate the buyBackAmount input. If the buyBackAmount is greater than the ercDebt or if it is zero, the function should revert with an error message. But instead, it only checks if buyBackAmount is greater than ercDebt or equal to zero, and if so, it reverts with an error message. This means that if buyBackAmount is less than zero, the function will not revert and will continue to execute, potentially leading to unexpected behavior or financial loss for the user. that could be exploited by an attacker to manipulate the contract's state and cause financial damage.

Tools Used

vscode

Recommendations

The issue can be resolved by adding an additional check to ensure that the buyBackAmount is greater than zero. This will prevent the function from executing if the buyBackAmount is less than or equal to zero. Here is the recommended code change:

Replace the existing check:

if (buyBackAmount > ercDebt || buyBackAmount == 0) revert Errors.InvalidBuyback();

With the following:

if (buyBackAmount > ercDebt || buyBackAmount <= 0) revert Errors.InvalidBuyback();

This will ensure that the function reverts if the buyBackAmount is not within the expected range (greater than zero and less than or equal to ercDebt). This will prevent potential exploits and ensure the function behaves as expected.

Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.