<!-- XE-0119 · [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 · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0119>. The page is the record; this is the same page for reading.*

XE-0119 · Bounty

# \[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

Triaging
claimed Medium
[xe#195](https://github.com/xeprotocol/xe/issues/195)
filed 2026-10-29 16:27 UTC
by hayokakoweda75

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Medium

Area
:   Leasing / ledger

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:17 UTC

Told
:   2026-11-08 20:18 UTC

### Patches

- [xe#205](https://github.com/xeprotocol/xe/pull/205) open by NePreby
  fix(lease,vm): enforce minimum resource dimensions and align provider capacity accounting (fixes #195)

### History

- [43797](https://bounty.xe.network/log/43797) 2026-11-08 20:18 UTC reply.mirror\_failed
- [43317](https://bounty.xe.network/log/43317) 2026-11-08 20:18 UTC proposal.adopted
- [43316](https://bounty.xe.network/log/43316) 2026-11-08 20:18 UTC reply.sent
- [40090](https://bounty.xe.network/log/40090) 2026-11-08 20:17 UTC proposal.adopted
- [40089](https://bounty.xe.network/log/40089) 2026-11-08 20:17 UTC ticket.facts area
- [40088](https://bounty.xe.network/log/40088) 2026-11-08 20:17 UTC proposal.adopted
- [40087](https://bounty.xe.network/log/40087) 2026-11-08 20:17 UTC ticket.facts
- [40086](https://bounty.xe.network/log/40086) 2026-11-08 20:17 UTC proposal.adopted
- [40085](https://bounty.xe.network/log/40085) 2026-11-08 20:17 UTC ticket.facts
- [40084](https://bounty.xe.network/log/40084) 2026-11-08 20:17 UTC proposal.adopted
- [40083](https://bounty.xe.network/log/40083) 2026-11-08 20:17 UTC ticket.facts
- [40082](https://bounty.xe.network/log/40082) 2026-11-08 20:17 UTC proposal.adopted

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

### Report

**Suggested severity: Medium (2,500 XE)**
**Area:** leasing / provider capacity accounting (`api/vm.go`, `core/ledger.go`, `node/node.go`, `node/vm.go`, `vm/`)
**Repo pin:** 9787859 (testnet-0005)

## Summary

A 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.

Net 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**.

## Root cause

Validation only rejects the all-zero triple, so a memory-only lease passes:

```
// core/ledger.go:125
func ValidateLeaseDimensions(vcpus, memoryMB, diskGB, duration uint64) error {
	if vcpus == 0 && memoryMB == 0 && diskGB == 0 {
		return fmt.Errorf("lease must request at least one resource (vcpus, memory, or disk)")
	}
```

```
// api/vm.go:129
if req.VCPUs == 0 && req.MemoryMB == 0 && req.DiskGB == 0 {
```

The declared values go straight to provisioning:

```
// node/vm.go:74
info, err := n.VMManager.Provision(leaseBlock.Hash, vm.Resources{
	VCPUs:    leaseBlock.VCPUs,
	MemoryMB: leaseBlock.MemoryMB,
	DiskGB:   leaseBlock.DiskGB,
}, leaseBlock.AccessPubKey)
```

The Lima template clamps up to the minimums:

```
// vm/lima_template.go:58
cpus := res.VCPUs
if cpus < 1 {
	cpus = 1
}
memMB := res.MemoryMB
if memMB < 512 {
	memMB = 512
}
diskGB := res.DiskGB
if diskGB < 5 {
	diskGB = 5
}
```

QEMU does the same with the configured defaults (`vm/qemu_manager.go:181-192`).

But the manager stores and reports the **declared** struct, not the clamped one:

```
// vm/lima_manager.go:147
m.vms[leaseHash] = &limaVM{
	name:      name,
	leaseHash: leaseHash,
	...
	resources: res,      // declared, e.g. {0, 1, 0}
}
```

```
// vm/lima_manager.go:216 — List() returns the declared resources
for hash, v := range m.vms {
	out = append(out, &Info{LeaseHash: hash, Status: "running", Resources: &v.resources, ...})
}
```

and the capacity gate sums only that:

```
// node/node.go:1519
for _, vi := range n.VMManager.List() {
	if vi.Resources != nil {
		usedVCPUs += vi.Resources.VCPUs      // 0
		usedMemMB += vi.Resources.MemoryMB   // 1
		usedDiskGB += vi.Resources.DiskGB    // 0
	}
}
...
if exceedsCapacity(usedDiskGB, leaseBlock.DiskGB, n.providerDiskGB) { ... }
```

## PoC (run against 9787859\)

Two self-contained tests, no node required:

```
// core/zz_probe_zerolease_test.go
func TestZZZeroDimensionLeaseIsPricedAsNothing(t *testing.T) {
	if err := ValidateLeaseDimensions(0, 1, 0, LeaseMinDuration); err != nil {
		t.Fatalf("expected zero-dimension lease to validate, got: %v", err)
	}
	const mult = uint64(1000)
	cheap, _ := LeaseCost(0, 1, 0, LeaseMinDuration, mult)
	real, _ := LeaseCost(1, 512, 5, LeaseMinDuration, mult)
	t.Logf("declared 0vCPU/1MB/0GB -> cost %d micro-XUSD", cheap)
	t.Logf("actual   1vCPU/512MB/5GB -> cost %d micro-XUSD", real)
}

// vm/zz_probe_zerolease_test.go
func TestZZLimaClampsAboveDeclaredResources(t *testing.T) {
	out, err := renderLimaTemplate(Resources{VCPUs: 0, MemoryMB: 1, DiskGB: 0},
		"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB7b0l6m0m2m0m2m0m2m0m2m0m2m0m2m0m2m0m2m0m2m", "/tmp/xe-image.qcow2")
	if err != nil {
		t.Fatal(err)
	}
	s := string(out)
	for _, want := range []string{"cpus: 1", `memory: "512MiB"`, `disk: "5GiB"`} {
		if !strings.Contains(s, want) {
			t.Fatalf("expected %q, got:\n%s", want, s)
		}
	}
}
```

Output:

```
=== RUN   TestZZZeroDimensionLeaseIsPricedAsNothing
    zz_probe_zerolease_test.go:31: declared 0vCPU/1MB/0GB -> cost 167 micro-XUSD
    zz_probe_zerolease_test.go:32: actual   1vCPU/512MB/5GB -> cost 584 micro-XUSD
--- PASS
=== RUN   TestZZLimaClampsAboveDeclaredResources
    zz_probe_zerolease_test.go:22: declared {VCPUs:0 MemoryMB:1 DiskGB:0} rendered as 1 vCPU / 512MiB / 5GiB
--- PASS
```

## Attack

1. Consumer signs `lease_create` blocks with `vcpus=0, memory_mb=1, disk_gb=0`, `duration=3600` (ledger accepts: `core/ledger.go:1516`).
2. Provider auto-accept sees `usedDisk 0/1/0`, so `exceedsCapacity` never trips → accepts any number of these leases (`node/node.go:1519-1535`).
3. 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.
4. 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.
5. 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.

## Impact

- **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.
- **Free compute:** 1 vCPU \+ 512 MiB for \~167 micro-XUSD/minute.
- **Mispricing:** provider is underpaid 3.5× even for the clamped minimum, and unboundedly more for disk-heavy use.

## Suggested fix

Either (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.

### Thread

**hayokakoweda75**2026-10-29 16:28 UTCgithub

## Second, independent gate failure in the same admission path (same root cause class)

Even if the resource accounting above were fixed, the operator's `--max-concurrent-leases` cap is evaluated before provisioning, so it does not bind either:

```
// node/node.go:1477 — checked BEFORE any provisioning
if err := n.acceptPolicy.Allow(leaseBlock, n.activeLeaseCount()); err != nil {

// node/node.go:1429
func (n *Node) activeLeaseCount() uint64 {
	if n.VMManager == nil {
		return 0
	}
	return uint64(len(n.VMManager.List()))   // only VMs already registered
}
```

```
// node/policy.go:33 — MaxConcurrent compared against that same count
func (p LeaseAcceptPolicy) Allow(b *core.Block, activeCount uint64) error {
```

`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.

Combined with the clamp described in the main report, the cap is the only remaining operator control and it is bypassed the same way:

1. Operator sets `--max-concurrent-leases 10`.
2. Consumer publishes 50 distinct memory-only lease blocks within a few seconds.
3. All 50 see `activeCount ≈ 0` and pass; all 50 guests are provisioned at 1 vCPU / 512 MiB / 5 GiB each.

Fix: 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`.

**Joseph Denne**team2026-11-08 20:17 UTCdesk

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.
