Bitcoin Forum
May 06, 2024, 04:37:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to get an address/public key from a CTxIn ?  (Read 924 times)
earlz (OP)
Sr. Member
****
Offline Offline

Activity: 439
Merit: 250


mmmmmm


View Profile WWW
May 26, 2014, 06:21:08 PM
 #1

I'm trying to modify how change addresses work in Bitcoin 0.9 and desire to change the code (wallet.cpp:1399) so that instead of sending change from a transaction to a new key, it will send  it back to one of the addresses that was used as an input. The only thing I have access to in this area though is a list of CTxIns. I see no clear way of deriving a bitcoin address though from a CTxIn. There are things like the script used for the input, but I see no clear cut way of seeing the address the CTxIn is associated with

Can anyone give me a hint as to how to do this?

My best guess was to use a previous vout CScript from one of the CTxIn inputs, but this would cause problems when using non-standard transactions to send funds, and causes peculiar scripts from solomined transactions. 

Check out my full list of Coin Reviews
Currently working on the Qtum Project
My Skype account earlzdotnet has been compromised. Please report to me any usage seen from it, or from the email earlz@earlz.biz.tm
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
The network tries to produce one block per 10 minutes. It does this by automatically adjusting how difficult it is to produce blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
1715013426
Hero Member
*
Offline Offline

Posts: 1715013426

View Profile Personal Message (Offline)

Ignore
1715013426
Reply with quote  #2

1715013426
Report to moderator
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
May 26, 2014, 07:27:10 PM
 #2

That is a terrible idea. It circumvents behavior that is designed to make bitcoin safer for users, and does so in a way which may not be safe when interfacing with other transaction construction protocols. Please don't do it.

But so as to not be a complete jerk, I will answer your specific question: you need the input's referenced output. The transaction intput has a hash and vout index which you can use to lookup the output from the UTXO set (if it exists and is unspent). The scriptPubKey in that output is the "address" you are looking for.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
dexX7
Legendary
*
Offline Offline

Activity: 1106
Merit: 1024



View Profile WWW
May 26, 2014, 09:19:12 PM
 #3

Or you may extract the public key directly from the script sig - in the case you know the type of the incoming transaction.

Format: [signature] [public key], see: https://en.bitcoin.it/wiki/Script#Standard_Transaction_to_Bitcoin_address_.28pay-to-pubkey-hash.29

maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
May 26, 2014, 10:22:11 PM
 #4

you cannot assume anything about the values in the scriptSig without knowing the scriptPubKey

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
earlz (OP)
Sr. Member
****
Offline Offline

Activity: 439
Merit: 250


mmmmmm


View Profile WWW
May 27, 2014, 03:22:06 AM
 #5

That is a terrible idea. It circumvents behavior that is designed to make bitcoin safer for users, and does so in a way which may not be safe when interfacing with other transaction construction protocols. Please don't do it.

But so as to not be a complete jerk, I will answer your specific question: you need the input's referenced output. The transaction intput has a hash and vout index which you can use to lookup the output from the UTXO set (if it exists and is unspent). The scriptPubKey in that output is the "address" you are looking for.

Thanks for the hints Smiley As for the actual idea, change is usually pretty obvious anyway, since the actual amount sent is commonly a round number, and change is not. I'm curious what construction protocols it might break though, the code itself would only be used for building standard transactions in the wallet

Check out my full list of Coin Reviews
Currently working on the Qtum Project
My Skype account earlzdotnet has been compromised. Please report to me any usage seen from it, or from the email earlz@earlz.biz.tm
dexX7
Legendary
*
Offline Offline

Activity: 1106
Merit: 1024



View Profile WWW
May 27, 2014, 05:34:50 PM
 #6

you cannot assume anything about the values in the scriptSig without knowing the scriptPubKey

Well, this is why I wrote "in the case you know the type of the incoming transaction". Wink

You could furthermore test, if the alleged public key forms a valid ECDSA point or you could try to recover the public key from a signature.

In the php-bitcoin-signature-routines library there is a note to:

SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public Key Recovery Operation"
http://www.secg.org/download/aid-780/sec1-v2.pdf

maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
May 27, 2014, 08:49:10 PM
 #7

Thanks for the hints Smiley As for the actual idea, change is usually pretty obvious anyway, since the actual amount sent is commonly a round number, and change is not. I'm curious what construction protocols it might break though, the code itself would only be used for building standard transactions in the wallet

The fact that wallets are sending round numbers is the flaw. That's what you should be working to fix, not making users transactions even more identifiable.

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!