The saveProfit
mechanism in the profit distribution system contains a critical front-running vulnerability that allows malicious actors to manipulate their profit claims through strategic token transfers. This vulnerability directly impacts the protocol's financial integrity by enabling attackers to extract a disproportionate amount of profits from the system, effectively draining more funds than they are legitimately entitled to receive. The economic impact scales with the size of profit distributions and could potentially make the entire profit-sharing mechanism economically unviable.
The issue stems from the profit calculation logic being intrinsically tied to token transfers and the current global profit state. The contract maintains a global totalProfit
variable and individual lastProfit[account]
mappings that are updated during token transfers. When profits are distributed via sendProfit()
, the contract increases totalProfit
, and users can claim their share based on the difference between their lastProfit
and the current totalProfit
. However, the critical flaw lies in how saveProfit
is called during token transfers, allowing users to reset their profit checkpoints multiple times during a single profit distribution event.
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L182
https://github.com/Cyfrin/2024-11-one-world/blob/main/contracts/dao/tokens/MembershipERC1155.sol#L203
Consider the following scenario: An attacker monitors the mempool for incoming sendProfit
transactions. Upon detecting a profit distribution of 1000 tokens, they execute a series of transfers between their controlled addresses before the profit transaction is mined. When the profit distribution occurs, they can claim profits for each address they transferred to, as each transfer created a new profit checkpoint through saveProfit
. After the profit distribution, they consolidate the tokens back to their main address. Through this manipulation, they could claim significantly more profits than their fair share based on their actual token holding duration.
The profit distribution system should be redesigned to use a snapshot-based mechanism that prevents profit manipulation through transfers. Here's a proposed fix:
This solution creates immutable profit distribution snapshots that cannot be manipulated through transfers. Each profit distribution creates a new snapshot, and users can only claim profits they were eligible for at the time of each snapshot. This eliminates the front-running vulnerability while maintaining fair profit distribution based on actual token ownership at distribution time.
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.