GivingThanks

First Flight #28
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

[L-01] Lack of Duplicate Registration Check Leads to Unnecessary Gas Consumption

Summary

The CharityRegistry::registerCharity() function in the contract does not check if a charity address has already been registered. This lack of validation can lead to redundant write operations, resulting in unnecessary gas consumption when attempting to register the same charity address multiple times.

Vulnerability Details

function registerCharity(address charity) public {
registeredCharities[charity] = true;
}

The function sets a given address in the registeredCharities mapping to true without checking if it is already registered. If the same address is provided multiple times, the mapping will repeatedly write the same value (true). Although this does not alter the state from the user's perspective, it leads to unnecessary storage operations and gas costs.

Impact

Gas Inefficiency: Repeatedly registering the same address leads to unnecessary gas consumption. In the context of high-frequency or automated transactions, this can cause significant waste of gas over time.

No Direct State Impact: The mapping entry itself registeredCharities[charityAddress] remains set to true, so the logical state of the contract is not altered beyond increased gas usage.

Tools Used

Manual code review

Recommendations

function registerCharity(address charity) public {
require(!registeredCharities[charity], "Charity already registered");
registeredCharities[charity] = true;
}
Updates

Lead Judging Commences

n0kto Lead Judge 12 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.