The buyback
function calls swapExactETHForTokens
with amountOutMin
set to 1. This allows attackers to front-run the transaction and manipulate the price, resulting in the contract receiving far fewer tokens than expected. This can drain the contract's ETH with minimal token returns, leading to significant fund loss.
Calculate a reasonable amountOutMin
based on the current price and expected slippage. For example, use the current reserves in the Uniswap pool to determine the minimum acceptable tokens, or allow a configurable slippage tolerance.
Line 727 – 732
The distribute
function calculates profit
as share * timeElapsed
without ensuring it does not exceed dividendBalance_
or swapBalance_
. When profit
exceeds the balance, safeSub
sets the balance to zero, but the full profit
is added to profitPerShare_
and rewardsProfitPerShare_
. This allows users to claim more dividends than available, potentially draining the contract's funds.
Cap profit
to the current dividendBalance_
and swapBalance_
before subtraction. For example, use profit = Math.min(share * timeElapsed, dividendBalance_)
to prevent over-issuance.
Line 674 – 689
The purchaseTokens
function miscalculates the number of tokens minted by subtracting the entry fee from the incoming ETH directly. This results in users receiving fewer tokens than intended. For example, with a 10% entry fee, sending 1.1 ETH should yield 1 token, but the code mints 0.99 tokens instead, leading to an unfair token distribution and incorrect supply.
Calculate tokens as _incomingeth * 100 / (100 + entryFee_)
to correctly account for the entry fee percentage of the total cost.
Line 760 – 765
The buyback
function sets the minimum tokens received to 1, making it vulnerable to front-running and price manipulation. Attackers can exploit this to drain contract funds by forcing unfavorable swaps, resulting in substantial losses.
Calculate a reasonable amountOutMin
using current market rates with a slippage tolerance (e.g., 99% of the expected amount).
Line 727 – 732
The tokenBalance
function erroneously returns the address's ETH balance instead of their token balance, causing incorrect data exposure and potential integration errors.
Return tokenBalanceLedger_[_customerAddress]
to reflect the actual token holdings.
Line 526 – 530
The claim
function does not check the return value of the token transfer. If the token uses a boolean return instead of reverting, failed transfers go unnoticed, leading to incorrect claim accounting and user losses.
Use require(token.transfer(...), "Transfer failed")
or SafeERC20's safeTransfer
to handle transfer failures.
Line 322 – 322
The distribute
function does not cap the elapsed time since the last distribution. If inactive for over 24 hours, subsequent calls distribute more than the intended 2% daily rate, potentially depleting reserves faster than designed.
Cap now.safeSub(lastPayout)
to a maximum of 24 hours to enforce the daily drip limit.
Line 674 – 674