Author

Topic: I am searching real sample for CPubKey::Verify or explaining my sample (Read 146 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
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.
member
Activity: 138
Merit: 25
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!
Jump to: