2

there's a transaction txid is fa3467452918627ebd63a3e8570e70d38b0eefef683347510b204ba6962ebe44, using bitcoin-cli we can see it's size,vsize and weight

enter image description here

we can get it's hex and it's accurately 225. using the formula vsize=(weight+4-1)/4=576/4=144,there's no problem

but when calculating the vsize bytes,it should be (573-225)/3=116,but the witness data in this transaction is enter image description here

when i delete txinwitness hex data(selected in the following picture) from origin hex(225 bytes),i can't get the result 116.Where is wrong?Can anyone tell me how to calculate?much thanks. enter image description here

3
  • In your second calculation, what are you trying to calculate? The first calculation is the correct way to calculate vsize. Whatever you are doing in the second completely ignores the witness which is incorrect for vsize calculation.
    – Ava Chow
    Commented Jul 7, 2022 at 3:54
  • bitcoin.stackexchange.com/questions/80325/… like this question's example,i 'd like to calculate the base bytes.according to this posts,weight=3*base_bytes+total_bytes.now weight is 576,total bytes is 225,the base_bytes should be 116,and i wonder where is the 116 base bytes in the total hax 255byes?
    – noob
    Commented Jul 7, 2022 at 5:02
  • or i can simplify my question.If I only know the transaction's origin hex 225 bytes.How to calculate the weight and vsize?
    – noob
    Commented Jul 7, 2022 at 5:08

1 Answer 1

5

It is not possible to calculate the size, weight, or vsize, purely from the JSON decoding of the transaction as the JSON decoding does not output the hex values of various counters, as well as the segwit marker and flag bytes. If you try to reconstruct the transaction with only the information that is output, you will end up with a total size that is less than it's actual size.

In your example, the transaction hex is

020000000001017fb11165fc5a6edf3bf06176c8915b22e20c3c48966d1d5c5673d4bc76a98c6e0100000000fdffffff024a140000000000001976a9145e3a929c6f941ad02c352b47d33a65bd160afe2f88accc8c0700000000001600149aba0ec86126b94b4dfdff48c4855ec49975c8e50247304402200615b90428b7e857d074ef17da69d5d533adc2c02fb739b04ecb88e38723afcd0220070f30781a8020ba0330a96b2a58358c5b5073ed391cee50ea1650e3972fcb0d012102030df0337a88e6f5c77f593eeb8b9d425742fbee78a4dcfeb66f90dec8e30bf25d560b00

Let's break this down into the separate fields so we can distinguish which are part of the base size.

  • 02000000 - Transaction version, base size and total size += 4
  • 00 - Segwit marker, total size += 1
  • 01 - Segwit flag, total size += 1
  • 01 - Input count, base size and total size += 1
  • 7fb11165fc5a6edf3bf06176c8915b22e20c3c48966d1d5c5673d4bc76a98c6e - Previous txid, base size and total size += 32
  • 01000000 - Output index, base size and total size += 4
  • 00 - Length of scriptSig, base size and total size += 1
  • fdffffff - Sequence number, base size and total size += 4
  • 02 - Output count, base size and total size += 1
  • 4a14000000000000 - Output amount, base size and total size += 8
  • 19 = scriptPubKey length, base size and total size += 1
  • 76a9145e3a929c6f941ad02c352b47d33a65bd160afe2f88ac - scriptPubKey, base size and total size += 25
  • cc8c070000000000 - Output amount, base size and total size += 8
  • 16 - scriptPubKey length, base size and total size += 1
  • 00149aba0ec86126b94b4dfdff48c4855ec49975c8e5 - scriptPubKey, base size and total size += 22
  • 02 - Witness stack item count, total size += 1
  • 47 - Witness stack item length, total size += 1
  • 304402200615b90428b7e857d074ef17da69d5d533adc2c02fb739b04ecb88e38723afcd022070f30781a8020ba0330a96b2a58358c5b5073ed391cee50ea1650e3972fcb0d01 - Witness stack item, total size += 71
  • 21 - Witness stack item length, total size += 1
  • 02030df0337a88e6f5c77f593eeb8b9d425742fbee78a4dcfeb66f90dec8e30bf2 - Witness stack item, total size += 33
  • 5d560b00 - Locktime, base size and total size += 4

So the base size comes out to be 116, the total size is 225. The weight is 3 * 116 + 225 = 573.

The vsize calculated from the weight is (573 + 4 - 1) / 4 = 144. Calculating the vsize from the sizes is ceil(116 + (225 - 116) / 4) = 144.

1
  • very clear!.Thanks for your answer
    – noob
    Commented Jul 8, 2022 at 1:32

Your Answer

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

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