From 5b7a0e18a366f04d053aec1d30214a3cfda3ec89 Mon Sep 17 00:00:00 2001
From: koe <ukoe@protonmail.com>
Date: Tue, 17 May 2022 13:59:29 -0500
Subject: [PATCH] clsag patch demo

---
 src/ringct/rctSigs.cpp | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index 3e85f60ce..868366f6a 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -272,8 +272,8 @@ namespace rct {
         scalarmultKey(sig.D,D,INV_EIGHT);
 
         // Aggregation hashes
-        keyV mu_P_to_hash(2*n+4); // domain, I, D, P, C, C_offset
-        keyV mu_C_to_hash(2*n+4); // domain, I, D, P, C, C_offset
+        keyV mu_P_to_hash(2*n+5); // domain, I, D, P, C, C_offset, message
+        keyV mu_C_to_hash(2*n+5); // domain, I, D, P, C, C_offset, message
         sc_0(mu_P_to_hash[0].bytes);
         memcpy(mu_P_to_hash[0].bytes,config::HASH_KEY_CLSAG_AGG_0,sizeof(config::HASH_KEY_CLSAG_AGG_0)-1);
         sc_0(mu_C_to_hash[0].bytes);
@@ -289,15 +289,17 @@ namespace rct {
         mu_P_to_hash[2*n+1] = sig.I;
         mu_P_to_hash[2*n+2] = sig.D;
         mu_P_to_hash[2*n+3] = C_offset;
+        mu_P_to_hash[2*n+4] = message;
         mu_C_to_hash[2*n+1] = sig.I;
         mu_C_to_hash[2*n+2] = sig.D;
         mu_C_to_hash[2*n+3] = C_offset;
+        mu_C_to_hash[2*n+4] = message;
         key mu_P, mu_C;
         mu_P = hash_to_scalar(mu_P_to_hash);
         mu_C = hash_to_scalar(mu_C_to_hash);
 
         // Initial commitment
-        keyV c_to_hash(2*n+5); // domain, P, C, C_offset, message, aG, aH
+        keyV c_to_hash(2*n+7); // domain, P, C, C_offset, I, D, message, aG, aH
         key c;
         sc_0(c_to_hash[0].bytes);
         memcpy(c_to_hash[0].bytes,config::HASH_KEY_CLSAG_ROUND,sizeof(config::HASH_KEY_CLSAG_ROUND)-1);
@@ -307,19 +309,21 @@ namespace rct {
             c_to_hash[i+n] = C_nonzero[i-1];
         }
         c_to_hash[2*n+1] = C_offset;
-        c_to_hash[2*n+2] = message;
+        c_to_hash[2*n+2] = sig.I;
+        c_to_hash[2*n+3] = sig.D;
+        c_to_hash[2*n+4] = message;
 
         // Multisig data is present
         if (kLRki)
         {
             a = kLRki->k;
-            c_to_hash[2*n+3] = kLRki->L;
-            c_to_hash[2*n+4] = kLRki->R;
+            c_to_hash[2*n+5] = kLRki->L;
+            c_to_hash[2*n+6] = kLRki->R;
         }
         else
         {
-            c_to_hash[2*n+3] = aG;
-            c_to_hash[2*n+4] = aH;
+            c_to_hash[2*n+5] = aG;
+            c_to_hash[2*n+6] = aH;
         }
         hwdev.clsag_hash(c_to_hash,c);
         
@@ -358,8 +362,8 @@ namespace rct {
             ge_dsm_precomp(H_precomp.k, &Hi_p3);
             addKeys_aAbBcC(R,sig.s[i],H_precomp.k,c_p,I_precomp.k,c_c,D_precomp.k);
 
-            c_to_hash[2*n+3] = L;
-            c_to_hash[2*n+4] = R;
+            c_to_hash[2*n+5] = L;
+            c_to_hash[2*n+6] = R;
             hwdev.clsag_hash(c_to_hash,c_new);
             copy(c,c_new);
             
@@ -932,8 +936,8 @@ namespace rct {
             precomp(D_precomp.k,D_8);
 
             // Aggregation hashes
-            keyV mu_P_to_hash(2*n+4); // domain, I, D, P, C, C_offset
-            keyV mu_C_to_hash(2*n+4); // domain, I, D, P, C, C_offset
+            keyV mu_P_to_hash(2*n+5); // domain, I, D, P, C, C_offset, message
+            keyV mu_C_to_hash(2*n+5); // domain, I, D, P, C, C_offset, message
             sc_0(mu_P_to_hash[0].bytes);
             memcpy(mu_P_to_hash[0].bytes,config::HASH_KEY_CLSAG_AGG_0,sizeof(config::HASH_KEY_CLSAG_AGG_0)-1);
             sc_0(mu_C_to_hash[0].bytes);
@@ -949,15 +953,17 @@ namespace rct {
             mu_P_to_hash[2*n+1] = sig.I;
             mu_P_to_hash[2*n+2] = sig.D;
             mu_P_to_hash[2*n+3] = C_offset;
+            mu_P_to_hash[2*n+4] = message;
             mu_C_to_hash[2*n+1] = sig.I;
             mu_C_to_hash[2*n+2] = sig.D;
             mu_C_to_hash[2*n+3] = C_offset;
+            mu_C_to_hash[2*n+4] = message;
             key mu_P, mu_C;
             mu_P = hash_to_scalar(mu_P_to_hash);
             mu_C = hash_to_scalar(mu_C_to_hash);
 
             // Set up round hash
-            keyV c_to_hash(2*n+5); // domain, P, C, C_offset, message, L, R
+            keyV c_to_hash(2*n+7); // domain, P, C, C_offset, I, D, message, L, R
             sc_0(c_to_hash[0].bytes);
             memcpy(c_to_hash[0].bytes,config::HASH_KEY_CLSAG_ROUND,sizeof(config::HASH_KEY_CLSAG_ROUND)-1);
             for (size_t i = 1; i < n+1; ++i)
@@ -966,7 +972,9 @@ namespace rct {
                 c_to_hash[i+n] = pubs[i-1].mask;
             }
             c_to_hash[2*n+1] = C_offset;
-            c_to_hash[2*n+2] = message;
+            c_to_hash[2*n+2] = sig.I;
+            c_to_hash[2*n+3] = sig.D;
+            c_to_hash[2*n+4] = message;
             key c_p; // = c[i]*mu_P
             key c_c; // = c[i]*mu_C
             key c_new;
@@ -1001,8 +1009,8 @@ namespace rct {
                 ge_dsm_precomp(hash_precomp.k, &hash8_p3);
                 addKeys_aAbBcC(R,sig.s[i],hash_precomp.k,c_p,I_precomp.k,c_c,D_precomp.k);
 
-                c_to_hash[2*n+3] = L;
-                c_to_hash[2*n+4] = R;
+                c_to_hash[2*n+5] = L;
+                c_to_hash[2*n+6] = R;
                 c_new = hash_to_scalar(c_to_hash);
                 CHECK_AND_ASSERT_MES(!(c_new == rct::zero()), false, "Bad signature hash");
                 copy(c,c_new);
-- 
2.21.1 (Apple Git-122.3)

