{"id":"XE-0119","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"195","source_url":"https://github.com/xeprotocol/xe/issues/195","reporter_id":39,"title":"[Lease/VM] Declared resources are clamped to 1 vCPU / 512 MiB / 5 GiB at provision time while provider capacity accounting only sees the declared values — near-free guests and host disk exhaustion","area":"leasing-ledger","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T16:28:52.766927+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":"2026-10-29T16:27:29+00:00","told_at":"2026-11-08T20:18:38.970665+00:00","status_changed_at":"2026-11-08T20:17:47.495723+00:00","url":"https://bounty.xe.network/XE-0119","body":"**Suggested severity: Medium (2,500 XE)**\n**Area:** leasing / provider capacity accounting (`api/vm.go`, `core/ledger.go`, `node/node.go`, `node/vm.go`, `vm/`)\n**Repo pin:** 9787859 (testnet-0005)\n\n## Summary\n\nA lease may declare `vcpus=0, memory_mb=1, disk_gb=0` (validation only rejects the all-zero triple, which matches `docs/api.md:947` \"at least one ≥1\"). Both VM backends then **clamp the guest up to 1 vCPU / 512 MiB / 5 GiB**, but the provider's capacity accounting only ever sees the declared numbers: the managers record the *declared* `Resources`, `List()` returns those, and the auto-accept capacity check sums exactly that.\n\nNet effect: every minimum-clamped guest consumes up to 5 GiB of host disk and 512 MiB RAM while counting as **0 vCPU / 1 MiB / 0 GiB** against the provider's limits. A consumer can therefore hold an unbounded number of near-free guests and exhaust a provider's disk (guest-controlled `dd` fills the 5 GiB), for about **0.01 XUSD per lease-hour**.\n\n## Root cause\n\nValidation only rejects the all-zero triple, so a memory-only lease passes:\n\n```go\n// core/ledger.go:125\nfunc ValidateLeaseDimensions(vcpus, memoryMB, diskGB, duration uint64) error {\n\tif vcpus == 0 && memoryMB == 0 && diskGB == 0 {\n\t\treturn fmt.Errorf(\"lease must request at least one resource (vcpus, memory, or disk)\")\n\t}\n```\n\n```go\n// api/vm.go:129\nif req.VCPUs == 0 && req.MemoryMB == 0 && req.DiskGB == 0 {\n```\n\nThe declared values go straight to provisioning:\n\n```go\n// node/vm.go:74\ninfo, err := n.VMManager.Provision(leaseBlock.Hash, vm.Resources{\n\tVCPUs:    leaseBlock.VCPUs,\n\tMemoryMB: leaseBlock.MemoryMB,\n\tDiskGB:   leaseBlock.DiskGB,\n}, leaseBlock.AccessPubKey)\n```\n\nThe Lima template clamps up to the minimums:\n\n```go\n// vm/lima_template.go:58\ncpus := res.VCPUs\nif cpus < 1 {\n\tcpus = 1\n}\nmemMB := res.MemoryMB\nif memMB < 512 {\n\tmemMB = 512\n}\ndiskGB := res.DiskGB\nif diskGB < 5 {\n\tdiskGB = 5\n}\n```\n\nQEMU does the same with the configured defaults (`vm/qemu_manager.go:181-192`).\n\nBut the manager stores and reports the **declared** struct, not the clamped one:\n\n```go\n// vm/lima_manager.go:147\nm.vms[leaseHash] = &limaVM{\n\tname:      name,\n\tleaseHash: leaseHash,\n\t...\n\tresources: res,      // declared, e.g. {0, 1, 0}\n}\n```\n\n```go\n// vm/lima_manager.go:216 — List() returns the declared resources\nfor hash, v := range m.vms {\n\tout = append(out, &Info{LeaseHash: hash, Status: \"running\", Resources: &v.resources, ...})\n}\n```\n\nand the capacity gate sums only that:\n\n```go\n// node/node.go:1519\nfor _, vi := range n.VMManager.List() {\n\tif vi.Resources != nil {\n\t\tusedVCPUs += vi.Resources.VCPUs      // 0\n\t\tusedMemMB += vi.Resources.MemoryMB   // 1\n\t\tusedDiskGB += vi.Resources.DiskGB    // 0\n\t}\n}\n...\nif exceedsCapacity(usedDiskGB, leaseBlock.DiskGB, n.providerDiskGB) { ... }\n```\n\n## PoC (run against 9787859)\n\nTwo self-contained tests, no node required:\n\n```go\n// core/zz_probe_zerolease_test.go\nfunc TestZZZeroDimensionLeaseIsPricedAsNothing(t *testing.T) {\n\tif err := ValidateLeaseDimensions(0, 1, 0, LeaseMinDuration); err != nil {\n\t\tt.Fatalf(\"expected zero-dimension lease to validate, got: %v\", err)\n\t}\n\tconst mult = uint64(1000)\n\tcheap, _ := LeaseCost(0, 1, 0, LeaseMinDuration, mult)\n\treal, _ := LeaseCost(1, 512, 5, LeaseMinDuration, mult)\n\tt.Logf(\"declared 0vCPU/1MB/0GB -> cost %d micro-XUSD\", cheap)\n\tt.Logf(\"actual   1vCPU/512MB/5GB -> cost %d micro-XUSD\", real)\n}\n\n// vm/zz_probe_zerolease_test.go\nfunc TestZZLimaClampsAboveDeclaredResources(t *testing.T) {\n\tout, err := renderLimaTemplate(Resources{VCPUs: 0, MemoryMB: 1, DiskGB: 0},\n\t\t\"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB7b0l6m0m2m0m2m0m2m0m2m0m2m0m2m0m2m0m2m0m2m\", \"/tmp/xe-image.qcow2\")\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\ts := string(out)\n\tfor _, want := range []string{\"cpus: 1\", `memory: \"512MiB\"`, `disk: \"5GiB\"`} {\n\t\tif !strings.Contains(s, want) {\n\t\t\tt.Fatalf(\"expected %q, got:\\n%s\", want, s)\n\t\t}\n\t}\n}\n```\n\nOutput:\n\n```\n=== RUN   TestZZZeroDimensionLeaseIsPricedAsNothing\n    zz_probe_zerolease_test.go:31: declared 0vCPU/1MB/0GB -> cost 167 micro-XUSD\n    zz_probe_zerolease_test.go:32: actual   1vCPU/512MB/5GB -> cost 584 micro-XUSD\n--- PASS\n=== RUN   TestZZLimaClampsAboveDeclaredResources\n    zz_probe_zerolease_test.go:22: declared {VCPUs:0 MemoryMB:1 DiskGB:0} rendered as 1 vCPU / 512MiB / 5GiB\n--- PASS\n```\n\n## Attack\n\n1. Consumer signs `lease_create` blocks with `vcpus=0, memory_mb=1, disk_gb=0`, `duration=3600` (ledger accepts: `core/ledger.go:1516`).\n2. Provider auto-accept sees `usedDisk 0/1/0`, so `exceedsCapacity` never trips → accepts any number of these leases (`node/node.go:1519-1535`).\n3. Each accepted lease provisions a guest with 1 vCPU / 512 MiB / **5 GiB** (`vm/lima_template.go:58-69`), and the consumer has SSH into it (`access_pub_key`), so it can `dd` the disk full.\n4. Cost per lease-hour to the attacker: `LeaseCost(0,1,0,3600,1000)` ≈ 10,020 micro-XUSD ≈ **0.01 XUSD**; provider stake is `core.LeaseStake(Amount)`, i.e. proportional to that same trivial amount.\n5. 100 such leases ≈ 500 GiB of host disk for ≈ 1 XUSD/hour, with the provider's disk counter still reading ~0. New provisions then fail host-side while the ledger believes the provider has capacity.\n\n## Impact\n\n- **Provider DoS at near-zero cost:** guest host disk/RAM exhaustion; subsequent leases fail to provision or the node degrades while `providerDiskGB` accounting is blind.\n- **Free compute:** 1 vCPU + 512 MiB for ~167 micro-XUSD/minute.\n- **Mispricing:** provider is underpaid 3.5× even for the clamped minimum, and unboundedly more for disk-heavy use.\n\n## Suggested fix\n\nEither (a) enforce the backend minimums in `ValidateLeaseDimensions` (`vcpus >= 1`, `memory_mb >= 512`, `disk_gb >= 5`), or (b) have `Provision` return/record the *effective* (clamped) `Resources` and make `List()` and the `node/node.go:1519` accounting use those. Add a regression test asserting `declared == effective` for every accepted lease.\n","patch_refs":[{"id":205,"repo":"xeprotocol/xe","kind":"pr","ref":"205","title":"fix(lease,vm): enforce minimum resource dimensions and align provider capacity accounting (fixes #195)","url":"https://github.com/xeprotocol/xe/pull/205","note":"","state":"open","author":"NePreby","added_by":"desk","created_at":"2026-10-29T17:22:23.813549+00:00"}],"thread":[{"id":54,"source":"github","source_ref":"6502379695","author":"hayokakoweda75","team":false,"body":"## Second, independent gate failure in the same admission path (same root cause class)\n\nEven if the resource accounting above were fixed, the operator's `--max-concurrent-leases` cap is evaluated before provisioning, so it does not bind either:\n\n```go\n// node/node.go:1477 — checked BEFORE any provisioning\nif err := n.acceptPolicy.Allow(leaseBlock, n.activeLeaseCount()); err != nil {\n\n// node/node.go:1429\nfunc (n *Node) activeLeaseCount() uint64 {\n\tif n.VMManager == nil {\n\t\treturn 0\n\t}\n\treturn uint64(len(n.VMManager.List()))   // only VMs already registered\n}\n```\n\n```go\n// node/policy.go:33 — MaxConcurrent compared against that same count\nfunc (p LeaseAcceptPolicy) Allow(b *core.Block, activeCount uint64) error {\n```\n\n`provisionVM` runs at `node/node.go:1554`, i.e. after the cap check, and `limactl create/start` takes minutes. `reservedRes` (node.go:1545-1549) accounts for in-flight *resources* but not for the *lease count*, and `beginAccept` only serialises per lease hash. So a burst of distinct `lease_create` blocks all observe the same `activeCount`, all pass `MaxConcurrent`, and all provision.\n\nCombined with the clamp described in the main report, the cap is the only remaining operator control and it is bypassed the same way:\n\n1. Operator sets `--max-concurrent-leases 10`.\n2. Consumer publishes 50 distinct memory-only lease blocks within a few seconds.\n3. All 50 see `activeCount ≈ 0` and pass; all 50 guests are provisioned at 1 vCPU / 512 MiB / 5 GiB each.\n\nFix: include in-flight accepts in the count (e.g. increment a pending counter under `blockCreateMu` before releasing it, decrement on failure/teardown), or move the `Allow` check under the same mutex that guards `reservedRes`.","created_at":"2026-10-29T16:28:24+00:00"},{"id":1591,"source":"desk","source_ref":"reply:486","author":"Joseph Denne","team":true,"body":"Thank you for the report. We have confirmed the mismatch you describe and it is being handled; we will update this ticket as the fix progresses.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}