# Incorrect BTC Delegation Reward Calculation Due to Using Current Stake Amount Instead of Historical Stake

Babylon incentive keeper computes BTC delegation rewards using current TotalActiveSat instead of historical stake, so stake changes before delayed reward calc misallocate rewards.

- Payout: Audit contest
- Severity: medium
- Program: Babylon
- Found by: 0xNirix
- Disclosed: 2024-12-09
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-babylon-judging/issues/70
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-babylon%3AM-4
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** Cosmos SDK incentive module reward tracker (x/incentive/keeper/reward_tracker.go)
**Root cause:** BTCDelegationRewardsTracker stores only current TotalActiveSat and starting period, not per-period historical stake. calculateDelegationRewardsBetween multiplies CumulativeRewardsPerSat delta by current TotalActiveSat, so stake changes during the FinalitySigTimeout delay (or a finality halt) skew rewards.
**Steps:**
1. Delegator A has 100,000 sats delegated to FinalityProviderX in Period 1; finality halts so rewards are not yet distributed.
2. Delegator A unbonds 50,000 sats via `BtcDelegationUnbonded`, incrementing period to 2 and setting TotalActiveSat=50,000.
3. Governance calls `HandleResumeFinalityProposal`, then `TallyBlocks`/`HandleRewarding` finalizes Period 1 rewards.
4. `calculateDelegationRewardsBetween` computes `differenceWithDecimals.MulInt(btcDelRwdTracker.TotalActiveSat)` using 50,000 instead of 100,000.
5. Delegator A withdraws and receives half the deserved reward; inverse (increasing stake) over-rewards and dilutes others.
**How found:** Code review of reward_tracker.go: noticed the tracker struct lacks historical stake fields and that the reward formula references the mutable TotalActiveSat rather than a period-snapshotted value, then traced the delayed-reward path through HandleRewarding.
**Exploitation:** A delegator times an unbond or new activation within the FinalitySigTimeout window (or during a finality halt before governance resumes) so that reward calculation for the prior period uses the post-change stake, capturing extra rewards or avoiding dilution at other delegators' expense.
**Insight:** When auditing reward/accounting modules, check whether per-period accumulators snapshot the user's balance at accrual time; any mutable 'current amount' multiplied against a cumulative index is suspect wherever reward settlement is delayed (timeouts, halts, governance).

## Proof of concept (copied exactly from the original report)

**Unbond reduces stake before reward calc**

```
k.BtcDelegationUnbonded(ctx, fpAddr, delegatorAddr, 50000)

// This function calls:
k.btcDelegationModifiedWithPreInitDel(ctx, fp, del, function(ctx, fp, del) {
    return k.subDelegationSat(ctx, fp, del, 50000)
})

// Which increments the period and calculates rewards for current period:
endedPeriod, err := k.IncrementFinalityProviderPeriod(ctx, fp)

// The delegation's TotalActiveSat is reduced:
if err := k.subDelegationSat(ctx, fp, del, amtSat); err != nil {
```

