codehawks-2023-08-sparkn-l06
[L-06] Potential DOS due to Gas Exhaustion Due to Large Array Iteration in _distribute Function
Summary
수상자가 너무 많은 경우 Gas 제한에 걸려 한 번에 처리할 수 없다.
Keyword
gas, gas limit, dos
Vulnerability
리워드를 분배할 때, 수상자 배열을 돌며 토큰을 나누어준다. 이 때, 배열의 길이가 너무 길다면 Gas 소비량이 Gas 한도를 초과하여 트랜잭션이 실패할 것이다.
function _distribute(address token, address[] memory winners, uint256[] memory percentages, bytes memory data)
internal
{
// ...
uint256 winnersLength = winners.length;
for (uint256 i; i < winnersLength;) {
uint256 amount = totalAmount * percentages[i] / BASIS_POINTS;
erc20.safeTransfer(winners[i], amount);
unchecked {
++i;
}
}
// ...
}Impact
많은 수의 수상자에게 토큰을 분배하는 경우 Gas 한도를 초과해 실패할 수 있다.
Mitigation
최대 수상자 숫자를 제한하거나, 여러번 나눠서 지급할 수 있도록 한다.
tags: bughunting, sparkn, smart contract, solidity, gas, gas limit, dos, severity low