The vulnerability originates from a fundamental design flaw in the profit tracking mechanism of MembershipERC1155.sol. The core issue stems from the _update function's implementation where profit calculations occur before token balance updates.
Key points of origin:
In the _update function: https://github.com/Cyfrin/2024-11-one-world/blob/1e872c7ab393c380010a507398d4b4caca1ae32b/contracts/dao/tokens/MembershipERC1155.sol#L203-L212
The profit calculation depends on shareOf() which uses current token balances:
This creates a race condition where profit calculations use outdated balance states, leading to incorrect profit distributions. The design assumes profits can be safely calculated before balance updates, but this assumption breaks the accounting system's integrity during transfers.
The profit distribution system in MembershipERC1155 contains a critical flaw in how profits are calculated and saved during token transfers. The _update function processes profit calculations before token balances are updated, allowing manipulation of profit distribution.
Technical Description The core issue lies in the sequence of operations during token transfers. Profits are calculated and saved using stale balances before the actual transfer occurs, leading to incorrect profit distribution and potential exploitation.
saveProfit() is called before the actual transfer occurs, which can lead to incorrect profit calculations since the token balances haven't been updated yet. https://github.com/Cyfrin/2024-11-one-world/blob/1e872c7ab393c380010a507398d4b4caca1ae32b/contracts/dao/tokens/MembershipERC1155.sol#L182-L187
The profit tracking system calculates and updates profits before token balances change during transfers. This creates a race condition where profit calculations use outdated balances, leading to incorrect profit distribution.
Attack Scenario:
Alice has 100 tokens with accumulated profits
Bob initiates a transfer from Alice
System calculates Alice's profits using her old balance (100 tokens)
Transfer executes, updating balances
Alice's profit calculation is incorrect as it used pre-transfer balance
Loss of user funds through incorrect calculations and breaking of the profit-sharing mechanism integrity
Two optional recommendations:
ensure profit calculations use the correct token balances by separating the profit saving from the transfer operation.
Here is the other option.
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.