Bitcoin Forum
November 05, 2024, 07:49:11 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Get multisig address from pubkey in a transaction  (Read 820 times)
reiven (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 28, 2014, 03:57:50 PM
Last edit: April 28, 2014, 08:09:45 PM by reiven
 #1

Hi!

I'm trying to get the source address of a transaction from the asm pubkey, which works fine for mainnet and testnet, but if the source is a multisig address, the resulting address is invalid.

For example, on testnet i create this 2/3 address 2N8DirDvhxVEm61b3JMc75Hsdqe8aWg9Vvu , get some funds and later i create this tx back to a "normal" address http://blockexplorer.com/testnet/tx/e7e04c76db37dc63cb903935c51ffe24b3019cb33e402346a271d3af503fe06b.
The vin.scriptSig.asm looks like
Code:
"0 30440220481206604c5d12c8a6b020d822a65e0c2f9eeb536bdcdc668fab56247b30e44102202caf1fb53475495bd15fb42eaa5dd49fce70ae613e35a67055d7637c32997cac01 3045022100f5d9576238d7ed616646336feaafbf42e3a9331da65d3a76872c41aa709a3926022039f7090c07049853a941e69d9b31d9d0e6e9a34e91c16e67d516a91bba4ef02701 52210355f3c263aeb7859e53d3549d3c9bc99cd581154d16e259fe390e029d6bda5b7821030a53f844570b8c26794276e205cdeab87ab0d7802d2abb5116a5472e3adc7dc1210210b58f846754a9d0d70e226688e0693a241fd58e315d738399e40e68308b88f953ae"

None of the that can be converted back to 2N8DirDvhxVEm61b3JMc75Hsdqe8aWg9Vvu

It will be possible to get the source address of a multisig in a tx?

Probably the documentation of https://en.bitcoin.it/wiki/Transactions#Input should be updated for multisig, actually it only explains the "two components, a signature and a public key" which is not true for this kind of transactions, correct?

Thanks
edmundedgar
Sr. Member
****
Offline Offline

Activity: 352
Merit: 250


https://www.realitykeys.com


View Profile WWW
April 29, 2014, 01:54:58 AM
 #2

I'm not absolutely confident I've understood what you're trying to get out, but what you've got there is a P2SH (pay-to-script-hash) address. P2SH is discussed lower down the page you link to:
https://en.bitcoin.it/wiki/Transactions#Pay-to-ScriptHash

What's confusing about this is that it was possible to do multisig before P2SH was introduced, and some docs you may read will talk about doing multisig the traditional way, but nowadays since in practice multisig nearly always means "multisig under P2SH", people sometimes talk about a multisig transaction without mentioning the fact that it's using P2SH.

The sigscript you posted:
Code:
"0 30440220481206604c5d12c8a6b020d822a65e0c2f9eeb536bdcdc668fab56247b30e44102202caf1fb53475495bd15fb42eaa5dd49fce70ae613e35a67055d7637c32997cac01 3045022100f5d9576238d7ed616646336feaafbf42e3a9331da65d3a76872c41aa709a3926022039f7090c07049853a941e69d9b31d9d0e6e9a34e91c16e67d516a91bba4ef02701 
52210355f3c263aeb7859e53d3549d3c9bc99cd581154d16e259fe390e029d6bda5b7821030a53f844570b8c26794276e205cdeab87ab0d7802d2abb5116a5472e3adc7dc1210210b58f846754a9d0d70e226688e0693a241fd58e315d738399e40e68308b88f953ae
"

...consists of:
- A zero (to work around a bug)
- Sig1
- Sig2
- A serialized script which, when hashed and appropriately encoded (I'd have to look this up - I haven't checked to see if the things you posted work as I expect) should make the "address" that somebody originally paid, eg 2N8DirDvhxVEm61b3JMc75Hsdqe8aWg9Vvu.

The serialized script (the long thing that comes last in your sigscript) should deserialize to something like:
Code:
2 pub pub pub 3 op_checkmultisig

...so you should also be able to get the public keys used in the signatures from there if you're interested in those.
reiven (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 29, 2014, 02:56:37 AM
 #3

Yes, you got the point of what i'm trying to do Smiley

What i cannot find (yet) is how to "deserialize" the P2SH which you describe. Can you bring me some light on this?
Additionally reading B13 it say "Version byte is 5 for a main-network address, 196 for a testnet address" and the scripts starts with 5 which is confusing me because all this txs was done on testnet.

Code:
52210355f3c263aeb7859e53d3549d3c9bc99cd581154d16e259fe390e029d6bda5b7821030a53f844570b8c26794276e205cdeab87ab0d7802d2abb5116a5472e3adc7dc1210210b58f846754a9d0d70e226688e0693a241fd58e315d738399e40e68308b88f953ae

Just to let you know, this test tx was done on core-client v0.9.1 (i dont know if that can be relevant to you)

Thanks
edmundedgar
Sr. Member
****
Offline Offline

Activity: 352
Merit: 250


https://www.realitykeys.com


View Profile WWW
April 29, 2014, 04:15:39 AM
 #4

If I've got this right the version byte goes in right at the end of the process when you convert something to base 58 check, which is the format designed for humans to transcribe and copy-paste. Don't worry that you don't see anything matching it in the hex.

I've been using vbuterin's pybitcointools for this stuff:
https://github.com/vbuterin/pybitcointools/blob/master/bitcoin/transaction.py

I can't test this on my phone but I think the deserialize_script function in there should work to unpack the content of the p2sh script. There's a p2sh_script_address function in there too which should let you recreate the address from the script, but it looks like it hard-codes the mainnet version byte, so you probably need to either fix it for testnet or pull out the inside of the function and use it directly with the correct version byte. (It's only two lines...)
reiven (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 29, 2014, 03:27:58 PM
 #5

Amazing, you make my day!

I've made a small change to transactions.py to support testnet and it worked smoothly

Code:
>>> p2sh_scriptaddr(p2sh)
'3GfWnUzgM2jQtDxVdDzETLtNdHvQiL3GjL'
>>> p2sh_scriptaddr(p2sh,testnet=True)
'2N8DirDvhxVEm61b3JMc75Hsdqe8aWg9Vvu'

Thanks a lot for your answers
edmundedgar
Sr. Member
****
Offline Offline

Activity: 352
Merit: 250


https://www.realitykeys.com


View Profile WWW
April 30, 2014, 12:38:07 AM
 #6

Glad to hear it worked.

I guess we should check for any other places where pybitcointool could handle testnet but doesn't and send vbuterin a pull request. Maybe better to pass in the version byte instead of a testnet flag - that way it should work for alt-coins as well.
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!