Moonwell

Moonwell
DeFiFoundry
15,000 USDC
View results
Submission Details
Severity: low
Invalid

Inconsistent error handling approach in the contract

Summary

In the MErc20DelegateFixer contract, inconsistent error handling is observed, particularly in the repayBadDebtWithCash function, where the error message is hardcoded and more descriptive compared to other functions. This inconsistency may lead to challenges in understanding and debugging issues or for user experience

Vulnerability Details

The vulnerability arises from the inconsistent error handling approach in the contract, where the error message in the repayBadDebtWithCash function is hardcoded and more descriptive than in other functions.

function repayBadDebtWithCash(uint256 amount) external nonReentrant {
// Hardcoded and descriptive error message
require(
token.transferFrom(msg.sender, address(this), amount),
"transfer in failed"
);
// Function implementation...
}
function repayBadDebtWithReserves() external nonReentrant {
uint256 currentReserves = totalReserves;
uint256 currentBadDebt = badDebt;
// Error message not as descriptive as in other functions
require(currentReserves != 0 && currentBadDebt != 0, "reserves or bad debt is zero");
// Function implementation...
}

Impact

Increased Risk of Oversight: Inconsistencies in error handling may cause developers to overlook critical errors or potential vulnerabilities. When error messages are inconsistent across different functions, developers may fail to recognize patterns of errors or identify recurring issues that require attention. This oversight increases the risk of leaving vulnerabilities undiscovered, potentially exposing the contract to security threats or financial risks.

Bad User Expereience / User Confusion: Users interacting with the contract may encounter inconsistencies in error messages, leading to confusion and frustration. Inconsistent error messages can make it difficult for users to understand why their transactions failed or how to resolve issues they encounter. This lack of clarity can erode user confidence in the contract and deter further engagement, resulting in a negative user experience.

Maintenance Challenges: Inconsistent error handling complicates the maintenance of the contract codebase over time. As the contract evolves and new features are added, developers must ensure that error messages remain consistent and reflect the current state of the contract. Failure to maintain consistency in error handling can result in a fragmented and confusing codebase, making it harder to maintain and update in the future.

Tools Used

Manual

Recommendations

To improve clarity and maintainability, it is recommended to ensure consistent and descriptive error messages across all functions. Developers should strive to provide informative error messages that accurately reflect the nature of the error and assist users and developers in understanding and addressing issues effectively.

function repayBadDebtWithCash(uint256 amount) external nonReentrant {
// Consistent and descriptive error message
bool success = token.transferFrom(msg.sender, address(this), amount);
require(success, "transfer in failed");
// Function implementation...
}
function repayBadDebtWithReserves() external nonReentrant {
uint256 currentReserves = totalReserves;
uint256 currentBadDebt = badDebt;
// Consistent and descriptive error message
require(currentReserves != 0 && currentBadDebt != 0, "insufficient reserves or bad debt");
// Function implementation...
}
Updates

Lead Judging Commences

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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