bulletproofs: add aggregated verification

Ported from sarang's java code
This commit is contained in:
moneromooo-monero 2018-02-03 14:36:29 +00:00
parent e895c3def1
commit bacf0a1e2f
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
11 changed files with 453 additions and 259 deletions

View file

@ -60,3 +60,41 @@ public:
private:
rct::Bulletproof proof;
};
template<bool batch, size_t start, size_t repeat, size_t mul, size_t add, size_t N>
class test_aggregated_bulletproof
{
public:
static const size_t loop_count = 500 / (N * repeat);
bool init()
{
size_t o = start;
for (size_t n = 0; n < N; ++n)
{
//printf("adding %zu times %zu\n", repeat, o);
for (size_t i = 0; i < repeat; ++i)
proofs.push_back(rct::bulletproof_PROVE(std::vector<uint64_t>(o, 749327532984), rct::skvGen(o)));
o = o * mul + add;
}
return true;
}
bool test()
{
if (batch)
{
return rct::bulletproof_VERIFY(proofs);
}
else
{
for (const rct::Bulletproof &proof: proofs)
if (!rct::bulletproof_VERIFY(proof))
return false;
return true;
}
}
private:
std::vector<rct::Bulletproof> proofs;
};

View file

@ -183,6 +183,17 @@ int main(int argc, char** argv)
TEST_PERFORMANCE2(filter, verbose, test_bulletproof, true, 15);
TEST_PERFORMANCE2(filter, verbose, test_bulletproof, false, 15);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, false, 2, 1, 1, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, true, 2, 1, 1, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, false, 8, 1, 1, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, true, 8, 1, 1, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, false, 1, 1, 2, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, true, 1, 1, 2, 0, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, false, 1, 8, 1, 1, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, true, 1, 8, 1, 1, 4);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, false, 2, 1, 1, 0, 64);
TEST_PERFORMANCE6(filter, verbose, test_aggregated_bulletproof, true, 2, 1, 1, 0, 64);
TEST_PERFORMANCE3(filter, verbose, test_ringct_mlsag, 1, 3, false);
TEST_PERFORMANCE3(filter, verbose, test_ringct_mlsag, 1, 5, false);
TEST_PERFORMANCE3(filter, verbose, test_ringct_mlsag, 1, 10, false);

View file

@ -169,3 +169,5 @@ void run_test(const std::string &filter, bool verbose, const char* test_name)
#define TEST_PERFORMANCE2(filter, verbose, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">")
#define TEST_PERFORMANCE3(filter, verbose, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">")
#define TEST_PERFORMANCE4(filter, verbose, test_class, a0, a1, a2, a3) run_test< test_class<a0, a1, a2, a3> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ">")
#define TEST_PERFORMANCE5(filter, verbose, test_class, a0, a1, a2, a3, a4) run_test< test_class<a0, a1, a2, a3, a4> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ">")
#define TEST_PERFORMANCE6(filter, verbose, test_class, a0, a1, a2, a3, a4, a5) run_test< test_class<a0, a1, a2, a3, a4, a5> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ", " QUOTEME(a5) ">")

View file

@ -135,6 +135,25 @@ TEST(bulletproofs, multi_splitting)
}
}
TEST(bulletproofs, valid_aggregated)
{
static const size_t N_PROOFS = 8;
std::vector<rct::Bulletproof> proofs(N_PROOFS);
for (size_t n = 0; n < N_PROOFS; ++n)
{
size_t outputs = 2 + n;
std::vector<uint64_t> amounts;
rct::keyV gamma;
for (size_t i = 0; i < outputs; ++i)
{
amounts.push_back(crypto::rand<uint64_t>());
gamma.push_back(rct::skGen());
}
proofs[n] = bulletproof_PROVE(amounts, gamma);
}
ASSERT_TRUE(rct::bulletproof_VERIFY(proofs));
}
TEST(bulletproofs, invalid_8)
{

View file

@ -1085,3 +1085,20 @@ TEST(ringct, zeroCommmit)
const rct::key manual = rct::addKeys(a, b);
ASSERT_EQ(z, manual);
}
TEST(ringct, aggregated)
{
static const size_t N_PROOFS = 16;
std::vector<rctSig> s(N_PROOFS);
std::vector<const rctSig*> sp(N_PROOFS);
for (size_t n = 0; n < N_PROOFS; ++n)
{
static const uint64_t inputs[] = {1000, 1000};
static const uint64_t outputs[] = {500, 1500};
s[n] = make_sample_simple_rct_sig(NELTS(inputs), inputs, NELTS(outputs), outputs, 0);
sp[n] = &s[n];
}
ASSERT_TRUE(verRctSemanticsSimple(sp));
}