Bitcoin Forum
April 27, 2024, 03:14:16 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Using SIGHASH_ANYONECANPAY  (Read 1842 times)
djuser (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
April 07, 2014, 10:05:05 PM
 #1

Hi,

I'm rather new to Bitcoin Protocol Development and would like to thank you in advance of any help you can offer me.

Essentially, I would like make use of SIGHASH_ANYONECANPAY hash type.

Currently, after following Ken Shirriff's blog entry on http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html, I was able to get a simple transaction working which is send from one input to multiple outputs. In addition, after doing some additional research and reading, I was able to extend the knowledge and get multiple inputs and multiple outputs working.

Right now, I'm at a loss at how to implement SIGHASH_ANYONECANPAY hash type and was wondering if someone can offer me where to look in terms of sample transaction script or code. I have taken a look at the contracts wiki but still unsure about the implementation steps.

My attempts at SIGHASH_ANYONECANPAY (assuming two inputs and one output) has been the following:

- Signing the first input with SIGHASH_ALL==> ("01") and second input with SIGHASH_ALL ("01") | SIGHASH_ANYONECANPAY ("80") ==> ("81")
- Here's the breakdown of my current signed transaction that's not being accepted by the TESTNET3:
I have highlighted in RED the SIGHASH_ALL==> ("01") and SIGHASH_ALL ("01") | SIGHASH_ANYONECANPAY ("80") ==> ("81")
https://s3.amazonaws.com/research.btc/btcmisc/TxBreakdown.png

Once again, any help would be greatly appreciated!

Thanks!
1714187656
Hero Member
*
Offline Offline

Posts: 1714187656

View Profile Personal Message (Offline)

Ignore
1714187656
Reply with quote  #2

1714187656
Report to moderator
"If you don't want people to know you're a scumbag then don't be a scumbag." -- margaritahuyan
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714187656
Hero Member
*
Offline Offline

Posts: 1714187656

View Profile Personal Message (Offline)

Ignore
1714187656
Reply with quote  #2

1714187656
Report to moderator
1714187656
Hero Member
*
Offline Offline

Posts: 1714187656

View Profile Personal Message (Offline)

Ignore
1714187656
Reply with quote  #2

1714187656
Report to moderator
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
April 08, 2014, 05:38:06 PM
 #2

When doing SIGHASH_ALL, each input script other than the current one is set to 0x00.  With SIGHASH_ANYONECANPAY, the other inputs are removed completely.

Are you creating the transaction with both inputs first, then calculating both signatures?  Or adding the ANYONECANPAY second input later, after the ALL has been signed?

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
djuser (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
April 08, 2014, 07:35:05 PM
 #3

Hi kjj,

Thanks for replying.

Given the two inputs and one output, I'm doing the following:

Yes, with SIGHASH_ALL, I'm currently using 0x00 to replace the second input script (not the current one). Also, with SIGHASH_ALL | SIGHASH_ANYONECANPAY, I removed all of the first input completely.

Now, when creating the transaction, first, I'm calculating the signature based on the first input using SIGHASH_ALL (which is the raw transaction that includes the first input script and the second input script set to 0x00).

Then I'm adding the second signature using SIGHASH_ANYONECANPAY after the SIGHASH_ALL has been signed (which is the raw transaction that only includes the second input script using the ANYONECANPAY).

Thanks again

When doing SIGHASH_ALL, each input script other than the current one is set to 0x00.  With SIGHASH_ANYONECANPAY, the other inputs are removed completely.

Are you creating the transaction with both inputs first, then calculating both signatures?  Or adding the ANYONECANPAY second input later, after the ALL has been signed?
djuser (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
April 10, 2014, 02:50:47 PM
 #4

I still have not figured out what might be wrong. Does anyone have any suggestions on how to debug or what I might be doing wrong?

Thanks in advanced!
djuser (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
April 12, 2014, 05:39:46 AM
 #5

Found the problem, it was because I was adding the wrong hash type code to the end of the trailing raw transaction prior to double hashing, signing, etc. I will post my detailed steps when I have some extra time and hopefully it will benefit others experiencing the same problem.

Cheers!
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!