<!-- XE-13250 · archiveExpiredLease blind overwrite races concurrent settle/renew: Settled lease relabelled Expired, renewal payment destroyed · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13250>. The page is the record; this is the same page for reading.*

XE-13250 · Bounty

# archiveExpiredLease blind overwrite races concurrent settle/renew: Settled lease relabelled Expired, renewal payment destroyed

Closed · duplicate
—claimed Medium
[xe#381](https://github.com/xeprotocol/xe/issues/381)
filed 2026-11-11 12:20 UTC
by Desri Susanti

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   Leasing / ledger

Duplicate of
:   —

Tracked
:   internally

Updated
:   2026-11-20 13:32 UTC

Told
:   2026-11-20 00:04 UTC

### Patches

- [xe#880](https://github.com/xeprotocol/xe/pull/880) open by tipprb
  fix(xe): archiveexpiredlease-blind-over (fixes #381)

### History

- [543806](https://bounty.xe.network/log/543806) 2026-11-20 00:05 UTC github.state\_pushed
- [543802](https://bounty.xe.network/log/543802) 2026-11-20 00:05 UTC github.labels
- [543749](https://bounty.xe.network/log/543749) 2026-11-20 00:04 UTC reply.mirrored
- [543067](https://bounty.xe.network/log/543067) 2026-11-20 00:04 UTC proposal.adopted
- [543066](https://bounty.xe.network/log/543066) 2026-11-20 00:04 UTC reply.sent
- [543065](https://bounty.xe.network/log/543065) 2026-11-20 00:04 UTC ticket.status new → closed
- [541198](https://bounty.xe.network/log/541198) 2026-11-20 00:03 UTC proposal.adopted
- [541197](https://bounty.xe.network/log/541197) 2026-11-20 00:03 UTC ticket.facts area
- [541196](https://bounty.xe.network/log/541196) 2026-11-20 00:03 UTC proposal.adopted
- [541195](https://bounty.xe.network/log/541195) 2026-11-20 00:03 UTC ticket.facts
- [541194](https://bounty.xe.network/log/541194) 2026-11-20 00:03 UTC proposal.adopted
- [541193](https://bounty.xe.network/log/541193) 2026-11-20 00:03 UTC ticket.facts

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

### Report

# archiveExpiredLease blind overwrite races concurrent settle/renew: Settled lease relabelled Expired, renewal payment destroyed

**Severity: Medium** (XE tier ceiling 2,500 XE). **CVSS 3.1: 4.8
(AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:L)** — see §7 for the scoring and the
renew-leg variant (I:H → 5.9, still Medium).

**Target:** `github.com/xeprotocol/xe` @
`89a542ea51d38375299aee54c6c99102e9bfa666` ("release: testnet-0005 quorum
withhold fix", 2026-11-10). Go 1.25.0.

## 1\. Impact (read this first)

A lease that has been **settled** — escrow paid out, provider emission
minted — is silently relabelled **Expired** by the node's own archive
sweep, because the archive writes a stale snapshot copy with a blind
`PutLease` and never re-reads the lease. The settled lease then disappears
from settled queries, and the node logs a false "burned N µXUSD escrow"
for escrow that was already paid. The supply auditor breaks (XUSD not
conserved, discrepancy \= the escrow amount).

The renew leg is worse: a **renew that commits after the archive's
snapshot is overwritten the same way, and the renewal payment is
destroyed with no record** — a live lease is killed mid-term, its renewal
escrow (31,000 µXUSD in the tested fixture) is deleted while the archive
log claims only the base escrow (62,000) burned, and the provider's
base\+renewal settlement emission never mints. The overwritten lease is
terminally dead: a second renew and a settle-shaped commit are both
CAS-rejected afterwards.

Fund loss is bounded per lease (one renewal payment \+ one lease's
emission); there is no double-spend and no unbounded drain. The trigger
is timing-dependent and is not attacker-controlled — see §5 for the exact
prerequisites and §7 for why this is Medium, not High.

## 2\. Root cause

`Node.archiveExpiredLease` (`node/node.go:1880-1895`), called from
`tryArchiveExpiredLeases` (`:1863`) in the single `settleLoop` goroutine
(`:1757`, 10 s ticks). Per lease it does:

1. Read a snapshot: `GetLeasesByState(Accepted)`.
2. Txn 1: `DeletePendingSend(leaseHash)`.
3. Txn 2: blind `PutLease` of a mutated copy (`State=Expired, Settled=true`).

There is **no lock, no CAS, and no re-read** anywhere in this path.
`PutLease` (`store/badger_store.go:1562-1570`) is a blind `txn.Set` that
never reads the key in-transaction, so Badger's optimistic concurrency
detects nothing. No `AddBlock` is involved, so no account or lease lock is
held. The settle path takes the provider account lock \+ lease lock and
its in-transaction CAS (`ExpectLeaseHash`/`ExpectLeaseState`) — but that
CAS protects only the settle-against-prior-archive direction: if the
settle commits first and the archive writes second, nothing checks.

The renew leg has the same hole, and it is wider: renew is the one lease
transition **without the in-process lease lock**
(`isLeaseStateTransition`, `core/ledger.go:492-498` — renew is not in the
list). Its in-transaction CAS is consulted on every ledger path, but the
archive never consults any CAS at all. A sweep of all writers on
lease/pending keys confirms the archive is the **only** lock-free/CAS-free
writer.

## 3\. Scenario (how it happens)

1. A lease is accepted; its escrow-expiry time passes (expiry \+
   `LeaseEscrowExpiry` \+ `LeaseArchiveGap`; 365 days by default, shorter
   on a network whose genesis sets a short `LeaseEscrowExpiryNs`).
2. The lease's provider authors a `lease_settle` block (or the consumer
   authors a `lease_renew`) — a valid signed block, authored inside the
   settle grace window, with real timekeeper attestations.
3. The victim node ingests that block via the **sync path** while its own
   archive sweep is between its snapshot read and its `PutLease` — or the
   block commits after the snapshot was taken.
4. The archive overwrites the settled/renewed lease with the stale
   `Expired` copy. The settle/renew block stays in the chain; the lease
   row says `Expired`.

The gossip path cannot deliver the old block (1 h timestamp window \+ 10
min attestation skew are enforced there). The sync path skips both — that
skip is the deciding gate (see §4).

## 4\. Proof of concept (local node/ledger only)

PoC: `hunt-v3/stage2/e2e/h2_e2e_test.go` (worktree copy
`stage2/worktree/node/h2_e2e_test.go`), run against a local node/ledger
built from the worktree copy at `89a542e`, isolated temp data dir, short
genesis escrow (660 s via real `ApplyGenesisLeaseTiming`, controlled clock
via `core.Now`). Fixture: cost 667 µXUSD, emission 1,334 XE, expiry
T0\+62s, settleTime expiry\+30s, archive T0\+783s.

Reproduction (deterministic, production Badger backend):

| State | Lease | Settled | Escrow | Provider XE | `GetLeasesByState(Settled)` | Auditor XUSD |
| --- | --- | --- | --- | --- | --- | --- |
| BEFORE | accepted | false | present (667) | 1,000,000 | 0 | conserved, disc 0 |
| MID (after sync settle) | settled | true | nil | 1,001,334 | 1 | conserved, disc 0 |
| AFTER (real archive from stale snapshot) | **expired** | true | nil | 1,001,334 | **0** | **NOT conserved, disc 667** |

Node logs the false burn verbatim: `Archived expired lease b0c9b1fd59b6...: burned 667 µXUSD escrow (both parties offline)`.

Renew leg (deterministic, both backends): renew commits (block in chain,
31,000 µXUSD paid), archive runs both txns from the stale snapshot →
final lease `Expired`/`Settled=true`, **0 renewal segments, effective
duration back to 3,600, escrow nil**. The 93,000 escrow (62,000 base \+
31,000 renewal) is deleted while the log claims only 62,000 burned.
Barrier (30 reps): Badger 1/30 corrupt, MemStore 15/30 (18/30 on rerun).
Aftermath: second renew and settle-shaped commit both CAS-rejected
(`Expired != Accepted`).

Gate table (old settle — gossip rejects, sync accepts):

- Hash binding, PoW, signature/credential, attestation signatures and
  threshold, previous/frontier, per-account timestamp monotonicity,
  `settleTime >= expiry`, `settleTime <= expiry+grace`, emission amount,
  escrow presence, balance, lease CAS: **enforced on both paths**
  (tampered settle rejected `verify: hash mismatch`; pre-expiry settle
  rejected; past-grace settle rejected).
- Block-timestamp window 1 h: enforced on gossip, **SKIPPED on sync**
  (`addBlock`, `core/ledger.go:769-783`, `skipTimestamp=true` via
  `AddSyncedBlock`).
- Attestation skew 10 min: gossip **REJECTS** (`only 0 valid attestations from trusted timekeepers, need 1`); sync **SKIPPED**
  (`ValidateAttestations(..., skipSkew=true)`,
  `core/attestation.go:86-98`).

Control (archive-first): PASS — settle rejected `"lease already settled"`. Full logs: `stage2/e2e/run1-gatetable.log` …
`run5-full-e2e.log`; renew logs: `stage2/renew/*.log`. Race detector: 0
`DATA RACE` in all runs (a logical race across transactions is invisible
to the detector; the proof is final-state loss).

## 5\. Attacker prerequisites

- A lease old enough to archive (expiry \+ escrow-expiry \+ archive gap
  elapsed), or a network with a short genesis escrow-expiry.
- A settle/renew block for that lease, validly signed by the lease's real
  provider/consumer, authored inside the settle grace window with real
  timekeeper attestations. **It cannot be forged after the fact.**
- Ingestion via the sync path by a node whose archive sweep is in the
  snapshot-to-`PutLease` window (a late-syncing / long-offline node, or
  any node on a short-escrow network).

No privileges on the victim node are needed; the archive is the victim
node's own clock-driven sweep. The counterparty actions are legitimate
honest actions — this is a lost update between honest paths, not an
attacker-crafted exploit. That is why the impact is Medium rather than
High (see §7).

## 6\. Independent validation and false-positive assessment

- **Store level (Stage 1):** deterministic rendezvous \+ stale-snapshot
  order both end `Expired` instead of `Settled`, both backends; MemStore
  barrier CORRUPT 19/30; archive-first order behaves as predicted (settle
  CAS-rejected).
- **Ledger level (Stage 2):** the gate table above — every gate checked
  on both paths; the only skips are the two documented sync-path skips.
- **Duplicate check (DB refreshed twice, 1,382 entries as of \~18:58
  WIB):** closest match xe#310 / XE-1640 is the same function but the
  **deterministic** burn (archive acting alone, no concurrent settle) —
  different mechanism, different prerequisites, different observable,
  different fix. xe#183 / XE-0105 covers block-vs-block pairs only; the
  archive is not a block and appears in neither pair. No filing names
  archive-vs-settle or archive-vs-renew. Classification: **NOVEL on
  public data** (private Critical/Severe reports may exist; uniqueness is
  not guaranteed).
- **Disproof attempts that failed:** (a) "the settle CAS protects it" —
  false: the CAS protects only settle-after-archive, proven by the
  archive-first control; (b) "Badger OCC detects it" — false: the write
  is a blind `Set` that never reads the key in-transaction; (c) "the
  gossip window blocks it" — true for gossip, irrelevant for sync;
  (d) "the archive takes the lease lock" — false: it takes no lock at
  all.
- **Not a false positive:** the corruption is measured final state
  (lease row, settled queries, auditor discrepancy), not a pattern match.
  The 7-Question Gate passes (Q1 conditional on the sync-path
  reachability above); fp-check deep route passes.

## 7\. Severity justification (Medium, ceiling 2,500 XE)

CVSS 3.1: **4.8 (AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:L)**. Attack vector is
network (sync ingestion from a peer); complexity is High (archivable
lease \+ in-window interleave \+ valid in-grace block); no privileges or
user interaction on the victim; integrity impact is Low in CVSS terms
(state corruption and false accounting on one lease) and availability
Low (that lease is dead; the node keeps running). Scoring the renew
fund-loss leg with Integrity High gives **5.9 — still Medium**.

Why not High: (a) the trigger is timing-dependent and not
attacker-controlled (the archive clock is the victim node's own);
(b) there is no remote unauthenticated trigger — the settle/renew must be
a valid signed block from the lease's real provider/consumer, authored
inside grace; (c) the loss is bounded per lease (one renewal payment \+
one lease's emission), with no double-spend and no cascade. If the
committee weighs the renew fund loss more heavily, High is the honest
alternative framing — the renew numbers are stated plainly above so the
committee can judge.

## 8\. Fix suggestion

Re-read \+ CAS the lease inside `archiveExpiredLease` (or take the lease
lock): re-fetch the lease row immediately before the `PutLease` and abort
when `curLease.Settled || State != Accepted`; or perform the
delete-pending \+ state change in a single transaction with an
`ExpectLeaseState(Accepted)` CAS, so a post-snapshot settle/renew makes
the archive transaction fail instead of overwriting it. Either fix must
cover the renew leg as well (same write path).

Note on fix PR #311 (open/unmerged, "gate lease archive on timekeeper
attestations"): its diff adds `blockCreateMu.Lock()` \+ a `GetLease`
re-read bailing when settled/not-Accepted — but the lock covers only
local block-creation paths (`settleLease`, `forceSettleLease`, etc.), NOT
gossip (`handleIncoming`), sync (`net/sync.go` → `AddSyncedBlock`), API
`SubmitBlock`, or phantom-pull ingestion. If #311 merges, the
stale-snapshot and local-settle legs close but the gossip/sync rendezvous
leg survives. A #311 merge alone would NOT fully fix this finding.

## 9\. Caveats (kept in the report)

1. Reachability is conditional (see §5). Default 365-day escrow makes the
   slow path slow; short genesis escrow-expiry makes it fast.
2. The gossip path rejects the old settle; only sync (and local
   block-creation paths) can deliver it.
3. PR #311 narrows but does not fully fix this (see §8).
4. Renew fund loss is bounded per lease; no double-spend, no unbounded
   drain.
5. NOVEL means no matching *public* finding as of the 2026-11-11 \~18:58
   WIB refresh (DB 1,382 entries); private reports may exist.

## 10\. Reproduction (for the committee)

Local only, worktree copy at `89a542e`, isolated temp data dir:

```
export PATH=~/workspace/go/go/bin:$PATH
export TMPDIR=~/workspace/xe-bounty/.tmp
cd <worktree>/node
go test -race -count=1 -run TestH2_E2E -v ./...
```

PoC: `hunt-v3/stage2/e2e/h2_e2e_test.go`. Renew PoC:
`hunt-v3/stage2/renew/stage2_renew_test.go`. Logs:
`hunt-v3/stage2/e2e/run*.log`, `hunt-v3/stage2/renew/*.log`.
Full analysis: `hunt-v3/stage2/STAGE2_VERDICT.md`; duplicate analyses:
`duplicate-intel/reports/v3-h2-archive-overwrite-duplicate-analysis.md`
and `v3-stage2-h2-duplicate-analysis-update.md`.

### Thread

**Joseph Denne**team2026-11-20 00:04 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-13250 and says what differs; it is read like any other.
