# Message is indexed as refundable even if the signature was over a fork

Babylon finality keeper slashes a forked-signature provider but lacks a return, so the invalid message is still indexed as refundable in IncentiveKeeper.

- Payout: Audit contest
- Severity: medium
- Program: Babylon
- Found by: 0xeix
- Disclosed: 2024-12-09
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-babylon-judging/issues/18
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-babylon%3AM-2
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:sherlock sev:medium tech:go technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Cosmos SDK module msg_server AddFinalitySig handler
**Root cause:** After slashFinalityProvider for a fork vote, the handler falls through to IncentiveKeeper.IndexRefundableMsg instead of returning, so a message that fails the 'canonical block' precondition is still indexed as refundable.
**Steps:**
1. Submit `MsgAddFinalitySig` with a finality sig over a fork at a height where evidence already exists (`HasEvidence` true).
2. Handler enters the slashing branch, calls `slashFinalityProvider`, but does not return.
3. Execution continues to `ms.IncentiveKeeper.IndexRefundableMsg(ctx, req)`, marking the invalid message refundable.
4. Compare with the earlier duplicate-evidence branch which correctly returns `&types.MsgAddFinalitySigResponse{}, nil`.
**How found:** Code reading of msg_server.go: noticed the comment claiming the sig is 'valid, over a canonical block, not duplicated' before indexing, but the slashing branch above lacks a return, unlike the sibling branch that returns explicitly.
**Exploitation:** A finality provider submits a forked finality signature; instead of being rejected after slashing, the message hash is added to the refundable set, allowing a refund for an invalid signature addition.
**Insight:** When a handler has multiple early-exit branches, check each one returns; a missing return after a state-changing slash lets execution fall through to post-condition code (refund indexing) that assumes the happy path.

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

**Missing return after slashing finality provider**

```
// if this finality provider has signed the canonical block before,
	// slash it via extracting its secret key, and emit an event
	if ms.HasEvidence(ctx, req.FpBtcPk, req.BlockHeight) {
		// the finality provider has voted for a fork before!
		// If this evidence is at the same height as this signature, slash this finality provider

		// get evidence
		evidence, err := ms.GetEvidence(ctx, req.FpBtcPk, req.BlockHeight)
		if err != nil {
			panic(fmt.Errorf("failed to get evidence despite HasEvidence returns true"))
		}

		// set canonical sig to this evidence
		evidence.CanonicalFinalitySig = req.FinalitySig
		ms.SetEvidence(ctx, evidence)

		// slash this finality provider, including setting its voting power to
		// zero, extracting its BTC SK, and emit an event
		ms.slashFinalityProvider(ctx, req.FpBtcPk, evidence)
	}

	// at this point, the finality signature is 1) valid, 2) over a canonical block,
	// and 3) not duplicated.
	// Thus, we can safely consider this message as refundable
	ms.IncentiveKeeper.IndexRefundableMsg(ctx, req)
```

