Debian Codegraph @

tests/core_tests/rct.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 #include "chaingen.h"
33
34 struct gen_rct_tx_validation_base : public test_chain_unit_base
35 {
36 gen_rct_tx_validation_base()
37 : m_invalid_tx_index(0)
38 , m_invalid_block_index(0)
39 {
40 REGISTER_CALLBACK_METHOD(gen_rct_tx_validation_base, mark_invalid_tx);
41 REGISTER_CALLBACK_METHOD(gen_rct_tx_validation_base, mark_invalid_block);
42 }
43
44 bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_idx, const cryptonote::transaction& /*tx*/)
45 {
46 if (m_invalid_tx_index == event_idx)
47 return tvc.m_verifivation_failed;
48 else
49 return !tvc.m_verifivation_failed && tx_added;
50 }
51
52 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*block*/)
53 {
54 if (m_invalid_block_index == event_idx)
55 return bvc.m_verifivation_failed;
56 else
57 return !bvc.m_verifivation_failed;
58 }
59
60 bool mark_invalid_block(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
61 {
62 m_invalid_block_index = ev_index + 1;
63 return true;
64 }
65
66 bool mark_invalid_tx(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
67 {
68 m_invalid_tx_index = ev_index + 1;
69 return true;
70 }
71
72 bool generate_with_full(std::vector<test_event_entry>& events, const int *out_idx, int mixin,
73 uint64_t amount_paid, size_t second_rewind, uint8_t last_version, const rct::RCTConfig &rct_config, bool use_view_tags, bool valid,
74 const std::function<void(std::vector<cryptonote::tx_source_entry> &sources, std::vector<cryptonote::tx_destination_entry> &destinations)> &pre_tx,
75 const std::function<void(cryptonote::transaction &tx)> &post_tx) const;
76 bool generate_with(std::vector<test_event_entry>& events, const int *out_idx, int mixin,
77 uint64_t amount_paid, bool valid,
78 const std::function<void(std::vector<cryptonote::tx_source_entry> &sources, std::vector<cryptonote::tx_destination_entry> &destinations)> &pre_tx,
79 const std::function<void(cryptonote::transaction &tx)> &post_tx) const;
80
81 private:
82 size_t m_invalid_tx_index;
83 size_t m_invalid_block_index;
84 };
85
86 template<>
87 struct get_test_options<gen_rct_tx_validation_base> {
88 const std::pair<uint8_t, uint64_t> hard_forks[4] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(0, 0)};
89 const cryptonote::test_options test_options = {
90 hard_forks, 0
91 };
92 };
93
94 // valid
95 struct gen_rct_tx_valid_from_pre_rct : public gen_rct_tx_validation_base
96 {
97 bool generate(std::vector<test_event_entry>& events) const;
98 };
99 template<> struct get_test_options<gen_rct_tx_valid_from_pre_rct>: public get_test_options<gen_rct_tx_validation_base> {};
100
101 struct gen_rct_tx_valid_from_rct : public gen_rct_tx_validation_base
102 {
103 bool generate(std::vector<test_event_entry>& events) const;
104 };
105 template<> struct get_test_options<gen_rct_tx_valid_from_rct>: public get_test_options<gen_rct_tx_validation_base> {};
106
107 struct gen_rct_tx_valid_from_mixed : public gen_rct_tx_validation_base
108 {
109 bool generate(std::vector<test_event_entry>& events) const;
110 };
111 template<> struct get_test_options<gen_rct_tx_valid_from_mixed>: public get_test_options<gen_rct_tx_validation_base> {};
112
113 // altered commitment/dest
114 struct gen_rct_tx_pre_rct_bad_real_dest : public gen_rct_tx_validation_base
115 {
116 bool generate(std::vector<test_event_entry>& events) const;
117 };
118 template<> struct get_test_options<gen_rct_tx_pre_rct_bad_real_dest>: public get_test_options<gen_rct_tx_validation_base> {};
119
120 struct gen_rct_tx_pre_rct_bad_real_mask : public gen_rct_tx_validation_base
121 {
122 bool generate(std::vector<test_event_entry>& events) const;
123 };
124 template<> struct get_test_options<gen_rct_tx_pre_rct_bad_real_mask>: public get_test_options<gen_rct_tx_validation_base> {};
125
126 struct gen_rct_tx_pre_rct_bad_fake_dest : public gen_rct_tx_validation_base
127 {
128 bool generate(std::vector<test_event_entry>& events) const;
129 };
130 template<> struct get_test_options<gen_rct_tx_pre_rct_bad_fake_dest>: public get_test_options<gen_rct_tx_validation_base> {};
131
132 struct gen_rct_tx_pre_rct_bad_fake_mask : public gen_rct_tx_validation_base
133 {
134 bool generate(std::vector<test_event_entry>& events) const;
135 };
136 template<> struct get_test_options<gen_rct_tx_pre_rct_bad_fake_mask>: public get_test_options<gen_rct_tx_validation_base> {};
137
138 struct gen_rct_tx_rct_bad_real_dest : public gen_rct_tx_validation_base
139 {
140 bool generate(std::vector<test_event_entry>& events) const;
141 };
142 template<> struct get_test_options<gen_rct_tx_rct_bad_real_dest>: public get_test_options<gen_rct_tx_validation_base> {};
143
144 struct gen_rct_tx_rct_bad_real_mask : public gen_rct_tx_validation_base
145 {
146 bool generate(std::vector<test_event_entry>& events) const;
147 };
148 template<> struct get_test_options<gen_rct_tx_rct_bad_real_mask>: public get_test_options<gen_rct_tx_validation_base> {};
149
150 struct gen_rct_tx_rct_bad_fake_dest : public gen_rct_tx_validation_base
151 {
152 bool generate(std::vector<test_event_entry>& events) const;
153 };
154 template<> struct get_test_options<gen_rct_tx_rct_bad_fake_dest>: public get_test_options<gen_rct_tx_validation_base> {};
155
156 struct gen_rct_tx_rct_bad_fake_mask : public gen_rct_tx_validation_base
157 {
158 bool generate(std::vector<test_event_entry>& events) const;
159 };
160 template<> struct get_test_options<gen_rct_tx_rct_bad_fake_mask>: public get_test_options<gen_rct_tx_validation_base> {};
161
162 struct gen_rct_tx_rct_spend_with_zero_commit : public gen_rct_tx_validation_base
163 {
164 bool generate(std::vector<test_event_entry>& events) const;
165 };
166 template<> struct get_test_options<gen_rct_tx_rct_spend_with_zero_commit>: public get_test_options<gen_rct_tx_validation_base> {};
167
168 // altered amounts
169 struct gen_rct_tx_pre_rct_zero_vin_amount : public gen_rct_tx_validation_base
170 {
171 bool generate(std::vector<test_event_entry>& events) const;
172 };
173 template<> struct get_test_options<gen_rct_tx_pre_rct_zero_vin_amount>: public get_test_options<gen_rct_tx_validation_base> {};
174
175 struct gen_rct_tx_rct_non_zero_vin_amount : public gen_rct_tx_validation_base
176 {
177 bool generate(std::vector<test_event_entry>& events) const;
178 };
179 template<> struct get_test_options<gen_rct_tx_rct_non_zero_vin_amount>: public get_test_options<gen_rct_tx_validation_base> {};
180
181 struct gen_rct_tx_non_zero_vout_amount : public gen_rct_tx_validation_base
182 {
183 bool generate(std::vector<test_event_entry>& events) const;
184 };
185 template<> struct get_test_options<gen_rct_tx_non_zero_vout_amount>: public get_test_options<gen_rct_tx_validation_base> {};
186
187 // key image
188 struct gen_rct_tx_pre_rct_duplicate_key_image : public gen_rct_tx_validation_base
189 {
190 bool generate(std::vector<test_event_entry>& events) const;
191 };
192 template<> struct get_test_options<gen_rct_tx_pre_rct_duplicate_key_image>: public get_test_options<gen_rct_tx_validation_base> {};
193
194 struct gen_rct_tx_rct_duplicate_key_image : public gen_rct_tx_validation_base
195 {
196 bool generate(std::vector<test_event_entry>& events) const;
197 };
198 template<> struct get_test_options<gen_rct_tx_rct_duplicate_key_image>: public get_test_options<gen_rct_tx_validation_base> {};
199
200 struct gen_rct_tx_pre_rct_wrong_key_image : public gen_rct_tx_validation_base
201 {
202 bool generate(std::vector<test_event_entry>& events) const;
203 };
204 template<> struct get_test_options<gen_rct_tx_pre_rct_wrong_key_image>: public get_test_options<gen_rct_tx_validation_base> {};
205
206 struct gen_rct_tx_rct_wrong_key_image : public gen_rct_tx_validation_base
207 {
208 bool generate(std::vector<test_event_entry>& events) const;
209 };
210 template<> struct get_test_options<gen_rct_tx_rct_wrong_key_image>: public get_test_options<gen_rct_tx_validation_base> {};
211
212 // fee
213 struct gen_rct_tx_pre_rct_wrong_fee : public gen_rct_tx_validation_base
214 {
215 bool generate(std::vector<test_event_entry>& events) const;
216 };
217 template<> struct get_test_options<gen_rct_tx_pre_rct_wrong_fee>: public get_test_options<gen_rct_tx_validation_base> {};
218
219 struct gen_rct_tx_rct_wrong_fee : public gen_rct_tx_validation_base
220 {
221 bool generate(std::vector<test_event_entry>& events) const;
222 };
223 template<> struct get_test_options<gen_rct_tx_rct_wrong_fee>: public get_test_options<gen_rct_tx_validation_base> {};
224
225 struct gen_rct_tx_pre_rct_increase_vin_and_fee : public gen_rct_tx_validation_base
226 {
227 bool generate(std::vector<test_event_entry>& events) const;
228 };
229 template<> struct get_test_options<gen_rct_tx_pre_rct_increase_vin_and_fee>: public get_test_options<gen_rct_tx_validation_base> {};
230
231 // modify vin/vout
232 struct gen_rct_tx_pre_rct_remove_vin : public gen_rct_tx_validation_base
233 {
234 bool generate(std::vector<test_event_entry>& events) const;
235 };
236 template<> struct get_test_options<gen_rct_tx_pre_rct_remove_vin>: public get_test_options<gen_rct_tx_validation_base> {};
237
238 struct gen_rct_tx_rct_remove_vin : public gen_rct_tx_validation_base
239 {
240 bool generate(std::vector<test_event_entry>& events) const;
241 };
242 template<> struct get_test_options<gen_rct_tx_rct_remove_vin>: public get_test_options<gen_rct_tx_validation_base> {};
243
244 struct gen_rct_tx_pre_rct_add_vout : public gen_rct_tx_validation_base
245 {
246 bool generate(std::vector<test_event_entry>& events) const;
247 };
248 template<> struct get_test_options<gen_rct_tx_pre_rct_add_vout>: public get_test_options<gen_rct_tx_validation_base> {};
249
250 struct gen_rct_tx_rct_add_vout : public gen_rct_tx_validation_base
251 {
252 bool generate(std::vector<test_event_entry>& events) const;
253 };
254 template<> struct get_test_options<gen_rct_tx_rct_add_vout>: public get_test_options<gen_rct_tx_validation_base> {};
255
256 // extra
257 struct gen_rct_tx_pre_rct_altered_extra : public gen_rct_tx_validation_base
258 {
259 bool generate(std::vector<test_event_entry>& events) const;
260 };
261 template<> struct get_test_options<gen_rct_tx_pre_rct_altered_extra>: public get_test_options<gen_rct_tx_validation_base> {};
262
263 struct gen_rct_tx_rct_altered_extra : public gen_rct_tx_validation_base
264 {
265 bool generate(std::vector<test_event_entry>& events) const;
266 };
267 template<> struct get_test_options<gen_rct_tx_rct_altered_extra>: public get_test_options<gen_rct_tx_validation_base> {};
268
269 struct gen_rct_tx_pre_rct_has_no_view_tag_before_hf_view_tags : public gen_rct_tx_validation_base
270 {
271 bool generate(std::vector<test_event_entry>& events) const;
272 };
273 template<> struct get_test_options<gen_rct_tx_pre_rct_has_no_view_tag_before_hf_view_tags>: public get_test_options<gen_rct_tx_validation_base> {};
274
275 struct gen_rct_tx_pre_rct_has_no_view_tag_from_hf_view_tags : public gen_rct_tx_validation_base
276 {
277 bool generate(std::vector<test_event_entry>& events) const;
278 };
279 template<> struct get_test_options<gen_rct_tx_pre_rct_has_no_view_tag_from_hf_view_tags> {
280 const std::pair<uint8_t, uint64_t> hard_forks[5] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(HF_VERSION_VIEW_TAGS, 69), std::make_pair(0, 0)};
281 const cryptonote::test_options test_options = {
282 hard_forks, 0
283 };
284 };
285
286 struct gen_rct_tx_pre_rct_has_view_tag_before_hf_view_tags : public gen_rct_tx_validation_base
287 {
288 bool generate(std::vector<test_event_entry>& events) const;
289 };
290 template<> struct get_test_options<gen_rct_tx_pre_rct_has_view_tag_before_hf_view_tags>: public get_test_options<gen_rct_tx_validation_base> {};
291
292 struct gen_rct_tx_pre_rct_has_view_tag_from_hf_view_tags : public gen_rct_tx_validation_base
293 {
294 bool generate(std::vector<test_event_entry>& events) const;
295 };
296 template<> struct get_test_options<gen_rct_tx_pre_rct_has_view_tag_from_hf_view_tags> {
297 const std::pair<uint8_t, uint64_t> hard_forks[5] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(HF_VERSION_VIEW_TAGS, 69), std::make_pair(0, 0)};
298 const cryptonote::test_options test_options = {
299 hard_forks, 0
300 };
301 };
302
303 struct gen_rct_tx_rct_has_no_view_tag_before_hf_view_tags : public gen_rct_tx_validation_base
304 {
305 bool generate(std::vector<test_event_entry>& events) const;
306 };
307 template<> struct get_test_options<gen_rct_tx_rct_has_no_view_tag_before_hf_view_tags>: public get_test_options<gen_rct_tx_validation_base> {};
308
309 struct gen_rct_tx_rct_has_no_view_tag_from_hf_view_tags : public gen_rct_tx_validation_base
310 {
311 bool generate(std::vector<test_event_entry>& events) const;
312 };
313 template<> struct get_test_options<gen_rct_tx_rct_has_no_view_tag_from_hf_view_tags> {
314 const std::pair<uint8_t, uint64_t> hard_forks[5] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(HF_VERSION_VIEW_TAGS+1, 69), std::make_pair(0, 0)};
315 const cryptonote::test_options test_options = {
316 hard_forks, 0
317 };
318 };
319
320 struct gen_rct_tx_rct_has_view_tag_before_hf_view_tags : public gen_rct_tx_validation_base
321 {
322 bool generate(std::vector<test_event_entry>& events) const;
323 };
324 template<> struct get_test_options<gen_rct_tx_rct_has_view_tag_before_hf_view_tags>: public get_test_options<gen_rct_tx_validation_base> {};
325
326 struct gen_rct_tx_rct_has_view_tag_from_hf_view_tags : public gen_rct_tx_validation_base
327 {
328 bool generate(std::vector<test_event_entry>& events) const;
329 };
330 template<> struct get_test_options<gen_rct_tx_rct_has_view_tag_from_hf_view_tags> {
331 const std::pair<uint8_t, uint64_t> hard_forks[5] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(HF_VERSION_VIEW_TAGS, 69), std::make_pair(0, 0)};
332 const cryptonote::test_options test_options = {
333 hard_forks, 0
334 };
335 };
336
337 struct gen_rct_tx_uses_output_too_early : public gen_rct_tx_validation_base
338 {
339 bool generate(std::vector<test_event_entry>& events) const;
340 };
341 template<> struct get_test_options<gen_rct_tx_uses_output_too_early> {
342 const std::pair<uint8_t, uint64_t> hard_forks[5] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(12, 69), std::make_pair(0, 0)};
343 const cryptonote::test_options test_options = {
344 hard_forks, 0
345 };
346 };