Root Cause:
The claimProfit and sendProfit functions in the MembershipERC1155 contract lack reentrancy guards. These functions involve external calls to ERC20 tokens via safeTransfer and safeTransferFrom, which could be exploited if a malicious token contract is used.
claimProfit Function:
The savedProfit is set to zero after the external call to safeTransfer.
A reentrancy attack could allow the attacker to call claimProfit again before savedProfit is zeroed out.
sendProfit Function:
The totalProfit is updated before the external call to safeTransferFrom.
A malicious token contract could exploit this ordering to manipulate the state.
Impact:
Financial Loss: Attackers could repeatedly drain the contract's funds by reentering the claimProfit function.
State Manipulation: In sendProfit, the attacker could manipulate the totalProfit calculation, affecting profit distribution to other users.
Recommendation:
Implement the ReentrancyGuard from OpenZeppelin and apply the nonReentrant modifier to both functions.
Reorder state changes to occur before external calls.
For claimProfit, set savedProfit[msg.sender] = 0; before the external call to safeTransfer.
For sendProfit, perform external calls before updating critical state variables or ensure reentrancy is not possible.
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.