<!-- XE-16737 · [Minor] Binary codecs accept non-canonical encodings: UnmarshalBlock ignores trailing garbage, DecodeVote accepts any nonzero final byte · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16737>. The page is the record; this is the same page for reading.*

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](https://github.com/xeprotocol/xe/issues/655)
filed 2026-11-17 05:38 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Consensus

Duplicate of
:   [XE-0945](https://bounty.xe.network/XE-0945) triaging

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770279](https://bounty.xe.network/log/770279) 2026-11-22 23:26 UTC reply.mirror\_failed
- [770081](https://bounty.xe.network/log/770081) 2026-11-22 23:26 UTC proposal.adopted
- [770080](https://bounty.xe.network/log/770080) 2026-11-22 23:26 UTC reply.sent
- [770079](https://bounty.xe.network/log/770079) 2026-11-22 23:26 UTC ticket.status new → closed
- [769292](https://bounty.xe.network/log/769292) 2026-11-22 23:26 UTC proposal.adopted
- [769291](https://bounty.xe.network/log/769291) 2026-11-22 23:26 UTC ticket.facts area
- [769290](https://bounty.xe.network/log/769290) 2026-11-22 23:26 UTC proposal.adopted
- [769289](https://bounty.xe.network/log/769289) 2026-11-22 23:26 UTC ticket.facts
- [769288](https://bounty.xe.network/log/769288) 2026-11-22 23:26 UTC proposal.adopted
- [769287](https://bounty.xe.network/log/769287) 2026-11-22 23:26 UTC ticket.facts
- [766141](https://bounty.xe.network/log/766141) 2026-11-22 23:17 UTC note.added
- [766139](https://bounty.xe.network/log/766139) 2026-11-22 23:17 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-16737) · [JSON](https://bounty.xe.network/v1/tickets/XE-16737) · [markdown](https://bounty.xe.network/XE-16737.md)

### 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 Denne**team2026-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.
