The upgradeTier() function in the membership factory has several vulnerabilities that can cause the function to misbehave and potentially lose user funds the vulnerabilities include:
Potential for arithmetic underflow/ overflow.
Lack of balance check before burning tokens.
Ability to upgrade from the lowest tier.
These vulnerabilities could allow an attacker to burn more tokens than they own or engage in invalid upgrade operations that could lead to loss of user funds.
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/MembershipFactory.sol
Potential for arithmetic underflow/overflow
The upgradeTier() function subtracts one(-1) from fromTierIndex to determine the new tier index when minting the new token. This could lead to an arithmetic underflow if the fromTierIndex is 0, subtracting 1 from 0 will result in an underflow.
No checks to ensure that, the fromTierIndex is within the valid range of tier indicies.
If an invalid tier index is provided like, value greater than oe equal to TIERMAX the subtraction operation could equally lead to a potential Arithemetic overflow/underflow.
Lack of Balance check before burning tokens:
The upgradeTier() function does not properly check the user's balance before burning tokens.
The function calls the burn on the IMembershipERC1155 contract, passing in the fromTierIndex and a fixed value of 2 for the amount to be burned.
This can lead to a situation where the user does not have enough tokens of fromTierIndex but the function will still attempt to burn two tokens. This will cause the burn() function to revert with an error which is not the expected behavior.
Ability to Upgrade from the lowest tier:
The upgradeTier() lacks checks to ensure that the fromTierIndex is a valid tier.
meaning a malicious user could potentially call the function with the lowest tier or otherwise. Subtracting 1 from 0 could lead to an underflow also allowing an upgrade from an invalid tier could also lead to an underflow.
POC
Output generated
Handling Undeflow Scenarios:
The function should check for underflow scenarios like, such as subtracting 1 from 0 or performing oerations within an invalid tier index.
Implementing Balance Checks:
The upgradeTier() function should check the user balance for the fromTierIndex if the balance is less than 2 if less than 2, the function should revert with an appropriate error message.
Validate Tier Indicies:
The function should validate the provided fromTierIndex to ensure that it is within the valid range of tier Indicies. if invalid the function should revert with appropriate error message.
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.