aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-09-11 15:45:56 +0200
committerRiccardo Spagni <ric@spagni.net>2018-09-11 15:45:56 +0200
commite6d36c17015e179aaa21f2353bdc608967833303 (patch)
tree39fb0829fe9f3b0d468bbb27393cd79fdefbda15 /tests
parentMerge pull request #4218 (diff)
parentblockchain: add a testnet v9 a day after v8 (diff)
downloadmonero-e6d36c17015e179aaa21f2353bdc608967833303.tar.xz
Merge pull request #4219
9137ad2c blockchain: add a testnet v9 a day after v8 (moneromooo-monero) ac4f71c2 wallet2: bump testnet rollback to account for coming reorg (moneromooo-monero) 8f418a6d bulletproofs: #include <openssl/bn.h> (moneromooo-monero) 2bf63650 bulletproofs: speed up the latest changes a bit (moneromooo-monero) 044dff5a bulletproofs: scale points by 8 to ensure subgroup validity (moneromooo-monero) c83012c4 bulletproofs: match aggregated verification to sarang's latest prototype (moneromooo-monero) ce0c7432 performance_tests: add padded bulletproof construction (moneromooo-monero) 1224e53b core_tests: add a test for 4-aggregated BP verification (moneromooo-monero) 0e6ed559 fuzz_tests: add a bulletproof fuzz test (moneromooo-monero) 463434d1 more comprehensive test for ge_p3 comparison to identity/point at infinity (moneromooo-monero) d0a0565f unit_tests: add a few more multiexp unit tests (moneromooo-monero) 6526d87f core_tests: add a test for a tx with empty bulletproof (moneromooo-monero) a129bbd9 multiexp: fix maxscalar off by one (moneromooo-monero) 7ed496cc ringct: error out when hashToPoint* returns the point at infinity (moneromooo-monero) d1591853 cryptonote_basic: check output type before using it (moneromooo-monero) 61632dc1 ringct: prevent a potential very large allocation (moneromooo-monero) a4317e61 crypto: some paranoid checks in generate_signature/check_signature (moneromooo-monero) 7434df1c crypto: never return zero in random32_unbiased (moneromooo-monero) 0825e974 multiexp: fix wrong Bos-Coster result for 1 non trivial input (moneromooo-monero) a1359ad4 Check inputs to addKeys are in range (moneromooo-monero) fe0fa3b9 bulletproofs: reject x, y, z, or w[i] being zero (moneromooo-monero) 5ffb2ff9 v8: per byte fee, pad bulletproofs, fixed 11 ring size (moneromooo-monero) 869b3bf8 bulletproofs: a few fixes from the Kudelski review (moneromooo-monero) c4291762 bulletproofs: reject points not in the main subgroup (moneromooo-monero) 15697177 bulletproofs: speed up a few multiplies using existing Hi cache (moneromooo-monero) 0b05a0fa Add Pippenger cache and limit Straus cache size (moneromooo-monero) 51eb3bdc add pippenger unit tests (moneromooo-monero) b17b8db3 performance_tests: add stats and loop count multiplier options (moneromooo-monero) 7314d919 perf_timer: split timer class into a base one and a logging one (moneromooo-monero) d126a02b performance_tests: add aggregated bulletproof tx verification (moneromooo-monero) 263431c4 Pippenger multiexp (moneromooo-monero) 1ed0ed4d multiexp: cut down on memory allocations (moneromooo-monero) 1b867e7f precalc the ge_p3 representation of H (moneromooo-monero) ef56529f performance_tests: document the tested bulletproof layouts (moneromooo-monero) 30111780 unit_tests: a couple more bulletproof unit tests for gamma (moneromooo-monero) c444b1b2 require canonical multi output bulletproof layout (moneromooo-monero) 7e67c52f Add a define for the max number of bulletproof multi-outputs (moneromooo-monero) 2a8fcb42 Bulletproof aggregated verification and tests (moneromooo-monero) 126196b0 multiexp: some speedups (moneromooo-monero) 71d67bda aligned: aligned memory alloc/realloc/free (moneromooo-monero) cb9ecab1 performance_tests: add signature generation/verification (moneromooo-monero) bacf0a1e bulletproofs: add aggregated verification (moneromooo-monero) e895c3de make straus cached mode thread safe, and add tests for it (moneromooo-monero) 7f48bf05 multiexp: bos coster now works for just one point (moneromooo-monero) 9ce9f8ca bulletproofs: add multi output bulletproofs to rct (moneromooo-monero) f34e2e20 performance_tests: add tx checking tests with more than 2 outputs (moneromooo-monero) 0793184b performance_tests: add a --verbose flag, and default to terse (moneromooo-monero) 939bc223 add Straus multiexp (moneromooo-monero) 9ff6e6a0 ringct: add bos coster multiexp (moneromooo-monero) e9164bb3 bulletproofs: misc optimizations (moneromooo-monero) 112f32f0 performance_tests: add crypto ops (moneromooo-monero) f5d7b993 performance_tests: add bulletproofs (moneromooo-monero) 8f4ce989 performance_tests: add RingCT MLSAG gen/ver tests (moneromooo-monero) 1aa10c43 performance_tests: add (Borromean) range proofs (moneromooo-monero) aacfd6e3 bulletproofs: multi-output bulletproofs (moneromooo-monero) cb1cc757 performance_tests: don't override log level to 0 (moneromooo-monero)
Diffstat (limited to 'tests')
-rw-r--r--tests/core_tests/CMakeLists.txt7
-rw-r--r--tests/core_tests/block_reward.cpp54
-rw-r--r--tests/core_tests/block_validation.cpp4
-rw-r--r--tests/core_tests/bulletproofs.cpp361
-rw-r--r--tests/core_tests/bulletproofs.h193
-rw-r--r--tests/core_tests/chaingen.cpp76
-rw-r--r--tests/core_tests/chaingen.h60
-rw-r--r--tests/core_tests/chaingen_main.cpp16
-rw-r--r--tests/core_tests/chaingen_tests_list.h1
-rw-r--r--tests/core_tests/multisig.cpp2
-rw-r--r--tests/core_tests/rct.cpp2
-rw-r--r--tests/data/fuzz/bulletproof/BP0bin0 -> 674 bytes
-rw-r--r--tests/fuzz/CMakeLists.txt15
-rw-r--r--tests/fuzz/bulletproof.cpp70
-rw-r--r--tests/performance_tests/CMakeLists.txt5
-rw-r--r--tests/performance_tests/bulletproof.h100
-rw-r--r--tests/performance_tests/check_tx_signature.h84
-rw-r--r--tests/performance_tests/construct_tx.h4
-rw-r--r--tests/performance_tests/crypto_ops.h122
-rw-r--r--tests/performance_tests/main.cpp532
-rw-r--r--tests/performance_tests/multiexp.h94
-rw-r--r--tests/performance_tests/performance_tests.h126
-rw-r--r--tests/performance_tests/range_proof.h63
-rw-r--r--tests/performance_tests/signature.h68
-rw-r--r--tests/unit_tests/CMakeLists.txt4
-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/json_serialization.cpp2
-rw-r--r--tests/unit_tests/multiexp.cpp254
-rw-r--r--tests/unit_tests/ringct.cpp31
34 files changed, 2507 insertions, 248 deletions
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index c8ee7d9db..1ac0e7864 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -41,7 +41,8 @@ set(core_tests_sources
transaction_tests.cpp
tx_validation.cpp
v2_tests.cpp
- rct.cpp)
+ rct.cpp
+ bulletproofs.cpp)
set(core_tests_headers
block_reward.h
@@ -58,7 +59,8 @@ set(core_tests_headers
transaction_tests.h
tx_validation.h
v2_tests.h
- rct.h)
+ rct.h
+ bulletproofs.h)
add_executable(core_tests
${core_tests_sources}
@@ -73,6 +75,7 @@ target_link_libraries(core_tests
device
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
+enable_stack_trace(core_tests)
set_property(TARGET core_tests
PROPERTY
FOLDER "tests")
diff --git a/tests/core_tests/block_reward.cpp b/tests/core_tests/block_reward.cpp
index 9b0e74911..e55378439 100644
--- a/tests/core_tests/block_reward.cpp
+++ b/tests/core_tests/block_reward.cpp
@@ -36,24 +36,24 @@ using namespace cryptonote;
namespace
{
- bool construct_miner_tx_by_size(transaction& miner_tx, uint64_t height, uint64_t already_generated_coins,
- const account_public_address& miner_address, std::vector<size_t>& block_sizes, size_t target_tx_size,
- size_t target_block_size, uint64_t fee = 0)
+ bool construct_miner_tx_by_weight(transaction& miner_tx, uint64_t height, uint64_t already_generated_coins,
+ const account_public_address& miner_address, std::vector<size_t>& block_weights, size_t target_tx_weight,
+ size_t target_block_weight, uint64_t fee = 0)
{
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, target_block_size, fee, miner_address, miner_tx))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, fee, miner_address, miner_tx))
return false;
- size_t current_size = get_object_blobsize(miner_tx);
+ size_t current_weight = get_transaction_weight(miner_tx);
size_t try_count = 0;
- while (target_tx_size != current_size)
+ while (target_tx_weight != current_weight)
{
++try_count;
if (10 < try_count)
return false;
- if (target_tx_size < current_size)
+ if (target_tx_weight < current_weight)
{
- size_t diff = current_size - target_tx_size;
+ size_t diff = current_weight - target_tx_weight;
if (diff <= miner_tx.extra.size())
miner_tx.extra.resize(miner_tx.extra.size() - diff);
else
@@ -61,28 +61,28 @@ namespace
}
else
{
- size_t diff = target_tx_size - current_size;
+ size_t diff = target_tx_weight - current_weight;
miner_tx.extra.resize(miner_tx.extra.size() + diff);
}
- current_size = get_object_blobsize(miner_tx);
+ current_weight = get_transaction_weight(miner_tx);
}
return true;
}
- bool construct_max_size_block(test_generator& generator, block& blk, const block& blk_prev, const account_base& miner_account,
+ bool construct_max_weight_block(test_generator& generator, block& blk, const block& blk_prev, const account_base& miner_account,
size_t median_block_count = CRYPTONOTE_REWARD_BLOCKS_WINDOW)
{
- std::vector<size_t> block_sizes;
- generator.get_last_n_block_sizes(block_sizes, get_block_hash(blk_prev), median_block_count);
+ std::vector<size_t> block_weights;
+ generator.get_last_n_block_weights(block_weights, get_block_hash(blk_prev), median_block_count);
- size_t median = misc_utils::median(block_sizes);
+ size_t median = misc_utils::median(block_weights);
median = std::max(median, static_cast<size_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1));
transaction miner_tx;
- bool r = construct_miner_tx_by_size(miner_tx, get_block_height(blk_prev) + 1, generator.get_already_generated_coins(blk_prev),
- miner_account.get_keys().m_account_address, block_sizes, 2 * median, 2 * median);
+ bool r = construct_miner_tx_by_weight(miner_tx, get_block_height(blk_prev) + 1, generator.get_already_generated_coins(blk_prev),
+ miner_account.get_keys().m_account_address, block_weights, 2 * median, 2 * median);
if (!r)
return false;
@@ -97,7 +97,7 @@ namespace
for (size_t i = 0; i < block_count; ++i)
{
block blk_i;
- if (!construct_max_size_block(generator, blk_i, blk, miner_account))
+ if (!construct_max_weight_block(generator, blk_i, blk, miner_account))
return false;
events.push_back(blk_i);
@@ -141,18 +141,18 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
// Test: block reward is calculated using median of the latest CRYPTONOTE_REWARD_BLOCKS_WINDOW blocks
DO_CALLBACK(events, "mark_invalid_block");
block blk_1_bad_1;
- if (!construct_max_size_block(generator, blk_1_bad_1, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW + 1))
+ if (!construct_max_weight_block(generator, blk_1_bad_1, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW + 1))
return false;
events.push_back(blk_1_bad_1);
DO_CALLBACK(events, "mark_invalid_block");
block blk_1_bad_2;
- if (!construct_max_size_block(generator, blk_1_bad_2, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1))
+ if (!construct_max_weight_block(generator, blk_1_bad_2, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1))
return false;
events.push_back(blk_1_bad_2);
block blk_1;
- if (!construct_max_size_block(generator, blk_1, blk_0r, miner_account))
+ if (!construct_max_weight_block(generator, blk_1, blk_0r, miner_account))
return false;
events.push_back(blk_1);
@@ -187,16 +187,16 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
{
transaction tx_1 = construct_tx_with_fee(events, blk_5, miner_account, bob_account, MK_COINS(1), 11 * TESTS_DEFAULT_FEE);
transaction tx_2 = construct_tx_with_fee(events, blk_5, miner_account, bob_account, MK_COINS(1), 13 * TESTS_DEFAULT_FEE);
- size_t txs_1_size = get_object_blobsize(tx_1) + get_object_blobsize(tx_2);
+ size_t txs_1_weight = get_transaction_weight(tx_1) + get_transaction_weight(tx_2);
uint64_t txs_fee = get_tx_fee(tx_1) + get_tx_fee(tx_2);
- std::vector<size_t> block_sizes;
- generator.get_last_n_block_sizes(block_sizes, get_block_hash(blk_7), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
- size_t median = misc_utils::median(block_sizes);
+ std::vector<size_t> block_weights;
+ generator.get_last_n_block_weights(block_weights, get_block_hash(blk_7), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ size_t median = misc_utils::median(block_weights);
transaction miner_tx;
- bool r = construct_miner_tx_by_size(miner_tx, get_block_height(blk_7) + 1, generator.get_already_generated_coins(blk_7),
- miner_account.get_keys().m_account_address, block_sizes, 2 * median - txs_1_size, 2 * median, txs_fee);
+ bool r = construct_miner_tx_by_weight(miner_tx, get_block_height(blk_7) + 1, generator.get_already_generated_coins(blk_7),
+ miner_account.get_keys().m_account_address, block_weights, 2 * median - txs_1_weight, 2 * median, txs_fee);
if (!r)
return false;
@@ -206,7 +206,7 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
block blk_8;
generator.construct_block_manually(blk_8, blk_7, miner_account, test_generator::bf_miner_tx | test_generator::bf_tx_hashes,
- 0, 0, 0, crypto::hash(), 0, miner_tx, txs_1_hashes, txs_1_size);
+ 0, 0, 0, crypto::hash(), 0, miner_tx, txs_1_hashes, txs_1_weight);
events.push_back(blk_8);
DO_CALLBACK(events, "mark_checked_block");
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp
index 598cd4098..760cc4328 100644
--- a/tests/core_tests/block_validation.cpp
+++ b/tests/core_tests/block_validation.cpp
@@ -586,11 +586,11 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
block blk_test;
std::vector<crypto::hash> tx_hashes;
tx_hashes.push_back(get_transaction_hash(tx_0));
- size_t txs_size = get_object_blobsize(tx_0);
+ size_t txs_weight = get_transaction_weight(tx_0);
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1);
if (!generator.construct_block_manually(blk_test, blk_last, miner_account,
test_generator::bf_diffic | test_generator::bf_timestamp | test_generator::bf_tx_hashes, 0, 0, blk_last.timestamp,
- crypto::hash(), diffic, transaction(), tx_hashes, txs_size))
+ crypto::hash(), diffic, transaction(), tx_hashes, txs_weight))
return false;
blobdata blob = t_serializable_object_to_blob(blk_test);
diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp
new file mode 100644
index 000000000..db875d2a2
--- /dev/null
+++ b/tests/core_tests/bulletproofs.cpp
@@ -0,0 +1,361 @@
+// Copyright (c) 2014-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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "ringct/rctSigs.h"
+#include "ringct/bulletproofs.h"
+#include "chaingen.h"
+#include "bulletproofs.h"
+#include "device/device.hpp"
+
+using namespace epee;
+using namespace crypto;
+using namespace cryptonote;
+
+//----------------------------------------------------------------------------------------------------------------------
+// Tests
+
+bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& events,
+ size_t mixin, size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RangeProofType *range_proof_type,
+ const std::function<bool(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations, size_t tx_idx)> &pre_tx,
+ const std::function<bool(transaction &tx, size_t tx_idx)> &post_tx) const
+{
+ uint64_t ts_start = 1338224400;
+
+ GENERATE_ACCOUNT(miner_account);
+ MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
+
+ // create 12 miner accounts, and have them mine the next 12 blocks
+ cryptonote::account_base miner_accounts[12];
+ const cryptonote::block *prev_block = &blk_0;
+ cryptonote::block blocks[12 + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW];
+ for (size_t n = 0; n < 12; ++n) {
+ miner_accounts[n].generate();
+ CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n],
+ test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version,
+ 2, 2, prev_block->timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
+ crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
+ false, "Failed to generate block");
+ events.push_back(blocks[n]);
+ prev_block = blocks + n;
+ LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
+ }
+
+ // rewind
+ cryptonote::block blk_r, blk_last;
+ {
+ blk_last = blocks[11];
+ for (size_t i = 0; i < CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; ++i)
+ {
+ CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[12+i], blk_last, miner_account,
+ test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version,
+ 2, 2, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
+ crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
+ false, "Failed to generate block");
+ events.push_back(blocks[12+i]);
+ blk_last = blocks[12+i];
+ }
+ blk_r = blk_last;
+ }
+
+ // create 4 txes from these miners in another block, to generate some rct outputs
+ std::vector<transaction> rct_txes;
+ cryptonote::block blk_txes;
+ std::vector<crypto::hash> starting_rct_tx_hashes;
+ static const uint64_t input_amounts_available[] = {5000000000000, 30000000000000, 100000000000, 80000000000};
+ for (size_t n = 0; n < n_txes; ++n)
+ {
+ std::vector<tx_source_entry> sources;
+
+ sources.resize(1);
+ tx_source_entry& src = sources.back();
+
+ const uint64_t needed_amount = input_amounts_available[n];
+ src.amount = input_amounts_available[n];
+ size_t real_index_in_tx = 0;
+ for (size_t m = 0; m <= mixin; ++m) {
+ size_t index_in_tx = 0;
+ for (size_t i = 0; i < blocks[m].miner_tx.vout.size(); ++i)
+ if (blocks[m].miner_tx.vout[i].amount == needed_amount)
+ index_in_tx = i;
+ CHECK_AND_ASSERT_MES(blocks[m].miner_tx.vout[index_in_tx].amount == needed_amount, false, "Expected amount not found");
+ src.push_output(m, boost::get<txout_to_key>(blocks[m].miner_tx.vout[index_in_tx].target).key, src.amount);
+ if (m == n)
+ real_index_in_tx = index_in_tx;
+ }
+ src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(blocks[n].miner_tx);
+ src.real_output = n;
+ src.real_output_in_tx_index = real_index_in_tx;
+ src.mask = rct::identity();
+ src.rct = false;
+
+ //fill outputs entry
+ tx_destination_entry td;
+ td.addr = miner_accounts[n].get_keys().m_account_address;
+ std::vector<tx_destination_entry> destinations;
+ for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o)
+ {
+ td.amount = amounts_paid[o];
+ destinations.push_back(td);
+ }
+
+ if (pre_tx && !pre_tx(sources, destinations, n))
+ {
+ MDEBUG("pre_tx returned failure");
+ return false;
+ }
+
+ crypto::secret_key tx_key;
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
+ rct_txes.resize(rct_txes.size() + 1);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, range_proof_type[n]);
+ CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
+
+ if (post_tx && !post_tx(rct_txes.back(), n))
+ {
+ MDEBUG("post_tx returned failure");
+ return false;
+ }
+
+ //events.push_back(rct_txes.back());
+ starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes.back()));
+ LOG_PRINT_L0("Test tx: " << obj_to_json_str(rct_txes.back()));
+
+ for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o)
+ {
+ crypto::key_derivation derivation;
+ bool r = crypto::generate_key_derivation(destinations[o].addr.m_view_public_key, tx_key, derivation);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
+ crypto::secret_key amount_key;
+ crypto::derivation_to_scalar(derivation, o, amount_key);
+ rct::key rct_tx_mask;
+ if (rct_txes.back().rct_signatures.type == rct::RCTTypeSimple || rct_txes.back().rct_signatures.type == rct::RCTTypeBulletproof)
+ rct::decodeRctSimple(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
+ else
+ rct::decodeRct(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
+ }
+
+ while (amounts_paid[0] != (size_t)-1)
+ ++amounts_paid;
+ ++amounts_paid;
+ }
+ if (!valid)
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(rct_txes);
+
+ CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes, blk_last, miner_account,
+ test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_tx_hashes | test_generator::bf_hf_version | test_generator::bf_max_outs,
+ 8, 8, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
+ crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, 6, 8),
+ false, "Failed to generate block");
+ if (!valid)
+ DO_CALLBACK(events, "mark_invalid_block");
+ events.push_back(blk_txes);
+ blk_last = blk_txes;
+
+ return true;
+}
+
+bool gen_bp_tx_validation_base::check_bp(const cryptonote::transaction &tx, size_t tx_idx, const size_t *sizes, const char *context) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT(context);
+ CHECK_TEST_CONDITION(tx.version >= 2);
+ CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type));
+ size_t n_sizes = 0, n_amounts = 0;
+ for (size_t n = 0; n < tx_idx; ++n)
+ {
+ while (sizes[0] != (size_t)-1)
+ ++sizes;
+ ++sizes;
+ }
+ while (sizes[n_sizes] != (size_t)-1)
+ n_amounts += sizes[n_sizes++];
+ CHECK_TEST_CONDITION(tx.rct_signatures.p.bulletproofs.size() == n_sizes);
+ CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs) == n_amounts);
+ for (size_t n = 0; n < n_sizes; ++n)
+ CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs[n]) == sizes[n]);
+ return true;
+}
+
+bool gen_bp_tx_valid_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
+ const size_t bp_sizes[] = {1, (size_t)-1};
+ const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
+ return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_1"); });
+}
+
+bool gen_bp_tx_invalid_1_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
+}
+
+bool gen_bp_tx_valid_2::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
+ const size_t bp_sizes[] = {2, (size_t)-1};
+ const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
+ return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_2"); });
+}
+
+bool gen_bp_tx_valid_3::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {5000, 5000, 5000, (uint64_t)-1};
+ const size_t bp_sizes[] = {4, (size_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_3"); });
+}
+
+bool gen_bp_tx_valid_16::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, (uint64_t)-1};
+ const size_t bp_sizes[] = {16, (size_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_16"); });
+}
+
+bool gen_bp_tx_invalid_4_2_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofMultiOutputBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
+}
+
+bool gen_bp_tx_invalid_16_16::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofMultiOutputBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
+}
+
+bool gen_bp_txs_valid_2_and_2::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {1000, 1000, (size_t)-1, 1000, 1000, (uint64_t)-1};
+ const size_t bp_sizes[] = {2, (size_t)-1, 2, (size_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof, rct::RangeProofPaddedBulletproof};
+ return generate_with(events, mixin, 2, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_and_2"); });
+}
+
+bool gen_bp_txs_invalid_2_and_8_2_and_16_16_1::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = {rct::RangeProofMultiOutputBulletproof, rct::RangeProofMultiOutputBulletproof, rct::RangeProofMultiOutputBulletproof};
+ return generate_with(events, mixin, 3, amounts_paid, false, range_proof_type, NULL, NULL);
+}
+
+bool gen_bp_txs_valid_2_and_3_and_2_and_4::generate(std::vector<test_event_entry>& events) const
+{
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {11111115000, 11111115000, (uint64_t)-1, 11111115000, 11111115000, 11111115001, (uint64_t)-1, 11111115000, 11111115002, (uint64_t)-1, 11111115000, 11111115000, 11111115000, 11111115003, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof, rct::RangeProofPaddedBulletproof, rct::RangeProofPaddedBulletproof, rct::RangeProofPaddedBulletproof};
+ const size_t bp_sizes[] = {2, (size_t)-1, 4, (size_t)-1, 2, (size_t)-1, 4, (size_t)-1};
+ return generate_with(events, mixin, 4, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx) { return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_and_3_and_2_and_4"); });
+}
+
+bool gen_bp_tx_invalid_not_enough_proofs::generate(std::vector<test_event_entry>& events) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_not_enough_proofs");
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
+ CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
+ CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
+ tx.rct_signatures.p.bulletproofs.pop_back();
+ CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
+ return true;
+ });
+}
+
+bool gen_bp_tx_invalid_empty_proofs::generate(std::vector<test_event_entry>& events) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_empty_proofs");
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {50000, 50000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
+ CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
+ tx.rct_signatures.p.bulletproofs.clear();
+ return true;
+ });
+}
+
+bool gen_bp_tx_invalid_too_many_proofs::generate(std::vector<test_event_entry>& events) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_too_many_proofs");
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
+ CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
+ CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
+ tx.rct_signatures.p.bulletproofs.push_back(tx.rct_signatures.p.bulletproofs.back());
+ return true;
+ });
+}
+
+bool gen_bp_tx_invalid_wrong_amount::generate(std::vector<test_event_entry>& events) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_wrong_amount");
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
+ CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
+ CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
+ tx.rct_signatures.p.bulletproofs.back() = rct::bulletproof_PROVE(1000, rct::skGen());
+ return true;
+ });
+}
+
+bool gen_bp_tx_invalid_borromean_type::generate(std::vector<test_event_entry>& events) const
+{
+ DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_borromean_type");
+ const size_t mixin = 10;
+ const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
+ const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
+ return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){
+ CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
+ tx.rct_signatures.type = rct::RCTTypeSimple;
+ return true;
+ });
+}
diff --git a/tests/core_tests/bulletproofs.h b/tests/core_tests/bulletproofs.h
new file mode 100644
index 000000000..e29b34690
--- /dev/null
+++ b/tests/core_tests/bulletproofs.h
@@ -0,0 +1,193 @@
+// Copyright (c) 2014-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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+#include "chaingen.h"
+
+struct gen_bp_tx_validation_base : public test_chain_unit_base
+{
+ gen_bp_tx_validation_base()
+ : m_invalid_tx_index(0)
+ , m_invalid_block_index(0)
+ {
+ REGISTER_CALLBACK_METHOD(gen_bp_tx_validation_base, mark_invalid_tx);
+ REGISTER_CALLBACK_METHOD(gen_bp_tx_validation_base, mark_invalid_block);
+ }
+
+ bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_idx, const cryptonote::transaction& /*tx*/)
+ {
+ if (m_invalid_tx_index == event_idx)
+ return tvc.m_verifivation_failed;
+ else
+ return !tvc.m_verifivation_failed && tx_added;
+ }
+
+ bool check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_idx, const std::vector<cryptonote::transaction>& /*txs*/)
+ {
+ size_t failed = 0;
+ for (const cryptonote::tx_verification_context &tvc: tvcs)
+ if (tvc.m_verifivation_failed)
+ ++failed;
+ if (m_invalid_tx_index == event_idx)
+ return failed > 0;
+ else
+ return failed == 0 && tx_added == tvcs.size();
+ }
+
+ bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*block*/)
+ {
+ if (m_invalid_block_index == event_idx)
+ return bvc.m_verifivation_failed;
+ else
+ return !bvc.m_verifivation_failed;
+ }
+
+ bool mark_invalid_block(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
+ {
+ m_invalid_block_index = ev_index + 1;
+ return true;
+ }
+
+ bool mark_invalid_tx(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
+ {
+ m_invalid_tx_index = ev_index + 1;
+ return true;
+ }
+
+ bool generate_with(std::vector<test_event_entry>& events, size_t mixin,
+ size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RangeProofType *range_proof_type,
+ const std::function<bool(std::vector<cryptonote::tx_source_entry> &sources, std::vector<cryptonote::tx_destination_entry> &destinations, size_t)> &pre_tx,
+ const std::function<bool(cryptonote::transaction &tx, size_t)> &post_tx) const;
+
+ bool check_bp(const cryptonote::transaction &tx, size_t tx_idx, const size_t *sizes, const char *context) const;
+
+private:
+ size_t m_invalid_tx_index;
+ size_t m_invalid_block_index;
+};
+
+template<>
+struct get_test_options<gen_bp_tx_validation_base> {
+ const std::pair<uint8_t, uint64_t> hard_forks[4] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(8, 73), std::make_pair(0, 0)};
+ const cryptonote::test_options test_options = {
+ hard_forks
+ };
+};
+
+// valid
+struct gen_bp_tx_valid_1 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_valid_1>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_1_1 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_1_1>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_valid_2 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_valid_2>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_valid_3 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_valid_3>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_valid_16 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_valid_16>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_4_2_1 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_4_2_1>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_16_16 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_16_16>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_txs_valid_2_and_2 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_txs_valid_2_and_2>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_txs_invalid_2_and_8_2_and_16_16_1 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_txs_invalid_2_and_8_2_and_16_16_1>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_txs_valid_2_and_3_and_2_and_4 : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_txs_valid_2_and_3_and_2_and_4>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_not_enough_proofs : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_not_enough_proofs>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_empty_proofs : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_empty_proofs>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_too_many_proofs : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_too_many_proofs>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_wrong_amount : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_wrong_amount>: public get_test_options<gen_bp_tx_validation_base> {};
+
+struct gen_bp_tx_invalid_borromean_type : public gen_bp_tx_validation_base
+{
+ bool generate(std::vector<test_event_entry>& events) const;
+};
+template<> struct get_test_options<gen_bp_tx_invalid_borromean_type>: public get_test_options<gen_bp_tx_validation_base> {};
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 41256a4f1..d3cb52246 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -69,13 +69,13 @@ void test_generator::get_block_chain(std::vector<block_info>& blockchain, const
std::reverse(blockchain.begin(), blockchain.end());
}
-void test_generator::get_last_n_block_sizes(std::vector<size_t>& block_sizes, const crypto::hash& head, size_t n) const
+void test_generator::get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const
{
std::vector<block_info> blockchain;
get_block_chain(blockchain, head, n);
BOOST_FOREACH(auto& bi, blockchain)
{
- block_sizes.push_back(bi.block_size);
+ block_weights.push_back(bi.block_weight);
}
}
@@ -95,17 +95,17 @@ uint64_t test_generator::get_already_generated_coins(const cryptonote::block& bl
return get_already_generated_coins(blk_hash);
}
-void test_generator::add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins, uint8_t hf_version)
+void test_generator::add_block(const cryptonote::block& blk, size_t txs_weight, std::vector<size_t>& block_weights, uint64_t already_generated_coins, uint8_t hf_version)
{
- const size_t block_size = tsx_size + get_object_blobsize(blk.miner_tx);
+ const size_t block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
uint64_t block_reward;
- get_block_reward(misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward, hf_version);
- m_blocks_info[get_block_hash(blk)] = block_info(blk.prev_id, already_generated_coins + block_reward, block_size);
+ get_block_reward(misc_utils::median(block_weights), block_weight, already_generated_coins, block_reward, hf_version);
+ m_blocks_info[get_block_hash(blk)] = block_info(blk.prev_id, already_generated_coins + block_reward, block_weight);
}
bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
- std::vector<size_t>& block_sizes, const std::list<cryptonote::transaction>& tx_list)
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list)
{
blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
@@ -121,52 +121,52 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
}
uint64_t total_fee = 0;
- size_t txs_size = 0;
+ size_t txs_weight = 0;
BOOST_FOREACH(auto& tx, tx_list)
{
uint64_t fee = 0;
bool r = get_tx_fee(tx, fee);
CHECK_AND_ASSERT_MES(r, false, "wrong transaction passed to construct_block");
total_fee += fee;
- txs_size += get_object_blobsize(tx);
+ txs_weight += get_transaction_weight(tx);
}
blk.miner_tx = AUTO_VAL_INIT(blk.miner_tx);
- size_t target_block_size = txs_size + get_object_blobsize(blk.miner_tx);
+ size_t target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
while (true)
{
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, target_block_size, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10))
return false;
- size_t actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (target_block_size < actual_block_size)
+ size_t actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (target_block_weight < actual_block_weight)
{
- target_block_size = actual_block_size;
+ target_block_weight = actual_block_weight;
}
- else if (actual_block_size < target_block_size)
+ else if (actual_block_weight < target_block_weight)
{
- size_t delta = target_block_size - actual_block_size;
+ size_t delta = target_block_weight - actual_block_weight;
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() + delta, 0);
- actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (actual_block_size == target_block_size)
+ actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (actual_block_weight == target_block_weight)
{
break;
}
else
{
- CHECK_AND_ASSERT_MES(target_block_size < actual_block_size, false, "Unexpected block size");
- delta = actual_block_size - target_block_size;
+ CHECK_AND_ASSERT_MES(target_block_weight < actual_block_weight, false, "Unexpected block size");
+ delta = actual_block_weight - target_block_weight;
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() - delta);
- actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (actual_block_size == target_block_size)
+ actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (actual_block_weight == target_block_weight)
{
break;
}
else
{
- CHECK_AND_ASSERT_MES(actual_block_size < target_block_size, false, "Unexpected block size");
+ CHECK_AND_ASSERT_MES(actual_block_weight < target_block_weight, false, "Unexpected block size");
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() + delta, 0);
- target_block_size = txs_size + get_object_blobsize(blk.miner_tx);
+ target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
}
}
}
@@ -183,16 +183,16 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
while (!miner::find_nonce_for_given_block(blk, get_test_difficulty(), height))
blk.timestamp++;
- add_block(blk, txs_size, block_sizes, already_generated_coins);
+ add_block(blk, txs_weight, block_weights, already_generated_coins);
return true;
}
bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp)
{
- std::vector<size_t> block_sizes;
+ std::vector<size_t> block_weights;
std::list<cryptonote::transaction> tx_list;
- return construct_block(blk, 0, null_hash, miner_acc, timestamp, 0, block_sizes, tx_list);
+ return construct_block(blk, 0, null_hash, miner_acc, timestamp, 0, block_weights, tx_list);
}
bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev,
@@ -204,10 +204,10 @@ bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::b
// Keep difficulty unchanged
uint64_t timestamp = blk_prev.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN;
uint64_t already_generated_coins = get_already_generated_coins(prev_id);
- std::vector<size_t> block_sizes;
- get_last_n_block_sizes(block_sizes, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ std::vector<size_t> block_weights;
+ get_last_n_block_weights(block_weights, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
- return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_sizes, tx_list);
+ return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_weights, tx_list);
}
bool test_generator::construct_block_manually(block& blk, const block& prev_block, const account_base& miner_acc,
@@ -216,7 +216,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
const crypto::hash& prev_id/* = crypto::hash()*/, const difficulty_type& diffic/* = 1*/,
const transaction& miner_tx/* = transaction()*/,
const std::vector<crypto::hash>& tx_hashes/* = std::vector<crypto::hash>()*/,
- size_t txs_sizes/* = 0*/, size_t max_outs/* = 0*/, uint8_t hf_version/* = 1*/)
+ size_t txs_weight/* = 0*/, size_t max_outs/* = 0*/, uint8_t hf_version/* = 1*/)
{
blk.major_version = actual_params & bf_major_ver ? major_ver : CURRENT_BLOCK_MAJOR_VERSION;
blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION;
@@ -228,17 +228,17 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
size_t height = get_block_height(prev_block) + 1;
uint64_t already_generated_coins = get_already_generated_coins(prev_block);
- std::vector<size_t> block_sizes;
- get_last_n_block_sizes(block_sizes, get_block_hash(prev_block), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ std::vector<size_t> block_weights;
+ get_last_n_block_weights(block_weights, get_block_hash(prev_block), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (actual_params & bf_miner_tx)
{
blk.miner_tx = miner_tx;
}
else
{
- size_t current_block_size = txs_sizes + get_object_blobsize(blk.miner_tx);
+ size_t current_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
// TODO: This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, current_block_size, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, current_block_weight, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
return false;
}
@@ -247,16 +247,16 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
difficulty_type a_diffic = actual_params & bf_diffic ? diffic : get_test_difficulty();
fill_nonce(blk, a_diffic, height);
- add_block(blk, txs_sizes, block_sizes, already_generated_coins, hf_version);
+ add_block(blk, txs_weight, block_weights, already_generated_coins, hf_version);
return true;
}
bool test_generator::construct_block_manually_tx(cryptonote::block& blk, const cryptonote::block& prev_block,
const cryptonote::account_base& miner_acc,
- const std::vector<crypto::hash>& tx_hashes, size_t txs_size)
+ const std::vector<crypto::hash>& tx_hashes, size_t txs_weight)
{
- return construct_block_manually(blk, prev_block, miner_acc, bf_tx_hashes, 0, 0, 0, crypto::hash(), 0, transaction(), tx_hashes, txs_size);
+ return construct_block_manually(blk, prev_block, miner_acc, bf_tx_hashes, 0, 0, 0, crypto::hash(), 0, transaction(), tx_hashes, txs_weight);
}
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index bbc9edd19..34b205ae5 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -135,7 +135,7 @@ VARIANT_TAG(binary_archive, serialized_block, 0xcd);
VARIANT_TAG(binary_archive, serialized_transaction, 0xce);
VARIANT_TAG(binary_archive, event_visitor_settings, 0xcf);
-typedef boost::variant<cryptonote::block, cryptonote::transaction, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings> test_event_entry;
+typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings> test_event_entry;
typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
class test_chain_unit_base
@@ -159,20 +159,20 @@ public:
block_info()
: prev_id()
, already_generated_coins(0)
- , block_size(0)
+ , block_weight(0)
{
}
- block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_size)
+ block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
: prev_id(a_prev_id)
, already_generated_coins(an_already_generated_coins)
- , block_size(a_block_size)
+ , block_weight(a_block_weight)
{
}
crypto::hash prev_id;
uint64_t already_generated_coins;
- size_t block_size;
+ size_t block_weight;
};
enum block_fields
@@ -190,15 +190,15 @@ public:
};
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
- void get_last_n_block_sizes(std::vector<size_t>& block_sizes, const crypto::hash& head, size_t n) const;
+ void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;
- void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins,
+ void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_weights, uint64_t already_generated_coins,
uint8_t hf_version = 1);
bool construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
- std::vector<size_t>& block_sizes, const std::list<cryptonote::transaction>& tx_list);
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list);
bool construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp);
bool construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev, const cryptonote::account_base& miner_acc,
const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>());
@@ -263,6 +263,30 @@ bool check_tx_verification_context(const cryptonote::tx_verification_context& tv
}
//--------------------------------------------------------------------------
template<class t_test_class>
+auto do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator, int)
+ -> decltype(validator.check_tx_verification_context(tvcs, tx_added, event_index, txs))
+{
+ return validator.check_tx_verification_context(tvcs, tx_added, event_index, txs);
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
+bool do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/, t_test_class&, long)
+{
+ // Default block verification context check
+ for (const cryptonote::tx_verification_context &tvc: tvcs)
+ if (tvc.m_verifivation_failed)
+ throw std::runtime_error("Transaction verification failed");
+ return true;
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
+bool check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator)
+{
+ // SFINAE in action
+ return do_check_tx_verification_context(tvcs, tx_added, event_index, txs, validator, 0);
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
auto do_check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_index, const cryptonote::block& blk, t_test_class& validator, int)
-> decltype(validator.check_block_verification_context(bvc, event_index, blk))
{
@@ -339,6 +363,26 @@ public:
return true;
}
+ bool operator()(const std::vector<cryptonote::transaction>& txs) const
+ {
+ log_event("cryptonote::transaction");
+
+ std::vector<cryptonote::blobdata> tx_blobs;
+ std::vector<cryptonote::tx_verification_context> tvcs;
+ cryptonote::tx_verification_context tvc0 = AUTO_VAL_INIT(tvc0);
+ for (const auto &tx: txs)
+ {
+ tx_blobs.push_back(t_serializable_object_to_blob(tx));
+ tvcs.push_back(tvc0);
+ }
+ size_t pool_size = m_c.get_pool_transactions_count();
+ m_c.handle_incoming_txs(tx_blobs, tvcs, m_txs_keeped_by_block, false, false);
+ size_t tx_added = m_c.get_pool_transactions_count() - pool_size;
+ bool r = check_tx_verification_context(tvcs, tx_added, m_ev_index, txs, m_validator);
+ CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed");
+ return true;
+ }
+
bool operator()(const cryptonote::block& b) const
{
log_event("cryptonote::block");
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index c31655070..abc412318 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -224,6 +224,22 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(gen_multisig_tx_invalid_33_1_2_no_threshold);
GENERATE_AND_PLAY(gen_multisig_tx_invalid_33_1_3_no_threshold);
+ GENERATE_AND_PLAY(gen_bp_tx_valid_1);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_1_1);
+ GENERATE_AND_PLAY(gen_bp_tx_valid_2);
+ GENERATE_AND_PLAY(gen_bp_tx_valid_3);
+ GENERATE_AND_PLAY(gen_bp_tx_valid_16);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_4_2_1);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_16_16);
+ GENERATE_AND_PLAY(gen_bp_txs_valid_2_and_2);
+ GENERATE_AND_PLAY(gen_bp_txs_invalid_2_and_8_2_and_16_16_1);
+ GENERATE_AND_PLAY(gen_bp_txs_valid_2_and_3_and_2_and_4);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_not_enough_proofs);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_empty_proofs);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_too_many_proofs);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_wrong_amount);
+ GENERATE_AND_PLAY(gen_bp_tx_invalid_borromean_type);
+
el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
MLOG(level, "\nREPORT:");
MLOG(level, " Test run: " << tests_count);
diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h
index 174610d5d..c12e97f95 100644
--- a/tests/core_tests/chaingen_tests_list.h
+++ b/tests/core_tests/chaingen_tests_list.h
@@ -42,6 +42,7 @@
#include "v2_tests.h"
#include "rct.h"
#include "multisig.h"
+#include "bulletproofs.h"
/************************************************************************/
/* */
/************************************************************************/
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index 936a4b742..46cc0ff35 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -285,7 +285,7 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry
#endif
std::vector<crypto::secret_key> additional_tx_secret_keys;
auto sources_copy = sources;
- r = construct_tx_and_get_tx_key(miner_account[creator].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_secret_keys, true, false, msoutp);
+ r = construct_tx_and_get_tx_key(miner_account[creator].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_secret_keys, true, rct::RangeProofBorromean, msoutp);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
#ifndef NO_MULTISIG
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index 55401c4cb..342c3f1ee 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -133,7 +133,7 @@ bool gen_rct_tx_validation_base::generate_with(std::vector<test_event_entry>& ev
CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
crypto::secret_key amount_key;
crypto::derivation_to_scalar(derivation, o, amount_key);
- if (rct_txes[n].rct_signatures.type == rct::RCTTypeSimple || rct_txes[n].rct_signatures.type == rct::RCTTypeSimpleBulletproof)
+ if (rct_txes[n].rct_signatures.type == rct::RCTTypeSimple || rct_txes[n].rct_signatures.type == rct::RCTTypeBulletproof)
rct::decodeRctSimple(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default"));
else
rct::decodeRct(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default"));
diff --git a/tests/data/fuzz/bulletproof/BP0 b/tests/data/fuzz/bulletproof/BP0
new file mode 100644
index 000000000..17590b770
--- /dev/null
+++ b/tests/data/fuzz/bulletproof/BP0
Binary files differ
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index dfbbaeca6..fdb745699 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -173,3 +173,18 @@ set_property(TARGET levin_fuzz_tests
PROPERTY
FOLDER "tests")
+add_executable(bulletproof_fuzz_tests bulletproof.cpp fuzzer.cpp)
+target_link_libraries(bulletproof_fuzz_tests
+ PRIVATE
+ common
+ epee
+ ${Boost_THREAD_LIBRARY}
+ ${Boost_CHRONO_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+set_property(TARGET bulletproof_fuzz_tests
+ PROPERTY
+ FOLDER "tests")
+
diff --git a/tests/fuzz/bulletproof.cpp b/tests/fuzz/bulletproof.cpp
new file mode 100644
index 000000000..2f4dfd0ea
--- /dev/null
+++ b/tests/fuzz/bulletproof.cpp
@@ -0,0 +1,70 @@
+// Copyright (c) 2017-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 "include_base_utils.h"
+#include "file_io_utils.h"
+#include "cryptonote_basic/blobdatatype.h"
+#include "cryptonote_basic/cryptonote_basic.h"
+#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "fuzzer.h"
+
+class BulletproofFuzzer: public Fuzzer
+{
+public:
+ virtual int run(const std::string &filename);
+
+private:
+};
+
+int BulletproofFuzzer::run(const std::string &filename)
+{
+ std::string s;
+
+ if (!epee::file_io_utils::load_file_to_string(filename, s))
+ {
+ std::cout << "Error: failed to load file " << filename << std::endl;
+ return 1;
+ }
+ std::stringstream ss;
+ ss << s;
+ binary_archive<false> ba(ss);
+ rct::Bulletproof proof = AUTO_VAL_INIT(proof);
+ bool r = ::serialization::serialize(ba, proof);
+ if(!r)
+ {
+ std::cout << "Error: failed to parse bulletproof from file " << filename << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, const char **argv)
+{
+ BulletproofFuzzer fuzzer;
+ return run_fuzzer(argc, argv, fuzzer);
+}
diff --git a/tests/performance_tests/CMakeLists.txt b/tests/performance_tests/CMakeLists.txt
index 8cbd71444..837d39bd3 100644
--- a/tests/performance_tests/CMakeLists.txt
+++ b/tests/performance_tests/CMakeLists.txt
@@ -40,8 +40,13 @@ set(performance_tests_headers
generate_key_image.h
generate_key_image_helper.h
generate_keypair.h
+ signature.h
is_out_to_acc.h
subaddress_expand.h
+ range_proof.h
+ bulletproof.h
+ crypto_ops.h
+ multiexp.h
multi_tx_test_base.h
performance_tests.h
performance_utils.h
diff --git a/tests/performance_tests/bulletproof.h b/tests/performance_tests/bulletproof.h
new file mode 100644
index 000000000..7bb702c3d
--- /dev/null
+++ b/tests/performance_tests/bulletproof.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2014-2017, 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "ringct/rctSigs.h"
+#include "ringct/bulletproofs.h"
+
+template<bool a_verify, size_t n_amounts>
+class test_bulletproof
+{
+public:
+ static const size_t approx_loop_count = 100 / n_amounts;
+ static const size_t loop_count = (approx_loop_count >= 10 ? approx_loop_count : 10) / (a_verify ? 1 : 5);
+ static const bool verify = a_verify;
+
+ bool init()
+ {
+ proof = rct::bulletproof_PROVE(std::vector<uint64_t>(n_amounts, 749327532984), rct::skvGen(n_amounts));
+ return true;
+ }
+
+ bool test()
+ {
+ bool ret = true;
+ if (verify)
+ ret = rct::bulletproof_VERIFY(proof);
+ else
+ rct::bulletproof_PROVE(std::vector<uint64_t>(n_amounts, 749327532984), rct::skvGen(n_amounts));
+ return ret;
+ }
+
+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;
+};
diff --git a/tests/performance_tests/check_tx_signature.h b/tests/performance_tests/check_tx_signature.h
index ec570e69d..ee382d9ad 100644
--- a/tests/performance_tests/check_tx_signature.h
+++ b/tests/performance_tests/check_tx_signature.h
@@ -40,14 +40,15 @@
#include "multi_tx_test_base.h"
-template<size_t a_ring_size, bool a_rct>
+template<size_t a_ring_size, size_t a_outputs, bool a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean>
class test_check_tx_signature : private multi_tx_test_base<a_ring_size>
{
static_assert(0 < a_ring_size, "ring_size must be greater than 0");
public:
- static const size_t loop_count = a_rct ? 10 : a_ring_size < 100 ? 100 : 10;
+ static const size_t loop_count = a_rct ? (a_ring_size <= 2 ? 50 : 10) : a_ring_size < 100 ? 100 : 10;
static const size_t ring_size = a_ring_size;
+ static const size_t outputs = a_outputs;
static const bool rct = a_rct;
typedef multi_tx_test_base<a_ring_size> base_class;
@@ -62,13 +63,15 @@ public:
m_alice.generate();
std::vector<tx_destination_entry> destinations;
- destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address, false));
+ destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
+ for (size_t n = 1; n < outputs; ++n)
+ destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
- if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct))
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, range_proof_type))
return false;
get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);
@@ -80,7 +83,7 @@ public:
{
if (rct)
{
- if (m_tx.rct_signatures.type == rct::RCTTypeFull || m_tx.rct_signatures.type == rct::RCTTypeFullBulletproof)
+ if (m_tx.rct_signatures.type == rct::RCTTypeFull)
return rct::verRct(m_tx.rct_signatures);
else
return rct::verRctSimple(m_tx.rct_signatures);
@@ -97,3 +100,74 @@ private:
cryptonote::transaction m_tx;
crypto::hash m_tx_prefix_hash;
};
+
+template<size_t a_ring_size, size_t a_outputs, size_t a_num_txes, size_t extra_outs = 0>
+class test_check_tx_signature_aggregated_bulletproofs : private multi_tx_test_base<a_ring_size>
+{
+ static_assert(0 < a_ring_size, "ring_size must be greater than 0");
+
+public:
+ static const size_t loop_count = a_ring_size <= 2 ? 50 : 10;
+ static const size_t ring_size = a_ring_size;
+ static const size_t outputs = a_outputs;
+
+ typedef multi_tx_test_base<a_ring_size> base_class;
+
+ bool init()
+ {
+ using namespace cryptonote;
+
+ if (!base_class::init())
+ return false;
+
+ m_alice.generate();
+
+ std::vector<tx_destination_entry> destinations;
+ destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
+ for (size_t n = 1; n < outputs; ++n)
+ destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
+
+ crypto::secret_key tx_key;
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
+
+ m_txes.resize(a_num_txes + (extra_outs > 0 ? 1 : 0));
+ for (size_t n = 0; n < a_num_txes; ++n)
+ {
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], 0, tx_key, additional_tx_keys, true, rct::RangeProofPaddedBulletproof))
+ return false;
+ }
+
+ if (extra_outs)
+ {
+ destinations.clear();
+ destinations.push_back(tx_destination_entry(this->m_source_amount - extra_outs + 1, m_alice.get_keys().m_account_address, false));
+ for (size_t n = 1; n < extra_outs; ++n)
+ destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
+
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes.back(), 0, tx_key, additional_tx_keys, true, rct::RangeProofMultiOutputBulletproof))
+ return false;
+ }
+
+ return true;
+ }
+
+ bool test()
+ {
+ std::vector<const rct::rctSig*> rvv;
+ rvv.reserve(m_txes.size());
+ for (size_t n = 0; n < m_txes.size(); ++n)
+ {
+ const rct::rctSig &rv = m_txes[n].rct_signatures;
+ if (!rct::verRctNonSemanticsSimple(rv))
+ return false;
+ rvv.push_back(&rv);
+ }
+ return rct::verRctSemanticsSimple(rvv);
+ }
+
+private:
+ cryptonote::account_base m_alice;
+ std::vector<cryptonote::transaction> m_txes;
+};
diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h
index 99c7f1b18..378065ddd 100644
--- a/tests/performance_tests/construct_tx.h
+++ b/tests/performance_tests/construct_tx.h
@@ -36,7 +36,7 @@
#include "multi_tx_test_base.h"
-template<size_t a_in_count, size_t a_out_count, bool a_rct>
+template<size_t a_in_count, size_t a_out_count, bool a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean>
class test_construct_tx : private multi_tx_test_base<a_in_count>
{
static_assert(0 < a_in_count, "in_count must be greater than 0");
@@ -73,7 +73,7 @@ public:
std::vector<crypto::secret_key> additional_tx_keys;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
- return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, m_destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct);
+ return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, m_destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, range_proof_type);
}
private:
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h
new file mode 100644
index 000000000..3c68583c5
--- /dev/null
+++ b/tests/performance_tests/crypto_ops.h
@@ -0,0 +1,122 @@
+// Copyright (c) 2014-2017, 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "crypto/crypto.h"
+#include "ringct/rctOps.h"
+
+enum test_op
+{
+ op_sc_add,
+ op_sc_sub,
+ op_sc_mul,
+ op_ge_add_raw,
+ op_ge_add_p3_p3,
+ ops_fast,
+
+ op_addKeys,
+ op_scalarmultBase,
+ op_scalarmultKey,
+ op_scalarmultH,
+ op_scalarmult8,
+ op_ge_double_scalarmult_base_vartime,
+ op_ge_double_scalarmult_precomp_vartime,
+ op_ge_double_scalarmult_precomp_vartime2,
+ op_addKeys2,
+ op_addKeys3,
+ op_addKeys3_2,
+ op_isInMainSubgroup,
+};
+
+template<test_op op>
+class test_crypto_ops
+{
+public:
+ static const size_t loop_count = op < ops_fast ? 10000000 : 1000;
+
+ bool init()
+ {
+ scalar0 = rct::skGen();
+ scalar1 = rct::skGen();
+ point0 = rct::scalarmultBase(rct::skGen());
+ point1 = rct::scalarmultBase(rct::skGen());
+ if (ge_frombytes_vartime(&p3_0, point0.bytes) != 0)
+ return false;
+ if (ge_frombytes_vartime(&p3_1, point1.bytes) != 0)
+ return false;
+ ge_p3_to_cached(&cached, &p3_0);
+ rct::precomp(precomp0, point0);
+ rct::precomp(precomp1, point1);
+ return true;
+ }
+
+ bool test()
+ {
+ rct::key key;
+ ge_cached tmp_cached;
+ ge_p1p1 tmp_p1p1;
+ ge_p2 tmp_p2;
+ switch (op)
+ {
+ case op_sc_add: sc_add(key.bytes, scalar0.bytes, scalar1.bytes); break;
+ case op_sc_sub: sc_sub(key.bytes, scalar0.bytes, scalar1.bytes); break;
+ case op_sc_mul: sc_mul(key.bytes, scalar0.bytes, scalar1.bytes); break;
+ case op_ge_add_p3_p3: {
+ ge_p3_to_cached(&tmp_cached, &p3_0);
+ ge_add(&tmp_p1p1, &p3_1, &tmp_cached);
+ ge_p1p1_to_p3(&p3_1, &tmp_p1p1);
+ break;
+ }
+ case op_ge_add_raw: ge_add(&tmp_p1p1, &p3_1, &cached); break;
+ case op_addKeys: rct::addKeys(key, point0, point1); break;
+ case op_scalarmultBase: rct::scalarmultBase(scalar0); break;
+ case op_scalarmultKey: rct::scalarmultKey(point0, scalar0); break;
+ case op_scalarmultH: rct::scalarmultH(scalar0); break;
+ case op_scalarmult8: rct::scalarmult8(point0); break;
+ case op_ge_double_scalarmult_base_vartime: ge_double_scalarmult_base_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes); break;
+ case op_ge_double_scalarmult_precomp_vartime: ge_double_scalarmult_precomp_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes, precomp0); break;
+ case op_ge_double_scalarmult_precomp_vartime2: ge_double_scalarmult_precomp_vartime2(&tmp_p2, scalar0.bytes, precomp0, scalar1.bytes, precomp1); break;
+ case op_addKeys2: rct::addKeys2(key, scalar0, scalar1, point0); break;
+ case op_addKeys3: rct::addKeys3(key, scalar0, point0, scalar1, precomp1); break;
+ case op_addKeys3_2: rct::addKeys3(key, scalar0, precomp0, scalar1, precomp1); break;
+ case op_isInMainSubgroup: rct::isInMainSubgroup(point0); break;
+ default: return false;
+ }
+ return true;
+ }
+
+private:
+ rct::key scalar0, scalar1;
+ rct::key point0, point1;
+ ge_p3 p3_0, p3_1;
+ ge_cached cached;
+ ge_dsmp precomp0, precomp1;
+};
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index 1733e3409..7c5135c65 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -46,12 +46,18 @@
#include "generate_key_image.h"
#include "generate_key_image_helper.h"
#include "generate_keypair.h"
+#include "signature.h"
#include "is_out_to_acc.h"
#include "subaddress_expand.h"
#include "sc_reduce32.h"
#include "cn_fast_hash.h"
#include "rct_mlsag.h"
#include "equality.h"
+#include "range_proof.h"
+#include "rct_mlsag.h"
+#include "bulletproof.h"
+#include "crypto_ops.h"
+#include "multiexp.h"
namespace po = boost::program_options;
@@ -63,11 +69,16 @@ int main(int argc, char** argv)
set_thread_high_priority();
mlog_configure(mlog_get_default_log_path("performance_tests.log"), true);
- mlog_set_log_level(0);
po::options_description desc_options("Command line options");
const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" };
- command_line::add_arg(desc_options, arg_filter);
+ const command_line::arg_descriptor<bool> arg_verbose = { "verbose", "Verbose output", false };
+ const command_line::arg_descriptor<bool> arg_stats = { "stats", "Including statistics (min/median)", false };
+ const command_line::arg_descriptor<unsigned> arg_loop_multiplier = { "loop-multiplier", "Run for that many times more loops", 1 };
+ command_line::add_arg(desc_options, arg_filter, "");
+ command_line::add_arg(desc_options, arg_verbose, "");
+ command_line::add_arg(desc_options, arg_stats, "");
+ command_line::add_arg(desc_options, arg_loop_multiplier, "");
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
@@ -80,82 +91,455 @@ int main(int argc, char** argv)
return 1;
const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
+ Params p;
+ p.verbose = command_line::get_arg(vm, arg_verbose);
+ p.stats = command_line::get_arg(vm, arg_stats);
+ p.loop_multiplier = command_line::get_arg(vm, arg_loop_multiplier);
performance_timer timer;
timer.start();
- TEST_PERFORMANCE3(filter, test_construct_tx, 1, 1, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 1, 2, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 1, 10, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 1, 100, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 1, 1000, false);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 1, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 2, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 10, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 100, false);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 1, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 2, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 10, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 100, false);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 1, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 2, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 10, false);
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 100, false);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 1, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 2, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 2, 10, true);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 1, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 2, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 10, 10, true);
-
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 1, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 2, true);
- TEST_PERFORMANCE3(filter, test_construct_tx, 100, 10, true);
-
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 1, false);
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 2, false);
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 10, false);
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 100, false);
-
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 2, true);
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 10, true);
- TEST_PERFORMANCE2(filter, test_check_tx_signature, 100, true);
-
- TEST_PERFORMANCE0(filter, test_is_out_to_acc);
- TEST_PERFORMANCE0(filter, test_is_out_to_acc_precomp);
- TEST_PERFORMANCE0(filter, test_generate_key_image_helper);
- TEST_PERFORMANCE0(filter, test_generate_key_derivation);
- TEST_PERFORMANCE0(filter, test_generate_key_image);
- TEST_PERFORMANCE0(filter, test_derive_public_key);
- TEST_PERFORMANCE0(filter, test_derive_secret_key);
- TEST_PERFORMANCE0(filter, test_ge_frombytes_vartime);
- TEST_PERFORMANCE0(filter, test_generate_keypair);
- TEST_PERFORMANCE0(filter, test_sc_reduce32);
-
- TEST_PERFORMANCE2(filter, test_wallet2_expand_subaddresses, 50, 200);
-
- TEST_PERFORMANCE0(filter, test_cn_slow_hash);
- TEST_PERFORMANCE1(filter, test_cn_fast_hash, 32);
- TEST_PERFORMANCE1(filter, test_cn_fast_hash, 16384);
-
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 3, false);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 5, false);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 10, false);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 100, false);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 3, true);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 5, true);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 10, true);
- TEST_PERFORMANCE3(filter, test_ringct_mlsag, 1, 100, true);
-
- TEST_PERFORMANCE2(filter, test_equality, memcmp32, true);
- TEST_PERFORMANCE2(filter, test_equality, memcmp32, false);
- TEST_PERFORMANCE2(filter, test_equality, verify32, false);
- TEST_PERFORMANCE2(filter, test_equality, verify32, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 1, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 100, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 1000, false);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 1, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 100, false);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 1, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 100, false);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 1, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 100, false);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 1, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 2, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 10, true);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 1, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 2, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 10, true);
+
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 1, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 2, true);
+ TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 10, true);
+
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 2, 1, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 2, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 2, 10, true, rct::RangeProofPaddedBulletproof);
+
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 10, 1, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 10, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 10, 10, true, rct::RangeProofPaddedBulletproof);
+
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 100, 1, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 100, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_construct_tx, 100, 10, true, rct::RangeProofPaddedBulletproof);
+
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 1, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 10, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 100, 2, false);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 10, false);
+
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofBorromean);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofBorromean);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofBorromean);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofBorromean);
+
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofMultiOutputBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofMultiOutputBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofMultiOutputBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofPaddedBulletproof);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofMultiOutputBulletproof);
+
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 2, 64);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 10, 2, 64);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 100, 2, 64);
+ TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 10, 64);
+
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 2, 62, 4);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 10, 2, 62, 4);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 2, 56, 16);
+ TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 10, 2, 56, 16);
+
+ TEST_PERFORMANCE0(filter, p, test_is_out_to_acc);
+ TEST_PERFORMANCE0(filter, p, test_is_out_to_acc_precomp);
+ TEST_PERFORMANCE0(filter, p, test_generate_key_image_helper);
+ TEST_PERFORMANCE0(filter, p, test_generate_key_derivation);
+ TEST_PERFORMANCE0(filter, p, test_generate_key_image);
+ TEST_PERFORMANCE0(filter, p, test_derive_public_key);
+ TEST_PERFORMANCE0(filter, p, test_derive_secret_key);
+ TEST_PERFORMANCE0(filter, p, test_ge_frombytes_vartime);
+ TEST_PERFORMANCE0(filter, p, test_generate_keypair);
+ TEST_PERFORMANCE0(filter, p, test_sc_reduce32);
+ TEST_PERFORMANCE1(filter, p, test_signature, false);
+ TEST_PERFORMANCE1(filter, p, test_signature, true);
+
+ TEST_PERFORMANCE2(filter, p, test_wallet2_expand_subaddresses, 50, 200);
+
+ TEST_PERFORMANCE0(filter, p, test_cn_slow_hash);
+ TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 32);
+ TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 16384);
+
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, true);
+
+ TEST_PERFORMANCE2(filter, p, test_equality, memcmp32, true);
+ TEST_PERFORMANCE2(filter, p, test_equality, memcmp32, false);
+ TEST_PERFORMANCE2(filter, p, test_equality, verify32, false);
+ TEST_PERFORMANCE2(filter, p, test_equality, verify32, false);
+
+ TEST_PERFORMANCE1(filter, p, test_range_proof, true);
+ TEST_PERFORMANCE1(filter, p, test_range_proof, false);
+
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 1); // 1 bulletproof with 1 amount
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 1);
+
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 2); // 1 bulletproof with 2 amounts
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 2);
+
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 15); // 1 bulletproof with 15 amounts
+ TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 15);
+
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 2, 1, 1, 0, 4);
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 2, 1, 1, 0, 4); // 4 proofs, each with 2 amounts
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 8, 1, 1, 0, 4);
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 8, 1, 1, 0, 4); // 4 proofs, each with 8 amounts
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 1, 1, 2, 0, 4);
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 1, 1, 2, 0, 4); // 4 proofs with 1, 2, 4, 8 amounts
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 1, 8, 1, 1, 4);
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 1, 8, 1, 1, 4); // 32 proofs, with 1, 2, 3, 4 amounts, 8 of each
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 2, 1, 1, 0, 64);
+ TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 2, 1, 1, 0, 64); // 64 proof, each with 2 amounts
+
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, false);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, true);
+ TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, true);
+
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_sc_add);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_sc_sub);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_sc_mul);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_add_raw);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_add_p3_p3);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmultBase);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmultKey);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmultH);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmult8);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_double_scalarmult_base_vartime);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_double_scalarmult_precomp_vartime);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_double_scalarmult_precomp_vartime2);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys2);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys3);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_addKeys3_2);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_isInMainSubgroup);
+
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 2);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 4);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 8);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 16);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 32);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 64);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 128);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 256);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 512);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 1024);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 2048);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_bos_coster, 4096);
+
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 2);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 4);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 8);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 16);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 32);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 64);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 128);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 256);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 512);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 1024);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 2048);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus, 4096);
+
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 2);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 4);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 8);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 16);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 32);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 64);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 128);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 256);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 512);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 1024);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 2048);
+ TEST_PERFORMANCE2(filter, p, test_multiexp, multiexp_straus_cached, 4096);
+
+#if 1
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 9);
+#else
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 8, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 16, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 32, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 64, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 128, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 256, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 512, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 1024, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 2048, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger_cached, 4096, 9);
+
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 8, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 16, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 32, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 64, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 128, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 256, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 512, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 9);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 1);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 2);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 3);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 4);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 5);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 6);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 7);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 8);
+ TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 9);
+#endif
std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;
diff --git a/tests/performance_tests/multiexp.h b/tests/performance_tests/multiexp.h
new file mode 100644
index 000000000..b8b87b3a6
--- /dev/null
+++ b/tests/performance_tests/multiexp.h
@@ -0,0 +1,94 @@
+// 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include <vector>
+#include "ringct/rctOps.h"
+#include "ringct/multiexp.h"
+
+enum test_multiexp_algorithm
+{
+ multiexp_bos_coster,
+ multiexp_straus,
+ multiexp_straus_cached,
+ multiexp_pippenger,
+ multiexp_pippenger_cached,
+};
+
+template<test_multiexp_algorithm algorithm, size_t npoints, size_t c=0>
+class test_multiexp
+{
+public:
+ static const size_t loop_count = npoints >= 1024 ? 10 : npoints < 256 ? 1000 : 100;
+
+ bool init()
+ {
+ data.resize(npoints);
+ res = rct::identity();
+ for (size_t n = 0; n < npoints; ++n)
+ {
+ data[n].scalar = rct::skGen();
+ rct::key point = rct::scalarmultBase(rct::skGen());
+ if (ge_frombytes_vartime(&data[n].point, point.bytes))
+ return false;
+ rct::key kn = rct::scalarmultKey(point, data[n].scalar);
+ res = rct::addKeys(res, kn);
+ }
+ straus_cache = rct::straus_init_cache(data);
+ pippenger_cache = rct::pippenger_init_cache(data);
+ return true;
+ }
+
+ bool test()
+ {
+ switch (algorithm)
+ {
+ case multiexp_bos_coster:
+ return res == bos_coster_heap_conv_robust(data);
+ case multiexp_straus:
+ return res == straus(data);
+ case multiexp_straus_cached:
+ return res == straus(data, straus_cache);
+ case multiexp_pippenger:
+ return res == pippenger(data, NULL, c);
+ case multiexp_pippenger_cached:
+ return res == pippenger(data, pippenger_cache, c);
+ default:
+ return false;
+ }
+ }
+
+private:
+ std::vector<rct::MultiexpData> data;
+ std::shared_ptr<rct::straus_cached_data> straus_cache;
+ std::shared_ptr<rct::pippenger_cached_data> pippenger_cache;
+ rct::key res;
+};
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h
index 29d296571..d37dda729 100644
--- a/tests/performance_tests/performance_tests.h
+++ b/tests/performance_tests/performance_tests.h
@@ -36,6 +36,9 @@
#include <boost/chrono.hpp>
#include <boost/regex.hpp>
+#include "misc_language.h"
+#include "common/perf_timer.h"
+
class performance_timer
{
public:
@@ -62,13 +65,21 @@ private:
clock::time_point m_start;
};
+struct Params
+{
+ bool verbose;
+ bool stats;
+ unsigned loop_multiplier;
+};
template <typename T>
class test_runner
{
public:
- test_runner()
+ test_runner(const Params &params)
: m_elapsed(0)
+ , m_params(params)
+ , m_per_call_timers(T::loop_count * params.loop_multiplier, {true})
{
}
@@ -81,13 +92,18 @@ public:
performance_timer timer;
timer.start();
warm_up();
- std::cout << "Warm up: " << timer.elapsed_ms() << " ms" << std::endl;
+ if (m_params.verbose)
+ std::cout << "Warm up: " << timer.elapsed_ms() << " ms" << std::endl;
timer.start();
- for (size_t i = 0; i < T::loop_count; ++i)
+ for (size_t i = 0; i < T::loop_count * m_params.loop_multiplier; ++i)
{
+ if (m_params.stats)
+ m_per_call_timers[i].resume();
if (!test.test())
return false;
+ if (m_params.stats)
+ m_per_call_timers[i].pause();
}
m_elapsed = timer.elapsed_ms();
@@ -99,9 +115,62 @@ public:
int time_per_call(int scale = 1) const
{
static_assert(0 < T::loop_count, "T::loop_count must be greater than 0");
- return m_elapsed * scale / T::loop_count;
+ return m_elapsed * scale / (T::loop_count * m_params.loop_multiplier);
+ }
+
+ uint64_t per_call_min() const
+ {
+ uint64_t v = std::numeric_limits<uint64_t>::max();
+ for (const auto &pt: m_per_call_timers)
+ v = std::min(v, pt.value());
+ return v;
+ }
+
+ uint64_t per_call_max() const
+ {
+ uint64_t v = std::numeric_limits<uint64_t>::min();
+ for (const auto &pt: m_per_call_timers)
+ v = std::max(v, pt.value());
+ return v;
}
+ uint64_t per_call_mean() const
+ {
+ uint64_t v = 0;
+ for (const auto &pt: m_per_call_timers)
+ v += pt.value();
+ return v / m_per_call_timers.size();
+ }
+
+ uint64_t per_call_median() const
+ {
+ std::vector<uint64_t> values;
+ values.reserve(m_per_call_timers.size());
+ for (const auto &pt: m_per_call_timers)
+ values.push_back(pt.value());
+ return epee::misc_utils::median(values);
+ }
+
+ uint64_t per_call_stddev() const
+ {
+ if (m_per_call_timers.size() <= 1)
+ return 0;
+ const uint64_t mean = per_call_mean();
+ uint64_t acc = 0;
+ for (const auto &pt: m_per_call_timers)
+ {
+ int64_t dv = pt.value() - mean;
+ acc += dv * dv;
+ }
+ acc /= m_per_call_timers.size () - 1;
+ return sqrt(acc);
+ }
+
+ uint64_t min_time_ns() const { return tools::ticks_to_ns(per_call_min()); }
+ uint64_t max_time_ns() const { return tools::ticks_to_ns(per_call_max()); }
+ uint64_t median_time_ns() const { return tools::ticks_to_ns(per_call_median()); }
+ uint64_t standard_deviation_time_ns() const { return tools::ticks_to_ns(per_call_stddev()); }
+
private:
/**
* Warm up processor core, enabling turbo boost, etc.
@@ -120,22 +189,39 @@ private:
private:
volatile uint64_t m_warm_up; ///<! This field is intended for preclude compiler optimizations
int m_elapsed;
+ Params m_params;
+ std::vector<tools::PerformanceTimer> m_per_call_timers;
};
template <typename T>
-void run_test(const std::string &filter, const char* test_name)
+void run_test(const std::string &filter, const Params &params, const char* test_name)
{
boost::smatch match;
if (!filter.empty() && !boost::regex_match(std::string(test_name), match, boost::regex(filter)))
return;
- test_runner<T> runner;
+ test_runner<T> runner(params);
if (runner.run())
{
- std::cout << test_name << " - OK:\n";
- std::cout << " loop count: " << T::loop_count << '\n';
- std::cout << " elapsed: " << runner.elapsed_time() << " ms\n";
+ if (params.verbose)
+ {
+ std::cout << test_name << " - OK:\n";
+ std::cout << " loop count: " << T::loop_count * params.loop_multiplier << '\n';
+ std::cout << " elapsed: " << runner.elapsed_time() << " ms\n";
+ if (params.stats)
+ {
+ std::cout << " min: " << runner.min_time_ns() << " ns\n";
+ std::cout << " max: " << runner.max_time_ns() << " ns\n";
+ std::cout << " median: " << runner.median_time_ns() << " ns\n";
+ std::cout << " std dev: " << runner.standard_deviation_time_ns() << " ns\n";
+ }
+ }
+ else
+ {
+ std::cout << test_name << " (" << T::loop_count * params.loop_multiplier << " calls) - OK:";
+ }
const char *unit = "ms";
+ uint64_t scale = 1000000;
int time_per_call = runner.time_per_call();
if (time_per_call < 30000) {
time_per_call = runner.time_per_call(1000);
@@ -144,8 +230,17 @@ void run_test(const std::string &filter, const char* test_name)
#else
unit = "µs";
#endif
+ scale = 1000;
+ }
+ std::cout << (params.verbose ? " time per call: " : " ") << time_per_call << " " << unit << "/call" << (params.verbose ? "\n" : "");
+ if (params.stats)
+ {
+ uint64_t min_ns = runner.min_time_ns() / scale;
+ uint64_t med_ns = runner.median_time_ns() / scale;
+ uint64_t stddev_ns = runner.standard_deviation_time_ns() / scale;
+ std::cout << " (min " << min_ns << " " << unit << ", median " << med_ns << " " << unit << ", std dev " << stddev_ns << " " << unit << ")";
}
- std::cout << " time per call: " << time_per_call << " " << unit << "/call\n" << std::endl;
+ std::cout << std::endl;
}
else
{
@@ -154,7 +249,10 @@ void run_test(const std::string &filter, const char* test_name)
}
#define QUOTEME(x) #x
-#define TEST_PERFORMANCE0(filter, test_class) run_test< test_class >(filter, QUOTEME(test_class))
-#define TEST_PERFORMANCE1(filter, test_class, a0) run_test< test_class<a0> >(filter, QUOTEME(test_class<a0>))
-#define TEST_PERFORMANCE2(filter, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">")
-#define TEST_PERFORMANCE3(filter, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">")
+#define TEST_PERFORMANCE0(filter, params, test_class) run_test< test_class >(filter, params, QUOTEME(test_class))
+#define TEST_PERFORMANCE1(filter, params, test_class, a0) run_test< test_class<a0> >(filter, params, QUOTEME(test_class<a0>))
+#define TEST_PERFORMANCE2(filter, params, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">")
+#define TEST_PERFORMANCE3(filter, params, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">")
+#define TEST_PERFORMANCE4(filter, params, test_class, a0, a1, a2, a3) run_test< test_class<a0, a1, a2, a3> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ">")
+#define TEST_PERFORMANCE5(filter, params, test_class, a0, a1, a2, a3, a4) run_test< test_class<a0, a1, a2, a3, a4> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ">")
+#define TEST_PERFORMANCE6(filter, params, test_class, a0, a1, a2, a3, a4, a5) run_test< test_class<a0, a1, a2, a3, a4, a5> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ", " QUOTEME(a5) ">")
diff --git a/tests/performance_tests/range_proof.h b/tests/performance_tests/range_proof.h
new file mode 100644
index 000000000..0ce962cd9
--- /dev/null
+++ b/tests/performance_tests/range_proof.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2014-2017, 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "ringct/rctSigs.h"
+
+template<bool a_verify>
+class test_range_proof
+{
+public:
+ static const size_t loop_count = 50;
+ static const bool verify = a_verify;
+
+ bool init()
+ {
+ rct::key mask;
+ sig = rct::proveRange(C, mask, 84932483243793);
+ return true;
+ }
+
+ bool test()
+ {
+ bool ret = true;
+ rct::key mask;
+ if (verify)
+ ret = rct::verRange(C, sig);
+ else
+ rct::proveRange(C, mask, 84932483243793);
+ return ret;
+ }
+
+private:
+ rct::key C;
+ rct::rangeSig sig;
+};
diff --git a/tests/performance_tests/signature.h b/tests/performance_tests/signature.h
new file mode 100644
index 000000000..21110b525
--- /dev/null
+++ b/tests/performance_tests/signature.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2014-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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "crypto/crypto.h"
+#include "cryptonote_basic/cryptonote_basic.h"
+
+#include "single_tx_test_base.h"
+
+template<bool verify>
+class test_signature : public single_tx_test_base
+{
+public:
+ static const size_t loop_count = 10000;
+
+ bool init()
+ {
+ if (!single_tx_test_base::init())
+ return false;
+
+ message = crypto::rand<crypto::hash>();
+ keys = cryptonote::keypair::generate(hw::get_device("default"));
+ crypto::generate_signature(message, keys.pub, keys.sec, m_signature);
+
+ return true;
+ }
+
+ bool test()
+ {
+ if (verify)
+ return crypto::check_signature(message, keys.pub, m_signature);
+ crypto::generate_signature(message, keys.pub, keys.sec, m_signature);
+ return true;
+ }
+
+private:
+ cryptonote::keypair keys;
+ crypto::hash message;
+ crypto::signature m_signature;
+};
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 7366990ad..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
@@ -78,7 +79,8 @@ set(unit_tests_sources
vercmp.cpp
ringdb.cpp
wipeable_string.cpp
- is_hdd.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/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));
+}