|
July 30, 2018, 07:22:26 AM |
|
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!
|