{"id":"XE-0011","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"20","source_url":"https://github.com/xeprotocol/xe/issues/20","reporter_id":8,"title":"LeaseStakeDivisor hardcoded to 0 — provider collateral stake is silently zero","area":"leasing-ledger","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:14.551240+00:00","updated_at":"2026-11-11T13:35:44.511268+00:00","source_created_at":"2026-10-23T19:47:05+00:00","told_at":null,"status_changed_at":"2026-10-29T14:22:10.453652+00:00","url":"https://bounty.xe.network/XE-0011","body":"# TITLE (kolom title issue):\n# LeaseStakeDivisor hardcoded to 0 — provider collateral stake is silently zero\n\n# ===== BODY (textarea) =====\n\n**Severity:** Medium — validation gap (economic invariant). See escalation note.\n**Area:** Compute leasing · `core/ledger.go`\n\n## Summary\n\nProvider collateral stake is silently disabled: `LeaseStakeDivisor` is hardcoded to `0`, so\n`LeaseStake(cost)` returns `0` for every input and `validateAndAddLeaseAccept` enforces\n`block.amount == 0`. A provider therefore accepts and settles leases with **zero XUSD at risk**,\nremoving the economic disincentive against accepting compute without delivering it.\n\n## Root cause\n\n`core/ledger.go`:\n\n```go\nconst (\n    LeaseVCPURate     = uint64(20_000)\n    LeaseMemGBRate    = uint64(10_000)\n    LeaseDiskGBRate   = uint64(1_000)\n    LeaseStakeDivisor = uint64(0)   // ← collateral divisor is zero\n)\n\nfunc LeaseStake(cost uint64) uint64 {\n    if LeaseStakeDivisor == 0 {\n        return 0                    // ← always this branch\n    }\n    stake := ceilDiv(cost, LeaseStakeDivisor)\n    if stake == 0 { stake = 1 }     // ← min-1µXUSD clamp: unreachable\n    return stake\n}\n```\n\nThe clamp `if stake == 0 { stake = 1 }` is dead code — it only has meaning for a non-zero divisor.\n`validateAndAddLeaseAccept` then requires `b.Amount == 0` (rejecting any non-zero stake),\n`lease_settle` returns `lease.Stake` (always `0`), and `lease_force_settle` forfeits `0`.\n\n## Why this is not intentional\n\nThe code itself assumes non-zero stake, independent of any documentation:\n\n1. The minimum clamp in `LeaseStake` (above) is only reachable with `LeaseStakeDivisor != 0`.\n2. `core/supply.go` tracks `locked_stake` and `stake_forfeited` and reports them in `GET /supply`;\n   both are permanently `0` — dead accounting that only exists to describe a collateralized network.\n3. The CLI `pickProvider()` filters providers on `balance >= stake`, which is a no-op at stake `0`.\n\n## Impact\n\n`stake` is the only mechanism that punishes a provider for accepting a lease and not delivering\ncompute. With it zero:\n\n- A provider can `lease_accept` with nothing at risk, never provision a VM, then `lease_settle` at\n  expiry — the timekeeper attestation proves only *elapsed time*, not delivery — burning the\n  consumer's escrow and minting XE for themselves. This is the \"escrow taken without service\" case\n  from the Track 1 leasing scope, made costless.\n- `lease_force_settle` forfeits `0`, so abandoning a lease has no downside for the provider.\n\nThis is **not** a double-spend: the escrow remains single-use (`settle` burns it, `force_settle`\nrefunds it; `ExpectLeaseState` + the atomic commit still block double-claims). It is a removed\ndefensive control, not a direct theft primitive — hence Medium rather than High/Critical.\n\n## Reproduce\n\n```bash\ncurl -s 'https://ldn.core.test.network/leases?limit=3'   # every lease carries \"stake\": 0\ncurl -s 'https://ldn.core.test.network/supply'           # XUSD.locked_stake:0, stake_forfeited:0 across 101 leases\n```\n\n## Proof of concept\n\nTwo tests added to a checkout (Go 1.25), then executed:\n\n```\n$ go test ./core -run TestAudit -v\n=== RUN   TestAuditLeaseStakeAlwaysZero\n    audit_probe_test.go:22: CONFIRMED: LeaseStakeDivisor=0 => LeaseStake(cost) always 0; provider collateral is fully disabled\n--- PASS: TestAuditLeaseStakeAlwaysZero (0.00s)\n=== RUN   TestAuditMul64OverflowDetection\n--- PASS: TestAuditMul64OverflowDetection (0.00s)\n=== RUN   TestAuditZeroCollateralEmission\n2026/10/24 03:55:44 Genesis block applied: 42000000000000 XE to 378d0f5c2063...\n    audit_e2e_test.go:103: provider BEFORE lease: XE=1 XUSD=0\n    audit_e2e_test.go:129: lease cost = 500 µXUSD\n    audit_e2e_test.go:156: required stake = LeaseStake(500) = 0\n    audit_e2e_test.go:184: provider AFTER accept: XE=1 XUSD=0\n    audit_e2e_test.go:212: provider FINAL: XE=501 XUSD=0\n    audit_e2e_test.go:213: consumer FINAL: XE=999999 XUSD=999500\n    audit_e2e_test.go:221: CONFIRMED: provider minted 500 µXE emission with ZERO XUSD collateral at risk (stake=0)\n--- PASS: TestAuditZeroCollateralEmission (0.00s)\nPASS\nok  github.com/xeprotocol/xe/core  0.022s\n```\n\n`TestAuditZeroCollateralEmission` drives the full lifecycle (send → receive → lease → lease_accept\nwith `amount=0` → lease_settle) through the real `Ledger`; the provider starts with `0` XUSD and\nmints `500` µXE with no collateral.\n\n### core/audit_probe_test.go\n\n```go\npackage core\n\nimport (\n\t\"math\"\n\t\"math/big\"\n\t\"testing\"\n)\n\n// FINDING 1: provider collateral stake is always zero.\nfunc TestAuditLeaseStakeAlwaysZero(t *testing.T) {\n\tinputs := []uint64{0, 1, 2, 5, 10, 100, 1_000_000, 1_000_000_000, math.MaxUint64}\n\tfor _, cost := range inputs {\n\t\tgot := LeaseStake(cost)\n\t\tif got != 0 {\n\t\t\tt.Fatalf(\"LeaseStake(%d) = %d, want 0 (LeaseStakeDivisor is hardcoded 0)\", cost, got)\n\t\t}\n\t}\n\tif LeaseStakeDivisor != 0 {\n\t\tt.Fatalf(\"LeaseStakeDivisor = %d (documented as 5)\", LeaseStakeDivisor)\n\t}\n\tt.Logf(\"CONFIRMED: LeaseStakeDivisor=%d => LeaseStake(cost) always 0; provider collateral is fully disabled\", LeaseStakeDivisor)\n}\n\n// Reference: verify mul64 (hand-rolled 128-bit multiply used in ParseAmount overflow detection)\nfunc TestAuditMul64OverflowDetection(t *testing.T) {\n\tref := func(a, b uint64) (hi, lo uint64) {\n\t\tA := new(big.Int).SetUint64(a)\n\t\tB := new(big.Int).SetUint64(b)\n\t\tP := new(big.Int).Mul(A, B)\n\t\tmask := new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 64), big.NewInt(1))\n\t\tlo = new(big.Int).And(P, mask).Uint64()\n\t\thi = new(big.Int).Rsh(P, 64).Uint64()\n\t\treturn\n\t}\n\tcases := []struct{ a, b uint64 }{\n\t\t{1, 1}, {math.MaxUint32, math.MaxUint32}, {math.MaxUint64, 1},\n\t\t{0xffffffff, 0xffffffff}, {0x100000000, 0x100000000},\n\t\t{math.MaxUint64, math.MaxUint64}, {1_000_000, 18_446_744_073_709},\n\t\t{1_000_000, 18_446_744_073_710},\n\t}\n\tfor _, c := range cases {\n\t\th, l := mul64(c.a, c.b)\n\t\trh, rl := ref(c.a, c.b)\n\t\tif h != rh || l != rl {\n\t\t\tt.Errorf(\"mul64(%d,%d) = (%d,%d), want (%d,%d)\", c.a, c.b, h, l, rh, rl)\n\t\t}\n\t}\n}\n```\n\n### core/audit_e2e_test.go\n\n```go\npackage core_test\n\nimport (\n\t\"bytes\"\n\t\"encoding/hex\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/xeprotocol/xe/core\"\n\t\"github.com/xeprotocol/xe/store\"\n)\n\nvar testNow time.Time\n\nfunc stamp() int64 { return testNow.UnixNano() }\n\nfunc seedAsset(t *testing.T, l *core.Ledger, kp *core.KeyPair, asset string, amount uint64) string {\n\tb := &core.Block{\n\t\tType:      core.BlockMint,\n\t\tAccount:   kp.Address(),\n\t\tPrevious:  \"0\",\n\t\tBalance:   amount,\n\t\tAmount:    amount,\n\t\tAsset:     asset,\n\t\tTimestamp: stamp(),\n\t\tPubKey:    kp.PubKeyHex(),\n\t}\n\tif err := core.SignBlock(b, kp); err != nil {\n\t\tt.Fatalf(\"sign mint: %v\", err)\n\t}\n\tif err := l.SeedAssetForTesting(b); err != nil {\n\t\tt.Fatalf(\"seed %s: %v\", asset, err)\n\t}\n\treturn b.Hash\n}\n\n// provider with ZERO XUSD collateral accepts a lease and settles it, minting XE emission.\nfunc TestAuditZeroCollateralEmission(t *testing.T) {\n\ttestNow = time.Unix(1_700_000_000, 0)\n\tcore.Now = func() time.Time { return testNow }\n\tdefer func() { core.Now = func() time.Time { return time.Now() } }()\n\n\tconsumer := core.KeyPairFromSeed(bytes.Repeat([]byte{0x01}, 32))\n\tprovider := core.KeyPairFromSeed(bytes.Repeat([]byte{0x02}, 32))\n\ttimekeeper := core.KeyPairFromSeed(bytes.Repeat([]byte{0x03}, 32))\n\tcertHash := hex.EncodeToString(bytes.Repeat([]byte{0x77}, 32))\n\n\tms := store.NewMemStore()\n\tledger := core.NewLedger(ms, core.LedgerConfig{\n\t\tDifficulty:      0,\n\t\tTimestampWindow: core.DefaultTimestampWindow,\n\t\tTimekeeperConfigFn: func() *core.TimekeeperConfig {\n\t\t\treturn &core.TimekeeperConfig{Keys: []string{timekeeper.PubKeyHex()}, Threshold: 1}\n\t\t},\n\t\tCertificateLookupFn: func(hash string) *core.CertificateInfo {\n\t\t\treturn &core.CertificateInfo{Provider: provider.Address(), ExpiresAt: testNow.UnixNano() + int64(365*24*time.Hour), PriceMultiplierMilli: 1000}\n\t\t},\n\t\tEpochAtFn: func(ns int64) []core.EpochParams {\n\t\t\treturn []core.EpochParams{{R: 1000, PayoutCap: 0, TWAP: 0}}\n\t\t},\n\t\tFeatureActiveFn: func(string) bool { return false },\n\t})\n\n\tseedAsset(t, ledger, consumer, \"XE\", 1_000_000)\n\n\tsendBlock := &core.Block{\n\t\tType:        core.BlockSend,\n\t\tAccount:     consumer.Address(),\n\t\tPrevious:    ledger.GetChain(consumer.Address())[0].Hash,\n\t\tBalance:     1_000_000 - 1,\n\t\tAmount:      1,\n\t\tAsset:       \"XE\",\n\t\tDestination: provider.Address(),\n\t\tTimestamp:   stamp(),\n\t}\n\tif err := core.SignBlock(sendBlock, consumer); err != nil {\n\t\tt.Fatalf(\"sign send: %v\", err)\n\t}\n\tif err := ledger.AddBlock(sendBlock); err != nil {\n\t\tt.Fatalf(\"consumer send: %v\", err)\n\t}\n\trecvBlock := &core.Block{\n\t\tType:      core.BlockReceive,\n\t\tAccount:   provider.Address(),\n\t\tPrevious:  \"0\",\n\t\tBalance:   1,\n\t\tAsset:     \"XE\",\n\t\tSource:    sendBlock.Hash,\n\t\tTimestamp: stamp(),\n\t\tPubKey:    provider.PubKeyHex(),\n\t}\n\tif err := core.SignBlock(recvBlock, provider); err != nil {\n\t\tt.Fatalf(\"sign receive: %v\", err)\n\t}\n\tif err := ledger.AddBlock(recvBlock); err != nil {\n\t\tt.Fatalf(\"provider open receive: %v\", err)\n\t}\n\n\tprovBefore := ledger.GetAssetBalances(provider.Address())\n\tt.Logf(\"provider BEFORE lease: XE=%d XUSD=%d\", provBefore[\"XE\"], provBefore[\"XUSD\"])\n\tif provBefore[\"XUSD\"] != 0 {\n\t\tt.Fatalf(\"precondition failed: provider should start with 0 XUSD, has %d\", provBefore[\"XUSD\"])\n\t}\n\n\tconsumerChain := ledger.GetChain(consumer.Address())\n\tmintXUSD := &core.Block{\n\t\tType:      core.BlockMint,\n\t\tAccount:   consumer.Address(),\n\t\tPrevious:  consumerChain[len(consumerChain)-1].Hash,\n\t\tBalance:   1_000_000,\n\t\tAmount:    1_000_000,\n\t\tAsset:     \"XUSD\",\n\t\tTimestamp: stamp(),\n\t}\n\tif err := core.SignBlock(mintXUSD, consumer); err != nil {\n\t\tt.Fatalf(\"sign xusd mint: %v\", err)\n\t}\n\tif err := ledger.SeedAssetForTesting(mintXUSD); err != nil {\n\t\tt.Fatalf(\"seed XUSD: %v\", err)\n\t}\n\n\tcost, err := core.LeaseCost(1, 1024, 0, 60, 1000)\n\tif err != nil {\n\t\tt.Fatalf(\"LeaseCost: %v\", err)\n\t}\n\tt.Logf(\"lease cost = %d µXUSD\", cost)\n\n\tconsBal := ledger.GetAssetBalances(consumer.Address())\n\tconsumerChain = ledger.GetChain(consumer.Address())\n\tleaseBlock := &core.Block{\n\t\tType:            core.BlockLease,\n\t\tAccount:         consumer.Address(),\n\t\tPrevious:        consumerChain[len(consumerChain)-1].Hash,\n\t\tBalance:         consBal[\"XUSD\"] - cost,\n\t\tAsset:           \"XUSD\",\n\t\tDestination:     provider.Address(),\n\t\tAmount:          cost,\n\t\tVCPUs:           1,\n\t\tMemoryMB:        1024,\n\t\tDiskGB:          0,\n\t\tDuration:        60,\n\t\tCertificateHash: certHash,\n\t\tTimestamp:       stamp(),\n\t}\n\tif err := core.SignBlock(leaseBlock, consumer); err != nil {\n\t\tt.Fatalf(\"sign lease: %v\", err)\n\t}\n\tif err := ledger.AddBlock(leaseBlock); err != nil {\n\t\tt.Fatalf(\"lease block: %v\", err)\n\t}\n\n\tstake := core.LeaseStake(cost)\n\tt.Logf(\"required stake = LeaseStake(%d) = %d\", cost, stake)\n\n\tatt1, err := core.SignAttestation(leaseBlock.Hash, stamp(), timekeeper)\n\tif err != nil {\n\t\tt.Fatalf(\"sign accept attestation: %v\", err)\n\t}\n\tacceptBlock := &core.Block{\n\t\tType:            core.BlockLeaseAccept,\n\t\tAccount:         provider.Address(),\n\t\tPrevious:        recvBlock.Hash,\n\t\tBalance:         0,\n\t\tAsset:           \"XUSD\",\n\t\tSource:          leaseBlock.Hash,\n\t\tAmount:          stake,\n\t\tCertificateHash: certHash,\n\t\tLockedR:         1000,\n\t\tLockedPayoutCap: 0,\n\t\tLockedTWAP:      0,\n\t\tAttestations:    []core.TimekeeperAttestation{*att1},\n\t\tTimestamp:       stamp(),\n\t}\n\tif err := core.SignBlock(acceptBlock, provider); err != nil {\n\t\tt.Fatalf(\"sign accept: %v\", err)\n\t}\n\tif err := ledger.AddBlock(acceptBlock); err != nil {\n\t\tt.Fatalf(\"lease_accept (stake=%d): %v\", stake, err)\n\t}\n\tprovAfterAccept := ledger.GetAssetBalances(provider.Address())\n\tt.Logf(\"provider AFTER accept: XE=%d XUSD=%d\", provAfterAccept[\"XE\"], provAfterAccept[\"XUSD\"])\n\n\ttestNow = testNow.Add(61 * time.Second)\n\tatt2, err := core.SignAttestation(leaseBlock.Hash, stamp(), timekeeper)\n\tif err != nil {\n\t\tt.Fatalf(\"sign settle attestation: %v\", err)\n\t}\n\temission := cost\n\tsettleBlock := &core.Block{\n\t\tType:         core.BlockLeaseSettle,\n\t\tAccount:      provider.Address(),\n\t\tPrevious:     acceptBlock.Hash,\n\t\tBalance:      provAfterAccept[\"XE\"] + emission,\n\t\tAsset:        \"XE\",\n\t\tSource:       leaseBlock.Hash,\n\t\tAmount:       emission,\n\t\tAttestations: []core.TimekeeperAttestation{*att2},\n\t\tTimestamp:    stamp(),\n\t}\n\tif err := core.SignBlock(settleBlock, provider); err != nil {\n\t\tt.Fatalf(\"sign settle: %v\", err)\n\t}\n\tif err := ledger.AddBlock(settleBlock); err != nil {\n\t\tt.Fatalf(\"lease_settle: %v\", err)\n\t}\n\n\tprovFinal := ledger.GetAssetBalances(provider.Address())\n\tconsFinal := ledger.GetAssetBalances(consumer.Address())\n\tt.Logf(\"provider FINAL: XE=%d XUSD=%d\", provFinal[\"XE\"], provFinal[\"XUSD\"])\n\tt.Logf(\"consumer FINAL: XE=%d XUSD=%d\", consFinal[\"XE\"], consFinal[\"XUSD\"])\n\n\tif provFinal[\"XUSD\"] != 0 {\n\t\tt.Fatalf(\"provider should still hold 0 XUSD (never staked collateral), has %d\", provFinal[\"XUSD\"])\n\t}\n\tif provFinal[\"XE\"] != provBefore[\"XE\"]+emission {\n\t\tt.Fatalf(\"expected provider XE to grow by emission %d, got before=%d after=%d\", emission, provBefore[\"XE\"], provFinal[\"XE\"])\n\t}\n\tt.Logf(\"CONFIRMED: provider minted %d µXE emission with ZERO XUSD collateral at risk (stake=0)\", emission)\n}\n```\n\n## Escalation note\n\nIf the consequence above (\"escrow without service\" via the settle-before-force-settle ordering) is\ntreated as an abused state transition rather than a bare validation gap, High may apply. Left to the\nteam's discretion.\n\n## Remediation\n\nSet `LeaseStakeDivisor = 5` (restoring `stake = ceil(cost/5)`, and making the min-1µXUSD clamp\nreachable), or move the divisor into `ApplyGenesisLeaseTiming()` beside the other genesis-pinned\nlease parameters. Add a test asserting that `lease_accept` with `amount == 0` (or\n`amount != ceil(cost/5)`) is rejected.","patch_refs":[{"id":115,"repo":"xeprotocol/xe","kind":"pr","ref":"24","title":"fix(core): restore LeaseStakeDivisor to 5 so provider collateral stake is enforced","url":"https://github.com/xeprotocol/xe/pull/24","note":"","state":"open","author":"ocakciomursel-pixel","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[]}