15,000 USDC
View results
Submission Details
Severity: gas

There is no need to return a variable declare as **named return**

Summary

function getAccountCollateralValue has a named return, this meand that you can avoid having the return, removig extra opcodes inside the function.

Vulnerability Details

function getAccountCollateralValue(address user) public view returns (uint256 totalCollateralValueInUsd) {
    // loop through each collateral token, get the amount they have deposited, and map it to
    // the price, to get the USD value
    for (uint256 i = 0; i < s_collateralTokens.length; i++) {
        address token = s_collateralTokens[i];
        uint256 amount = s_collateralDeposited[user][token];
        totalCollateralValueInUsd += getUsdValue(token, amount);
    }
    return totalCollateralValueInUsd;
}

Impact

Tools Used

Recommendations

remove return totalCollateralValueInUsd;

diff --git a/src/DSCEngine.sol b/src/DSCEngine.sol
index a7a6639..51a1021 100644
--- a/src/DSCEngine.sol
+++ b/src/DSCEngine.sol
@@ -355,7 +355,6 @@ contract DSCEngine is ReentrancyGuard {
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
}
- return totalCollateralValueInUsd;
}
function getUsdValue(address token, uint256 amount) public view returns (uint256) {

Support

FAQs

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