# Discounted fee calculation is imprecise and calculates less fees than anticipated

Juicebox _feeAmount divides by discountedFee+MAX_FEE instead of MAX_FEE, so discounted fees are undercharged versus protocol intent.

- Payout: Contest reward
- Severity: medium
- Program: Juicebox
- Credited: berndartmueller
- Disclosed: 2022-10-11
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-07-juicebox-findings/issues/275
- Library page: https://bugbountylibrary.com/r/c4%3A2022-07-juicebox%3AM-05
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity vuln:accounting-error vuln:fee-bypass

**Target:** JBPayoutRedemptionPaymentTerminal._feeAmount fee math
**Root cause:** Fee amount computed as amount - amount*MAX_FEE/(discountedFee+MAX_FEE) instead of amount*discountedFee/MAX_FEE, yielding a smaller fee than the discounted rate implies.
**Steps:**
1. Take amount=1000, fee=5, feeDiscount=10, MAX_FEE=100, MAX_FEE_DISCOUNT=100
2. Compute discountedFee = 5 - 5*10/100 = 4.5
3. Call _feeAmount: returns 1000 - 1000*100/(4.5+100) ≈ 43
4. Expected fee = 1000*4.5/100 = 45; observe undercharge
**How found:** Code review of the _feeAmount formula; noticed the denominator adds discountedFee to MAX_FEE, which is dimensionally wrong versus the intended fee-rate division.
**Insight:** When a fee is expressed as a fraction of MAX_FEE, dividing by (rate+MAX_FEE) instead of MAX_FEE silently shrinks the result; sanity-check fee math against a hand-computed example.
