1

I'm trying to understand block weight, a metric introduced by segwit (BIP-141):

block weight = 3 * base size + total size

"base size" is the length of a pre-segwit block, which contains only serialized base transactions. "total size" is the length of a post-segwit block, which contains both serialized base transactions and serialized witness transactions (as defined in BIP-144). The weight of any block must not exceed 4 MB.

The weight of a block without pay-to-witness scripts can found by computing total size. It's tempting to set base size equal to total size:

block weight = 3 * base size + base size = 4 * base size

But this assumes the length of the serialization of a non-segwit base transaction equals the length of the serialization of a non-segwit witness transaction. This doesn't appear to be the case:

Serialization

The witness transaction serialization format appears to follow the structure shown above (which is also the input to find wtxid). Notice two additional bytes before the list of inputs (marker and flag, respectively). Moreover, the witness requires at least one byte (the witness field count) even if no fields are present.

In other words, a witness transaction serialization will always be at least three bytes longer than a base transaction serialization, regardless of whether a witness is present.

If this is correct, then segwit is in fact reducing the block size limit for blocks devoid of pay-to-witness scripts by a factor proportional to the number of transactions in the block.

What am I missing?

2 Answers 2

3

The witness serialization format only applies to transactions that have witnesses. If a transaction does not have witnesses, then its witness serialization format is the non-witness serialization format.

From BIP 144:

If the witness is empty, the old serialization format should be used.

1
  • Thanks - silly mistake on my part. I even knew that's what BIP-144 said and somehow forgot it. Jun 22, 2017 at 16:42
3

From BIP 144: If the witness is empty, the old serialization format should be used.

It is illegal to encode a transaction using the extended serialization format if the witness is empty. Another way to see it is that every transaction has a witness, which may be empty, and the correct way to encode that empty witness is using the old serialization format.

This also holds for the serialization done for the purposes of computing weight.

A non-witness transaction will be counted 3 times as its base size (which is the size of the serialization in the old format), and then once as its witness size (which is again the size of the serialization in the old format). The result is that the weight of a non-witness transaction is just 4 times its old size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.