Bounty
XE-16737 · Bounty

[Minor] Binary codecs accept non-canonical encodings: UnmarshalBlock ignores trailing garbage, DecodeVote accepts any nonzero final byte

Closed · duplicate —claimed Minor xe#655 filed 2026-11-17 05:38 UTC by kecedanzz77-bit

Report

Summary

Neither binary decoder enforces canonical form: UnmarshalBlock never rejects trailing bytes, and DecodeVote accepts 255 distinct "final" byte values. Multiple distinct byte strings therefore decode to the same block/vote, breaking byte-level identity for any future binary consumer, debug tool, or port that assumes decode->encode round-trip parity.

Root Cause

  • unmarshalBlock (core/encoding.go:545-549): after the memo/timing tail, the nonce is read only if len(data) == tailOffset+8; any other trailing length is silently ignored -- no length check rejects trailing garbage.
  • DecodeVote (core/encoding.go:719): final := data[137] != 0 -- any nonzero byte decodes as Final=true, while EncodeVote writes 0x01.

Impact

Latent at HEAD: the binary codec has no callers outside core/encoding.go (JSON is the wire/store format), so there is no attacker-reachable trigger today. It breaks byte-level identity for any future binary consumer -- the same reasoning #100/#563 were accepted under.

Verification (executed, deterministic)

Directed tests against a valid canonical send block with 2, 7, 9, and 100 trailing bytes appended: all decode successfully to the identical block ("trailing N bytes silently ignored"). A vote with final byte 0x02 decodes to Final=true and re-encodes to the same bytes as the 0x01 original. The fuzzer independently found the same defect (FuzzDecodeVote failed in 12s on an input with final byte 0x30). Audited at HEAD 8cc209d (testnet-0006).

Note on related reports

Distinct from #563 (DecodeVote panic via uint16 wraparound -- different defect, same function), #100 (PoWNonce drop on round-trip -- different defect, same file), and #8 (vote hex malleability -- JSON hex case, different mechanism).

Suggested fix

In unmarshalBlock, reject len(data) that is neither tailOffset nor tailOffset+8. In DecodeVote, reject data[137] values other than 0x00/0x01.

Thread

Joseph Denneteam2026-11-22 23:26 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0945, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-16737 and says what differs; it is read like any other.