Title: Accomplish an AnyOneCanPay transaction? Post by: ethicnology on March 22, 2019, 09:18:31 PM Hi the community !
I've made a post two month ago to understand how does an AnyOneCanPay transaction works. (here -> https://bitcointalk.org/index.php?topic=5108249.new#new (https://bitcointalk.org/index.php?topic=5108249.new#new)) I tried many times to accomplish an AnyOneCanPay transaction on the TestNet but i still have some problems and questions. The scenario is : - Donator create a rawTx of his donation - Donator sign it with sigHash NONE|ANYONECANPAY - Receiver create a rawTx with one of his input and the donator input - Receiver sign it with sigHash ALL|ANYONECANPAY I'm using RPC commands on Bitcoin Core 17.1, below an exemple of what i've tried : //listunspent of the donator "txid": "29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991", "vout": 0, "address": "2N2CiqHX6zkk2L2ehppCfDPnZqpdSZDgGCQ", "label": "", "redeemScript": "0014e7edde28efdc0f40ef2c5608fe9adc49d10e7ee5", "scriptPubKey": "a914623ff66fb88ff802fe1b8eaff666ba52307eecb087", "amount": 0.10100000, "confirmations": 3, "spendable": true, "solvable": true, "safe": true //Donator create a rawTx with the gifted amount Code: createrawtransaction '[{"txid":"29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0}]' '[{"2MzFJHqvQtSAr35VWfbMz3sWDQBg28qgQPy":0.1}]' //Hex result : 020000000191195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a802900000 00000ffffffff01809698000000000017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b187 00000000 //Donator sign his rawTax with the sigHash "NONE|ANYONECANPAY" Code: signrawtransactionwithwallet "020000000191195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a80290000000000ffffffff01809698000000000017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b18700000000" '[{"txid":"29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0,"scriptPubKey":"a914623ff66fb88ff802fe1b8eaff666ba52307eecb087","redeemScript":"0014e7edde28efdc0f40ef2c5608fe9adc49d10e7ee5","amount":0.101}]' "NONE|ANYONECANPAY" //Hex result : 0200000000010191195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a80290 000000017160014e7edde28efdc0f40ef2c5608fe9adc49d10e7ee5ffffffff0180969800000000 0017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b18702473044022022fa9caf5c716c268 64bd474fd867cc8bf161244387b22a84f5b48e6608b53c70220209e9e1d47aa8a95d890824b1c41 0e340db523c8958f3657fb8a414998e90b20822102fa5aec9fe43bba4f70deb4e53acede24e5e62 1425f4b00575fce601874e8658300000000 _____________________________________________________________________ //listunspent of the Receiver "txid": "776be22ffbdda86283b247f99f7b2c6f7f53185cb8bc570bc65c6e6bb7ed8558", "vout": 1, "address": "2NDXeZ7hbSzbSiV6sMfUEMBjjwbRKH85BDd", "label": "", "redeemScript": "0014df7bcc159ade813e6bd6290d97ed0bc8987dc084", "scriptPubKey": "a914de7dad83bb2d6e9638d347dcb3c53fe238773c9387", "amount": 0.01000000, "confirmations": 5, "spendable": true, "solvable": true, "safe": true //Receiver create a rawTx and put donator input inside Code: createrawtransaction '[{"txid":"29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0}, //Hex result : 020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a802900000 00000ffffffff5885edb76b6e5cc60b57bcb85c18537f6f2c7b9ff947b28362a8ddfb2fe26b7701 00000000ffffffff01d08ea5000000000017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b 18700000000 //Receiver sign his rawTx with the sigHash "ALL|ANYONECANPAY" Code: signrawtransactionwithwallet "020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a80290000000000ffffffff5885edb76b6e5cc60b57bcb85c18537f6f2c7b9ff947b28362a8ddfb2fe26b770100000000ffffffff01d08ea5000000000017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b18700000000" '["txid":"29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0,"scriptPubKey":"a914623ff66fb88ff802fe1b8eaff666ba52307eecb087","redeemScript":"0014e7edde28efdc0f40ef2c5608fe9adc49d10e7ee5","amount":0.101}, {"txid":"776be22ffbdda86283b247f99f7b2c6f7f53185cb8bc570bc65c6e6bb7ed8558","vout":1, "scriptPubKey":"a914de7dad83bb2d6e9638d347dcb3c53fe238773c9387","redeemScript":"0014df7bcc159ade813e6bd6290d97ed0bc8987dc084","amount":0.01}]' "ALL|ANYONECANPAY" // Final result "hex": "0200000000010291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a80290 000000000ffffffff5885edb76b6e5cc60b57bcb85c18537f6f2c7b9ff947b28362a8ddfb2fe26b 770100000017160014df7bcc159ade813e6bd6290d97ed0bc8987dc084ffffffff01d08ea500000 0000017a9144ccc78e595a15f13a1a94c1cbe7b77de6f9c83b18700024730440220303e8c46356c 8b8b630cf0850e895d731c8e29196d01d344c9bd4f3d2fff6d4d02201c3d0df25f8d1cd2786488c 22ab404f236c05fdc2839328eedc2d5f54508278a812103794ac3861b38ab72a9c3fab8fc4adf0a f0c8ddb910d8ae9ac947d9529f6f447200000000", "complete": false, "errors": [ { "txid": "29803ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991", "vout": 0, "witness": [ ], "scriptSig": "", "sequence": 4294967295, "error": "Unable to sign input, invalid stack size (possibly missing key)" } It doesn't work, and it's normal. The donator signature is missing from the final Tx. Actually, i have no idea of where i have to put the scriptSig inside the Receiver Tx (there is no argument in signrawtransactionwithwallet that let you put a scriptSig). I probably missing something or misunderstanding how to process, if someone got the knowledge around AnyOneCanPay Tx, some help would be apprecied ;) Title: Re: Accomplish an AnyOneCanPay transaction? Post by: achow101 on March 22, 2019, 10:14:29 PM The donator's signature isn't in the final transaction, so obviously it is incorrect.
To get the signature in, you will need to modify the raw transaction by hand to include it. There is no way to provide signatures to the signrawtransaction commands as this is not really a supported use case. Title: Re: Accomplish an AnyOneCanPay transaction? Post by: ethicnology on March 23, 2019, 06:09:55 PM Thank you so much for answering, you confirmed my doubts.
If you tried a signrawtransactionwithwallet --help. It will display : 3. "sighashtype" (string, optional, default=ALL) The signature hash type. Must be one of "ALL" "NONE" "SINGLE" "ALL|ANYONECANPAY" "NONE|ANYONECANPAY" "SINGLE|ANYONECANPAY" That why I tried to achieve the AnyOneCanPay scenario using RPC commands, this is a bit sad that we can't make all the steps on Bitcoin core. So now i have to find a library that implement this SigHash (JavaScript lib would be perfect). I have few questions, what is the differences between NONE and NONE|ANYONECANPAY (same as SINGLE and SINGLE|ANYONECANPAY) ? Does a NONE or a SINGLE without ANYONECANPAY could work if the Receiver use ALL|ANYONECANPAY ? According to aliashraf (I thank him for explaining this to me): - NONE is unsecure because miners could steal it. - SINGLE is too expensive because it include the output. When donator create his gift Tx, which amount does he has to put inside, global final amount or the amount that he want to gift ? Is the scenario good ? - Donator create Tx with SINGLE/NONE|ANYONECANPAY, send their Tx + signature (no broadcast) they send it to the receiver. - Receiver build a new Tx which include donators inputs and signatures with ALL|ANYONECANPAY and he broadcast it. |