Bounty
XE-0691 · Bounty

Emission formula docs claim a LockedR==0 fallback to the current epoch R at settle time; the code has no such fallback

Closed · duplicate —claimed Minor xe#273 filed 2026-11-05 11:54 UTC by rusdiwireng

Report

Suggested severity tier: Minor

Area: documentation, docs/emission-formula.md, versus core/ledger.go and core/lease_renew.go

Repository state checked: xeprotocol/xe HEAD 978785929bc17a2f4ab30c383e5fc9cf4d634512

Summary

The emission formula document states that legacy leases with LockedR == 0 fall back to the current epoch R at settle time. The code has no such fallback anywhere. A lease accept with lockedR == 0 is rejected outright, a lease renew with LockedR == 0 is rejected outright, and the settle path calls LeaseTotalEmission with the lease's LockedR directly. A provider who follows the document to settle a legacy lease will compute an amount from the current epoch R and receive a 400 error, or, if they send 1 micro-XE, will be paid 1 micro-XE. The program counts documentation errors as Minor, and this report is filed in that tier.

What was proven

  1. docs/emission-formula.md, in the section "Reading inputs from chain data", states: "Legacy leases with LockedR == 0 fall back to the current epoch R at settle time."
  2. core/ledger.go (lines 1706-1708) in validateAndAddLeaseAccept rejects lockedR == 0 with the message "lease_accept missing locked emission params: locked_r must be set".
  3. core/lease_renew.go (line 92) rejects b.LockedR == 0 on renew.
  4. validateAndAddLeaseSettle (core/ledger.go:2117-2183) contains no fallback. It calls LeaseTotalEmission (ledger.go:2070-2088), which applies CapR(lease.LockedR, ...) directly. An exhaustive search finds LockedR == 0 only in the two rejections above.
  5. A local harness confirms the arithmetic: LeaseTotalEmission(cost=31000, LockedR=0) returns 1, the 1 micro-XE floor from LeaseEmissionChecked (ledger.go:2059-2061), not 62,000, which is what the documented fallback would produce (31000 * 2000 / 1000 with R=2000).

Reproduction

  1. Clone https://github.com/xeprotocol/xe and confirm HEAD is 978785929bc17a2f4ab30c383e5fc9cf4d634512.
  2. Read docs/emission-formula.md and note the fallback sentence.
  3. Search the repository for LockedR == 0 and observe the only matches are the two rejections in ledger.go and lease_renew.go.
  4. Call LeaseTotalEmission with cost 31000 and LockedR 0 and observe the result 1.

Impact

A provider settling a legacy lease by the document's arithmetic will send an amount based on the current epoch R and be rejected with a 400 "lease_settle XE mismatch: expected 1 ..." error. The live impact is probably nil, because a lease with LockedR == 0 would have to have been accepted by an older build before the rejection was added, and no such lease was observed in the testnet store during this work. The sentence is categorically wrong and misleads anyone computing a settle amount. If the team regards the document as the specification instead, then this is a code bug (a missing fallback) and legacy lease settles pay 1 micro-XE. This report claims only that the document and the code contradict each other, not which side is right.

Suggested fix

Either remove the fallback sentence from the document, or implement the fallback in the settle path. The document should also state plainly that accept and renew reject LockedR == 0.

Honest limits of this proof

This is a documentation-versus-code comparison, proven from the code at the stated HEAD. Whether any lease with LockedR == 0 exists in the testnet-0005 store was not checked, because that needs a read of the live store. If no such lease exists, the live impact of this sentence is nil.

Thread

rusdiwireng2026-11-09 02:35 UTCgithub

Hi, thanks for triaging. I am asking for a re-check of the duplicate closure on this issue. I could not find any public issue that covers the sentence this report is about, and the nearest candidate differs concretely.

The report concerns one sentence in docs/emission-formula.md ("Reading inputs from chain data"): "Legacy leases with LockedR == 0 fall back to the current epoch R at settle time." The code has no such fallback: accept rejects lockedR == 0 (core/ledger.go:1706-1708), renew rejects LockedR == 0 (core/lease_renew.go:92), and settle applies the lease's LockedR directly — a local harness shows cost 31000 with LockedR 0 pays 1 micro-XE, not the 62,000 the documented fallback would produce. The report claims only that the document and the code contradict each other, not which side is right.

Concrete difference from the nearest public report, #175 ("LeaseAccept locks emission terms from any of the last 4 epochs"): #175 is about code behaviour — the ledger accepting stale locked terms — fixed by restricting terms to the active epoch (PR #176). This report is about a documentation sentence claiming a fallback that does not exist anywhere in the code. Different artifact (document vs code), different claim (missing fallback vs accepted stale terms), different fix (remove or correct the sentence vs restrict the epoch). #175 does not mention LockedR == 0 at all, and no other public issue mentions docs/emission-formula.md or this fallback sentence.

I note my own report's honest limit: the live impact is probably nil, since no lease with LockedR == 0 was observed in the testnet store. That limit is about impact, not about whether the sentence is covered by an earlier report.

One honest caveat: I cannot see the duplicate target. If this was closed as a duplicate of a desk entry that already quoted this exact sentence, please point me to it and I will withdraw this appeal. If it was closed as a duplicate of #175 (or another public issue), I ask that it be reconsidered on the difference above.

Thank you for re-checking.

XE deskteam2026-11-14 22:53 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-0691 and says what differs; it is read like any other.