Bitcoin Forum
December 12, 2024, 12:43:33 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is there a way to get the hash digest used for signing tx from bitcoin core?  (Read 145 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1043
Merit: 2824


Bitcoin and C♯ Enthusiast


View Profile WWW
August 03, 2019, 03:01:07 AM
Last edit: August 03, 2019, 06:27:55 AM by Coding Enthusiast
Merited by bones261 (2), ABCbits (1)
 #1

When signing a transaction, before passing the data to ECDSA related function it is hashed using SHA256x2, BIP143 refers to them as "sigHash". I was wondering if there was a way to get them for any given transaction using bitcoin core, or if they could be found among test cases.
They are very useful for testing specific part of the code instead of just testing the end result (signed transaction).


I also need help figuring out why bitcoin core can not sign the following:
Code:
signrawtransactionwithkey "0200000002aecc62c5db92bb213a0bfdfd3e15aab7367c06ce995ec30936b08b40c513b0560100000000ffffffffaecc62c5db92bb213a0bfdfd3e15aab7367c06ce995ec30936b08b40c513b0560200000000ffffffff0160e31600000000001976a91468cfed146aced22f422a68015ff8ca180761912a88acffffffff" '["_removed_base58_privatekey_"]' '[{"txid":"56b013c5408bb03609c35e99ce067c36b7aa153efdfd0b3a21bb92dbc562ccae", "vout":1, "scriptPubKey":"4104692d8520af5ac174143a928998fd9e8bd767bfd90fc1815e927bc84fdaf912e6687fe598ea324f25890abceb8d99040f70c35f8fd9e82ee206d19f963922dc16ac"}]'

I can sign the other output (vout=2) with the scriptpubkey of 2102fbbd836e18cb88f6dad65ca12dee3270b57818dd91a1cd500dd4c812ed93651cac and a different private key but this one (vout=1) which has a scriptpubkey with an uncompressed public key, fails.
The error message is:
Code:
Unable to sign input, invalid stack size (possibly missing key)
... using Bitcoin Core v0.18.0 (64-bit) testnet on Ubuntu 14.04, offline (no blockchain) and the private key is the correct one (will give the same public key)

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.20.0)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3570
Merit: 6927


Just writing some code


View Profile WWW
August 03, 2019, 03:42:36 PM
Merited by bones261 (2), Coding Enthusiast (2), ABCbits (1)
 #2

The only way to get the sighashes that are actually signed is to modify the code to give them to you. In the SignatureHash function, change the two return ss.GetHash() lines to:

Code:
uint256 hash = ss.GetHash();
fprintf(stderr, "%s", HexStr(hash).c_str());
return hash;

That will print out ALL signature hashes in reverse byte order to stderr. You can then find the sighashes you need in that output.


Are you sure that the private key you are providing is the correct format for uncompressed keys? It should begin with a 9, not a c.

Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1043
Merit: 2824


Bitcoin and C♯ Enthusiast


View Profile WWW
August 03, 2019, 04:54:26 PM
 #3

Are you sure that the private key you are providing is the correct format for uncompressed keys? It should begin with a 9, not a c.

Thanks, that was it. I forgot to change my isCompressed for this output to false when printing that command.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.20.0)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
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!