<!-- XE-0017 · Invalid lease_cancel still unwinds provider accept (cancel-wins before validation) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0017>. The page is the record; this is the same page for reading.*

XE-0017 · Bounty

# Invalid lease\_cancel still unwinds provider accept (cancel-wins before validation)

Accepted
claimed High
[xe#38](https://github.com/xeprotocol/xe/issues/38)
filed 2026-10-24 20:19 UTC
by efootballyay-dot

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   High

Area
:   Consensus

Duplicate of
:   —

Tracked
:   internally

Updated
:   2026-11-10 11:38 UTC

Told
:   2026-11-10 00:15 UTC

### Patches

- [xe#39](https://github.com/xeprotocol/xe/pull/39) open by ocakciomursel-pixel
  fix(core): validate lease\_cancel before unwinding racing provider accept
- [xe#149](https://github.com/xeprotocol/xe/pull/149) open by arturbarszcz78
  fix(core): validate lease\_cancel before unwinding racing provider accept (#38)

### History

- [61375](https://bounty.xe.network/log/61375) 2026-11-10 00:15 UTC reply.mirrored
- [61332](https://bounty.xe.network/log/61332) 2026-11-10 00:15 UTC reply.sent
- [15185](https://bounty.xe.network/log/15185) 2026-11-06 19:56 UTC proposal.adopted
- [15184](https://bounty.xe.network/log/15184) 2026-11-06 19:56 UTC ticket.award
- [15183](https://bounty.xe.network/log/15183) 2026-11-06 19:56 UTC proposal.rejected
- [6865](https://bounty.xe.network/log/6865) 2026-11-05 13:45 UTC proposal.created
- [1789](https://bounty.xe.network/log/1789) 2026-11-02 19:16 UTC proposal.created
- [1445](https://bounty.xe.network/log/1445) 2026-11-02 10:11 UTC note.added
- [675](https://bounty.xe.network/log/675) 2026-10-29 14:22 UTC note.added
- [674](https://bounty.xe.network/log/674) 2026-10-29 14:22 UTC ticket.facts area
- [614](https://bounty.xe.network/log/614) 2026-10-29 14:05 UTC github.labels
- [336](https://bounty.xe.network/log/336) 2026-10-29 14:04 UTC ticket.status triaging → accepted

[Full history](https://bounty.xe.network/log?ref=XE-0017) · [JSON](https://bounty.xe.network/v1/tickets/XE-0017) · [markdown](https://bounty.xe.network/XE-0017.md)

### Report

# Invalid lease\_cancel still unwinds a provider accept (cancel-wins runs before cancel validation)

**Credit:** Mgal Ghifari
**Target:** XE Protocol — https://test.network/bounty
**Repo:** https://github.com/xeprotocol/xe @ `978785929bc17a2f4ab30c383e5fc9cf4d634512`
**Component:** `core/ledger.go` — `validateAndAddLeaseCancel` / `resolveCancelWinsOverAccept`
**Reward address (XE):** `fe280837c418c6a918cb046d9531648163316d339d93f1498f7b3b9740560570`

---

## Summary

An **invalid** `lease_cancel` (valid consumer signature, but body fails ledger checks — wrong balance, wrong previous, or timestamp-before-previous) still triggers `resolveCancelWinsOverAccept` → `undoBlockApply` and permanently unwinds a provider's not-yet-finalized accept. The unwind runs **before** the cancel's own pending / previous / timestamp / balance checks. So a block the ledger ultimately **rejects** still mutates state.

On any node that received that junk cancel: the accept is gone, re-sending the real accept is a silent no-op, after restart the provider's `LeasesAcceptedAsProvider` reads 0 vs 1 on honest nodes, and the provider's next block fails forever with `previous mismatch`. Honest nodes that never saw the cancel keep the accept. Lasting node split. Honest-path finality **locks** the damage — 0 conflicts on the victim, so voting never repairs it.

I'm filing this as **High**. You could also read it as **Severe** under XE's wording (validation bypass / node compromise) — a rejected block still corrupts ledger state, and finality locks it. Not Critical: no mint, no double-spend, no escrow theft, and honest nodes that never saw the cancel stay consistent.

---

## Severity

**High** (XE High tier: targeted DoS / race / privilege escalation a single client can cause)

Also readable as **Severe**: validation-ordering bug. `undoBlockApply` runs before the cancel is fully validated, so a block that fails checks still mutates the ledger, and honest finality locks the split.

Not claiming Critical. No mint / double-spend / escrow drain. Honest nodes that never received the junk cancel stay consistent with each other.

---

## Affected code

Commit: `978785929bc17a2f4ab30c383e5fc9cf4d634512`

**Call site — unwind before cancel checks** (`core/ledger.go`):

```
// validateAndAddLeaseCancel — lines 1814-1856
if existing != nil && existing.State == LeaseAccepted && existing.Provider != b.Account {
    if rerr := l.resolveCancelWinsOverAccept(b.Source, existing.Provider); rerr != nil {
        return rerr
    }
}
// ... only AFTER that:
// previous mismatch  (1842-1843)
// timestamp before previous (1847-1848)
// balance mismatch   (1854-1855)
```

**Unwind itself** (`core/ledger.go:1749-1789`):

```
func (l *Ledger) resolveCancelWinsOverAccept(leaseHash, provider string) error {
    // ... find non-finalized tip accept ...
    if err := l.undoBlockApply(provider, acceptBlock); err != nil {  // line 1784
        return fmt.Errorf("cancel-wins: unwind provider accept: %w", err)
    }
    return nil
}
```

**Gossip delivery** (`node/node.go:705-711`):

```
func (n *Node) handleIncoming(blocks <-chan *core.Block) {
    for b := range blocks {
        // ...
        err := n.Ledger.AddBlock(b)  // every gossiped block, including ones that will be rejected
```

**Why re-sync does not heal** (`core/ledger.go:793-799`): known-hash early return. The rejected accept body stays in the block store, so `AddSyncedBlock(accept)` returns `nil` and does nothing.

---

## Preconditions

1. A lease exists and a provider has accepted it (`LeaseAccepted`), accept **not** yet finalized.
2. Attacker is the **lease consumer** (only the consumer can sign a cancel for that lease).
3. Cancel has a **valid consumer signature**. A bad-sig cancel does **not** unwind (I checked — credential check runs before cancel-wins). The body is just semantically invalid.
4. Delivery: gossip → `AddBlock`. Stock `SubmitBlock` will not re-gossip a rejected cancel. A malicious peer can `Gossip.Publish` the signed junk cancel directly onto the mesh; `handleIncoming` feeds it into `AddBlock`.
5. Window: only before the accept is finalized. Once finalized, cancel-wins refuses with `accept is finalized`.

---

## Steps to reproduce

All testing was **local** — in-memory `store.MemStore` \+ in-process `core.Ledger`. No traffic to test.network. No public load.

PoC lives under `reports/poc/` in a checkout of this commit. Relevant tests: `h4_cancel_test.go` (`TestH4b_*`), `h4b_multinode_test.go`, `round2_test.go` (`TestH9_*`).

### 1\) Core bug — three invalidity variants

```
cd /path/to/xe
go test ./reports/poc/ -run 'TestH4b_InvalidCancelStillUnwindsAccept' -v
```

What you see (each of `wrong_balance`, `wrong_previous`, `timestamp_before_prev`):

- log line: `cancel-wins over a racing accept — unwound provider ...`
- cancel error e.g. `balance mismatch: expected 1000000, got 1000999` (cancel **rejected**)
- `lease state=created`, `provider frontier==accept? false`, accept status Rejected
- re-submit canonical accept: `err=<nil>`, frontier still not accept (silent no-op)
- provider's next block: `previous mismatch`
- honest node that never saw the junk cancel: `provider frontier==accept? true`

### 2\) Multi-node lasting split \+ finality lock

```
go test ./reports/poc/ -run 'TestH4b_MultiNode_LastingSplit|TestH4b_HonestFinalityCannotRepair' -v
```

Observed:

- junk cancel → victim only: victim lease\=`created`, honest stays `accepted`
- honest finalizes accept; victim re-sync of accept: `healed=false`, body still in store
- victim restart: `accepted-as-provider=0` vs honest `1`
- provider next block on victim: permanent `previous mismatch`
- `GetConflictsForAccount(provider)` on victim \= **0** → voting never engages

### 3\) Amplification (H9) — dual-accept reality after unwind

```
go test ./reports/poc/ -run 'TestH9_' -v
```

After the junk cancel on victim, a **new** accept on the restored frontier:

- victim applies it (`lease=accepted` on a new hash)
- honest keeps the original accept frontier and stages a conflict (`conflicts=1`)
- lasting dual-accept reality across nodes

### 4\) Follow-on refund asymmetry (same root cause)

```
go test ./reports/poc/ -run 'TestH4b_FollowOn_RefundAfterNetworkFinalizedAccept' -v
```

After junk cancel on victim, both nodes mark accept finalized network-wide; a later **valid** cancel:

- victim: succeeds, lease\=`cancelled`, consumer refunded
- honest: `accept is finalized`, lease stays `accepted`

Same lease, opposite outcomes, depending on who saw the junk cancel.

---

## Root cause

Ordering bug in `validateAndAddLeaseCancel`:

1. See lease in `Accepted` → call `resolveCancelWinsOverAccept`
2. That calls `undoBlockApply` and **persists** the unwind
3. **Then** check pending / previous / timestamp / balance
4. Those checks fail → cancel is rejected
5. Unwind is **not** rolled back

So a rejected cancel still mutates provider chain \+ lease state. No conflict object is registered on the provider account, so quorum / finality has nothing to vote on. Honest-side finality of the original accept then freezes the victim on `previous mismatch`.

---

## Impact

With one signed junk cancel, a lease consumer can:

- Permanently unwind a provider's not-yet-finalized accept on every peer that receives the gossip
- Freeze that provider's account chain on those peers (`previous mismatch` forever)
- Split node state: affected peers vs honest peers disagree on lease state, frontier, and reputation (0 vs 1 after restart)
- Create a dual-accept reality if a new accept is built on the unwound frontier (H9)
- Leave no on-chain explanation — the cancel itself was rejected

Attack cost: one properly signed consumer block \+ PoW, delivered via gossip. No special role beyond being the lease consumer.

---

## Suggested fix

1. Fully validate the cancel (pending / previous / timestamp / balance — in a staged overlay) **before** any unwind.
2. Only call `resolveCancelWinsOverAccept` / `undoBlockApply` after the cancel itself would commit.
3. Make the unwind part of the cancel's atomic commit (same commit guards / `ExpectLeaseState`), so a rejected cancel cannot leave a half-applied unwind.
4. Optional hardening: delete or tombstone rejected accept bodies so a later re-sync can re-apply the canonical accept instead of hitting the known-hash early return.

---

## Testing note

All of this was local: `MemStore` \+ in-process ledgers only. No traffic to test.network, no Track 2 load on the public testnet, no contact with the project before this report.

### Thread

**efootballyay-dot**2026-10-24 20:19 UTCgithub

PoC source (local `MemStore` \+ in-process ledger tests only — no traffic to test.network):

https://gist.github.com/efootballyay-dot/b096fe5ea57de21dcc0ccc8c699cc556

Relevant tests in the gist: `TestH4b_*`, `TestH4b_MultiNode_*`, `TestH9_*`.

**XE desk**team2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is
updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0017.

**Reyzz95**2026-11-10 10:28 UTCgithub

Still reproduces at HEAD `89a542e` (testnet-0005, 2026-11-10).

`validateAndAddLeaseCancel` (`core/ledger.go:1792-1877`) still runs `resolveCancelWinsOverAccept` before the pending / previous / timestamp / balance checks, so a rejected cancel still permanently unwinds the provider's not-yet-finalized accept.

PoC (local `go test`, `core/zz_poc_area_b_test.go` `TestPOCAreaB_XE0017_InvalidCancelUnwindsAccept`): cancel with balance off by 1 → rejected with `balance mismatch`, but the lease state reverted to `created` and the provider chain lost the accept. Fix PRs xe#39 / xe#149 are both still open.
