Bitcoin Forum
April 30, 2024, 11:15:32 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: different version have different SignatureHash?  (Read 167 times)
zhengjianxun (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 0


View Profile
July 30, 2018, 07:22:26 AM
 #1

in bitcoin 0.1.5  : SignatureHash (txto-sig+scriptCode),but the scriptCode insert into the position of sig,  but now i find in bitcoin 0.10,i find the scriptCode  is append into the back!!!

in bitcoin 0.1.5  :
1: uint256 SignatureHash(CScript scriptCode, const CTransaction&
txTo, unsigned int nIn, int nHashType)
2: {
3: if (nIn >= txTo.vin.size())
4: {
5: printf("ERROR: SignatureHash() : nIn=%d out of range\n",
nIn);
6: return 1;
7: }
8: CTransaction txTmp(txTo);
9: // In case concatenating two scripts ends up with two codeseparators
10: // or an extra one at the end, this prevents all those
possible incompatibilities.
11: scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
12: // Blank out other inputs' signatures
13: for (int i = 0; i < txTmp.vin.size(); i++)
14: txTmp.vin.scriptSig = CScript();
15: txTmp.vin[nIn].scriptSig = scriptCode;

16: // Blank out some of the outputs
17: if ((nHashType & 0x1f) == SIGHASH_NONE)
18: {
19: // Wildcard payee
20: txTmp.vout.clear();
21: // Let the others update at will
22: for (int i = 0; i < txTmp.vin.size(); i++)
23: if (i != nIn)
24: txTmp.vin.nSequence = 0;
25: }
26: else if ((nHashType & 0x1f) == SIGHASH_SINGLE)
27: {
28: // Only lockin the txout payee at same index as txin
29: unsigned int nOut = nIn;
30: if (nOut >= txTmp.vout.size())
31: {
32: printf("ERROR: SignatureHash() : nOut=%d out of
range\n", nOut);
33: return 1;
34: }
35: txTmp.vout.resize(nOut+1);
36: for (int i = 0; i < nOut; i++)
37: txTmp.vout.SetNull();
38: // Let the others update at will
39: for (int i = 0; i < txTmp.vin.size(); i++)
40: if (i != nIn)
41: txTmp.vin.nSequence = 0;
42: }
43: // Blank out other inputs completely, not recommended for open
transactions
44: if (nHashType & SIGHASH_ANYONECANPAY)
45: {
46: txTmp.vin[0] = txTmp.vin[nIn];
47: txTmp.vin.resize(1);
48: }
49: // Serialize and hash
50: CDataStream ss(SER_GETHASH);
51: ss.reserve(10000);
52: ss << txTmp << nHashType;
53: return Hash(ss.begin(), ss.end());
54: }




in  0.10:

uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{
    if (nIn >= txTo.vin.size()) {
        //  nIn out of range
        return 1;
    }

    // Check for invalid use of SIGHASH_SINGLE
    if ((nHashType & 0x1f) == SIGHASH_SINGLE) {
        if (nIn >= txTo.vout.size()) {
            //  nOut out of range
            return 1;
        }
    }

    // Wrapper to serialize only the necessary parts of the transaction being signed
    CTransactionSignatureSerializer txTmp(txTo, scriptCode, nIn, nHashType);


    // Serialize and hash
    CHashWriter ss(SER_GETHASH, 0);
    ss << txTmp << nHashType;
    return ss.GetHash();
}


so the diffirent version  mean the Signature is different Signature even though the  everything  is same? that ' s amazy!

1714475732
Hero Member
*
Offline Offline

Posts: 1714475732

View Profile Personal Message (Offline)

Ignore
1714475732
Reply with quote  #2

1714475732
Report to moderator
1714475732
Hero Member
*
Offline Offline

Posts: 1714475732

View Profile Personal Message (Offline)

Ignore
1714475732
Reply with quote  #2

1714475732
Report to moderator
1714475732
Hero Member
*
Offline Offline

Posts: 1714475732

View Profile Personal Message (Offline)

Ignore
1714475732
Reply with quote  #2

1714475732
Report to moderator
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6565


Just writing some code


View Profile WWW
July 30, 2018, 07:33:08 AM
Merited by gmaxwell (2), ABCbits (1)
 #2

No, it is not. You are completely misunderstanding the logic. The signature hash is exactly the same, it just uses different logic to construct it. CTransactionSignatureSerializer does not just stick the arguments to it together, it actually has logic to place things in the correct places. If you actually followed the code for it, you would see that it has it is an object that has its own serialize method which makes use of the arguments passed to it. It is the same signature hash, but with the logic abstracted out to a different object.

zhengjianxun (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 0


View Profile
July 30, 2018, 09:46:00 AM
 #3

ho my god ,you are the real bitcoin expert .   i am reading the  bitcoin source code .it is difficult but exciting for me. database、network  there are so many thing i should to understanding.  thank you . i hope i can  strong like you  Kiss
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!