{"id":"XE-13244","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"373","source_url":"https://github.com/xeprotocol/xe/issues/373","reporter_id":14,"title":"node/policy: --min-lease-cost / --max-lease-cost are documented in whole XUSD but compared against micro-XUSD amounts; the floor never fires and any realistic cap rejects every lease (Medium)","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:03.309307+00:00","updated_at":"2026-11-20T00:06:58.078650+00:00","source_created_at":"2026-11-11T11:39:14+00:00","told_at":"2026-11-20T00:05:15+00:00","status_changed_at":"2026-11-20T00:04:41.500302+00:00","url":"https://bounty.xe.network/XE-13244","body":"Payout address: ead8ad792b4452de17e897155ed6efe9f928d0c8b07bdf6a9cbf4f4d67941dd2\n\n**Suggested severity:** Medium (validation gap with real effect on provider economics: the documented cost policy is silently off by 10^6; one direction never fires, the other rejects every real lease). Minor if you treat it as a CLI/docs defect only.\n**Area:** `node/policy.go` (`LeaseAcceptPolicy.Allow`), `cmd/xe/main.go` (`--min-lease-cost`, `--max-lease-cost`)\n**Version:** master @ `9787859`; the code is unchanged at HEAD as far as I can see in `node/policy.go`\n**Network:** testnet-0005 (unit-test reproduction, no network interaction)\n\n## Summary\n\nThe provider accept policy takes its cost bounds in **whole XUSD**:\n\n- `cmd/xe/main.go:1309-1310`: `--min-lease-cost` / `--max-lease-cost` — \"Reject leases below/above this cost in **whole XUSD**. 0 = no min/max.\"\n- docs (`/docs/compute` → Provider Policy): \"`--min-lease-cost` — minimum cost in **whole XUSD** (uint64)\".\n\nBut `LeaseAcceptPolicy.Allow` compares them directly against `b.Amount`, which (like every amount on the wire) is in **micro-XUSD** (1 XUSD = 1,000,000 µXUSD):\n\n```go\n// node/policy.go\nif p.MinCostXUSD > 0 && b.Amount < p.MinCostXUSD { ... }   // whole XUSD vs µXUSD\nif p.MaxCostXUSD > 0 && b.Amount > p.MaxCostXUSD { ... }\n```\n\nNo conversion happens anywhere between the flag and the comparison (`cmd/xe/main.go:1357-1358` copies the flag values straight into `MinCostXUSD` / `MaxCostXUSD`). The error message then prints the micro value with an \"XUSD\" label (`cost 31000 XUSD > policy max 100 XUSD`), which hides the mismatch from the operator.\n\n## Effect\n\nTake a realistic lease, 1 vCPU / 1 GB / 1 GB for one hour at 1.0×: cost = 31,000 µXUSD = 0.031 XUSD.\n\n| Operator sets | Intent | What happens |\n|---|---|---|\n| `--min-lease-cost 1` | reject leases under 1 XUSD | **Accepted.** 31,000 > 1. The floor can only ever trigger on a lease priced below 1 µXUSD, which `core.LeaseCost` cannot produce (floor is 1 µXUSD; the cheapest legal lease is 9 µXUSD). The flag is dead. |\n| `--max-lease-cost 100` | accept leases up to 100 XUSD | **Rejected** as \"cost 31000 XUSD > policy max 100 XUSD\". Any cap below 1,000,000 rejects every lease that costs ≥ 1 XUSD-millionth… i.e. in practice everything. |\n\nA provider who sets a sane-looking `--max-lease-cost` simply stops accepting leases, and the log tells them the lease cost thirty-one thousand XUSD. A provider who sets `--min-lease-cost` to filter dust gets no filtering at all.\n\n## Reproduce (unit test, `node` package)\n\n```\n=== RUN   TestPoC_PolicyCostUnits\n    poc_policy_units_test.go:17: --min-lease-cost 1 should reject a 0.031 XUSD lease, but it was ACCEPTED (compared 31000 µXUSD against 1)\n    poc_policy_units_test.go:23: --max-lease-cost 100 should accept a 0.031 XUSD lease, but it was REJECTED: cost 31000 XUSD > policy max 100 XUSD\n--- FAIL: TestPoC_PolicyCostUnits (0.00s)\n```\n\n```go\npackage node\n\nimport (\n\t\"testing\"\n\t\"github.com/xeprotocol/xe/core\"\n)\n\nfunc TestPoC_PolicyCostUnits(t *testing.T) {\n\tlease := &core.Block{Type: core.BlockLease, Amount: 31_000, Duration: 3600} // 0.031 XUSD\n\n\tif err := (LeaseAcceptPolicy{MinCostXUSD: 1}).Allow(lease, 0); err == nil {\n\t\tt.Errorf(\"--min-lease-cost 1 should reject a 0.031 XUSD lease, but it was ACCEPTED\")\n\t}\n\tif err := (LeaseAcceptPolicy{MaxCostXUSD: 100}).Allow(lease, 0); err != nil {\n\t\tt.Errorf(\"--max-lease-cost 100 should accept a 0.031 XUSD lease, but it was REJECTED: %v\", err)\n\t}\n}\n```\n\nRun: `GOTOOLCHAIN=go1.25.0 go test ./node/ -run TestPoC_PolicyCostUnits -v`\n\n## Suggested fix\n\nPick one unit and make it consistent end to end:\n\n1. Convert at the boundary: in `cmd/xe/main.go` multiply the flags by `1_000_000` (`core` already has the per-asset decimals; a `core.ToMicro`-style helper would avoid magic numbers), **or** rename the fields/flags to `MinCostMicroXUSD` and document them as micro-units.\n2. Fix the error strings in `Allow` to print the same unit they compare (`%d µXUSD`, or format via `core.FormatAmount`).\n3. Add a test like the one above to the `node` package so the units cannot drift again.\n4. The same check should also run on `lease_renew` (see #162), with the same units.\n\nRelated: #162 (policy not applied to renewals) is a different bug in the same code; this one is about the units of the comparison itself.\n","patch_refs":[],"thread":[{"id":12859,"source":"github","source_ref":"7025805790","author":"Joseph Denne","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-13244 and says what differs; it is read like any other.","created_at":"2026-11-20T00:05:15+00:00"}]}