Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: NicosKaralis on May 05, 2015, 02:15:44 PM



Title: Identify the sender in transactions with more than one sender
Post by: NicosKaralis on May 05, 2015, 02:15:44 PM
I'm developing a lottery based game similar to http://luckyb.it for a third party, everything was fine until I come up with this transaction: https://blockchain.info/tx/a7d35ae556e866ca4d2fa692ae4760782c2c95622fbcf22f9c05aa59996e7e5f

How do I detect which address is the sender in a transaction with multiple sender(and if is relevant multiple receivers)?

I sent the BTC to 164fCo3798s6Nk99MRQ5bkT9bEvNnSGc5b but my wallet (HD) also transfer some funds to 15DTdHq2TaZDvzKcHCeCp24CmhNJhQhHpa
In this case how can I detect to which address I should return the winnings?

Outputs
Quote
1HAYB6Sa6nJkB1bgGcAxVHVMnWLuGx5egi (0.01067782 BTC)
15fSktiWqTNf4wsGnG6XHqPpj3r6aMhj9N (0.01617602 BTC)
1ESLiFtyK2nKw98MLbupYSsgGyLz5w3KxU (0.0885 BTC)
1BJ7dZqeQEFV22Dr1KSRKqSY6jqnbFTG3p (0.01142016 BTC)
Inputs
Quote
164fCo3798s6Nk99MRQ5bkT9bEvNnSGc5b - 0.015904 BTC
15DTdHq2TaZDvzKcHCeCp24CmhNJhQhHpa - 0.11077 BTC

I tried to open some old transactions from luckyb.it and I found this examples:

https://blockchain.info/tx/a2a48b476111ca163f917028c11930887b49d9f22354f3c923243b1b528738e9
In this case each output is a different bet, so no problem at all

https://blockchain.info/tx/9456a0715b2ef5bb7274771c7622999d35d3f2991d667f7da3d84a2e5a8ba826
In this one the same address sent 2 outputs but one for luckybit and other for himself, does luckybit recognise 2 bets? I think not.
Also this is fine because each output have the same address, meaning we have just one address to return.

But what about this one: https://blockchain.info/tx/bc7d54aed374fafa0efce2add6b03e446cb3193c38a7c582d5d443af1bb44f05
This have 2 outputs with different addresses and 2 inputs also for different addresses.
How can I determinate in which address I should return the winnings?


Title: Re: Identify the sender in transactions with more than one sender
Post by: DannyHamilton on May 05, 2015, 02:50:00 PM
I'm developing a lottery based game similar to http://luckyb.it for a third party, everything was fine until I come up with this transaction: https://blockchain.info/tx/a7d35ae556e866ca4d2fa692ae4760782c2c95622fbcf22f9c05aa59996e7e5f

How do I detect which address is the sender in a transaction with multiple sender(and if is relevant multiple receivers)?

I sent the BTC to 164fCo3798s6Nk99MRQ5bkT9bEvNnSGc5b but my wallet (HD) also transfer some funds to 15DTdHq2TaZDvzKcHCeCp24CmhNJhQhHpa
In this case how can I detect to which address I should return the winnings?

Outputs
Quote
1HAYB6Sa6nJkB1bgGcAxVHVMnWLuGx5egi (0.01067782 BTC)
15fSktiWqTNf4wsGnG6XHqPpj3r6aMhj9N (0.01617602 BTC)
1ESLiFtyK2nKw98MLbupYSsgGyLz5w3KxU (0.0885 BTC)
1BJ7dZqeQEFV22Dr1KSRKqSY6jqnbFTG3p (0.01142016 BTC)
Inputs
Quote
164fCo3798s6Nk99MRQ5bkT9bEvNnSGc5b - 0.015904 BTC
15DTdHq2TaZDvzKcHCeCp24CmhNJhQhHpa - 0.11077 BTC

I tried to open some old transactions from luckyb.it and I found this examples:

https://blockchain.info/tx/a2a48b476111ca163f917028c11930887b49d9f22354f3c923243b1b528738e9
In this case each output is a different bet, so no problem at all

https://blockchain.info/tx/9456a0715b2ef5bb7274771c7622999d35d3f2991d667f7da3d84a2e5a8ba826
In this one the same address sent 2 outputs but one for luckybit and other for himself, does luckybit recognise 2 bets? I think not.
Also this is fine because each output have the same address, meaning we have just one address to return.

But what about this one: https://blockchain.info/tx/bc7d54aed374fafa0efce2add6b03e446cb3193c38a7c582d5d443af1bb44f05
This have 2 outputs with different addresses and 2 inputs also for different addresses.
How can I determinate in which address I should return the winnings?

You should never try to guess what address to send bitcoins to.  If you guess wrong, then the bitcoins are permanently lost.

You should never look at inputs to try to figure out where bitcoins should be sent "back" to, since the original sender might not have control of that address.

Instead you should ALWAYS ask your users where they want their bitcoins sent.  You should allow them to enter a bitcoin address, and then send the bitcoins to the entered address.

(There's no such thing as a "sending address".  Attempting to guess at a "return address" by looking at the previous outputs that were used to supply value for the inputs of a transaction is a good way to cause frustration, lose money, and create confusion.)


Title: Re: Identify the sender in transactions with more than one sender
Post by: spin on May 05, 2015, 02:51:45 PM
You probably want to read up on this: https://en.bitcoin.it/wiki/From_address
Which Danny gave a short summary of.


Title: Re: Identify the sender in transactions with more than one sender
Post by: grtthegreat on May 05, 2015, 04:25:46 PM
----------SNIP---------

If you are developing a game similar to LuckyBit, then you need to know that it allows only some wallets, which they call "compatible wallets". These wallets are those which specifically allow you to control your own private keys. Some wallets are Electrum, Bitcoin-Qt, Multibit, Armory. Third party wallets like Coinbase, Xapo, etc use multiple addresses (also, they are anonymous) and they send money from completely new addresses every time which aren't under your control. So, better notify users to use only the compatible wallets like Blockchain, Electrum, Bitcoin-Qt, Multibit, Armory once the site comes live. If someone still uses incompatible wallets, its something you cannot help the user with.

Anyways, wishing you good luck with your new game.


Title: Re: Identify the sender in transactions with more than one sender
Post by: altcoinex on May 05, 2015, 04:52:47 PM
In addition to everything outlined above, 'reusing addresses' is considered bad practice. It is better and more secure for them to have a new receiving address, rather than it returned to the sending one, even if that one could be verified as the sender. (see: https://en.bitcoin.it/wiki/Address_reuse)