Skip to content

elements-29.x: signblock witness counted at 4 WU/byte in GetBlockWeight — witness discount lost relative to 23.x #1611

Open

Description

@tomt1664

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

On elements-29.x, the dynafed block-signature witness (CBlockHeader::m_signblock_witness) is counted at full weight (4 WU/byte) in GetBlockWeight, instead of receiving the witness discount (1 WU/byte) as it does on elements-23.x. This is a consensus-relevant change to block weight that appears to be an accidental regression from the serialization-parameters refactor, not an intentional change: the code comments and the miner’s weight reservation both still assume the discount applies.

Root cause

In 23.x, CBlockHeader::Serialize decided witness inclusion from the stream flag, so the stripped (SERIALIZE_TRANSACTION_NO_WITNESS) serialization used for weight correctly skipped the signblock witness (23.3.4 block.h#L259-L262):

const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
...
if (fAllowWitness) { s << m_signblock_witness.stack; }

In 29.x this became a params-aware two-arg overload plus a one-arg fallback that hardcodes TX_WITH_WITNESS (block.h#L256-L259, block.h#L381-L384):

template <typename Stream>
inline void Serialize(Stream& s, const TransactionSerParams& params) const {
    ...
    if (params.allow_witness) { s << m_signblock_witness.stack; }
}
// Backwards-compatible overload for serializers that don't pass params:
template <typename Stream>
inline void Serialize(Stream& s) const { Serialize(s, TX_WITH_WITNESS); }

CBlock serializes its header via AsBase (block.h#L276-L280), and the generic serializer calls the one-arg member a.Serialize(os). That reaches the fallback above, which hardcodes TX_WITH_WITNESS — so TX_NO_WITNESS(block) does not strip the signblock witness. By contrast, CTransaction’s one-arg Serialize pulls the params from the stream (s.GetParams()), which is exactly what the header is missing.

GetBlockWeight (validation.h#L137-L140) is stripped*(WITNESS_SCALE_FACTOR-1) + total. Since the stripped size still contains the signblock witness, that witness is charged in both terms → 4 WU/byte.

Note the hashing path is not affected: 29.x hand-writes CBlockHeader::GetHash() to exclude the signblock witness (comment citing the SER_GETHASH removal, Bitcoin #28508), so block hashes are unchanged. This is purely a weight-accounting divergence.

Impact

Weight divergence 23.x ↔ 29.x. The same block weighs more under 29.x by 3 × (signblock witness bytes) — for a federation multisig, a few thousand WU. A block near MAX_BLOCK_WEIGHT can be valid under one version and bad-blk-weight under the other, i.e. a hard-fork-class difference in block validity. Relevant to coordinate across a functionary upgrade.
Miner vs validation mismatch. The assembler still reserves the signblock witness at 1× (“Note witness discount”, miner.cpp#L169-L170) while validation now charges 4×, so a near-full block could exceed MAX_BLOCK_WEIGHT after assembly. Latent given typical block fullness, but it’s a real inconsistency.
The block.h comment “We do not serialize witness for hashes, or weight calculation” is now false for the weight case, confirming the discount was still intended.

Expected behaviour

Suggested fix

Have CBlock serialization pass the stream’s params to the header rather than routing through the witness-hardcoding one-arg fallback. A CBlock stream always carries TransactionSerParams already (its vtx serialization requires it), so this is safe and restores the 23.x stripped-size behaviour, while standalone-header and network/disk serialization (always TX_WITH_WITNESS) are untouched. The no-witness form is only ever used for GetSerializeSize, never deserialized, so round-trips are unaffected.

A regression test should assert that for a dynafed block with a non-empty signblock witness, GetBlockWeight == stripped_size + 1×(signblock witness) (not +4×), and that 23.x and 29.x agree on the weight of the same block.

Expected vs actual
Expected: signblock witness discounted at 1 WU/byte (as in 23.x, and as the miner reserves).
Actual: counted at 4 WU/byte.

Steps to reproduce

Consensus divergence between master (29.x) and 23.x with full blocks.

Relevant log output

No response

How did you obtain Bitcoin Core

Compiled from source

What version of Bitcoin Core are you using?

29.x

Operating system and version

Ubuntu 22.04

Machine specifications

No response

Activity

  1. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions