Predict multi signature transaction size

4

2

I was looking for answer everywhere. Basically is there any way of calculate multi-sig transaction size when the transaction is creating, before the signing procedure? I was trying to find any pattern for that, with no results.

Informations I have:

  • num of inputs;
  • num of outputs;
  • num of required signatures

I will appreciate any clue to solve this problem.

Mr.Coffee

Posted 2014-09-18T09:24:47.377

Reputation: 141

Are you asking about transactions with several inputs or about input/output from/to msig-address?amaclin 2014-09-18T14:19:23.517

About transaction from multisig address. So I have few transactions belonging to multisig address and I want to send money to whatever address. Before broadcast to the network multisig transaction require signing, in my case two signatures. The base transaction after calling './bitcoin-cli createrawtransaction trans_list recipients' is quite small, after first sign becoming around 1000 bytes and after second 2000 bytes it also depending from how many transactions is coming as inputMr.Coffee 2014-09-18T14:57:24.770

OK, next question is: bare multisig output or p2sh multisig?amaclin 2014-09-18T15:00:37.023

It is p2sh script, created by './bitcoin-cli createmultisig <num required> <addresses|pubkeys>'Mr.Coffee 2014-09-18T15:11:54.337

Answers

4

pubkeySize=33
sigSize=72


SizeOfRedeemScript = 1+n*pubkeySize+1+1
SizeOfScriptSig = 1+m*(1+sigSize)+SizeOfVarIntFor(RedeemScript)+SizeOfRedeemScript
sizeOf(input) = 32+4+SizeOfVarIntFor(SizeOfScriptSig) + SizeOfScriptSig + 4

SizeOfScriptPubKey = SizeOfVarIntFor(lengthOfScript) + len(script)
sizeOf(output) = 8 + SizeOfScriptPubKey

sizeOf(tx) = 4 + SizeOfVarIntFor(numInputs) + sum(SizeOfInputsArray) + SizeOfVarIntFor(numOutputs) + sum(SizeOfOutputsArray) + 4

Basically, once you know m & n (for your multisig), whether public keys are compressed (pubkeySize), plus the number of inputs and outputs, plus the types of outputs, you can come up with a pretty accurate figure for the size.

karimkorun

Posted 2014-09-18T09:24:47.377

Reputation: 763

I've added "sum(SizeOfOutputsArray)" to the last line, because it seemed to be missing.Murch 2017-08-02T18:25:16.540

@karimkorun what means SizeOfVarIntForGoko Gorgiovski 2017-08-30T16:06:04.283

https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer it's documented here. scripts and vectors are both data-types with variable length, so we prefix them with the length the parser should try to read. They have variable size also, and so are relevant to size estimation :)karimkorun 2018-01-14T22:20:02.707

what is len(script) here ? should SizeOfVarIntFor(RedeemScript) be SizeOfVarIntFor(SizeOfRedeemScript) ? is lengthOfScript the same as SizeOfScriptSig? If not, how is lengthOfScript generated?tipu 2018-12-26T19:15:45.160

0

I stepped over this while trying to solve a similiar question: "how much tx fees do I need to prepare?"... Though this is an older question, I thought it would be good still be ok to reply, so that others might benefit from the same research.

https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm

... Signatures are either 73, 72, or 71 bytes long, with probabilities approximately 25%, 50% and 25% respectively, although sizes even smaller than that are possible with exponentially decreasing probability.

Behind the Sigs there is normally the pubkey in hex, adding 33 Bytes for compressed, and 65 Bytes for uncompressed keys. So I calculate for a standard TX roughly 100 Bytes per sig. You already have your figures for inputs and outputs. My std 2 inputs/2 outputs TX is roughly 400Bytes. The Inputs part of a TX depends on the number of

pebwindkraft

Posted 2014-09-18T09:24:47.377

Reputation: 4 568

2Since the low-S rules was introduced, signature are 50% of the time 72 bytes and 50% of the time 71.Pieter Wuille 2017-07-10T19:27:11.713