The current implementation of the MembershipERC1155 contract contains a critical flaw in its profit distribution tracking system that could lead to incorrect profit calculations during token transfers and subsequent distributions. This vulnerability stems from inconsistent weight application in the contract's accounting system and could result in users receiving incorrect profit shares, particularly when tokens change ownership across different distribution periods.
The vulnerability lies in the contract's dual application of weights - once in totalSupply tracking and again in shareOf() calculations - which creates inconsistencies in historical profit tracking during token transfers. When tokens are transferred, the contract updates the profit records using saveProfit(), which relies on the current shareOf() value. However, since totalSupply already includes weighted values, this creates a misalignment in how historical profits are recorded and how new profits are calculated after transfers.
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L60
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L169
Consider this scenario:
Alice owns 1 token of ID 0 (weight 64)
Initial totalSupply = 64 (weighted)
A profit distribution of 1000 USDC occurs
totalProfit += (1000 * 1e30) / 64
Alice transfers her token to Bob, triggering _update():
saveProfit(Alice) calculates her unsaved profits using shareOf(Alice) = 64
Sets lastProfit[Alice] = totalProfit
saveProfit(Bob) sets his lastProfit = totalProfit
When a new profit distribution occurs:
Bob's profit calculation uses the lastProfit value set during the transfer, which was based on a different weighting scheme than what's used in totalSupply, potentially leading to incorrect profit calculations.
This fix ensures consistent weight tracking throughout the contract by maintaining unweighted token supplies per ID and calculating weights only when needed. The solution provides better encapsulation of the weighting logic, makes the code more maintainable, and eliminates the potential for profit calculation errors during token transfers. Most importantly, it maintains accurate historical profit tracking by using a consistent weighting scheme across all operations.
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.