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?
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?
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.
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 indexThen, if the outpoint is a non-segwit p2pkh output the scriptSig uses:
1 byte to denote the scriptSig size1 byte to denote the signature size71 bytes (on average) for the signature1 byte to denote the public key size33 bytes for the public keyIn 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 size1 byte to denote the witness version (0x00)1 byte to denote the public key hash size20 bytes for the public key hashFurther, 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.
1And to address OP's specific question, yes, this means that transaction size grows linearly with the number of inputs. – Nate Eldredge – 2018-09-27T14:13:03.153
Thank you for the answer, I am however still wondering how heavy an input is? – Bertram Lund – 2018-09-27T19:23:35.357
It depends on the scriptSig, see https://bitcoin.stackexchange.com/questions/68811/what-is-the-absolute-smallest-size-of-the-data-bytes-that-a-blockchain-transac and https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin
– JBaczuk – 2018-09-27T19:37:00.163