{"id":"XE-0942","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":13,"title":"addAssetBalance wraps on overflow and subAssetBalance clamps under zero","area":"leasing-ledger","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"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:45:27.491276+00:00","updated_at":"2026-11-14T22:53:33.031826+00:00","source_created_at":null,"told_at":"2026-11-14T22:53:33.473016+00:00","status_changed_at":"2026-11-08T20:32:08.099819+00:00","url":"https://bounty.xe.network/XE-0942","body":"## Summary\r\naddAssetBalance and subAssetBalance are the unexported helpers every asset credit and debit is supposed to share, so a wrapping delta should error instead of persisting a wrong balance. At core/ledger.go:509-529, addAssetBalance does += with no overflow check (MaxUint64+5 becomes 4) and subAssetBalance clamps 9-100 to 0 and does not return an error. Higher-level paths mostly have their own checks, so this is the missing safety net those paths claim to share. Any ledger caller that feeds these helpers a wrapping or underflowing delta hits the gap. GitHub #43 is swap unwind and the lease_cancel wrap is the admitted credit path; these are the unexported helpers every asset credit and debit goes through, without the guards the higher-level paths claim to have.\r\n\r\n## Affected components\r\ncore/ledger.go:509-529 addAssetBalance (+= with no overflow check) and subAssetBalance (clamp to 0 on underflow) at xe 02e9641b0ac64437f57e09d63301f88cce61a802.\r\n\r\n## Impact\r\nAny caller that feeds these helpers a wrapping or underflowing delta persists a wrong balance. Today the higher-level paths mostly have their own checks, so this is the missing safety net those paths are supposed to share. Worst case is a silent wrap or clamp on a future path that forgets to re-check.\r\n\r\n## PoC\r\n\r\n```go\r\npackage core\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"math\"\r\n\t\"testing\"\r\n)\r\n\r\n// Overlay into package core. addAssetBalance / subAssetBalance are unexported.\r\nfunc TestPoC_B6(t *testing.T) {\r\n\tfmt.Println(\"PROVENANCE: xe=02e9641b0ac64437f57e09d63301f88cce61a802 file=poc/round3/overlay/b6_asset_balance_test.go\")\r\n\tl := &Ledger{assetBalances: make(map[string]map[string]uint64)}\r\n\tacc := \"acct\"\r\n\r\n\tl.addAssetBalance(acc, \"XE\", 7)\r\n\tctrl := l.getAssetBalance(acc, \"XE\")\r\n\r\n\tl2 := &Ledger{assetBalances: make(map[string]map[string]uint64)}\r\n\tl2.addAssetBalance(acc, \"XE\", math.MaxUint64)\r\n\tl2.addAssetBalance(acc, \"XE\", 5)\r\n\twrapped := l2.getAssetBalance(acc, \"XE\")\r\n\r\n\tl3 := &Ledger{assetBalances: make(map[string]map[string]uint64)}\r\n\tl3.setAssetBalance(acc, \"XUSD\", 9)\r\n\tl3.subAssetBalance(acc, \"XUSD\", 100)\r\n\tclamped := l3.getAssetBalance(acc, \"XUSD\")\r\n\r\n\tfmt.Printf(\"CONTROL add 7 -> %d\\n\", ctrl)\r\n\tfmt.Printf(\"ATTACK add MaxUint64+5 -> %d (want 4)\\n\", wrapped)\r\n\tfmt.Printf(\"ATTACK sub 9-100 clamp -> %d\\n\", clamped)\r\n\r\n\tstake := LeaseStake(1000)\r\n\tfmt.Printf(\"LeaseStakeDivisor=%d LeaseStake(1000)=%d (AssetCredit path)\\n\", LeaseStakeDivisor, stake)\r\n\r\n\tif ctrl == 7 && wrapped == 4 && clamped == 0 {\r\n\t\tfmt.Println(\"PASS: addAssetBalance wraps; subAssetBalance clamps under zero; CONTROL add is exact\")\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\n\r\n```\r\nATTACK add MaxUint64+5 -> 4\r\nATTACK sub 9-100 clamp -> 0\r\nPASS: addAssetBalance wraps; subAssetBalance clamps under zero\r\n```\r\n\r\n## Suggested fix\r\nReturn error on overflow in addAssetBalance and on underflow in subAssetBalance. Do not wrap and do not clamp to zero.\r\n---","patch_refs":[],"thread":[{"id":3758,"source":"desk","source_ref":"reply:2500","author":"XE desk","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, 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-0942 and says what differs; it is read like any other.","created_at":"2026-11-14T22:53:33.031826+00:00"}]}