Bitcoin Forum
November 05, 2024, 07:31:07 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I am searching real sample for CPubKey::Verify or explaining my sample  (Read 144 times)
Frodek (OP)
Member
**
Offline Offline

Activity: 138
Merit: 25


View Profile
October 23, 2019, 02:03:13 PM
 #1

In block 500186 BTC:
in transaction (big endian) 83951f7cb7db18e22f30f319ecbfba2adfc0828a31a0df4edecb46a580c4df10
input script is:
Code:
ScriptSig: PUSHDATA(72)[3045022100df7b1f04615972c7e9d05e9c6c176b95f1a9fc9b73e86eb6d6747336da118a4d02202021d00dab65b6000ef2fcae7525427d1dbec40a2def4196111b8b11c5247bfd01] PUSHDATA(33)[03eafee16adb27d36dc89e4aae0d1b5e0f8ddb2c9136612dc733ec65b1db128cca]
and hash previous transaction is 132d98c0bf70264d224f8a2d19325a1f34edd5fddd387939c1f51dd9790aead5

and
Code:
CPubKey key = (normal or reverse?, le or be)03eafee16adb27d36dc89e4aae0d1b5e0f8ddb2c9136612dc733ec65b1db128cca
hash = (from big endian) 132d98c0bf70264d224f8a2d19325a1f34edd5fddd387939c1f51dd9790aead5
signature = (from little endian)3045022100df7b1f04615972c7e9d05e9c6c176b95f1a9fc9b73e86eb6d6747336da118a4d02202021d00dab65b6000ef2fcae7525427d1dbec40a2def4196111b8b11c5247bfd01
now:
key.Verify(hash, signature) - give me false!
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6885


Just writing some code


View Profile WWW
October 23, 2019, 08:19:37 PM
 #2

The message that is signed is not the hash of the previous transaction. Nor is it the hash of the current transaction. Rather it is the current transaction with some parts modified.

For non-segwit inputs, the message that is signed is the current transaction with all input scriptSigs blanked out except for the current input that is being signed (or verified). For that particular input, the redeemScript is put into the scriptSig if one exists. If there is no redeemScript, the scriptPubKey of the output that was spent in that input is put in the scriptPubKey. At the end of the transaction you append a 4 byte little endian integer for the sighash type being used, in most cases, it's sighash all which is type 1. That is hashed once, then hashed again to get the value that is passed into the signing/verifying function.

For segwit inputs, read BIP 143.

Code:
CPubKey key = (normal or reverse?, le or be)03eafee16adb27d36dc89e4aae0d1b5e0f8ddb2c9136612dc733ec65b1db128cca
Neither, it isn't an integer. It's a byte array, do not modify.

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!