codehawks-2023-07-dsc-l06
[L-06] Unbounded Loops Found in DSCEngine.sol can lead to DoS of liquidations
Summary
반복문에 상한이 없다. 가스 리밋으로 인해 revert 될 수 있다.
Keyword
dos, gas limit, gas
Vulnerability
s_collateralTokens 배열을 순회하며 담보의 총 가치를 계산한다.
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;
}배열의 길이가 너무 길다면 가스 제한에 걸려 트랜잭션이 revert 될 것이다.
Impact
담보 토큰 수가 너무 많으면 반복문에서 가스 리미트에 걸려 트랜잭션이 revert 된다. DoS가 발생할 수 있다.
Mitigation
추가할 수 있는 담보 토큰의 개수를 명시적으로 제한하여 반복 횟수에 상한을 둔다.
tags: bughunting, codehawks, smart contract, solidity, gas limit, gas, dos, severity low