0

I have ready about 10 posts that are similar and none of them seem to answer my question so any help is appreciated.

My question is how to miners technically determine if a "wallets" has the "balance" to complete the transaction. Before you say this is a duplicate let me elaborate:

User A has private key A and Public key A.1 and A.2 User B has private key B and Public key B.1 and B.2

Transaction 1 A-> B.1 by User B sending B.1 to A and A signs the transaction (0.5 BTC for illustration) with that private Key. Transaction 2 A-> B.2 by user B sending B.2 to A and A signs the transaction (0.5 BTC) with that same private key.

Now private Key B has 1 BTC. But sense No one knows that B.1 a and B.2 belong to B because those are derived dynamically from B how can you know how much A has? Further suppose you loose track of you public keys, so B.1 and B.2 have been forgotten. How are you able to figure out the bitcoins that B has access to?

5

The blockchain does not see wallets at all. It only sees spent and unspent transaction outputs (txouts). A txout is either completely spent or completely unspent - it cannot be "partially" spent and so there is no notion of balance. (If you want to spend less than the full value of a transaction, you create a change output.)

In your example, there are now two txouts that B can spend. The "private key" B would actually be a master private key - each "derived" key is really a keypair consisting of a private key B.1.priv and a public key B.1.pub. So in order to spend the txout that was paid to B.1, user B must sign a transaction using the private key B.1.priv. If B wants to spend the entire 1 BTC, she can create a transaction with two inputs and signed by both B.1.priv and B.2.priv.

It is true that nobody except B (and maybe A) knows that both txouts are spendable by the same person. That is fine - they don't need to know. This is considered a desirable privacy feature.

If B should lose B.1.pub, no problem - it can be regenerated from B.1.priv. This is part of how ECDSA works. If she should lose B.1.priv, it can be regenerated from the master private key B. If she loses the master private key, she is out of luck and cannot spend her coins.

  • wait but suppose I have my 12 word backup and I loose everything and re import my master private key from the words, how would I determine which private keys B.1.priv and B.2.priv? – noone392 Oct 22 at 1:32
  • @noone392 the wallet will derive keypairs from the master key, and then check to see if there are any valid UTXOs that are spendable by a key the wallet controls. – chytrik Oct 22 at 2:30
  • @chytrik so you saying there is some policy to derive keys sequentially in a repeatable way, then you generate the first say 100 keys and perform a verification on all 18 million BTC?! So validating the spendable amount requires probably 1.8 billion asymmetric operations? – noone392 Oct 22 at 2:40
  • 4
    No, that would be a very inefficient way to do it. For details of the key derivation see BIP32/39/44/84, eg: github.com/bitcoin/bips/blob/master/bip-0032.mediawiki. For the balance check, it will depend on what type of wallet you are using, there are several different ways it might be done (full node vs SPV, etc). But in general, the network does not keep track of individual coins, it keeps track of 'UTXOs', so the wallet just needs to filter the current UTXO set for any entries that are spendable by one of it's keys. See BIP 37/157/158 for more info. – chytrik Oct 22 at 2:49
  • 1
    A signature actually includes the public key corresponding to the private key that is used to sign. So yes, if you want to send 0.75 BTC, you will need at least two inputs, each signed by the corresponding (derived) private key and including the corresponding (derived) public key. – Nate Eldredge Oct 22 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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