Bounty
XE-0627 · Bounty

[Core/Ledger] addBlock shallow copy mutates caller's Signatures slice — core/ledger.go:740-744

Triaging web filed 2026-11-05 07:20 UTC by Ashev Ardiansyah

Report

Summary

addBlock() at core/ledger.go:740 creates a shallow copy via bc := *b, then calls normalizeBlockHex(&bc) which lowercases Signatures[i].PublicKey and Signatures[i].Sig in-place. Because bc.Signatures shares the backing array with b.Signatures, the caller's block object has its Signature fields silently mutated.

Affected Code

core/ledger.go:740-745:

bc := *b                                          // shallow copy
bc.Attestations = make([]BlockAttestation, ...)    // deep copy
copy(bc.Attestations, b.Attestations)
// NOTE: Signatures is NOT deep-copied here
return n.normalizeBlockHex(&bc)                    // mutates shared backing array

normalizeBlockHex lowercases every Signatures[i].PublicKey and Signatures[i].Sig. Since bc.Signatures and b.Signatures point to the same underlying array, the original block is modified as a side effect.

Impact

Any caller that re-uses the block object after addBlock returns gets lowercased signature fields. This is a correctness bug — signature hex casing should not be the caller's concern and side-effecting their data is unexpected.

Severity

Low — correctness issue, not directly exploitable, but violates caller expectations and could cause subtle bugs.

Fix

Deep-copy the Signatures slice, following the same pattern as Attestations at line 742:

bc.Signatures = make([]BlockSignature, len(b.Signatures))
copy(bc.Signatures, b.Signatures)

Thread

Joseph Denneteam2026-11-08 20:47 UTCdesk

Thanks for the report. We have read the code you point at and agree the copy is shallower than it looks; we could not find a behavioural consequence beyond the casing of the caller's fields, and are treating it as a small hardening item. https://bounty.xe.network/XE-0627 will be updated when it is addressed.