GivingThanks

First Flight #28
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

Improper Initialization of CharityRegistry in GivingThanks.sol Constructor

Summary

The constructor in GivingThanks.sol improperly initializes the registry variable, intended to reference an external CharityRegistry contract, by setting it to msg.sender (the contract deployer's address) instead of the provided _registry parameter. This misconfiguration causes the GivingThanks contract to interact with the deployer's address as though it were the CharityRegistry, resulting in critical failures for all charity verification and registry functions. This flaw directly breaks the purpose of the contract, as it cannot validate charity addresses or manage donations correctly, making it a critical bug with high impact.

Vulnerability Details

constructor(address _registry) ERC721("DonationReceipt", "DRC") {
registry = CharityRegistry(msg.sender); // Incorrect initialization
owner = msg.sender;
tokenCounter = 0;
}

In the constructor of GivingThanks.sol, the line registry = CharityRegistry(msg.sender); mistakenly sets registry to the deployer’s address (msg.sender) instead of the _registry parameter, which should be the actual address of the CharityRegistry contract instance. This initialization error leads GivingThanks to treat the deployer's address as the CharityRegistry, rendering functions like donate() ineffective because the contract fails to verify and validate charity addresses, causing donation transactions to fail.

Impact

This is a critical bug that impacts the entire donation system:

  • Failed Donations: Since the GivingThanks contract cannot reference a legitimate CharityRegistry instance, it fails to verify charities and process donations as intended. Donors attempting to contribute to verified charities will experience repeated transaction failures.

  • Platform Integrity Compromise: The donation process, core to the platform’s functionality, becomes unusable due to the contract’s inability to interact with verified charities, compromising the platform's mission and reputation.

  • Risk of Fraudulent Interactions: By pointing to the deployer's address as the registry, there is an increased risk of unauthorized access or manipulation if the contract mistakenly treats an unintended address as a valid registry authority.

  • Financial and Legal Repercussions: Donor funds could become stuck or mismanaged, resulting in legal implications and a loss of donor trust.

Tools Used

Manual Code Review: The issue was identified through a detailed review of the constructor's initialization logic.

Recommendations

  1. Correct Initialization in Constructor:

    • Update the constructor to initialize registry with the _registry parameter instead of msg.sender, ensuring the contract references the actual CharityRegistry instance:

    constructor(address _registry) ERC721("DonationReceipt", "DRC") {
    registry = CharityRegistry(_registry); // Correct initialization
    owner = msg.sender;
    tokenCounter = 0;
    }
  2. Add Deployment Validation Checks:

    • Implement a check in the constructor to confirm that _registry points to a valid CharityRegistry contract instance by verifying the contract’s bytecode presence:

    require(Address.isContract(_registry), "Invalid CharityRegistry address");

    Additional Unit Testing:

    • Include robust unit tests for initialization to confirm the GivingThanks contract references a valid CharityRegistry instance, ensuring accurate registry interactions and donation processing.

  3. Post-Deployment Audit:

    • After deployment, conduct a comprehensive audit to verify that all contract dependencies are properly initialized and functioning as expected.

By addressing this critical initialization flaw, the platform can ensure that GivingThanks correctly references the CharityRegistry, enabling proper donation functionality and securing user funds. This fix will re-establish the contract's core functionality, safeguarding the donation process and restoring donor confidence.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-bad-registry-set-at-construction

Likelyhood: High, the parameter is not well used and won't be set. Impact: Low, can be changed with the setter and no one will be able to donate to malicious charity.

Support

FAQs

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