Bitcoin Forum
July 12, 2024, 07:49:35 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Pybitcointools txhash function, and SIGHASH_ALL = 0  (Read 801 times)
HeadsOrTails (OP)
Full Member
***
Offline Offline

Activity: 233
Merit: 101



View Profile
August 06, 2015, 07:48:11 AM
 #1

pybitcointools has a txhash function which returns the singable form of a transaction, with SIGHASH appended.

However the code returns a reversed hash without the appended SIGHASH bytes for SIGHASH=None, as seen here: https://github.com/vbuterin/pybitcointools/blob/master/bitcoin/transaction.py#L177-L178

Code:
def txhash(tx, hashcode=None):
    if isinstance(tx, str) and re.match('^[0-9a-fA-F]*$', tx):
        tx = changebase(tx, 16, 256)
    if hashcode:
        return dbl_sha256(from_string_to_bytes(tx) + encode(int(hashcode), 256, 4)[::-1])
    else:
        return safe_hexlify(bin_dbl_sha256(tx)[::-1])


That doesn't seem right; is it?

Also, how is a SIGHASH_ALL value of zero (rare case) calculated? (See this related SE question)

Is it just changing the 00 to 01?
HeadsOrTails (OP)
Full Member
***
Offline Offline

Activity: 233
Merit: 101



View Profile
August 10, 2015, 01:50:14 PM
 #2

How does this work?

Code:
txh = "01000000010276b76b07f4935c70acf54fbf1f438a4c397a9fb7e633873c4dd3bc062b6b40000000008c493046022100d23459d03ed7e9511a47d13292d3430a04627de6235b6e51a40f9cd386f2abe3022100e7d25b080f0bb8d8d5f878bba7d54ad2fda650ea8d158a33ee3cbd11768191fd004104b0e2c879e4daf7b9ab68350228c159766676a14f5815084ba166432aab46198d4cca98fa3e9981d0a90b2effc514b76279476550ba3663fdcaff94c38420e9d5000000000100093d00000000001976a9149a7b0f3b80c6baaeedce0a0842553800f832ba1f88ac00000000"
 
>>> hexlify(bin_dbl_sha256(unhexlify(txh))[::-1])
'c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73'
 
>>>fetchtx('c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73') == txh
True

txh is the test vector (for TxID c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73);

Isn't that impossible? It's signing the Tx structure which has the scriptSig in it; usually the scriptSig is replaced by the scriptpubkey for signing
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!