Bitcoin Forum
May 24, 2024, 04:17:35 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: help generating "hashOutputs" for segwit tx  (Read 148 times)
dbitcoin100k (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
November 06, 2019, 02:44:04 AM
 #1

I'm trying to sign a segwit transaction but I need help generating the signature. Specifically, I'm getting stuck on the bit where I have to generate hashOutputs.

Since my transaction has two outputs, what do I hash exactly?

I'm doing SIGHASH_ALL, so I believe this is the relevant bit from bip143, but I have no idea what it means:

"If the sighash type is neither SINGLE nor NONE, hashOutputs is the double SHA256 of the serialization of all output amount (8-byte little endian) with scriptPubKey (serialized as scripts inside CTxOuts);"

"all output amount" - so do I add up the total value of the outputs?
Do I just put one scriptPubKey after the other?

Thanks
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3402
Merit: 6648


Just writing some code


View Profile WWW
November 06, 2019, 03:41:54 AM
 #2

You serialize it as the outputs one after another, just like they are in the transaction. So it would be the first output's value, then it's scriptPubKey, then the second output value and it's scriptPubKey, and so on.

pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10579



View Profile
November 06, 2019, 03:43:54 AM
Merited by hugeblack (1)
 #3

"all output amount" - so do I add up the total value of the outputs?
Do I just put one scriptPubKey after the other?

you have to "concatenate" the bytes together.
so your "hashOutputs" is hash of the serialized TxOuts concatenated together. so for your 2 outputs it will be:
Code:
SHA256_d(amount1 || scriptPub1 || amount2 || scrioptPub2);
from the first example of BIP-143:
output 1:
    amount = 202cb20600000000
    scriptPub = 1976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac
output 2:
    amount = 9093510d00000000
    scriptPub = 1976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac
Code:
SHA256_d(202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac);

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!