Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: piuk on August 17, 2011, 03:39:20 PM



Title: Question about transaction outputs.
Post by: piuk on August 17, 2011, 03:39:20 PM
When a bitcoin user sends an amount smaller than the size of their balance it is my understanding that two transactions are created and the remainder is sent back to the user. In a transaction such as this:

Quote
{
            "hash" : "6d124d67f4ebfd7a2b4e05852a86980b665f3e46903dd3177c12b3ebeb6ffbb6",
            "version" : 1,
            "lock_time" : 0,
            "size" : 259,
            "in" : [
                {
                    "prev_out" : {
                        "hash" : "5add561ad3d8e0e554809623509681101c85a666c5e48a5c3887c7c922e7841a",
                        "n" : 0
                    },
                    "scriptSig" : "3046022100b05a8751279e78c5096c536af528532f37e16c92ca9a4ac0f91e279f5f65990302210 0be87185a99bc6ace21209f13b148d44eaef2a2d7df6fda67bef84ab2e927b71701 04e6a2a199649366be01cabb1d9019ab755de0add011bfc2ea34c4c0243f1f80a708a2c2d53a91b f44bba215df1a4b1c8ebbe13480da35db73f080b425e05532ad"
                }
            ],
            "out" : [
                {
                    "value" : 18.44000000,
                    "scriptPubKey" : "OP_DUP OP_HASH160 1106a35156e021ac69bfb0fc0922a633447214e0 OP_EQUALVERIFY OP_CHECKSIG"
                },
                {
                    "value" : 0.01000000,
                    "scriptPubKey" : "OP_DUP OP_HASH160 b644b4754ea9a24ff7932b6d63e0878be63bd155 OP_EQUALVERIFY OP_CHECKSIG"
                }
            ]
 }

Is there anyway to determine which output was "real" and which one was returned to the original owner?


Title: Re: Question about transaction outputs.
Post by: piuk on August 17, 2011, 08:27:03 PM
I guess it is not possible then? i.e. there is no relationship between prev_out hash and any of the out hashes?


Title: Re: Question about transaction outputs.
Post by: jackjack on August 17, 2011, 08:40:36 PM
Nope, impossible to know because the output address is a pool key which never was used before


Title: Re: Question about transaction outputs.
Post by: samr7 on August 17, 2011, 08:41:14 PM
I guess it is not possible then? i.e. there is no relationship between prev_out hash and any of the out hashes?

Somebody who knows the source better than I can correct, but it looks like the output for "change" is inserted at a random position in the transaction.  See CWallet::CreateTransaction(), wallet.c:969 (https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L969).  So, there shouldn't be any deterministic clues.


Title: Re: Question about transaction outputs.
Post by: piuk on August 17, 2011, 08:52:57 PM
Ok thanks.


Title: Re: Question about transaction outputs.
Post by: Forp on August 17, 2011, 09:06:40 PM
Somebody who knows the source better than I can correct, but it looks like the output for "change" is inserted at a random position in the transaction.  See CWallet::CreateTransaction(), wallet.c:969 (https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L969).  So, there shouldn't be any deterministic clues.

From my point of view it is a correct reading of the source but an incorrectly drawn conclusion.

Example: Assume a transaction hat the outputs X and Y. Then usually ONE is the recipient of the payment and the OTHER is the original owner of the coins. Now assume that X is a well known bitcoin address (for example a donation address mentioned here in the forum). In this case you can safely conclude that Y belongs to the original owner of the coins.







Title: Re: Question about transaction outputs.
Post by: kjj on August 18, 2011, 12:00:13 PM
You can guess based on the amounts and have a very good chance of getting it right.  The code looks for the smallest single transaction larger than the spend amount to redeem, if possible, and then the smallest group of transactions.

For better privacy, the client could attempt to make the spend and the change roughly equal in size, but that will churn the wallet and make you pay higher fees in the long run.


Title: Re: Question about transaction outputs.
Post by: piuk on August 18, 2011, 05:04:20 PM
thanks for your help kjj and forp, I think i can come up with a pretty accurate guess using both those methods.

Another thing i'm confused about. How to I determine the address the block reward was sent to? e.g. is their some way to extract the address out of "scriptSig"?


Title: Re: Question about transaction outputs.
Post by: jackjack on August 18, 2011, 05:14:30 PM
thanks for your help kjj and forp, I think i can come up with a pretty accurate guess using both those methods.

Another thing i'm confused about. How to I determine the address the block reward was sent to? e.g. is their some way to extract the address out of "scriptSig"?
Take the 65 bytes starting with 04, it's the public key
Then, do that: http://dl.dropbox.com/u/1139081/BitcoinImg/PubKeyToAddr.png