Monero
block_validation.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 
34 template<size_t invalid_block_idx = 0>
36 {
37 public:
39  {
41  }
42 
44  {
45  if (invalid_block_idx == event_idx)
46  return bvc.m_verifivation_failed;
47  else
48  return !bvc.m_verifivation_failed;
49  }
50 
51  bool check_block_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
52  {
53  DEFINE_TESTS_ERROR_CONTEXT("gen_block_verification_base::check_block_purged");
54 
55  CHECK_TEST_CONDITION(invalid_block_idx < ev_index);
56  CHECK_EQ(0, c.get_pool_transactions_count());
57  CHECK_EQ(invalid_block_idx, c.get_current_blockchain_height());
58 
59  return true;
60  }
61 };
62 
63 template<size_t expected_blockchain_height>
65 {
67  {
69  }
70 
71  bool check_block_accepted(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& /*events*/)
72  {
73  DEFINE_TESTS_ERROR_CONTEXT("gen_block_accepted_base::check_block_accepted");
74 
75  CHECK_EQ(0, c.get_pool_transactions_count());
76  CHECK_EQ(expected_blockchain_height, c.get_current_blockchain_height());
77 
78  return true;
79  }
80 };
81 
83 {
84  bool generate(std::vector<test_event_entry>& events) const;
85 };
86 
88 {
89  bool generate(std::vector<test_event_entry>& events) const;
90 };
91 
92 struct gen_block_ts_not_checked : public gen_block_accepted_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
93 {
94  bool generate(std::vector<test_event_entry>& events) const;
95 };
96 
97 struct gen_block_ts_in_past : public gen_block_verification_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
98 {
99  bool generate(std::vector<test_event_entry>& events) const;
100 };
101 
103 {
104  bool generate(std::vector<test_event_entry>& events) const;
105 };
106 
108 {
109  bool generate(std::vector<test_event_entry>& events) const;
110  bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
111 };
112 
114 {
115  bool generate(std::vector<test_event_entry>& events) const;
116 };
117 
119 {
120  bool generate(std::vector<test_event_entry>& events) const;
121 };
122 
124 {
125  bool generate(std::vector<test_event_entry>& events) const;
126 };
127 
129 {
130  bool generate(std::vector<test_event_entry>& events) const;
131 };
132 
134 {
135  bool generate(std::vector<test_event_entry>& events) const;
136 };
137 
139 {
140  bool generate(std::vector<test_event_entry>& events) const;
141 };
142 
144 {
145  bool generate(std::vector<test_event_entry>& events) const;
146 };
147 
149 {
150  bool generate(std::vector<test_event_entry>& events) const;
151 };
152 
154 {
155  bool generate(std::vector<test_event_entry>& events) const;
156 };
157 
158 struct gen_block_miner_tx_has_2_in : public gen_block_verification_base<CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 1>
159 {
160  bool generate(std::vector<test_event_entry>& events) const;
161 };
162 
163 struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base<CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 2>
164 {
165  bool generate(std::vector<test_event_entry>& events) const;
166 };
167 
169 {
170  bool generate(std::vector<test_event_entry>& events) const;
171 };
172 
174 {
175  bool generate(std::vector<test_event_entry>& events) const;
176 };
177 
179 {
180  bool generate(std::vector<test_event_entry>& events) const;
181 };
182 
184 {
185  bool generate(std::vector<test_event_entry>& events) const;
186 };
187 
189 {
190  bool generate(std::vector<test_event_entry>& events) const;
191 };
192 
194 {
195  bool generate(std::vector<test_event_entry>& events) const;
196 };
197 
199 {
201  bool generate(std::vector<test_event_entry>& events) const;
202  bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
203  bool check_all_blocks_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
204  bool corrupt_blocks_boundary(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
205 
206 private:
208 };
209 
211 {
212  bool generate(std::vector<test_event_entry>& events) const;
213 };
214 template<>
216  const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_MIN_V2_COINBASE_TX, 1), std::make_pair(0, 0)};
218  hard_forks, 0
219  };
220 };
221 
223 {
224  bool generate(std::vector<test_event_entry>& events) const;
225 };
226 template<>
228  const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_EXACT_COINBASE, 1), std::make_pair(0, 0)};
230  hard_forks, 0
231  };
232 };
233 
235 {
236  bool generate(std::vector<test_event_entry>& events) const;
237 };
238 
240 {
241  bool generate(std::vector<test_event_entry>& events) const;
242 };
243 template<>
245  const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_VIEW_TAGS+1, 1), std::make_pair(0, 0)};
247  hard_forks, 0
248  };
249 };
250 
252 {
253  bool generate(std::vector<test_event_entry>& events) const;
254 };
255 
257 {
258  bool generate(std::vector<test_event_entry>& events) const;
259 };
260 template<>
262  const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_VIEW_TAGS, 1), std::make_pair(0, 0)};
264  hard_forks, 0
265  };
266 };
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:443
Definition: block_validation.h:128
bool corrupt_blocks_boundary(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: block_validation.cpp:628
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:132
Definition: block_validation.h:168
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:329
Definition: block_validation.h:158
Definition: block_validation.h:148
#define HF_VERSION_EXACT_COINBASE
Definition: cryptonote_config.h:189
Definition: block_validation.h:198
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:168
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition: block_validation.h:43
bool check_all_blocks_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: block_validation.cpp:634
Definition: cryptonote_basic.h:474
Definition: block_validation.h:118
Definition: block_validation.h:82
size_t m_corrupt_blocks_begin_idx
Definition: block_validation.h:207
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:117
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:246
Definition: block_validation.h:64
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition: block_validation.cpp:160
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:310
Definition: verification_context.h:65
Definition: block_validation.h:123
Definition: block_validation.h:183
#define HF_VERSION_VIEW_TAGS
Definition: cryptonote_config.h:193
Definition: block_validation.h:210
Definition: block_validation.h:35
Definition: block_validation.h:133
#define CHECK_TEST_CONDITION(cond)
Definition: chaingen.h:1088
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:103
Definition: block_validation.h:138
gen_block_verification_base()
Definition: block_validation.h:38
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:551
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:278
gen_block_invalid_binary_format()
Definition: block_validation.cpp:544
const std::pair< uint8_t, uint64_t > hard_forks[2]
Definition: chaingen.h:726
Definition: block_validation.h:163
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:262
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:644
Definition: block_validation.h:102
handles core cryptonote functionality
Definition: cryptonote_core.h:86
bool check_block_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: block_validation.h:51
#define REGISTER_CALLBACK(CB_NAME, CLBACK)
Definition: chaingen.h:856
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:504
Definition: block_validation.h:113
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:90
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:702
Definition: block_validation.h:143
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:145
Definition: block_validation.h:107
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:675
gen_block_accepted_base()
Definition: block_validation.h:66
Definition: cryptonote_core.h:61
Definition: block_validation.h:222
bool check_block_accepted(cryptonote::core &c, size_t, const std::vector< test_event_entry > &)
Definition: block_validation.h:71
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:659
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:411
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:198
Definition: chaingen.h:725
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:230
Definition: block_validation.h:188
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:427
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:214
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:730
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:77
const cryptonote::test_options test_options
Definition: chaingen.h:727
Definition: block_validation.h:178
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:761
#define HF_VERSION_MIN_V2_COINBASE_TX
Definition: cryptonote_config.h:184
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:368
Definition: block_validation.h:193
Definition: block_validation.h:173
Definition: chaingen.h:165
#define CHECK_EQ(v1, v2)
Definition: chaingen.h:1089
bool m_verifivation_failed
Definition: verification_context.h:68
Definition: block_validation.h:87
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:459
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition: chaingen.h:1087
Definition: block_validation.h:153
Definition: block_validation.h:97
c
Definition: pymoduletest.py:79
Definition: block_validation.h:92
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:488
bool generate(std::vector< test_event_entry > &events) const
Definition: block_validation.cpp:294
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition: block_validation.cpp:614