{"id":"XE-0916","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":13,"title":"Web dao.js compact string values hash differently after Go store and gossip re-encoding","area":"consensus","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0465","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-06T16:51:28.386627+00:00","updated_at":"2026-11-14T22:53:33.031826+00:00","source_created_at":null,"told_at":"2026-11-14T22:53:33.724089+00:00","status_changed_at":"2026-11-08T20:32:08.743857+00:00","url":"https://bounty.xe.network/XE-0916","body":"## Summary\r\nThe embedded dao.js tool is supposed to submit state-chain blocks that hash the same after Go storage and gossip as they did at admission. JS JSON.stringify leaves <>& compact; Go encoding/json default SetEscapeHTML re-encodes on PutStateBlock (store/badger_store.go:1741-1748), MemStore copyStateBlock (store/mem_store.go:865-876), and gossip Publish (net/gossip.go:324-330), while MarshalCanonical (statechain/encoding.go:47-51) hashed the compact bytes. NewChain.replay at statechain/chain.go:51-86 then VerifyBlockHash at :68 fails on the escaped stored bytes. Submit is POST /api/statechain/blocks (api/handler.go:938-950) via node.SubmitStateChainBlock (node/node.go:2289-2293) from the FS embedded at web/embed.go:5 and served at api/ui.go:63-64. GitHub #45 is statechain gossip admitting any 64-hex with a non-empty signature list, and XE-0465/XE-0569 is Python compact_json leaving U+2028 raw; the poison here is the browser dao tool plus Go SetEscapeHTML on the submitter's own node.\r\n\r\n## Affected components\r\nweb/assets/dao.js:202-243 onGenerateHash, :362-399 serializeBlockJson; web/assets/statechain-block.js:40 hash of textarea bytes; web/embed.go:5; api/ui.go:63-64; api/handler.go:210, :938-950 handleSubmitStateChainBlock; node/node.go:2289-2293 SubmitStateChainBlock; statechain/types.go:14-17 Op.Value; statechain/encoding.go:10 MarshalCanonical, op-value encode at :47-51; statechain/chain.go:51-86 replay, :68 VerifyBlockHash, :155 AddBlock size marshal, :207; store/badger_store.go:1741-1748 PutStateBlock; store/mem_store.go:865-876 copyStateBlock; net/gossip.go:324-330 Publish at xe 02e9641b0ac64437f57e09d63301f88cce61a802.\r\n\r\n## Impact\r\nThe submitter's node admits the compact block, persists escaped bytes, then cannot restart until that block is gone. Gossip peers never store it. If the block collected threshold signatures before the mismatch surfaced, that resolution is lost. The web dao tool is the submission path, and funds stay put.\r\n\r\n## PoC\r\n\r\n```go\r\npackage round2b\r\n\r\nimport (\r\n\t\"bytes\"\r\n\t\"encoding/json\"\r\n\t\"fmt\"\r\n\t\"os\"\r\n\t\"strings\"\r\n\t\"testing\"\r\n\t\"unicode/utf8\"\r\n\r\n\t\"github.com/xeprotocol/xe/core\"\r\n\t\"github.com/xeprotocol/xe/statechain\"\r\n\t\"github.com/xeprotocol/xe/store\"\r\n)\r\n\r\n// TestPoC_B1 drives AddBlock of a DAO state-chain block whose op value is the\r\n// compact JSON string dao.js would submit (unescaped <, >, &), then reloads\r\n// the stored bytes the way NewChain.replay does.\r\nfunc TestPoC_B1(t *testing.T) {\r\n\tpass, detail := runB1()\r\n\tif pass {\r\n\t\tfmt.Println(\"PASS:\", detail)\r\n\t\treturn\r\n\t}\r\n\tfmt.Println(\"FAIL:\", detail)\r\n\tos.Exit(1)\r\n}\r\n\r\nfunc runB1() (bool, string) {\r\n\tcore.SetNetworkID(\"\")\r\n\r\n\tdao1, err := core.GenerateKeyPair()\r\n\tif err != nil {\r\n\t\treturn false, \"dao1: \" + err.Error()\r\n\t}\r\n\tdao2, err := core.GenerateKeyPair()\r\n\tif err != nil {\r\n\t\treturn false, \"dao2: \" + err.Error()\r\n\t}\r\n\tgenesis, err := genesisDAO([]string{dao1.PubKeyHex(), dao2.PubKeyHex()}, 2)\r\n\tif err != nil {\r\n\t\treturn false, \"genesis: \" + err.Error()\r\n\t}\r\n\r\n\t// Compact JSON string as dao.js serializeBlockJson would emit for a\r\n\t// parsed string containing <, >, &. JS JSON.stringify does not HTML-escape.\r\n\tjsSubmitted := json.RawMessage(`\"<hello>&world>\"`)\r\n\tif !bytes.Contains(jsSubmitted, []byte(\"<\")) || !bytes.Contains(jsSubmitted, []byte(\">\")) || !bytes.Contains(jsSubmitted, []byte(\"&\")) {\r\n\t\treturn false, \"fixture lost compact <>&\"\r\n\t}\r\n\r\n\tms := store.NewMemStore()\r\n\tchain, err := statechain.NewChain(ms, genesis)\r\n\tif err != nil {\r\n\t\treturn false, \"NewChain: \" + err.Error()\r\n\t}\r\n\r\n\tblock, err := buildDAOBlock(chain, \"dao.note\", jsSubmitted, dao1, dao2)\r\n\tif err != nil {\r\n\t\treturn false, \"build: \" + err.Error()\r\n\t}\r\n\tadmitHash := block.Hash\r\n\tif err := statechain.VerifyBlockHash(block); err != nil {\r\n\t\treturn false, \"pre-admit hash: \" + err.Error()\r\n\t}\r\n\r\n\tif err := chain.AddBlock(block); err != nil {\r\n\t\treturn false, \"AddBlock rejected compact <>& value (admission should succeed): \" + err.Error()\r\n\t}\r\n\tlogf(\"ADMIT: index=%d hash=%s value_raw=%s\", block.Index, fmtShort(admitHash), string(jsSubmitted))\r\n\r\n\tstored, err := ms.GetStateBlock(block.Index)\r\n\tif err != nil || stored == nil {\r\n\t\treturn false, fmt.Sprintf(\"GetStateBlock: %v stored=%v\", err, stored)\r\n\t}\r\n\tstoredVal := string(stored.Ops[0].Value)\r\n\tgoMarshaled, err := json.Marshal(block)\r\n\tif err != nil {\r\n\t\treturn false, \"json.Marshal(block): \" + err.Error()\r\n\t}\r\n\r\n\thtmlEscaped := bytes.Contains(goMarshaled, []byte(`\\u003c`)) ||\r\n\t\tbytes.Contains(goMarshaled, []byte(`\\u003e`)) ||\r\n\t\tbytes.Contains(goMarshaled, []byte(`\\u0026`))\r\n\tstoredEscaped := strings.Contains(storedVal, `\\u003c`) ||\r\n\t\tstrings.Contains(storedVal, `\\u003e`) ||\r\n\t\tstrings.Contains(storedVal, `\\u0026`)\r\n\r\n\tlogf(\"STORE json.Marshal contains HTML escapes: %v\", htmlEscaped)\r\n\tlogf(\"STORE GetStateBlock value bytes: %s\", storedVal)\r\n\tlogf(\"STORE value escaped: %v (admission value was %s)\", storedEscaped, string(jsSubmitted))\r\n\r\n\tstoredHashErr := statechain.VerifyBlockHash(stored)\r\n\tlogf(\"REPLAY VerifyBlockHash(stored): %v\", storedHashErr)\r\n\r\n\t_, replayErr := statechain.NewChain(ms, genesis)\r\n\tlogf(\"RESTART NewChain.replay: %v\", replayErr)\r\n\r\n\t// Gossip Publish path: json.Marshal(StateChainMsg{Block}) then peer Unmarshal + VerifyBlockHash.\r\n\ttype stateChainMsg struct {\r\n\t\tBlock *statechain.Block `json:\"block\"`\r\n\t}\r\n\tgossipBytes, err := json.Marshal(stateChainMsg{Block: block})\r\n\tif err != nil {\r\n\t\treturn false, \"gossip marshal: \" + err.Error()\r\n\t}\r\n\tvar peerMsg stateChainMsg\r\n\tif err := json.Unmarshal(gossipBytes, &peerMsg); err != nil {\r\n\t\treturn false, \"gossip unmarshal: \" + err.Error()\r\n\t}\r\n\tpeerHashErr := statechain.VerifyBlockHash(peerMsg.Block)\r\n\tlogf(\"GOSSIP peer VerifyBlockHash after Go marshal: %v\", peerHashErr)\r\n\tlogf(\"GOSSIP payload snippet: %s\", snippetAround(gossipBytes, `\\u003c`))\r\n\r\n\t// U+2028: JS JSON.stringify already emits \\u2028. Also try an actual LINE SEPARATOR in RawMessage.\r\n\tu2028escaped := json.RawMessage(`\"line\\u2028sep\"`)\r\n\tu2028raw := json.RawMessage(\"\\\"line\" + string(rune(0x2028)) + \"sep\\\"\")\r\n\tencEsc, _ := json.Marshal(&statechain.Op{Action: \"set\", Key: \"k\", Value: u2028escaped})\r\n\tencRaw, _ := json.Marshal(&statechain.Op{Action: \"set\", Key: \"k\", Value: u2028raw})\r\n\tlogf(\"U+2028 already-escaped RawMessage marshal=%s\", encEsc)\r\n\tlogf(\"U+2028 actual-char RawMessage marshal=%s utf8=%v\", encRaw, utf8.Valid(u2028raw))\r\n\r\n\t// CONTROL: no special chars, restart must succeed.\r\n\tmsCtrl := store.NewMemStore()\r\n\tctrlChain, err := statechain.NewChain(msCtrl, genesis)\r\n\tif err != nil {\r\n\t\treturn false, \"control NewChain: \" + err.Error()\r\n\t}\r\n\tctrlVal := json.RawMessage(`\"hello world\"`)\r\n\tctrlBlock, err := buildDAOBlock(ctrlChain, \"dao.note\", ctrlVal, dao1, dao2)\r\n\tif err != nil {\r\n\t\treturn false, \"control build: \" + err.Error()\r\n\t}\r\n\tif err := ctrlChain.AddBlock(ctrlBlock); err != nil {\r\n\t\treturn false, \"control AddBlock: \" + err.Error()\r\n\t}\r\n\t_, ctrlReplay := statechain.NewChain(msCtrl, genesis)\r\n\tlogf(\"CONTROL replay (no <>&): %v\", ctrlReplay)\r\n\r\n\tif !htmlEscaped || !storedEscaped {\r\n\t\treturn false, fmt.Sprintf(\"Go marshal did not HTML-escape stored value (htmlEscaped=%v storedEscaped=%v storedVal=%s)\", htmlEscaped, storedEscaped, storedVal)\r\n\t}\r\n\tif storedHashErr == nil {\r\n\t\treturn false, \"stored bytes still hashed; expected VerifyBlockHash mismatch after HTML escape\"\r\n\t}\r\n\tif replayErr == nil {\r\n\t\treturn false, \"NewChain.replay succeeded; expected restart failure on escaped stored bytes\"\r\n\t}\r\n\tif peerHashErr == nil {\r\n\t\treturn false, \"gossip peer accepted re-marshalled block; expected hash mismatch\"\r\n\t}\r\n\tif ctrlReplay != nil {\r\n\t\treturn false, \"control replay failed: \" + ctrlReplay.Error()\r\n\t}\r\n\treturn true, fmt.Sprintf(\r\n\t\t\"compact <>& admitted hash=%s; stored value %s; replay=%v; gossip peer=%v; control replay ok\",\r\n\t\tfmtShort(admitHash), storedVal, replayErr, peerHashErr,\r\n\t)\r\n}\r\n\r\nfunc snippetAround(b []byte, needle string) string {\r\n\ts := string(b)\r\n\ti := strings.Index(s, needle)\r\n\tif i < 0 {\r\n\t\tif len(s) > 180 {\r\n\t\t\treturn s[:180] + \"...\"\r\n\t\t}\r\n\t\treturn s\r\n\t}\r\n\tlo := i - 40\r\n\tif lo < 0 {\r\n\t\tlo = 0\r\n\t}\r\n\thi := i + 60\r\n\tif hi > len(s) {\r\n\t\thi = len(s)\r\n\t}\r\n\treturn s[lo:hi]\r\n}\r\n```\r\n\r\n```\r\nstored value \"\\u003chello\\u003e\\u0026world\\u003e\"\r\nreplay=NewChain: replay: block 1: hash mismatch\r\nPASS: compact <>& admitted; stored bytes HTML-escaped; replay and gossip peer hash-mismatch\r\n```\r\n\r\n## Suggested fix\r\nDisable SetEscapeHTML on state-block marshal, or hash after a canonical compact encode shared by JS and Go. Store the submitted bytes instead of re-marshalling.","patch_refs":[],"thread":[{"id":3785,"source":"desk","source_ref":"reply:2527","author":"XE desk","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0465, 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-0916 and says what differs; it is read like any other.","created_at":"2026-11-14T22:53:33.031826+00:00"}]}