Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: low
Invalid

Inefficient Fee Type Handling Due to Excessive Conditional Branching in _updateCollectedFees() in FeeCollector.sol

Summary

The _updateCollectedFees function uses multiple if-else statements to update different fee types, leading to higher gas costs due to repeated conditional checks. This inefficiency increases as more fee types are added, making the function less scalable and costlier to execute.

Vulnerability Details

This function is gas inefficient.

Multiple if-else Checks Increase Gas Costs

  • The function compares feeType up to 7 times in the worst case before updating the relevant fee category.

  • Branching logic (if-else) forces sequential execution, leading to higher gas costs.

  • The worst-case scenario occurs when feeType == 7, as it requires checking all 7 conditions before execution.

function _updateCollectedFees(uint256 amount, uint8 feeType) internal { //@audit-issue : if else cause more gas, use mapping
if (feeType == 0) collectedFees.protocolFees += amount;
else if (feeType == 1) collectedFees.lendingFees += amount;
else if (feeType == 2) collectedFees.performanceFees += amount;
else if (feeType == 3) collectedFees.insuranceFees += amount;
else if (feeType == 4) collectedFees.mintRedeemFees += amount;
else if (feeType == 5) collectedFees.vaultFees += amount;
else if (feeType == 6) collectedFees.swapTaxes += amount;
else if (feeType == 7) collectedFees.nftRoyalties += amount;
}

Impact

Storage Writes are Expensive

  • Each condition results in a separate storage write, which costs around 20,000 gas per update.

  • The function doesn't optimize storage access patterns efficiently.

Limited Scalability

  • If new fee types need to be added in the future, the contract must introduce additional if-else conditions, further worsening gas inefficiency.

Tools Used

Manual review

Recommendations

A mapping (hash table) provides O(1) lookup time, making the function significantly more gas-efficient.

More Scalable: If more fee types are added in the future, no extra logic is required—simply reference a new feeType key.

Change the function to below type.

mapping(uint8 => uint256) public collectedFees;
function _updateCollectedFees(uint256 amount, uint8 feeType) internal {
collectedFees[feeType] += amount;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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