Monero
rct.h
Go to the documentation of this file.
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 
35 {
39  {
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 
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:
84 };
85 
86 template<>
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)};
90  hard_forks, 0
91  };
92 };
93 
94 // valid
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 
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 
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
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 
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 
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 
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 
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 
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 
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 
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 
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
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 
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 
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
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 
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 
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 
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
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 
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 
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
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 
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 
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 
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
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 
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 
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 
276 {
277  bool generate(std::vector<test_event_entry>& events) const;
278 };
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)};
282  hard_forks, 0
283  };
284 };
285 
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 
293 {
294  bool generate(std::vector<test_event_entry>& events) const;
295 };
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)};
299  hard_forks, 0
300  };
301 };
302 
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 
310 {
311  bool generate(std::vector<test_event_entry>& events) const;
312 };
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)};
316  hard_forks, 0
317  };
318 };
319 
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 
327 {
328  bool generate(std::vector<test_event_entry>& events) const;
329 };
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)};
333  hard_forks, 0
334  };
335 };
336 
338 {
339  bool generate(std::vector<test_event_entry>& events) const;
340 };
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)};
344  hard_forks, 0
345  };
346 };
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:536
Definition: rct.h:144
Definition: rct.h:206
Definition: rct.h:238
Definition: rct.h:101
Definition: rct.h:156
Definition: rct.h:232
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:547
bool generate_with_full(std::vector< test_event_entry > &events, const int *out_idx, int mixin, uint64_t amount_paid, size_t second_rewind, uint8_t last_version, const rct::RCTConfig &rct_config, bool use_view_tags, bool valid, const std::function< void(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations)> &pre_tx, const std::function< void(cryptonote::transaction &tx)> &post_tx) const
Definition: rct.cpp:43
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:579
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:432
Definition: rct.h:244
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:443
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:336
Definition: cryptonote_basic.h:474
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:323
Definition: rct.h:150
bool m_verifivation_failed
Definition: verification_context.h:45
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:394
Definition: rct.h:219
Definition: rct.h:34
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition: rct.h:52
Definition: verification_context.h:65
unsigned char uint8_t
Definition: stdint.h:124
#define HF_VERSION_VIEW_TAGS
Definition: cryptonote_config.h:193
gen_rct_tx_validation_base()
Definition: rct.h:36
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:293
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:557
Definition: verification_context.h:40
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:313
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:256
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:280
size_t m_invalid_block_index
Definition: rct.h:83
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:403
const std::pair< uint8_t, uint64_t > hard_forks[2]
Definition: chaingen.h:726
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:346
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:612
handles core cryptonote functionality
Definition: cryptonote_core.h:86
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:376
unsigned __int64 uint64_t
Definition: stdint.h:136
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:356
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:366
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:303
bool generate_with(std::vector< test_event_entry > &events, const int *out_idx, int mixin, uint64_t amount_paid, bool valid, const std::function< void(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations)> &pre_tx, const std::function< void(cryptonote::transaction &tx)> &post_tx) const
Definition: rct.cpp:246
Definition: rct.h:138
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:488
Definition: rct.h:250
bool check_tx_verification_context(const cryptonote::tx_verification_context &tvc, bool tx_added, size_t event_idx, const cryptonote::transaction &)
Definition: rct.h:44
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:516
#define REGISTER_CALLBACK_METHOD(CLASS, METHOD)
Definition: chaingen.h:859
Definition: cryptonote_core.h:61
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:526
Definition: chaingen.h:725
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:479
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:497
size_t m_invalid_tx_index
Definition: rct.h:82
bool mark_invalid_block(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Definition: rct.h:60
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:461
bool mark_invalid_tx(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Definition: rct.h:66
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:452
Definition: rct.h:213
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:601
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:264
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:385
cryptonote::transaction tx
Definition: transaction.cpp:40
Definition: rctTypes.h:308
const cryptonote::test_options test_options
Definition: chaingen.h:727
Definition: rct.h:95
Definition: chaingen.h:165
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:272
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:470
bool m_verifivation_failed
Definition: verification_context.h:68
Definition: rct.h:181
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:590
Definition: rct.h:263
Definition: cryptonote_basic.h:204
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:421
Definition: rct.h:107
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:412
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:506
bool generate(std::vector< test_event_entry > &events) const
Definition: rct.cpp:568