The claimProfit function in MembershipERC1155 contract is vulnerable to reentrancy attacks through ERC1155 token transfers that could occur during profit claiming. This vulnerability allows an attacker to drain more profit share than they are entitled to by manipulating the contract's state during the claim process. The severity is critical as it directly impacts the contract's fund distribution mechanism and could result in loss of funds for other legitimate token holders.
The issue stems from the contract's handling of profit claims and token transfers. When a user claims their profit share, the contract updates the profit state before executing the external token transfer. During this transfer, if tokens are moved, the ERC1155 standard mandates a callback to the recipient contract through onERC1155Received. A malicious contract could exploit this callback to reenter the claimProfit function before the initial claim is completed, finding the contract in an inconsistent state where profit calculations could be manipulated.
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L144
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L203
Consider the following attack scenario:
Attacker deploys a malicious contract that holds membership tokens and implements onERC1155Received
The attacker's contract initiates a claimProfit transaction
During the IERC20 transfer, the attacker's contract transfers some tokens, triggering _update
The _update function calls saveProfit, recalculating profits with the new token distribution
Through the onERC1155Received callback, the attacker reenters claimProfit
Due to the state inconsistency, the attacker can claim additional profits before the initial claim completes
This cycle can potentially continue until the contract's funds are drained
Consider implementing a pull-payment pattern where users first lock their claims and then withdraw in a separate transaction to further enhance security.
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.