Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Invalid

Gas Costs and DoS via Large Arrays

Summary

The claimFees function in the FeeDistributionBranch contract accepts an unbounded array of asset addresses, potentially leading to excessive gas consumption. This can result in failed transactions and potential denial-of-service (DoS) attacks, where the function becomes unusable for legitimate users.

Vulnerability Details

The claimFees function processes an array of asset addresses:

function claimFees(address[] memory assets) external {
for (uint256 i = 0; i < assets.length; i++) {
uint256 amount = feeBalances[assets[i]];
if (amount > 0) {
feeBalances[assets[i]] = 0;
IERC20(assets[i]).transfer(msg.sender, amount);
emit FeesClaimed(msg.sender, assets[i], amount);
}
}
}

Processing a large number of assets can consume more gas than is allowed in a single transaction, causing the transaction to fail.

DoS Vulnerability: An attacker could submit a deliberately large array of assets, rendering the function unusable for legitimate users.

Block Gas Limit: If the gas consumed by the loop exceeds the block gas limit, no transaction involving this function will succeed.

Underlying Cause:

The function does not restrict the size of the assets array or optimize the processing of external calls.

Impact

Legitimate users may face failed transactions if the array size exceeds what can be processed within the gas limits.

Denial of Service (DoS):

An attacker could exploit this issue to prevent others from successfully claiming fees by submitting overly large arrays.

Tools Used

slither

Recommendations

Enforce Limits on Input Array Size:

Restrict the maximum number of assets that can be processed in a single transaction.

uint256 public constant MAX_ASSETS = 10;
function claimFees(address[] memory assets) external {
require(assets.length <= MAX_ASSETS, "Too many assets");
for (uint256 i = 0; i < assets.length; i++) {
uint256 amount = feeBalances[assets[i]];
if (amount > 0) {
feeBalances[assets[i]] = 0;
require(IERC20(assets[i]).transfer(msg.sender, amount), "Transfer failed");
emit FeesClaimed(msg.sender, assets[i], amount);
}
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
5 months ago
inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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