Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Meni Rosenfeld on August 08, 2013, 05:03:03 PM



Title: Help using Multisig transactions
Post by: Meni Rosenfeld on August 08, 2013, 05:03:03 PM
I tried experimenting with Multisig and followed Gavin's example (https://gist.github.com/gavinandresen/3966071), running Bitcoin-qt v0.8.3 and using the debug console.

However, I could not get it to work.

I'm using the following 3 keys, all generated in my bitcoin-qt wallet:

privkey: L2JjrJNUJjLwLHcLShFsbJVt6KuWqE3svqMUrfwbNJXgssujVWgV
pubkey: 02fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc2

privkey: L1HKChJArnfKpApV7Cz7HEw9c5YKHRr9BwWtFf6f8RYmnyDXrq87
pubkey: 02a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d10

privkey: L1hbxmK8H4dkk2dyHpNEN7H7RvAhaJnQUH27cdC4yAtAjQ1TNkdA
pubkey: 037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f1123

I created a multisig address:

Code:
createmultisig 2 '["02fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc2","02a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d10","037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f1123"]'

{
"address" : "3P1TEdL5DJYeRTSxYsaR4onfjQyZrQ5oGL",
"redeemScript" : "522102fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc22102a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d1021037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f112353ae"
}

Went on to fund it (with the GUI). Details of funding transaction (https://blockchain.info/tx/683e77cbac7356bab448a90a0f652ab68314c1b026833431cd56abaf40d6031b):
Code:
decoderawtransaction 0100000001d97502e9eee14adedc356a000c8e506d1e62e49242c7519281410d6cacde91d11d0000006b483045022100f4dfccaa5871a28f2843e0179142693963c24ead8b8e7238fca1fe989d56debd02201526d623fcb53b1c295116eee655b800c7dc8f29f32d7eed2fe4974c4c2ae2df012102095d1ffb1a31b9adceb15d006230b1987e34a6816680ac9e8917019a5445a360ffffffff0232082a00000000001976a91498070b4f2c6f333ed11396830c9932d84ef9e2c788ac40420f000000000017a914e9d7420b3e02e16089372cd9b9c77c58b3e133248700000000

{
"txid" : "683e77cbac7356bab448a90a0f652ab68314c1b026833431cd56abaf40d6031b",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "d191deac6c0d41819251c74292e4621e6d508e0c006a35dcde4ae1eee90275d9",
"vout" : 29,
"scriptSig" : {
"asm" : "3045022100f4dfccaa5871a28f2843e0179142693963c24ead8b8e7238fca1fe989d56debd02201526d623fcb53b1c295116eee655b800c7dc8f29f32d7eed2fe4974c4c2ae2df01 02095d1ffb1a31b9adceb15d006230b1987e34a6816680ac9e8917019a5445a360",
"hex" : "483045022100f4dfccaa5871a28f2843e0179142693963c24ead8b8e7238fca1fe989d56debd02201526d623fcb53b1c295116eee655b800c7dc8f29f32d7eed2fe4974c4c2ae2df012102095d1ffb1a31b9adceb15d006230b1987e34a6816680ac9e8917019a5445a360"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.02754610,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 98070b4f2c6f333ed11396830c9932d84ef9e2c7 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91498070b4f2c6f333ed11396830c9932d84ef9e2c788ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1Err9baeyDLCqundwncXonx8ea1v1WmS5o"
]
}
},
{
"value" : 0.01000000,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_HASH160 e9d7420b3e02e16089372cd9b9c77c58b3e13324 OP_EQUAL",
"hex" : "a914e9d7420b3e02e16089372cd9b9c77c58b3e1332487",
"reqSigs" : 1,
"type" : "scripthash",
"addresses" : [
"3P1TEdL5DJYeRTSxYsaR4onfjQyZrQ5oGL"
]
}
}
]
}

And then tried to spend funds from the multisig address:
Code:
createrawtransaction '[{"txid":"683e77cbac7356bab448a90a0f652ab68314c1b026833431cd56abaf40d6031b","vout":1,"scriptPubKey":"a914e9d7420b3e02e16089372cd9b9c77c58b3e1332487","redeemscript":"522102fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc22102a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d1021037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f112353ae"}]' '{"1BBsbEq8Q29JpQr4jygjPof7F7uphqyUCQ":0.0002}'

01000000011b03d640afab56cd31348326b0c11483b62a650f0aa948b4ba5673accb773e680000000000ffffffff01204e0000000000001976a9146fbfa5eb9cf96799b0ff7d25f9e3ea9e4323db5988ac00000000

signrawtransaction '01000000011b03d640afab56cd31348326b0c11483b62a650f0aa948b4ba5673accb773e680100000000ffffffff01204e0000000000001976a9146fbfa5eb9cf96799b0ff7d25f9e3ea9e4323db5988ac00000000' '[{"txid":"683e77cbac7356bab448a90a0f652ab68314c1b026833431cd56abaf40d6031b","vout":1,"scriptPubKey":"a914e9d7420b3e02e16089372cd9b9c77c58b3e1332487","redeemscript":"522102fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc22102a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d1021037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f112353ae"}]' '["L2JjrJNUJjLwLHcLShFsbJVt6KuWqE3svqMUrfwbNJXgssujVWgV"]'

Missing redeemScript (code -3)
When trying to sign all I get is the error message "Missing redeemScript (code -3)", even though the redeemScript for the multisig address is included in the data. Same thing happens if I use a different privkey format.

If I don't specify privkeys at all, nothing happens, even though the needed keys are in the unlocked wallet:
Code:
signrawtransaction '01000000011b03d640afab56cd31348326b0c11483b62a650f0aa948b4ba5673accb773e680100000000ffffffff01204e0000000000001976a9146fbfa5eb9cf96799b0ff7d25f9e3ea9e4323db5988ac00000000' '[{"txid":"683e77cbac7356bab448a90a0f652ab68314c1b026833431cd56abaf40d6031b","vout":1,"scriptPubKey":"a914e9d7420b3e02e16089372cd9b9c77c58b3e1332487","redeemscript":"522102fff1a3da4dbc93d10fba4791689411a17d8308770f9cf6ea5854358441df6bc22102a06a164106420bcc36908700af4dccc727b1e834f7424f1627623523d6751d1021037bac6d147cd915b74f51c0e839d5345d816b2ab70da0a862b5bef6ab6d7f112353ae"}]'

{
"hex" : "01000000011b03d640afab56cd31348326b0c11483b62a650f0aa948b4ba5673accb773e680100000000ffffffff01204e0000000000001976a9146fbfa5eb9cf96799b0ff7d25f9e3ea9e4323db5988ac00000000",
"complete" : false
}

Any ideas what the problem is?


Title: Re: Help using Multisig transactions
Post by: genjix on August 08, 2013, 05:55:06 PM
Maybe this is useful for you: https://bitcointalk.org/index.php?topic=270205.0 (sx: bash script for creating, redeeming and sending multisignature transaction)

Tutorial: http://sx.dyne.org/multisig.html


Title: Re: Help using Multisig transactions
Post by: Meni Rosenfeld on August 08, 2013, 06:20:04 PM
Maybe this is useful for you: https://bitcointalk.org/index.php?topic=270205.0 (sx: bash script for creating, redeeming and sending multisignature transaction)

Tutorial: http://sx.dyne.org/multisig.html
Thanks, however this is less intuitive for me than using the raw transaction API directly. (though a GUI would have been much preferred over either)


Title: Re: Help using Multisig transactions
Post by: dserrano5 on August 08, 2013, 07:33:03 PM
Could it be that you're using "redeemscript" instead of "redeemScript", ie with a small "s" instead of a capital one?


Title: Re: Help using Multisig transactions
Post by: Judson on August 08, 2013, 07:54:02 PM
Yep, what dserrano5 said. The error should point you in the right direction: "Missing redeemScript".


Title: Re: Help using Multisig transactions
Post by: Meni Rosenfeld on August 08, 2013, 08:20:37 PM
Could it be that you're using "redeemscript" instead of "redeemScript", ie with a small "s" instead of a capital one?
Yep, what dserrano5 said. The error should point you in the right direction: "Missing redeemScript".
I'm an idiot. Thanks.

It pointed me at the right direction, but I didn't notice the case discrepancy, and since this datum was included in previous calls I assumed this kind of an error would have caused problems earlier.


Title: Re: Help using Multisig transactions
Post by: cbeast on August 08, 2013, 11:17:10 PM
Thanks for posting this Meni. I was missing some points to understanding this from Gavin's example. I wish someone would write a step-by-step guide to creating m-of-n and nLockTime transactions.


Title: Re: Help using Multisig transactions
Post by: kjj on August 09, 2013, 04:03:25 AM
Could it be that you're using "redeemscript" instead of "redeemScript", ie with a small "s" instead of a capital one?
Yep, what dserrano5 said. The error should point you in the right direction: "Missing redeemScript".
I'm an idiot. Thanks.

It pointed me at the right direction, but I didn't notice the case discrepancy, and since this datum was included in previous calls I assumed this kind of an error would have caused problems earlier.

In case you were wondering why it didn't trigger on previous calls, the redeemScript isn't needed until signing.  You can stuff arbitrarily named members into that object without a problem.  Those functions only check to make sure they have the parts they need, they don't reject extra stuff, they just ignore it.


Title: Re: Help using Multisig transactions
Post by: cbeast on August 15, 2013, 02:59:52 AM
I followed Gavin's example (https://gist.github.com/gavinandresen/3966071). I created 3 vanity testnet addresses and took 1.5 test bitcoins from the faucet. I followed the example and created a 2 of 3 multisig with "value" : 0.01000000 sent from n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8 (http://blockexplorer.com/testnet/address/n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8) to 2MuiZNuQR2vEmCq81XRTGRSHNETUGxEWR3C (http://blockexplorer.com/testnet/tx/d27ddcaf3542094ef0cd141b7133e4398a673e291a8c6bedd5d8956937f7bdef), but it sent the entire balance of 1.5 instead of 0.1. I have not yet imported the vanity addresses into a client to recover the test bitcoins. What happened to the change?


Title: Re: Help using Multisig transactions
Post by: kjj on August 15, 2013, 03:15:19 AM
I followed Gavin's example (https://gist.github.com/gavinandresen/3966071). I created 3 vanity testnet addresses and took 1.5 test bitcoins from the faucet. I followed the example and created a 2 of 3 multisig with "value" : 0.01000000 sent from n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8 (http://blockexplorer.com/testnet/address/n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8) to 2MuiZNuQR2vEmCq81XRTGRSHNETUGxEWR3C (http://blockexplorer.com/testnet/tx/d27ddcaf3542094ef0cd141b7133e4398a673e291a8c6bedd5d8956937f7bdef), but it sent the entire balance of 1.5 instead of 0.1. I have not yet imported the vanity addresses into a client to recover the test bitcoins. What happened to the change?

Transactions are redeemed in full.  When using the raw API, you are responsible for making your own change.

In this case, your inputs total 1.5 and out outputs total 0.01.  The difference, 1.49, is the fee.


Title: Re: Help using Multisig transactions
Post by: cbeast on August 15, 2013, 03:27:16 AM
I followed Gavin's example (https://gist.github.com/gavinandresen/3966071). I created 3 vanity testnet addresses and took 1.5 test bitcoins from the faucet. I followed the example and created a 2 of 3 multisig with "value" : 0.01000000 sent from n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8 (http://blockexplorer.com/testnet/address/n18BfALhuJ4cXAtTDSMLSpiRjLvB6czXP8) to 2MuiZNuQR2vEmCq81XRTGRSHNETUGxEWR3C (http://blockexplorer.com/testnet/tx/d27ddcaf3542094ef0cd141b7133e4398a673e291a8c6bedd5d8956937f7bdef), but it sent the entire balance of 1.5 instead of 0.1. I have not yet imported the vanity addresses into a client to recover the test bitcoins. What happened to the change?

Transactions are redeemed in full.  When using the raw API, you are responsible for making your own change.

In this case, your inputs total 1.5 and out outputs total 0.01.  The difference, 1.49, is the fee.
This is why we use TESTNET!