3

Please refer to this question:

Calculator for estimated TX-Fees

I have a question for clarity, in response to James' answer as in his example of 2 inputs/1 output, I recently calculated using the formula provided in that question (and found all over the web) and confirming my inputs are both compressed:

size := X * 148 + Y * 34 + 10 +- X

I'm using a standard Electrum wallet with 2FA. I had 2 inputs each it's own address and a single output and wanted to spend them to a single address w/ no change address. 2-in/1-out

I calculated: (2 x 148) + (1 x 34) + 10 +- 2 = 338-342 bytes and James came up with 404 bytes (he used uncompressed inputs @ 180 bytes and the formula works out), yet the real transaction would up being 638 bytes (stuck in the pool now) which makes using formulas like the one above a little less trustworthy.

What am I missing? Why when using the formula above, some transactions are spot on and others are way off with no way for me to make sense of it, math doesn't lie so I must be using the formula wrong and I just can't see the forest through through the trees?

Short Answer (derived from the help of all 3 fine gents below): I am using a 2FA wallet and that inherently is a multi-signature wallet of which the formula (in my case, 2 signers) changes the formula to:

size := X * 295 + Y * 34 + 10 +- X
  • 2
    Could you tell us what wallet or software you're using? Is it possible that you are using a 2-of-3 multisignature wallet? 2-of-3 multisignature inputs are 295 bytes, and 295+295+34+10=634 (which is pretty close). – Murch Oct 30 '17 at 18:51
  • Electrum (up-to-date) standard wallet w/ 2FA. Again, a lot of past transactions using the same wallet add up perfectly using the compressed input sizes of 148bytes for calculation. – Philip Ingram Oct 30 '17 at 21:14
  • Or you had four inputs instead of two: 4*148+34+10 = 636. If you could link the transaction we would probably be able to tell you more. – Murch Oct 30 '17 at 21:23
  • I just found in this thread (https://bitcointalk.org/index.php?topic=2316977.msg23541254#msg23541254) explaining that when using a 2fa wallet, TrustedCoin becomes the 2nd signing party and essentially I have a multi-sig wallet without realizing this, so does that double up all inputs x 2 or simply change the input byte size to be 2 x 148 = 294? – Philip Ingram Oct 30 '17 at 21:52
  • 1
    related: https://bitcoin.stackexchange.com/q/30570/5406 – Murch Oct 30 '17 at 23:48
  • Thx Murch but I wasn't able to gather whether my conclusion is correct about my 2FA wallet and simply multiplying all my inputs x 2 or number of signers first before multiplying by 148. i.e. (2 x (# of inputs x 148 ) + (# of outputs x 34 ) + 10 +/- # of inputs? – Philip Ingram Oct 31 '17 at 23:33
  • 1
    No, you don't double the input size, rather the script has a different size altogether. A single 2-of-3 multisig input comes in at approximately 295 bytes. – Murch Oct 31 '17 at 23:37
  • Ah, that is exactly the clarity I needed to understand. I kind of feel like I need this in the format of answer so I choose it as the most appropriate one, as it provides more clarity that is lacking in many of the write ups found around the web on how to calc fees and transaction sizes. The first part of course was realizing 2FA adds to the size, significantly. – Philip Ingram Nov 01 '17 at 00:16

2 Answers2

3

What am I missing?

  1. Public keys can be compressed or uncompressed
  2. Signature can has slightly different size

And yes, Murch is right in his comment. The formula works only for p2pkh inputs and p2pkh outputs. No p2sh, no segwit, no anything except p2pkh

amaclin
  • 6,760
  • 1
  • 21
  • 32
  • As mentioned in OP, they appear to be compressed when I look at other transactions using the same wallet and everything adds up perfectly multiplying inputs by 148. Shouldn't this be a consistent formula across all transactions using the same wallet?

  • Can the sigs add that much to the size? Is there any way to calculate this relatively accurately beforehand? I mean my calc of 340 is very different than 638 and got me into some trouble and I'm still clueless how to calculate it properly, this feels like a never-ending search for the holy grail of information.

  • – Philip Ingram Oct 30 '17 at 21:24
  • I now understand w/ 2FA I have a multisig wallet and I understand why its done this way for security. I also realize now that I was not just calculating only "send" transactions and that was an oversight on my part. All send transactions historically work with the formula: (# of Inputs x (148 x 2)) + (# of Outputs x 34) + 10 +- # of Inputs. Don't have enough cred yet to vote your answer up but thx, you both have been very helpful. – Philip Ingram Oct 30 '17 at 22:01