Summary
Missing DAO existence check in joinDAO function.
Vulnerability Details
The joinDAO function doesn't verify if the DAO exists before attempting to join it. Since daos is a mapping, accessing a non-existent DAO will return default values (0 for noOfTiers) rather than reverting.
function joinDAO(address daoMembershipAddress, uint256 tierIndex) external {
require(daos[daoMembershipAddress].noOfTiers > tierIndex, "Invalid tier.");
require(daos[daoMembershipAddress].tiers[tierIndex].amount > daos[daoMembershipAddress].tiers[tierIndex].minted, "Tier full.");
uint256 tierPrice = daos[daoMembershipAddress].tiers[tierIndex].price;
uint256 platformFees = (20 * tierPrice) / 100;
daos[daoMembershipAddress].tiers[tierIndex].minted += 1;
IERC20(daos[daoMembershipAddress].currency).transferFrom(_msgSender(), owpWallet, platformFees);
IERC20(daos[daoMembershipAddress].currency).transferFrom(_msgSender(), daoMembershipAddress, tierPrice - platformFees);
IMembershipERC1155(daoMembershipAddress).mint(_msgSender(), tierIndex, 1);
emit UserJoinedDAO(_msgSender(), daoMembershipAddress, tierIndex);
}
https://github.com/Cyfrin/2024-11-one-world/blob/1e872c7ab393c380010a507398d4b4caca1ae32b/contracts/dao/MembershipFactory.sol#L140C3-L151C1
When users try to join a non-existent DAO with tierIndex = 0, the first require statement will revert with "Invalid tier". For any other tierIndex > 0, it will also revert with "Invalid tier". These are wrong and misleading error messages.
Impact
Error message is misleading as it suggests the tier is invalid when the actual issue is that the DAO doesn't exist.
Tools Used
Manual review
Recommendations
Add a DAO existence check at the beginning of the function:
function joinDAO(address daoMembershipAddress, uint256 tierIndex) external {
require(daos[daoMembershipAddress].currency != address(0), "DAO does not exist");
require(daos[daoMembershipAddress].noOfTiers > tierIndex, "Invalid tier.");
}