Updated MLSAG and CLSAG tests for consistency

This commit is contained in:
Sarang Noether 2020-04-21 00:19:13 -04:00 committed by moneromooo-monero
parent 5aa1575e91
commit f964a92c57
3 changed files with 63 additions and 31 deletions

View file

@ -215,8 +215,18 @@ int main(int argc, char** argv)
TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 32);
TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 16384);
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 11, true); // MLSAG verification
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 11, 1); // CLSAG verification (with commitment offset)
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 8, 1); // MLSAG verification
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 16, 1);
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 32, 1);
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 64, 1);
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 128, 1);
TEST_PERFORMANCE2(filter, p, test_sig_mlsag, 256, 1);
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 8, 1); // CLSAG verification
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 16, 1);
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 32, 1);
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 64, 1);
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 128, 1);
TEST_PERFORMANCE2(filter, p, test_sig_clsag, 256, 1);
TEST_PERFORMANCE2(filter, p, test_ringct_mlsag, 11, false);
TEST_PERFORMANCE2(filter, p, test_ringct_mlsag, 11, true);

View file

@ -51,8 +51,9 @@ public:
if (!single_tx_test_base::init())
return false;
message = identity();
message = skGen();
// Random signing/commitment keys
pubs.reserve(N);
for (size_t i = 0; i < N; i++)
{
@ -65,18 +66,22 @@ public:
pubs.push_back(tmp);
}
// Signing key
key p;
skpkGen(p,pubs[l].dest);
// Commitment key
key t,u;
t = skGen();
u = skGen();
addKeys2(pubs[l].mask,t,u,H);
// Offset
key t2;
t2 = skGen();
addKeys2(C_offset,t2,u,H);
// Final signing keys
ctkey insk;
insk.dest = p;
insk.mask = t;

View file

@ -32,56 +32,73 @@
#include "ringct/rctSigs.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "device/device.hpp"
#include "single_tx_test_base.h"
template<size_t ring_size, bool ver>
using namespace rct;
template<size_t ring_size, size_t index>
class test_sig_mlsag : public single_tx_test_base
{
public:
static const size_t cols = ring_size;
static const size_t rows = 2; // 1 spend + 1 commitment
static const size_t N = ring_size;
static const size_t loop_count = 1000;
static const size_t l = index;
bool init()
{
if (!single_tx_test_base::init())
return false;
rct::keyV xtmp = rct::skvGen(rows);
rct::keyM xm = rct::keyMInit(rows, cols);// = [[None]*N] #just used to generate test public keys
sk = rct::skvGen(rows);
P = rct::keyMInit(rows, cols);// = keyM[[None]*N] #stores the public keys;
ind = 0; // fixed spend index
for (size_t j = 0 ; j < rows ; j++)
message = skGen();
// Random signing/commitment keys
pubs.reserve(N);
for (size_t i = 0; i < N; i++)
{
for (size_t i = 0 ; i < cols ; i++)
{
xm[i][j] = rct::skGen();
P[i][j] = rct::scalarmultBase(xm[i][j]);
}
key sk;
ctkey tmp;
skpkGen(sk, tmp.dest);
skpkGen(sk, tmp.mask);
pubs.push_back(tmp);
}
for (size_t j = 0 ; j < rows ; j++)
{
sk[j] = xm[ind][j];
}
IIccss = MLSAG_Gen(rct::identity(), P, sk, NULL, NULL, ind, rows-1, hw::get_device("default"));
// Signing key
key p;
skpkGen(p,pubs[l].dest);
// Commitment key
key t,u;
t = skGen();
u = skGen();
addKeys2(pubs[l].mask,t,u,H);
// Offset
key t2;
t2 = skGen();
addKeys2(C_offset,t2,u,H);
// Final signing keys
ctkey insk;
insk.dest = p;
insk.mask = t;
sig = proveRctMGSimple(message,pubs,insk,t2,C_offset,NULL,NULL,l,hw::get_device("default"));
return true;
}
bool test()
{
if (ver)
return MLSAG_Ver(rct::identity(), P, IIccss, rows-1);
else
MLSAG_Gen(rct::identity(), P, sk, NULL, NULL, ind, rows-1, hw::get_device("default"));
return true;
return verRctMGSimple(message,sig,pubs,C_offset);
}
private:
rct::keyV sk;
rct::keyM P;
size_t ind;
rct::mgSig IIccss;
ctkeyV pubs;
key C_offset;
mgSig sig;
key message;
};