Summary
The MembershipERC1155::sendProfit
function in MembershipERC1155
contract suffers from precision loss due to division rounding down, resulting in small amounts of tokens being permanently loss in the contract.
Vulnerability Details
function sendProfit(uint256 amount) external {
uint256 _totalSupply = totalSupply;
if (_totalSupply > 0) {
@>>> totalProfit += (amount * ACCURACY) / _totalSupply;
IERC20(currency).safeTransferFrom(msg.sender, address(this), amount);
emit Profit(amount);
}
}
Impact
Small amounts lost in each distribution
Cumulative effect over time
No mechanism to recover locked tokens
Affects all token holders proportionally
Tools Used
Manual review
Recommendations
Tracking of undistributed for future use for protocol or again distributing to users.
function sendProfit(uint256 amount) external {
uint256 _totalSupply = totalSupply;
if (_totalSupply > 0) {
totalProfit += (amount * ACCURACY) / _totalSupply;
IERC20(currency).safeTransferFrom(msg.sender, address(this), amount);
emit Profit(amount);
} else {
IERC20(currency).safeTransferFrom(msg.sender, creator, amount); // Redirect profit to creator if no supply
}
+ undistributedAmount += amount - actualDistributed;
// assume we want to send that amount to protocol
+ IERC20(currency).safeTransferFrom( address(this), OWPWallet, undistributedAmount);
}