aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt5
-rw-r--r--tests/unit_tests/aligned.cpp86
-rw-r--r--tests/unit_tests/block_reward.cpp84
-rw-r--r--tests/unit_tests/blockchain_db.cpp2
-rw-r--r--tests/unit_tests/bulletproofs.cpp175
-rw-r--r--tests/unit_tests/fee.cpp54
-rw-r--r--tests/unit_tests/hardfork.cpp4
-rw-r--r--tests/unit_tests/is_hdd.cpp17
-rw-r--r--tests/unit_tests/json_serialization.cpp2
-rw-r--r--tests/unit_tests/multiexp.cpp254
-rw-r--r--tests/unit_tests/ringct.cpp31
11 files changed, 640 insertions, 74 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 076a4a873..741bb1882 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -58,6 +58,7 @@ set(unit_tests_sources
mlocker.cpp
mnemonics.cpp
mul_div.cpp
+ multiexp.cpp
multisig.cpp
parse_amount.cpp
random.cpp
@@ -77,7 +78,9 @@ set(unit_tests_sources
output_selection.cpp
vercmp.cpp
ringdb.cpp
- wipeable_string.cpp)
+ wipeable_string.cpp
+ is_hdd.cpp
+ aligned.cpp)
set(unit_tests_headers
unit_tests_utils.h)
diff --git a/tests/unit_tests/aligned.cpp b/tests/unit_tests/aligned.cpp
new file mode 100644
index 000000000..ad4837bec
--- /dev/null
+++ b/tests/unit_tests/aligned.cpp
@@ -0,0 +1,86 @@
+// Copyright (c) 2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+
+#include "common/aligned.h"
+
+TEST(aligned, large_null) { ASSERT_TRUE(aligned_malloc((size_t)-1, 1) == NULL); }
+TEST(aligned, free_null) { aligned_free(NULL); }
+TEST(aligned, zero) { void *ptr = aligned_malloc(0, 1); ASSERT_TRUE(ptr); aligned_free(ptr); }
+TEST(aligned, aligned1) { void *ptr = aligned_malloc(1, 1); ASSERT_TRUE(ptr); aligned_free(ptr); }
+TEST(aligned, aligned4096) { void *ptr = aligned_malloc(1, 4096); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 4095) == 0); aligned_free(ptr); }
+TEST(aligned, aligned8) { void *ptr = aligned_malloc(1, 8); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 7) == 0); aligned_free(ptr); }
+TEST(aligned, realloc_null) { void *ptr = aligned_realloc(NULL, 1, 4096); ASSERT_TRUE(ptr && ((uintptr_t)ptr & 4095) == 0); aligned_free(ptr); }
+TEST(aligned, realloc_diff_align) { void *ptr = aligned_malloc(1, 4096); ASSERT_TRUE(!aligned_realloc(ptr, 1, 2048)); aligned_free(ptr); }
+TEST(aligned, realloc_same) { void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 1, 4096); ASSERT_TRUE(ptr == ptr2); aligned_free(ptr2); }
+TEST(aligned, realloc_larger) { void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 2, 4096); ASSERT_TRUE(ptr != ptr2); aligned_free(ptr2); }
+TEST(aligned, realloc_zero) { void *ptr = aligned_malloc(1, 4096), *ptr2 = aligned_realloc(ptr, 0, 4096); ASSERT_TRUE(ptr && !ptr2); }
+
+TEST(aligned, contents_larger)
+{
+ unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
+ ASSERT_TRUE(ptr);
+ for (int n = 0; n < 50; ++n)
+ ptr[n] = n;
+ unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 51, 256);
+ for (int n = 0; n < 50; ++n)
+ {
+ ASSERT_TRUE(ptr2[n] == n);
+ }
+ aligned_free(ptr2);
+}
+
+TEST(aligned, contents_same)
+{
+ unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
+ ASSERT_TRUE(ptr);
+ for (int n = 0; n < 50; ++n)
+ ptr[n] = n;
+ unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 50, 256);
+ for (int n = 0; n < 50; ++n)
+ {
+ ASSERT_TRUE(ptr2[n] == n);
+ }
+ aligned_free(ptr2);
+}
+
+TEST(aligned, contents_smaller)
+{
+ unsigned char *ptr = (unsigned char*)aligned_malloc(50, 256);
+ ASSERT_TRUE(ptr);
+ for (int n = 0; n < 50; ++n)
+ ptr[n] = n;
+ unsigned char *ptr2 = (unsigned char*)aligned_realloc(ptr, 49, 256);
+ for (int n = 0; n < 49; ++n)
+ {
+ ASSERT_TRUE(ptr2[n] == n);
+ }
+ aligned_free(ptr2);
+}
+
diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp
index ca863ded9..a897e4140 100644
--- a/tests/unit_tests/block_reward.cpp
+++ b/tests/unit_tests/block_reward.cpp
@@ -40,14 +40,14 @@ namespace
class block_reward_and_already_generated_coins : public ::testing::Test
{
protected:
- static const size_t current_block_size = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 / 2;
+ static const size_t current_block_weight = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 / 2;
bool m_block_not_too_big;
uint64_t m_block_reward;
};
#define TEST_ALREADY_GENERATED_COINS(already_generated_coins, expected_reward) \
- m_block_not_too_big = get_block_reward(0, current_block_size, already_generated_coins, m_block_reward,1); \
+ m_block_not_too_big = get_block_reward(0, current_block_weight, already_generated_coins, m_block_reward,1); \
ASSERT_TRUE(m_block_not_too_big); \
ASSERT_EQ(m_block_reward, expected_reward);
@@ -74,7 +74,7 @@ namespace
}
//--------------------------------------------------------------------------------------------------------------------
- class block_reward_and_current_block_size : public ::testing::Test
+ class block_reward_and_current_block_weight : public ::testing::Test
{
protected:
virtual void SetUp()
@@ -84,9 +84,9 @@ namespace
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward);
}
- void do_test(size_t median_block_size, size_t current_block_size)
+ void do_test(size_t median_block_weight, size_t current_block_weight)
{
- m_block_not_too_big = get_block_reward(median_block_size, current_block_size, already_generated_coins, m_block_reward, 1);
+ m_block_not_too_big = get_block_reward(median_block_weight, current_block_weight, already_generated_coins, m_block_reward, 1);
}
static const uint64_t already_generated_coins = 0;
@@ -96,28 +96,28 @@ namespace
uint64_t m_standard_block_reward;
};
- TEST_F(block_reward_and_current_block_size, handles_block_size_less_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_less_relevance_level)
{
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_current_block_size, handles_block_size_eq_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_eq_relevance_level)
{
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_current_block_size, handles_block_size_gt_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_gt_relevance_level)
{
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_current_block_size, handles_block_size_less_2_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_less_2_relevance_level)
{
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1);
ASSERT_TRUE(m_block_not_too_big);
@@ -125,21 +125,21 @@ namespace
ASSERT_LT(0, m_block_reward);
}
- TEST_F(block_reward_and_current_block_size, handles_block_size_eq_2_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_eq_2_relevance_level)
{
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(0, m_block_reward);
}
- TEST_F(block_reward_and_current_block_size, handles_block_size_gt_2_relevance_level)
+ TEST_F(block_reward_and_current_block_weight, handles_block_weight_gt_2_relevance_level)
{
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1);
ASSERT_FALSE(m_block_not_too_big);
}
#ifdef __x86_64__ // For 64-bit systems only, because block size is limited to size_t.
- TEST_F(block_reward_and_current_block_size, fails_on_huge_median_size)
+ TEST_F(block_reward_and_current_block_weight, fails_on_huge_median_size)
{
#if !defined(NDEBUG)
size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2);
@@ -147,7 +147,7 @@ namespace
#endif
}
- TEST_F(block_reward_and_current_block_size, fails_on_huge_block_size)
+ TEST_F(block_reward_and_current_block_weight, fails_on_huge_block_weight)
{
#if !defined(NDEBUG)
size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2);
@@ -157,94 +157,94 @@ namespace
#endif // __x86_64__
//--------------------------------------------------------------------------------------------------------------------
- class block_reward_and_last_block_sizes : public ::testing::Test
+ class block_reward_and_last_block_weights : public ::testing::Test
{
protected:
virtual void SetUp()
{
- m_last_block_sizes.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
- m_last_block_sizes.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
- m_last_block_sizes.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
- m_last_block_sizes.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
- m_last_block_sizes.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
+ m_last_block_weights.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
+ m_last_block_weights.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
+ m_last_block_weights.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
+ m_last_block_weights.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
+ m_last_block_weights.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
- m_last_block_sizes_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
+ m_last_block_weights_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
- m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), 0, already_generated_coins, m_standard_block_reward, 1);
+ m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_weights), 0, already_generated_coins, m_standard_block_reward, 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward);
}
- void do_test(size_t current_block_size)
+ void do_test(size_t current_block_weight)
{
- m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), current_block_size, already_generated_coins, m_block_reward, 1);
+ m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_weights), current_block_weight, already_generated_coins, m_block_reward, 1);
}
static const uint64_t already_generated_coins = 0;
- std::vector<size_t> m_last_block_sizes;
- uint64_t m_last_block_sizes_median;
+ std::vector<size_t> m_last_block_weights;
+ uint64_t m_last_block_weights_median;
bool m_block_not_too_big;
uint64_t m_block_reward;
uint64_t m_standard_block_reward;
};
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_less_median)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_less_median)
{
- do_test(m_last_block_sizes_median - 1);
+ do_test(m_last_block_weights_median - 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_eq_median)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_eq_median)
{
- do_test(m_last_block_sizes_median);
+ do_test(m_last_block_weights_median);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_gt_median)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_gt_median)
{
- do_test(m_last_block_sizes_median + 1);
+ do_test(m_last_block_weights_median + 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(m_block_reward, m_standard_block_reward);
}
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_less_2_medians)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_less_2_medians)
{
- do_test(2 * m_last_block_sizes_median - 1);
+ do_test(2 * m_last_block_weights_median - 1);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(m_block_reward, m_standard_block_reward);
ASSERT_LT(0, m_block_reward);
}
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_eq_2_medians)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_eq_2_medians)
{
- do_test(2 * m_last_block_sizes_median);
+ do_test(2 * m_last_block_weights_median);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(0, m_block_reward);
}
- TEST_F(block_reward_and_last_block_sizes, handles_block_size_gt_2_medians)
+ TEST_F(block_reward_and_last_block_weights, handles_block_weight_gt_2_medians)
{
- do_test(2 * m_last_block_sizes_median + 1);
+ do_test(2 * m_last_block_weights_median + 1);
ASSERT_FALSE(m_block_not_too_big);
}
- TEST_F(block_reward_and_last_block_sizes, calculates_correctly)
+ TEST_F(block_reward_and_last_block_weights, calculates_correctly)
{
- ASSERT_EQ(0, m_last_block_sizes_median % 8);
+ ASSERT_EQ(0, m_last_block_weights_median % 8);
- do_test(m_last_block_sizes_median * 9 / 8);
+ do_test(m_last_block_weights_median * 9 / 8);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward * 63 / 64);
// 3/2 = 12/8
- do_test(m_last_block_sizes_median * 3 / 2);
+ do_test(m_last_block_weights_median * 3 / 2);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward * 3 / 4);
- do_test(m_last_block_sizes_median * 15 / 8);
+ do_test(m_last_block_weights_median * 15 / 8);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_EQ(m_block_reward, m_standard_block_reward * 15 / 64);
}
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index 3a62fba69..7e7ce9bf7 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -319,7 +319,7 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
- ASSERT_EQ(t_sizes[0], this->m_db->get_block_size(0));
+ ASSERT_EQ(t_sizes[0], this->m_db->get_block_weight(0));
ASSERT_EQ(t_diffs[0], this->m_db->get_block_cumulative_difficulty(0));
ASSERT_EQ(t_diffs[0], this->m_db->get_block_difficulty(0));
ASSERT_EQ(t_coins[0], this->m_db->get_block_already_generated_coins(0));
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 00595a4c7..45075c63d 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -30,8 +30,12 @@
#include "gtest/gtest.h"
+#include "string_tools.h"
#include "ringct/rctOps.h"
+#include "ringct/rctSigs.h"
#include "ringct/bulletproofs.h"
+#include "device/device.hpp"
+#include "misc_log_ex.h"
TEST(bulletproofs, valid_zero)
{
@@ -54,6 +58,108 @@ TEST(bulletproofs, valid_random)
}
}
+TEST(bulletproofs, valid_multi_random)
+{
+ for (int n = 0; n < 8; ++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());
+ }
+ rct::Bulletproof proof = bulletproof_PROVE(amounts, gamma);
+ ASSERT_TRUE(rct::bulletproof_VERIFY(proof));
+ }
+}
+
+TEST(bulletproofs, multi_splitting)
+{
+ rct::ctkeyV sc, pc;
+ rct::ctkey sctmp, pctmp;
+ std::vector<unsigned int> index;
+ std::vector<uint64_t> inamounts, outamounts;
+
+ std::tie(sctmp, pctmp) = rct::ctskpkGen(6000);
+ sc.push_back(sctmp);
+ pc.push_back(pctmp);
+ inamounts.push_back(6000);
+ index.push_back(1);
+
+ std::tie(sctmp, pctmp) = rct::ctskpkGen(7000);
+ sc.push_back(sctmp);
+ pc.push_back(pctmp);
+ inamounts.push_back(7000);
+ index.push_back(1);
+
+ const int mixin = 3, max_outputs = 16;
+
+ for (int n_outputs = 1; n_outputs <= max_outputs; ++n_outputs)
+ {
+ std::vector<uint64_t> outamounts;
+ rct::keyV amount_keys;
+ rct::keyV destinations;
+ rct::key Sk, Pk;
+ uint64_t available = 6000 + 7000;
+ uint64_t amount;
+ rct::ctkeyM mixRing(sc.size());
+
+ //add output
+ for (size_t i = 0; i < n_outputs; ++i)
+ {
+ amount = rct::randXmrAmount(available);
+ outamounts.push_back(amount);
+ amount_keys.push_back(rct::hash_to_scalar(rct::zero()));
+ rct::skpkGen(Sk, Pk);
+ destinations.push_back(Pk);
+ available -= amount;
+ }
+
+ for (size_t i = 0; i < sc.size(); ++i)
+ {
+ for (size_t j = 0; j <= mixin; ++j)
+ {
+ if (j == 1)
+ mixRing[i].push_back(pc[i]);
+ else
+ mixRing[i].push_back({rct::scalarmultBase(rct::skGen()), rct::scalarmultBase(rct::skGen())});
+ }
+ }
+
+ rct::ctkeyV outSk;
+ rct::rctSig s = rct::genRctSimple(rct::zero(), sc, destinations, inamounts, outamounts, available, mixRing, amount_keys, NULL, NULL, index, outSk, rct::RangeProofPaddedBulletproof, hw::get_device("default"));
+ ASSERT_TRUE(rct::verRctSimple(s));
+ for (size_t i = 0; i < n_outputs; ++i)
+ {
+ rct::key mask;
+ rct::decodeRctSimple(s, amount_keys[i], i, mask, hw::get_device("default"));
+ ASSERT_TRUE(mask == outSk[i].mask);
+ }
+ }
+}
+
+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)
{
rct::key invalid_amount = rct::zero();
@@ -69,3 +175,72 @@ TEST(bulletproofs, invalid_31)
rct::Bulletproof proof = bulletproof_PROVE(invalid_amount, rct::skGen());
ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
}
+
+TEST(bulletproofs, invalid_gamma_0)
+{
+ rct::key invalid_amount = rct::zero();
+ invalid_amount[8] = 1;
+ rct::key gamma = rct::zero();
+ rct::Bulletproof proof = bulletproof_PROVE(invalid_amount, gamma);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+}
+
+static const char * const torsion_elements[] =
+{
+ "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa",
+ "0000000000000000000000000000000000000000000000000000000000000000",
+ "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85",
+ "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
+ "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05",
+ "0000000000000000000000000000000000000000000000000000000000000080",
+ "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a",
+};
+
+TEST(bulletproofs, invalid_torsion)
+{
+ rct::Bulletproof proof = bulletproof_PROVE(7329838943733, rct::skGen());
+ ASSERT_TRUE(rct::bulletproof_VERIFY(proof));
+ for (const auto &xs: torsion_elements)
+ {
+ rct::key x;
+ ASSERT_TRUE(epee::string_tools::hex_to_pod(xs, x));
+ ASSERT_FALSE(rct::isInMainSubgroup(x));
+ for (auto &k: proof.V)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ k = org_k;
+ }
+ for (auto &k: proof.L)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ k = org_k;
+ }
+ for (auto &k: proof.R)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ k = org_k;
+ }
+ const rct::key org_A = proof.A;
+ rct::addKeys(proof.A, org_A, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ proof.A = org_A;
+ const rct::key org_S = proof.S;
+ rct::addKeys(proof.S, org_S, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ proof.S = org_S;
+ const rct::key org_T1 = proof.T1;
+ rct::addKeys(proof.T1, org_T1, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ proof.T1 = org_T1;
+ const rct::key org_T2 = proof.T2;
+ rct::addKeys(proof.T2, org_T2, x);
+ ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
+ proof.T2 = org_T2;
+ }
+}
diff --git a/tests/unit_tests/fee.cpp b/tests/unit_tests/fee.cpp
index c5589ab96..8ccb38fc9 100644
--- a/tests/unit_tests/fee.cpp
+++ b/tests/unit_tests/fee.cpp
@@ -58,46 +58,46 @@ namespace
TEST_F(fee, 10xmr)
{
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, 1, 3), 2000000000);
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(2000000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(2000000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(2000000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, 1, 3), 2000000000);
// higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(2000000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(2000000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(2000000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(2000000000 / 20000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(2000000000 / 2));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(2000000000 / 10));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(2000000000 / 1000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(2000000000 / 20000));
}
TEST_F(fee, 1xmr)
{
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, 1, 3), 200000000);
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(200000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(200000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(200000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, 1, 3), 200000000);
// higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(200000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(200000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(200000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(200000000 / 20000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(200000000 / 2));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(200000000 / 10));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(200000000 / 1000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(200000000 / 20000));
}
TEST_F(fee, dot3xmr)
{
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, 1, 3), 60000000);
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(60000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(60000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(60000000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, 1, 3), 60000000);
// higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(60000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(60000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(60000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(60000000 / 20000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(60000000 / 2));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(60000000 / 10));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(60000000 / 1000));
+ ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(60000000 / 20000));
}
static bool is_more_or_less(double x, double y)
@@ -116,7 +116,7 @@ namespace
600000000000ull, // .6 monero, minimum reward per block at 2min
300000000000ull, // .3 monero, minimum reward per block at 1min
};
- static const uint64_t median_block_sizes[] = {
+ static const uint64_t median_block_weights[] = {
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2,
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2,
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10,
@@ -127,9 +127,9 @@ namespace
for (uint64_t block_reward: block_rewards)
{
- for (uint64_t median_block_size: median_block_sizes)
+ for (uint64_t median_block_weight: median_block_weights)
{
- ASSERT_TRUE(is_more_or_less(Blockchain::get_dynamic_per_kb_fee(block_reward, median_block_size, 3) * (median_block_size / 1024.) * MAX_MULTIPLIER / (double)block_reward, 1.992 * 1000 / 1024));
+ ASSERT_TRUE(is_more_or_less(Blockchain::get_dynamic_base_fee(block_reward, median_block_weight, 3) * (median_block_weight / 1024.) * MAX_MULTIPLIER / (double)block_reward, 1.992 * 1000 / 1024));
}
}
}
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 8155c65f9..47177db1c 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -72,7 +72,7 @@ public:
virtual uint64_t get_block_timestamp(const uint64_t& height) const { return 0; }
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const { return {}; }
virtual uint64_t get_top_block_timestamp() const { return 0; }
- virtual size_t get_block_size(const uint64_t& height) const { return 128; }
+ virtual size_t get_block_weight(const uint64_t& height) const { return 128; }
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const { return 10; }
virtual difficulty_type get_block_difficulty(const uint64_t& height) const { return 0; }
virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const { return 10000000000; }
@@ -130,7 +130,7 @@ public:
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }
virtual void add_block( const block& blk
- , const size_t& block_size
+ , size_t block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
diff --git a/tests/unit_tests/is_hdd.cpp b/tests/unit_tests/is_hdd.cpp
new file mode 100644
index 000000000..1be670e5e
--- /dev/null
+++ b/tests/unit_tests/is_hdd.cpp
@@ -0,0 +1,17 @@
+#include "common/util.h"
+#include <string>
+#include <gtest/gtest.h>
+
+#if defined(__GLIBC__)
+TEST(is_hdd, linux_os_root)
+{
+ std::string path = "/";
+ EXPECT_TRUE(tools::is_hdd(path.c_str()));
+}
+#else
+TEST(is_hdd, unknown_os)
+{
+ std::string path = "";
+ EXPECT_FALSE(tools::is_hdd(path.c_str()));
+}
+#endif
diff --git a/tests/unit_tests/json_serialization.cpp b/tests/unit_tests/json_serialization.cpp
index ac6b60846..234cb2c33 100644
--- a/tests/unit_tests/json_serialization.cpp
+++ b/tests/unit_tests/json_serialization.cpp
@@ -75,7 +75,7 @@ namespace
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[from.m_account_address.m_spend_public_key] = {0,0};
- if (!cryptonote::construct_tx_and_get_tx_key(from, subaddresses, actual_sources, to, boost::none, {}, tx, 0, tx_key, extra_keys, rct, bulletproof))
+ if (!cryptonote::construct_tx_and_get_tx_key(from, subaddresses, actual_sources, to, boost::none, {}, tx, 0, tx_key, extra_keys, rct, bulletproof ? rct::RangeProofBulletproof : rct::RangeProofBorromean))
throw std::runtime_error{"transaction construction error"};
return tx;
diff --git a/tests/unit_tests/multiexp.cpp b/tests/unit_tests/multiexp.cpp
new file mode 100644
index 000000000..d8d79a7a2
--- /dev/null
+++ b/tests/unit_tests/multiexp.cpp
@@ -0,0 +1,254 @@
+// Copyright (c) 2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+
+#include "crypto/crypto.h"
+#include "ringct/rctOps.h"
+#include "ringct/multiexp.h"
+
+static const rct::key TESTSCALAR = rct::skGen();
+static const rct::key TESTPOW2SCALAR = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+static const rct::key TESTSMALLSCALAR = {{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+static const rct::key TESTPOINT = rct::scalarmultBase(rct::skGen());
+
+static rct::key basic(const std::vector<rct::MultiexpData> &data)
+{
+ ge_p3 res_p3 = ge_p3_identity;
+ for (const auto &d: data)
+ {
+ ge_cached cached;
+ ge_p3 p3;
+ ge_p1p1 p1;
+ ge_scalarmult_p3(&p3, d.scalar.bytes, &d.point);
+ ge_p3_to_cached(&cached, &p3);
+ ge_add(&p1, &res_p3, &cached);
+ ge_p1p1_to_p3(&res_p3, &p1);
+ }
+ rct::key res;
+ ge_p3_tobytes(res.bytes, &res_p3);
+ return res;
+}
+
+static ge_p3 get_p3(const rct::key &point)
+{
+ ge_p3 p3;
+ EXPECT_TRUE(ge_frombytes_vartime(&p3, point.bytes) == 0);
+ return p3;
+}
+
+TEST(multiexp, bos_coster_empty)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+}
+
+TEST(multiexp, straus_empty)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == straus(data));
+}
+
+TEST(multiexp, pippenger_empty)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+}
+
+TEST(multiexp, bos_coster_zero_and_non_zero)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ data.push_back({TESTSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+}
+
+TEST(multiexp, straus_zero_and_non_zero)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ data.push_back({TESTSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == straus(data));
+}
+
+TEST(multiexp, pippenger_zero_and_non_zero)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ data.push_back({TESTSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+}
+
+TEST(multiexp, bos_coster_pow2_scalar)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({TESTPOW2SCALAR, get_p3(TESTPOINT)});
+ data.push_back({TESTSMALLSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+}
+
+TEST(multiexp, straus_pow2_scalar)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({TESTPOW2SCALAR, get_p3(TESTPOINT)});
+ data.push_back({TESTSMALLSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == straus(data));
+}
+
+TEST(multiexp, pippenger_pow2_scalar)
+{
+ std::vector<rct::MultiexpData> data;
+ data.push_back({TESTPOW2SCALAR, get_p3(TESTPOINT)});
+ data.push_back({TESTSMALLSCALAR, get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+}
+
+TEST(multiexp, bos_coster_only_zeroes)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+}
+
+TEST(multiexp, straus_only_zeroes)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == straus(data));
+}
+
+TEST(multiexp, pippenger_only_zeroes)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({rct::zero(), get_p3(TESTPOINT)});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+}
+
+TEST(multiexp, bos_coster_only_identities)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({TESTSCALAR, get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+}
+
+TEST(multiexp, straus_only_identities)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({TESTSCALAR, get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == straus(data));
+}
+
+TEST(multiexp, pippenger_only_identities)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 16; ++n)
+ data.push_back({TESTSCALAR, get_p3(rct::identity())});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+}
+
+TEST(multiexp, bos_coster_random)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 32; ++n)
+ {
+ data.push_back({rct::skGen(), get_p3(rct::scalarmultBase(rct::skGen()))});
+ ASSERT_TRUE(basic(data) == bos_coster_heap_conv_robust(data));
+ }
+}
+
+TEST(multiexp, straus_random)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 32; ++n)
+ {
+ data.push_back({rct::skGen(), get_p3(rct::scalarmultBase(rct::skGen()))});
+ ASSERT_TRUE(basic(data) == straus(data));
+ }
+}
+
+TEST(multiexp, pippenger_random)
+{
+ std::vector<rct::MultiexpData> data;
+ for (int n = 0; n < 32; ++n)
+ {
+ data.push_back({rct::skGen(), get_p3(rct::scalarmultBase(rct::skGen()))});
+ ASSERT_TRUE(basic(data) == pippenger(data));
+ }
+}
+
+TEST(multiexp, straus_cached)
+{
+ static constexpr size_t N = 256;
+ std::vector<rct::MultiexpData> P(N);
+ for (size_t n = 0; n < N; ++n)
+ {
+ P[n].scalar = rct::zero();
+ ASSERT_TRUE(ge_frombytes_vartime(&P[n].point, rct::scalarmultBase(rct::skGen()).bytes) == 0);
+ }
+ std::shared_ptr<rct::straus_cached_data> cache = rct::straus_init_cache(P);
+ for (size_t n = 0; n < N/16; ++n)
+ {
+ std::vector<rct::MultiexpData> data;
+ size_t sz = 1 + crypto::rand<size_t>() % (N-1);
+ for (size_t s = 0; s < sz; ++s)
+ {
+ data.push_back({rct::skGen(), P[s].point});
+ }
+ ASSERT_TRUE(basic(data) == straus(data, cache));
+ }
+}
+
+TEST(multiexp, pippenger_cached)
+{
+ static constexpr size_t N = 256;
+ std::vector<rct::MultiexpData> P(N);
+ for (size_t n = 0; n < N; ++n)
+ {
+ P[n].scalar = rct::zero();
+ ASSERT_TRUE(ge_frombytes_vartime(&P[n].point, rct::scalarmultBase(rct::skGen()).bytes) == 0);
+ }
+ std::shared_ptr<rct::pippenger_cached_data> cache = rct::pippenger_init_cache(P);
+ for (size_t n = 0; n < N/16; ++n)
+ {
+ std::vector<rct::MultiexpData> data;
+ size_t sz = 1 + crypto::rand<size_t>() % (N-1);
+ for (size_t s = 0; s < sz; ++s)
+ {
+ data.push_back({rct::skGen(), P[s].point});
+ }
+ ASSERT_TRUE(basic(data) == pippenger(data, cache));
+ }
+}
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 6e3958f8a..3877ef785 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -1085,3 +1085,34 @@ TEST(ringct, zeroCommmit)
const rct::key manual = rct::addKeys(a, b);
ASSERT_EQ(z, manual);
}
+
+TEST(ringct, H)
+{
+ ge_p3 p3;
+ ASSERT_EQ(ge_frombytes_vartime(&p3, rct::H.bytes), 0);
+ ASSERT_EQ(memcmp(&p3, &ge_p3_H, sizeof(ge_p3)), 0);
+}
+
+TEST(ringct, mul8)
+{
+ ASSERT_EQ(rct::scalarmult8(rct::identity()), rct::identity());
+ ASSERT_EQ(rct::scalarmult8(rct::H), rct::scalarmultKey(rct::H, rct::EIGHT));
+ ASSERT_EQ(rct::scalarmultKey(rct::scalarmultKey(rct::H, rct::INV_EIGHT), rct::EIGHT), rct::H);
+}
+
+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));
+}