Bounty
XE-0083 · Bounty

core/encoding: UnmarshalBlock silently drops the PoW nonce for multisig_open/multisig_update (tailOffset uses min keyset size) (Minor)

Accepted claimed Minor xe#100 filed 2026-10-27 17:05 UTC by BoomGone

Report

  • Area: core/encoding.go UnmarshalBlock
  • Found: 2026-10-27, repo master 9787859 (live node xe/92d83d1), via an in-process Go round-trip test
  • Related: #84 (lease_renew has no decode case); this is multisig and a silent-data-loss failure mode, distinct

Summary

UnmarshalBlock does not round-trip multisig_open or multisig_update blocks: the PoW nonce is silently dropped (decoded as 0), even though the encoded bytes contain it.

Root cause: minLen for the two multisig types is fixedHeaderSize + 8 + representativeSize, where the 8 is the keyset HEADER only (threshold + count), i.e. a zero-key floor. tailOffset is then initialised to minLen and only corrected for genesis and send/burn, never for multisig. So for a real multisig block (keyset = 8 + 32numKeys), tailOffset is left pointing 32numKeys bytes too early, and the nonce-presence check len(data) == tailOffset+8 never matches. The 8 trailing nonce bytes after keyset+representative are ignored.

Evidence (in-process Go test against the cloned core package)

encoded 202 bytes; last 8 (LE nonce) = efbeadde00000000     # 0xDEADBEEF little-endian IS present in the bytes
in  PoWNonce = 3735928559 (0xdeadbeef)
out PoWNonce = 0 (0x0)                                        # dropped on decode
keyset threshold in/out = 2/2, keys in/out = 2/2             # the keyset itself survives; only the nonce is lost

A full round-trip test over all 14 block types shows every other type round-trips (re-encode equals encode), multisig_open and multisig_update mismatch only in the final 8 bytes (orig nonce vs 0), and lease_renew fails to decode at all (that last one is #84).

Impact

  • PoWNonce is a real field: ValidatePoW(hashBytes, b.PoWNonce, difficulty) is called in core/ledger.go (x2) and core/quorum.go. A multisig block whose nonce is zeroed by a binary-codec round-trip would fail PoW re-verification.
  • Honest scope: the binary codec (MarshalBlock / UnmarshalBlock) currently has NO caller anywhere in the repo. Blocks are stored and gossiped as JSON (store/badger_store.go uses json.Marshal/json.Unmarshal), which preserves the nonce. So today this is a LATENT defect in an exported API function, not a live-path failure. It matters for any tool built on the exported codec, and it is the same codec and the same class of bug as the already-filed #84.
  • The nonce is not part of the block hash (HashBlock uses MarshalBlockCanonical, which excludes the nonce), so there is no hash/consensus impact. No fund risk.

Suggested fix

  • Compute tailOffset from the real decoded structure for every variable-length type. For multisig, set tailOffset = repOffset + representativeSize after the keyset is parsed, as is already done implicitly for fixed-size types, instead of leaving it at minLen.
  • Add a round-trip test over all 14 block types to the codec (there is currently none; the repo ships no *_test.go).

Payout

XE address: 6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc

Thread

fangjian-bit2026-10-28 08:40 UTCgithub

Hey team & @BoomGone, opened PR #118 addressing this issue:

  1. In core/encoding.go:unmarshalBlock, updated tailOffset to be computed dynamically as repOffset + representativeSize rather than the static minLen. This accounts for the dynamic ksLen = 8 + 32*numKeys keyset bytes on multisig blocks (multisig_open, multisig_update) so len(data) == tailOffset+8 evaluates correctly.
  2. Added core/encoding_test.go with TestMultisigPoWNonceRoundTrip verifying exact parity of PoWNonce on multi-key multisig roundtrips, plus standard block types.
XE deskteam2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0083.