# LotteryMath.calculateNewProfit returns wrong profit when there is no jackpot winner

LotteryMath.calculateNewProfit multiplies a percentage multiplier directly instead of via PercentageMath, corrupting currentNetProfit and reward sizing when no jackpot winner exists.

- Payout: Contest reward
- Severity: high
- Program: Wenwin
- Credited: Cyfrin
- Disclosed: 2023-04-12
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-03-wenwin-findings/issues/324
- Library page: https://bugbountylibrary.com/r/c4%3A2023-03-wenwin%3AH-01
- Tags: domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error

**Target:** Solidity lottery contract LotteryMath/Lottery
**Root cause:** When jackpotWon is false, calculateMultiplier returns a percentage (basis points) but the code multiplies it directly by ticketsSold*expectedPayout instead of applying it as a percentage via PercentageMath, producing a wildly wrong expectedRewardsOut.
**Steps:**
1. Call LotteryMath.calculateNewProfit(oldProfit=0, ticketsSold=1, ticketPrice=5 ether, jackpotWon=false, fixedJackpotSize=1_000_000e18, expectedPayout=38e16)
2. Observe returned newProfit/1e15 = -37996500 vs expected 3120
3. Note calculateMultiplier returns a PERCENTAGE-math value that must be applied via getPercentage, not raw multiplication
**How found:** Code review of calculateNewProfit's ternary branch: noticed the non-jackpot branch multiplies ticketsSold*expectedPayout by calculateMultiplier output directly, while the jackpot branch uses calculateReward; recognized calculateMultiplier returns a percentage needing PercentageMath.
**Escalation:** Wrong currentNetProfit feeds drawRewardSize, corrupting reward calculation for the protocol's core lottery functionality.
**Insight:** When a helper returns a value in percentage-math units (e.g. 1e4 = 100%), check every call site applies it via getPercentage/percentMul rather than raw multiplication; asymmetric branches of a ternary are a prime spot for this.
