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.
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.
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.
Manual Code Review: The issue was identified through a detailed review of the constructor's initialization logic.
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:
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:
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.
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.
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.
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.