In the GivingThanks contract, the registry variable is incorrectly initialized to msg.sender instead of the _registry parameter passed to the constructor. This results in the registry pointing to the address of the contract deployer rather than the intended CharityRegistry contract.
The vulnerability is an Initialization Error located in the constructor of the GivingThanks contract. The issue arises from the incorrect assignment of the registry variable. Instead of being initialized with the _registry parameter, which is intended to be the address of a CharityRegistry contract, it is mistakenly set to msg.sender. This oversight causes the registry to point to the deployer's address rather than the correct CharityRegistry contract, leading to the malfunction of critical functionalities such as charity verification and donation processing.
Output
Test with registry = CharityRegistry(msg.sender);
Test with registry = CharityRegistry(_registry);
The contract will not function as intended since the registry will not point to a valid CharityRegistry contract.
The donate function will always fail the require(registry.isVerified(charity), "Charity not verified") check, as the isVerified function will not be callable on a non-CharityRegistry address.
Manual Code Review and Foundry Unit Test
Modify the constructor to correctly initialize the registry variable with the _registry parameter:
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.