]> Git Repo - VerusCoin.git/commitdiff
Optimized signing fix
authormiketout <[email protected]>
Sun, 1 Dec 2019 06:02:28 +0000 (22:02 -0800)
committermiketout <[email protected]>
Sun, 1 Dec 2019 06:02:28 +0000 (22:02 -0800)
src/cryptoconditions/src/secp256k1.c
src/script/interpreter.cpp
src/script/interpreter.h
src/script/sign.cpp

index 89fdbbb92c427f154337ff19520b3536a61c62b5..b32d64c0b8cd527d578a0e8b8ea1d717e21dec36 100644 (file)
@@ -287,16 +287,18 @@ static int secp256k1Apply(CC *cond, CCVisitor visitor) {
     if (cond->type->typeId != CC_Secp256k1) return 1;
     struct SecP256k1ApplyData *apply = (struct SecP256k1ApplyData *)visitor.context;
 
+    /*
     char *jsonCondStr = cc_conditionToJSONString(cond);
     if (jsonCondStr)
     {
         printf("Ready to apply sig: %s\n", jsonCondStr);
         cJSON_free(jsonCondStr);
     }
+    */
 
     // if we match, add or replace the signature, if the signature is null, remove the signature
     int isPKHash = 0;
-    if (!memcmp(cond->publicKey, apply->publicKey, SECP256K1_PK_SIZE) || ((isPKHash = cc_secp256k1IsPKHash(cond->publicKey)) && !memcmp(cond->publicKey, apply->publicKey, SECP256K1_PK_SIZE)))
+    if (!memcmp(cond->publicKey, apply->publicKey, SECP256K1_PK_SIZE) || ((isPKHash = cc_secp256k1IsPKHash(cond->publicKey)) && !memcmp(cond->publicKey, apply->pubkeyHash20, 20)))
     {
         if (cond->signature)
         {
@@ -321,6 +323,15 @@ static int secp256k1Apply(CC *cond, CCVisitor visitor) {
         return 1;
     }
 
+    /*
+    jsonCondStr = cc_conditionToJSONString(cond);
+    if (jsonCondStr)
+    {
+        printf("After signature: %s\n", jsonCondStr);
+        cJSON_free(jsonCondStr);
+    }
+    */
+
     apply->applyCount++;
     return 1;
 }
index 5b0181f4b1e68ed55f92a9ec16db58c7407b2a15..25f12cab9d1e785193e09ac1bf47528f34b71d18 100644 (file)
@@ -1474,6 +1474,7 @@ int TransactionSignatureChecker::CheckCryptoCondition(
 
     int expectedEvals = 1;
     CC *outputCC = nullptr;
+    int nHashType;
 
     if (p.IsValid() && p.version >= p.VERSION_V3 && p.vData.size())
     {
@@ -1654,15 +1655,6 @@ int TransactionSignatureChecker::CheckCryptoCondition(
         }
         else
         {
-
-            /*
-            char *jsonCondStr = cc_conditionToJSONString(outputCC);
-            if (jsonCondStr)
-            {
-                printf("Reconstructed condition: %s\n", jsonCondStr);
-                cJSON_free(jsonCondStr);
-            }
-            */
             condBinary = CCPubKeyVec(outputCC);
 
             CSmartTransactionSignatures signatures(std::vector<unsigned char>((unsigned char*)ffillBin.data(), (unsigned char*)ffillBin.data() + ffillBin.size()));
@@ -1674,8 +1666,10 @@ int TransactionSignatureChecker::CheckCryptoCondition(
             else
             {
                 // apply signatures to the condition to create the fulfillment
+                nHashType = signatures.sigHashType;
                 for (auto &sig : signatures.signatures)
                 {
+
                     if (sig.second.sigType != sig.second.SIGTYPE_SECP256K1 || !sig.second.signature.size() || !cc_ApplySecp256k1Signature(outputCC, sig.second.pubKeyData.data(), sig.first.begin(), sig.second.signature.data()))
                     {
                         success = false;
@@ -1684,6 +1678,15 @@ int TransactionSignatureChecker::CheckCryptoCondition(
             }
             if (!success || !condBinary.size())
             {
+                /*
+                char *jsonCondStr = cc_conditionToJSONString(outputCC);
+                if (jsonCondStr)
+                {
+                    printf("Signed condition: %s\n", jsonCondStr);
+                    cJSON_free(jsonCondStr);
+                }
+                */
+
                 cc_free(outputCC);
                 condBinary.clear();
             }
@@ -1709,11 +1712,13 @@ int TransactionSignatureChecker::CheckCryptoCondition(
     {
         cond = outputCC;
         signScript = scriptCode;
+        error = false;
     }
     else
     {
         signScript = CScript() << condBinary << OP_CHECKCRYPTOCONDITION;
         error = cc_readFulfillmentBinaryExt((unsigned char*)ffillBin.data(), ffillBin.size()-1, &cond);
+        nHashType = ffillBin.back();
     }
     
     if (error || !cond)
@@ -1771,7 +1776,6 @@ int TransactionSignatureChecker::CheckCryptoCondition(
     }
 
     uint256 sighash;
-    int nHashType = ffillBin.back();
     try {
         sighash = SignatureHash(signScript, *txTo, nIn, nHashType, amount, consensusBranchId, this->txdata);
     } catch (logic_error ex) {
index ff77a4a1259ddf26b4dea55ebdc95b67eb5a270c..b1404f9f33de48147e3184c4371740f2b8b363f6 100644 (file)
@@ -151,6 +151,7 @@ public:
         obj.push_back(Pair("signaturetype", (int)sigType));
         obj.push_back(Pair("publickeydata", HexBytes(&pubKeyData[0], pubKeyData.size())));
         obj.push_back(Pair("signature", HexBytes(&signature[0], signature.size())));
+        return obj;
     }
 
     bool IsValid()
index 9263af021ac30a7d3a327aa0843fe791aa4a331a..72d67f08e12f2efc09571edbef91a526da3d882d 100644 (file)
@@ -65,6 +65,20 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char> &vchSig,
             free(onesig);
             signatures.AddSignature(signature);
             vchSig = signatures.AsVector();
+
+
+            /*
+            printf("signatures: %s\n", signatures.ToUniValue().write().c_str());
+            CC *cc = (CC *)extraData;
+            if (!cc || cc_signTreeSecp256k1Msg32(cc, key.begin(), hash.begin()) == 0)
+                return false;
+            char *jsonCondStr = cc_conditionToJSONString(cc);
+            if (jsonCondStr)
+            {
+                printf("Signed condition: %s\n", jsonCondStr);
+                cJSON_free(jsonCondStr);
+            }
+            */
         }
         else
         {
This page took 0.034764 seconds and 4 git commands to generate.