Bitcoin Forum
May 06, 2024, 04:04:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: SIGHASH_ANYONECANPAY.  (Read 1712 times)
Muhammed Zakir (OP)
Hero Member
*****
Offline Offline

Activity: 560
Merit: 506


I prefer Zakir over Muhammed when mentioning me!


View Profile WWW
February 15, 2015, 10:01:40 AM
 #1

https://bitcoin.org/en/developer-guide#term-sighash-anyonecanpay

Can anybody please give a brief explanation with example? Thanks!

Kindly,
Muhammed Zakir

1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
1715011446
Hero Member
*
Offline Offline

Posts: 1715011446

View Profile Personal Message (Offline)

Ignore
1715011446
Reply with quote  #2

1715011446
Report to moderator
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
February 15, 2015, 02:25:06 PM
 #2

When you sign a transaction, the wallet prepares a 'before-sign' transaction then calculates its hash. The hash is signed and put back into the raw transaction. The result is the final transaction to publish[1].
Normally signatures are SIGHASH_ALL (1). It's a byte appended to the signature. [Ex][2]: 3045022100d9e4dbe1d5cb4404e6d06c1f8ada2cee913f6fe192129a38d75834739f2d5a4202202 6d4354d769179cb9775d4ef5b4b4862f8bf1827a57fa8e1b42a18b3202cacff**01**

However, you can have other types of signatures. `SIGHASH_ANYONECANPAY` is one of them. It modifies how the Bitcoin forms the 'before-sign' transaction to sign/verify. This tx determines what is being signed. In other words, if something is omitted from it, it can be modified later without making the signature invalid.

In `SIGHASH_ANYONECANPAY` all the other inputs are removed before signing. For instance, if the tx has 3 inputs and you are signing the 2nd one, the 1st one and the 3rd one are removed and can be modified later *before* being published. The outputs are not modified so you are still paying the same people.

Let's say that you and your roommates are paying your rent in a single tx. You sign your share of the rent as `SIGHASH_ANYONECANPAY` so that your roommates can add their share later. Once everyone is done, you can publish the completed transaction.

Note that in this case, you may need a special wallet because the total output value is greater than the total input values while you build the tx.

In other words, you locked the destination but you don't care if others want to add more coins.

[1]: http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
[2]: https://blockchain.info/tx/0b5477156878eb16b6220e68f06e6a1685b8ab13545f792b833444fe7a85c9be

Muhammed Zakir (OP)
Hero Member
*****
Offline Offline

Activity: 560
Merit: 506


I prefer Zakir over Muhammed when mentioning me!


View Profile WWW
February 15, 2015, 05:03:42 PM
 #3


In `SIGHASH_ANYONECANPAY` all the other inputs are removed before signing. For instance, if the tx has 3 inputs and you are signing the 2nd one, the 1st one and the 3rd one are removed and can be modified later *before* being published. The outputs are not modified so you are still paying the same people.

Let's say that you and your roommates are paying your rent in a single tx. You sign your share of the rent as `SIGHASH_ANYONECANPAY` so that your roommates can add their share later. Once everyone is done, you can publish the completed transaction.

Note that in this case, you may need a special wallet because the total output value is greater than the total input values while you build the tx.

In other words, you locked the destination but you don't care if others want to add more coins.

Thanks, hhanh00! As the inputs will be larger than outputs, where would change go?

Is SIGHASH_SINGLE|SIGHASH_ANYONECANPAY better? As I could sign a single input & output and others can add/change other inputs and outputs, so the change can be managed.

   -MZ

hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
February 17, 2015, 08:35:41 AM
 #4

You can add dummy inputs before you sign. The pre-sig tx removes them but it makes the tx well formed. Using SIGHASH_SINGLE locks one txout. It kinda assumes that you are responsible for the txout that has the same index as the txin that you are signing. Therefore you don't have room for a change txout. I find them less useful than SIGHASH_ANYONECANPAY|SIGHASH_ALL.

Muhammed Zakir (OP)
Hero Member
*****
Offline Offline

Activity: 560
Merit: 506


I prefer Zakir over Muhammed when mentioning me!


View Profile WWW
February 17, 2015, 10:12:14 AM
 #5

You can add dummy inputs before you sign. The pre-sig tx removes them but it makes the tx well formed. Using SIGHASH_SINGLE locks one txout. It kinda assumes that you are responsible for the txout that has the same index as the txin that you are signing. Therefore you don't have room for a change txout. I find them less useful than SIGHASH_ANYONECANPAY|SIGHASH_ALL.

Okay! Understood except - none of the inputs are dummies

As the inputs will be larger than outputs, where would change go?

   -MZ

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!