15,000 USDC
View results
Submission Details
Severity: medium

Lack of Input Validation in `DSCEngine.sol` Contract Constructor

Summary

The constructor of the DSCEngine contract takes arrays of token addresses and price feed addresses as input but does not validate if these addresses are non-zero. This could lead to potential issues if invalid addresses are provided.

Vulnerability Details

The constructor of the DSCEngine contract accepts two arrays: tokenAddresses and priceFeedAddresses. These arrays are used to initialize the s_priceFeeds mapping and s_collateralTokens array. However, there is no validation to check if these addresses are non-zero. Providing a zero address (which is an invalid address in the Ethereum network) could lead to unexpected behavior in the contract's operation.

Code Snippet

In DSCEngine contract:

constructor(address[] memory tokenAddresses, address[] memory priceFeedAddresses, address dscAddress) {
if (tokenAddresses.length != priceFeedAddresses.length) {
revert DSCEngine__TokenAddressesAndPriceFeedAddressesMustBeSameLength();
}
for (uint256 i = 0; i < tokenAddresses.length; i++) {
s_priceFeeds[tokenAddresses[i]] = priceFeedAddresses[i];
s_collateralTokens.push(tokenAddresses[i]);
}
i_dsc = DecentralizedStableCoin(dscAddress);
}

Impact

If a zero address is provided as a token address or price feed address, it could lead to incorrect price feed data being used in the contract's operation. This could potentially affect the calculation of collateral value, health factor, and other critical operations, leading to incorrect minting, burning, or liquidation actions.

Tools Used

Manual code review

Recommendations

To mitigate this issue, add input validation to check if the provided addresses are non-zero. This can be done using a simple condition check in the constructor. Here is an example of how this could be implemented:

for (uint256 i = 0; i < tokenAddresses.length; i++) {
require(tokenAddresses[i] != address(0), "Token address cannot be zero");
require(priceFeedAddresses[i] != address(0), "Price feed address cannot be zero");
s_priceFeeds[tokenAddresses[i]] = priceFeedAddresses[i];
s_collateralTokens.push(tokenAddresses[i]);
}

This will ensure that only valid addresses are used to initialize the contract.

Support

FAQs

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