1

What is the weight unit cost of an input? And can you batch/aggregate the inputs or is it linearly growth when you add more inputs to a tx?

2 Answers 2

1

What is the weight unit cost of an input?

2 things affect the weight of a tx, the total number of bytes , and the total bytes minus witness data.

Transaction Weight = Base transaction size * 3 + Total transaction size, where

Base transaction size is the size of the transaction serialised with the witness data stripped.

Total transaction size is the transaction size in bytes serialized as described in BIP144, including base data and witness data.

See BIP141

Can you batch/aggregate the inputs or is it linearly growth when you add more inputs to a tx?

You can't batch inputs, but you can combine them and send them back to yourself first in a larger amount, but that requires an additional transaction. Probably the best you can do now is to use a segwit address to receive funds so when you go to spend the inputs, the witness data lowers the weight of each input.

3
1

The weight of a single input in a transaction always uses:

  • 32 bytes to reference the outpoint id (hash)
  • 4 bytes to reference the outpoint index

Then, if the outpoint is a non-segwit p2pkh output the scriptSig uses:

  • 1 byte to denote the scriptSig size
  • 1 byte to denote the signature size
  • 71 bytes (on average) for the signature
  • 1 byte to denote the public key size
  • 33 bytes for the public key

In total this makes 143 bytes (on average) to reference a non-segwit p2pkh output with your spending transaction.

For segwit p2sh nested p2pkh outputs, the scriptSig uses instead:

  • 1 byte to denote the scriptSig size
  • 1 byte to denote the witness version (0x00)
  • 1 byte to denote the public key hash size
  • 20 bytes for the public key hash

Further, the witnessScript will use the same amount of bytes as the scriptSig for spending non-witness p2pkh outpoints. However, the witnessScript only counts with a quarter to the total weight.

Therefore a segwit p2sh nested input has a weight contribution of 59 bytes + (107)/4 bytes = 86 bytes on average.

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.