1

I get it that the "OP_CHECKSIG" does this, but I can't see how to recreate it. I tried SHA1 and SHA256 of some of the info in a given bitcoin transaction but it didn't give me confirmed values of Z. Can someone please select a transaction, tell me which one it is and show me what I need to cut and paste into a SHA1 calculator to get the actual Z value?

The hash value of TX 9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1 is supposed to be z = c0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e and also z = 17b0f41c8c337ac1e18c98759e83a8cccbc368dd9d89e5f03cb633c265fd0ddc but I do not see how the z values are achieved.

1 Answer 1

1

0) read How to redeem a basic Tx?

1) take your transaction as array of bytes

2) replace all input scrips to empty scrips

3) replace one input script to original "OP_DUP OP_HASH160..."

4) append "hash code type" SIGHASH_ALL

5) take sha256 ( sha256 ( data ) )

that's all

Have a look on my code

const MyKey32 Transaction::getRawHash ( const int n, const QByteArray& scr ) const
{
  MyByteArray ret;                                    // create empty array
  Stream stream ( s );
  ret.putInt32 ( stream.readU32 ( ) );                // version
  ret.putVarInt ( stream.readVar ( ) );               // input count
  for ( int i ( 0 ); i < inputs; i++ )                // copy all inputs
  {
    ret.append ( stream.readHash ( ) );
    ret.putInt32 ( stream.readU32 ( ) );
    stream.skipVarData ( );                            // skip original script
    ret.putPrefixed ( i == n ? scr : QByteArray ( ) ); // !!! script replacement
    ret.putInt32 ( stream.readU32 ( ) );
  }
  ret.putVarInt ( stream.readVar ( ) );                // output count
  for ( int i ( 0 ); i < outputs; i++ )                // copy all outputs byte-by-byte
  {
    ret.putInt64 ( stream.readU64 ( ) );
    ret.putPrefixed ( stream.readVarData ( ) );
  }
  ret.putInt32 ( stream.readU32 ( ) );                 // lock
  ret.putInt32 ( SIGHASH_ALL );                        // !!! append hashcode
  return MyKey32 ( ret.constData ( ), ret.size ( ) );  // create hash256 of array
}
3
  • That helps me somewhat, but an example of an existing transaction would enable me (and others I'd assume) to understand it best. Also, are you sure that that results in what is referred to as the "Z" value in the equation?
    – Mine
    Commented May 17, 2014 at 6:33
  • Yes, I am sure that this method works. This is a part of a program which looks for compromised private keys. The results (not recent) are here bitcointalk.org/index.php?topic=461351.msg6408633#msg6408633 () I can help you more but not for free.
    – amaclin
    Commented May 19, 2014 at 4:15
  • Is there, by chance, a website I could simply paste something into and it'll give me this hash? Too many steps to this process are currently beyond me.
    – Mine
    Commented Nov 19, 2014 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.