Debian Codegraph @

tests/performance_tests/check_tx_signature.h

raw symbols SCIP
1 // Copyright (c) 2014-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31 #pragma once
32
33 #include <vector>
34
35 #include "cryptonote_basic/account.h"
36 #include "cryptonote_basic/cryptonote_basic.h"
37 #include "cryptonote_core/cryptonote_tx_utils.h"
38 #include "crypto/crypto.h"
39 #include "ringct/rctSigs.h"
40
41 #include "multi_tx_test_base.h"
42
43 template<size_t a_ring_size, size_t a_outputs, bool a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean, int bp_version = 2>
44 class test_check_tx_signature : private multi_tx_test_base<a_ring_size>
45 {
46 static_assert(0 < a_ring_size, "ring_size must be greater than 0");
47
48 public:
49 static const size_t loop_count = a_rct ? (a_ring_size <= 2 ? 50 : 10) : a_ring_size < 100 ? 100 : 10;
50 static const size_t ring_size = a_ring_size;
51 static const size_t outputs = a_outputs;
52 static const bool rct = a_rct;
53
54 typedef multi_tx_test_base<a_ring_size> base_class;
55
56 bool init()
57 {
58 using namespace cryptonote;
59
60 if (!base_class::init())
61 return false;
62
63 m_alice.generate();
64
65 std::vector<tx_destination_entry> destinations;
66 destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
67 for (size_t n = 1; n < outputs; ++n)
68 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
69
70 crypto::secret_key tx_key;
71 std::vector<crypto::secret_key> additional_tx_keys;
72 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
73 subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
74 rct::RCTConfig rct_config{range_proof_type, bp_version};
75 if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx, tx_key, additional_tx_keys, rct, rct_config))
76 return false;
77
78 get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);
79
80 return true;
81 }
82
83 bool test()
84 {
85 if (rct)
86 {
87 if (m_tx.rct_signatures.type == rct::RCTTypeFull)
88 return rct::verRct(m_tx.rct_signatures);
89 else
90 return rct::verRctSimple(m_tx.rct_signatures);
91 }
92 else
93 {
94 const cryptonote::txin_to_key& txin = boost::get<cryptonote::txin_to_key>(m_tx.vin[0]);
95 return crypto::check_ring_signature(m_tx_prefix_hash, txin.k_image, this->m_public_key_ptrs, ring_size, m_tx.signatures[0].data());
96 }
97 }
98
99 private:
100 cryptonote::account_base m_alice;
101 cryptonote::transaction m_tx;
102 crypto::hash m_tx_prefix_hash;
103 };
104
105 template<size_t a_ring_size, size_t a_outputs, size_t a_num_txes, size_t extra_outs = 0>
106 class test_check_tx_signature_aggregated_bulletproofs : private multi_tx_test_base<a_ring_size>
107 {
108 static_assert(0 < a_ring_size, "ring_size must be greater than 0");
109
110 public:
111 static const size_t loop_count = a_ring_size <= 2 ? 50 : 10;
112 static const size_t ring_size = a_ring_size;
113 static const size_t outputs = a_outputs;
114
115 typedef multi_tx_test_base<a_ring_size> base_class;
116
117 bool init()
118 {
119 using namespace cryptonote;
120
121 if (!base_class::init())
122 return false;
123
124 m_alice.generate();
125
126 std::vector<tx_destination_entry> destinations;
127 destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
128 for (size_t n = 1; n < outputs; ++n)
129 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
130
131 crypto::secret_key tx_key;
132 std::vector<crypto::secret_key> additional_tx_keys;
133 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
134 subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
135
136 m_txes.resize(a_num_txes + (extra_outs > 0 ? 1 : 0));
137 for (size_t n = 0; n < a_num_txes; ++n)
138 {
139 if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_txes[n], tx_key, additional_tx_keys, true, {rct::RangeProofPaddedBulletproof, 2}))
140 return false;
141 }
142
143 if (extra_outs)
144 {
145 destinations.clear();
146 destinations.push_back(tx_destination_entry(this->m_source_amount - extra_outs + 1, m_alice.get_keys().m_account_address, false));
147 for (size_t n = 1; n < extra_outs; ++n)
148 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
149
150 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(), tx_key, additional_tx_keys, true, {rct::RangeProofMultiOutputBulletproof, 2}))
151 return false;
152 }
153
154 return true;
155 }
156
157 bool test()
158 {
159 std::vector<const rct::rctSig*> rvv;
160 rvv.reserve(m_txes.size());
161 for (size_t n = 0; n < m_txes.size(); ++n)
162 {
163 const rct::rctSig &rv = m_txes[n].rct_signatures;
164 if (!rct::verRctNonSemanticsSimple(rv))
165 return false;
166 rvv.push_back(&rv);
167 }
168 return rct::verRctSemanticsSimple(rvv);
169 }
170
171 private:
172 cryptonote::account_base m_alice;
173 std::vector<cryptonote::transaction> m_txes;
174 };