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.
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.
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.
Manual review
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.