| 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 | #include "ringct/rctSigs.h" |
| 32 | #include "chaingen.h" |
| 33 | #include "rct.h" |
| 34 | #include "device/device.hpp" |
| 35 | |
| 36 | using namespace epee; |
| 37 | using namespace crypto; |
| 38 | using namespace cryptonote; |
| 39 | |
| 40 | //---------------------------------------------------------------------------------------------------------------------- |
| 41 | // Tests |
| 42 | |
| 43 | bool gen_rct_tx_validation_base::generate_with_full(std::vector<test_event_entry>& events, |
| 44 | 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, |
| 45 | const std::function<void(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations)> &pre_tx, |
| 46 | const std::function<void(transaction &tx)> &post_tx) const |
| 47 | { |
| 48 | uint64_t ts_start = 1338224400; |
| 49 | |
| 50 | GENERATE_ACCOUNT(miner_account); |
| 51 | MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start); |
| 52 | |
| 53 | // create 4 miner accounts, and have them mine the next 4 blocks |
| 54 | cryptonote::account_base miner_accounts[4]; |
| 55 | const cryptonote::block *prev_block = &blk_0; |
| 56 | cryptonote::block blocks[4]; |
| 57 | for (size_t n = 0; n < 4; ++n) { |
| 58 | miner_accounts[n].generate(); |
| 59 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n], |
| 60 | test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, |
| 61 | 2, 2, prev_block->timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 62 | crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2), |
| 63 | false, "Failed to generate block"); |
| 64 | events.push_back(blocks[n]); |
| 65 | prev_block = blocks + n; |
| 66 | } |
| 67 | |
| 68 | // rewind |
| 69 | cryptonote::block blk_r, blk_last; |
| 70 | { |
| 71 | blk_last = blocks[3]; |
| 72 | for (size_t i = 0; i < CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; ++i) |
| 73 | { |
| 74 | cryptonote::block blk; |
| 75 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_account, |
| 76 | test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, |
| 77 | 2, 2, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 78 | crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2), |
| 79 | false, "Failed to generate block"); |
| 80 | events.push_back(blk); |
| 81 | blk_last = blk; |
| 82 | } |
| 83 | blk_r = blk_last; |
| 84 | } |
| 85 | |
| 86 | // create 4 txes from these miners in another block, to generate some rct outputs |
| 87 | transaction rct_txes[4]; |
| 88 | rct::key rct_tx_masks[16]; |
| 89 | cryptonote::block blk_txes[4]; |
| 90 | for (size_t n = 0; n < 4; ++n) |
| 91 | { |
| 92 | std::vector<crypto::hash> starting_rct_tx_hashes; |
| 93 | std::vector<tx_source_entry> sources; |
| 94 | |
| 95 | sources.resize(1); |
| 96 | tx_source_entry& src = sources.back(); |
| 97 | |
| 98 | const size_t index_in_tx = 5; |
| 99 | src.amount = 30000000000000; |
| 100 | for (int m = 0; m < 4; ++m) { |
| 101 | crypto::public_key output_public_key; |
| 102 | cryptonote::get_output_public_key(blocks[m].miner_tx.vout[index_in_tx], output_public_key); |
| 103 | src.push_output(m, output_public_key, src.amount); |
| 104 | } |
| 105 | src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(blocks[n].miner_tx); |
| 106 | src.real_output = n; |
| 107 | src.real_output_in_tx_index = index_in_tx; |
| 108 | src.mask = rct::identity(); |
| 109 | src.rct = false; |
| 110 | |
| 111 | //fill outputs entry |
| 112 | tx_destination_entry td; |
| 113 | td.addr = miner_accounts[n].get_keys().m_account_address; |
| 114 | td.amount = 7390000000000; |
| 115 | std::vector<tx_destination_entry> destinations; |
| 116 | destinations.push_back(td); |
| 117 | destinations.push_back(td); |
| 118 | destinations.push_back(td); |
| 119 | destinations.push_back(td); // 30 -> 7.39 * 4 |
| 120 | |
| 121 | crypto::secret_key tx_key; |
| 122 | std::vector<crypto::secret_key> additional_tx_keys; |
| 123 | std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses; |
| 124 | subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0}; |
| 125 | bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), rct_txes[n], tx_key, additional_tx_keys, true); |
| 126 | CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction"); |
| 127 | events.push_back(rct_txes[n]); |
| 128 | starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes[n])); |
| 129 | |
| 130 | for (size_t o = 0; o < 4; ++o) |
| 131 | { |
| 132 | crypto::key_derivation derivation; |
| 133 | bool r = crypto::generate_key_derivation(destinations[o].addr.m_view_public_key, tx_key, derivation); |
| 134 | CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation"); |
| 135 | crypto::secret_key amount_key; |
| 136 | crypto::derivation_to_scalar(derivation, o, amount_key); |
| 137 | const uint8_t type = rct_txes[n].rct_signatures.type; |
| 138 | if (rct::is_rct_simple(type)) |
| 139 | rct::decodeRctSimple(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default")); |
| 140 | else |
| 141 | rct::decodeRct(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default")); |
| 142 | } |
| 143 | |
| 144 | uint64_t fee = 0; |
| 145 | get_tx_fee(rct_txes[n], fee); |
| 146 | |
| 147 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes[n], blk_last, miner_account, |
| 148 | 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 | test_generator::bf_tx_fees, |
| 149 | 4, 4, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 150 | crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, 6, 4, fee), |
| 151 | false, "Failed to generate block"); |
| 152 | events.push_back(blk_txes[n]); |
| 153 | blk_last = blk_txes[n]; |
| 154 | } |
| 155 | |
| 156 | // rewind |
| 157 | { |
| 158 | for (size_t i = 0; i < second_rewind; ++i) |
| 159 | { |
| 160 | cryptonote::block blk; |
| 161 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_account, |
| 162 | test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version | test_generator::bf_max_outs, |
| 163 | last_version, last_version, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 164 | crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 6, last_version), |
| 165 | false, "Failed to generate block"); |
| 166 | events.push_back(blk); |
| 167 | blk_last = blk; |
| 168 | } |
| 169 | blk_r = blk_last; |
| 170 | } |
| 171 | |
| 172 | // create a tx from the requested ouputs |
| 173 | std::vector<tx_source_entry> sources; |
| 174 | size_t global_rct_idx = 6; // skip first coinbase (6 outputs) |
| 175 | size_t rct_idx = 0; |
| 176 | size_t pre_rct_idx = 0; |
| 177 | for (size_t out_idx_idx = 0; out_idx[out_idx_idx] >= 0; ++out_idx_idx) { |
| 178 | sources.resize(sources.size()+1); |
| 179 | tx_source_entry& src = sources.back(); |
| 180 | |
| 181 | src.real_output = 0; |
| 182 | if (out_idx[out_idx_idx]) { |
| 183 | // rct |
| 184 | src.amount = 7390000000000; |
| 185 | src.real_out_tx_key = get_tx_pub_key_from_extra(rct_txes[rct_idx/4]); |
| 186 | src.real_output_in_tx_index = rct_idx&3; |
| 187 | src.mask = rct_tx_masks[rct_idx]; |
| 188 | src.rct = true; |
| 189 | for (int m = 0; m <= mixin; ++m) { |
| 190 | rct::ctkey ctkey; |
| 191 | ctkey.dest = rct::pk2rct(boost::get<txout_to_key>(rct_txes[rct_idx/4].vout[rct_idx&3].target).key); |
| 192 | ctkey.mask = rct_txes[rct_idx/4].rct_signatures.outPk[rct_idx&3].mask; |
| 193 | src.outputs.push_back(std::make_pair(global_rct_idx, ctkey)); |
| 194 | ++rct_idx; |
| 195 | ++global_rct_idx; |
| 196 | if (global_rct_idx % 10 == 0) |
| 197 | global_rct_idx += 6; // skip the coinbase |
| 198 | } |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | // pre rct |
| 203 | src.amount = 5000000000000; |
| 204 | src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(blocks[pre_rct_idx].miner_tx); |
| 205 | src.real_output_in_tx_index = 4; |
| 206 | src.mask = rct::identity(); |
| 207 | src.rct = false; |
| 208 | for (int m = 0; m <= mixin; ++m) { |
| 209 | src.push_output(m, boost::get<txout_to_key>(blocks[pre_rct_idx].miner_tx.vout[4].target).key, src.amount); |
| 210 | ++pre_rct_idx; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | //fill outputs entry |
| 216 | tx_destination_entry td; |
| 217 | td.addr = miner_account.get_keys().m_account_address; |
| 218 | td.amount = amount_paid; |
| 219 | std::vector<tx_destination_entry> destinations; |
| 220 | // from v12, we need two outputs at least |
| 221 | destinations.push_back(td); |
| 222 | destinations.push_back(td); |
| 223 | |
| 224 | if (pre_tx) |
| 225 | pre_tx(sources, destinations); |
| 226 | |
| 227 | transaction tx; |
| 228 | crypto::secret_key tx_key; |
| 229 | std::vector<crypto::secret_key> additional_tx_keys; |
| 230 | std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses; |
| 231 | subaddresses[miner_accounts[0].get_keys().m_account_address.m_spend_public_key] = {0,0}; |
| 232 | bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), tx, tx_key, additional_tx_keys, true, rct_config, use_view_tags); |
| 233 | CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction"); |
| 234 | |
| 235 | if (post_tx) |
| 236 | post_tx(tx); |
| 237 | |
| 238 | if (!valid) |
| 239 | DO_CALLBACK(events, "mark_invalid_tx"); |
| 240 | events.push_back(tx); |
| 241 | LOG_PRINT_L0("Test tx: " << obj_to_json_str(tx)); |
| 242 | |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | bool gen_rct_tx_validation_base::generate_with(std::vector<test_event_entry>& events, |
| 247 | const int *out_idx, int mixin, uint64_t amount_paid, bool valid, |
| 248 | const std::function<void(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations)> &pre_tx, |
| 249 | const std::function<void(transaction &tx)> &post_tx) const |
| 250 | { |
| 251 | const rct::RCTConfig rct_config { rct::RangeProofBorromean, 0 }; |
| 252 | bool use_view_tags = false; |
| 253 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, 4, rct_config, use_view_tags, valid, pre_tx, post_tx); |
| 254 | } |
| 255 | |
| 256 | bool gen_rct_tx_valid_from_pre_rct::generate(std::vector<test_event_entry>& events) const |
| 257 | { |
| 258 | const int mixin = 2; |
| 259 | const int out_idx[] = {0, -1}; |
| 260 | const uint64_t amount_paid = 10000; |
| 261 | return generate_with(events, out_idx, mixin, amount_paid, true, NULL, NULL); |
| 262 | } |
| 263 | |
| 264 | bool gen_rct_tx_valid_from_rct::generate(std::vector<test_event_entry>& events) const |
| 265 | { |
| 266 | const int mixin = 2; |
| 267 | const int out_idx[] = {1, -1}; |
| 268 | const uint64_t amount_paid = 10000; |
| 269 | return generate_with(events, out_idx, mixin, amount_paid, true, NULL, NULL); |
| 270 | } |
| 271 | |
| 272 | bool gen_rct_tx_valid_from_mixed::generate(std::vector<test_event_entry>& events) const |
| 273 | { |
| 274 | const int mixin = 2; |
| 275 | const int out_idx[] = {1, 0, -1}; |
| 276 | const uint64_t amount_paid = 10000; |
| 277 | return generate_with(events, out_idx, mixin, amount_paid, true, NULL, NULL); |
| 278 | } |
| 279 | |
| 280 | bool gen_rct_tx_pre_rct_bad_real_dest::generate(std::vector<test_event_entry>& events) const |
| 281 | { |
| 282 | const int mixin = 2; |
| 283 | const int out_idx[] = {0, -1}; |
| 284 | const uint64_t amount_paid = 10000; |
| 285 | bool tx_creation_succeeded = false; |
| 286 | // in the case, the tx will fail to create, due to mismatched sk/pk |
| 287 | bool ret = generate_with(events, out_idx, mixin, amount_paid, false, |
| 288 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {rct::key sk; rct::skpkGen(sk, sources[0].outputs[0].second.dest);}, |
| 289 | [&tx_creation_succeeded](const transaction &tx){tx_creation_succeeded=true;}); |
| 290 | return !ret && !tx_creation_succeeded; |
| 291 | } |
| 292 | |
| 293 | bool gen_rct_tx_pre_rct_bad_real_mask::generate(std::vector<test_event_entry>& events) const |
| 294 | { |
| 295 | const int mixin = 2; |
| 296 | const int out_idx[] = {0, -1}; |
| 297 | const uint64_t amount_paid = 10000; |
| 298 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 299 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {sources[0].outputs[0].second.mask = rct::zeroCommit(99999);}, |
| 300 | NULL); |
| 301 | } |
| 302 | |
| 303 | bool gen_rct_tx_pre_rct_bad_fake_dest::generate(std::vector<test_event_entry>& events) const |
| 304 | { |
| 305 | const int mixin = 2; |
| 306 | const int out_idx[] = {0, -1}; |
| 307 | const uint64_t amount_paid = 10000; |
| 308 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 309 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {rct::key sk; rct::skpkGen(sk, sources[0].outputs[1].second.dest);}, |
| 310 | NULL); |
| 311 | } |
| 312 | |
| 313 | bool gen_rct_tx_pre_rct_bad_fake_mask::generate(std::vector<test_event_entry>& events) const |
| 314 | { |
| 315 | const int mixin = 2; |
| 316 | const int out_idx[] = {0, -1}; |
| 317 | const uint64_t amount_paid = 10000; |
| 318 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 319 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {sources[0].outputs[1].second.mask = rct::zeroCommit(99999);}, |
| 320 | NULL); |
| 321 | } |
| 322 | |
| 323 | bool gen_rct_tx_rct_bad_real_dest::generate(std::vector<test_event_entry>& events) const |
| 324 | { |
| 325 | const int mixin = 2; |
| 326 | const int out_idx[] = {1, -1}; |
| 327 | const uint64_t amount_paid = 10000; |
| 328 | bool tx_creation_succeeded = false; |
| 329 | // in the case, the tx will fail to create, due to mismatched sk/pk |
| 330 | bool ret = generate_with(events, out_idx, mixin, amount_paid, false, |
| 331 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {rct::key sk; rct::skpkGen(sk, sources[0].outputs[0].second.dest);}, |
| 332 | [&tx_creation_succeeded](const transaction &tx){tx_creation_succeeded=true;}); |
| 333 | return !ret && !tx_creation_succeeded; |
| 334 | } |
| 335 | |
| 336 | bool gen_rct_tx_rct_bad_real_mask::generate(std::vector<test_event_entry>& events) const |
| 337 | { |
| 338 | const int mixin = 2; |
| 339 | const int out_idx[] = {1, -1}; |
| 340 | const uint64_t amount_paid = 10000; |
| 341 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 342 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {sources[0].outputs[0].second.mask = rct::zeroCommit(99999);}, |
| 343 | NULL); |
| 344 | } |
| 345 | |
| 346 | bool gen_rct_tx_rct_bad_fake_dest::generate(std::vector<test_event_entry>& events) const |
| 347 | { |
| 348 | const int mixin = 2; |
| 349 | const int out_idx[] = {1, -1}; |
| 350 | const uint64_t amount_paid = 10000; |
| 351 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 352 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {rct::key sk; rct::skpkGen(sk, sources[0].outputs[1].second.dest);}, |
| 353 | NULL); |
| 354 | } |
| 355 | |
| 356 | bool gen_rct_tx_rct_bad_fake_mask::generate(std::vector<test_event_entry>& events) const |
| 357 | { |
| 358 | const int mixin = 2; |
| 359 | const int out_idx[] = {1, -1}; |
| 360 | const uint64_t amount_paid = 10000; |
| 361 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 362 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {sources[0].outputs[1].second.mask = rct::zeroCommit(99999);}, |
| 363 | NULL); |
| 364 | } |
| 365 | |
| 366 | bool gen_rct_tx_rct_spend_with_zero_commit::generate(std::vector<test_event_entry>& events) const |
| 367 | { |
| 368 | const int mixin = 2; |
| 369 | const int out_idx[] = {1, -1}; |
| 370 | const uint64_t amount_paid = 10000; |
| 371 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 372 | [](std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations) {sources[0].outputs[0].second.mask = rct::zeroCommit(sources[0].amount); sources[0].mask = rct::identity();}, |
| 373 | [](transaction &tx){boost::get<txin_to_key>(tx.vin[0]).amount = 0;}); |
| 374 | } |
| 375 | |
| 376 | bool gen_rct_tx_pre_rct_zero_vin_amount::generate(std::vector<test_event_entry>& events) const |
| 377 | { |
| 378 | const int mixin = 2; |
| 379 | const int out_idx[] = {0, -1}; |
| 380 | const uint64_t amount_paid = 10000; |
| 381 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 382 | NULL, [](transaction &tx) {boost::get<txin_to_key>(tx.vin[0]).amount = 0;}); |
| 383 | } |
| 384 | |
| 385 | bool gen_rct_tx_rct_non_zero_vin_amount::generate(std::vector<test_event_entry>& events) const |
| 386 | { |
| 387 | const int mixin = 2; |
| 388 | const int out_idx[] = {1, -1}; |
| 389 | const uint64_t amount_paid = 10000; |
| 390 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 391 | NULL, [](transaction &tx) {boost::get<txin_to_key>(tx.vin[0]).amount = 5000000000000;}); // one that we know exists |
| 392 | } |
| 393 | |
| 394 | bool gen_rct_tx_non_zero_vout_amount::generate(std::vector<test_event_entry>& events) const |
| 395 | { |
| 396 | const int mixin = 2; |
| 397 | const int out_idx[] = {1, -1}; |
| 398 | const uint64_t amount_paid = 10000; |
| 399 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 400 | NULL, [](transaction &tx) {tx.vout[0].amount = 5000000000000;}); // one that we know exists |
| 401 | } |
| 402 | |
| 403 | bool gen_rct_tx_pre_rct_duplicate_key_image::generate(std::vector<test_event_entry>& events) const |
| 404 | { |
| 405 | const int mixin = 2; |
| 406 | const int out_idx[] = {0, -1}; |
| 407 | const uint64_t amount_paid = 10000; |
| 408 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 409 | NULL, [&events](transaction &tx) {boost::get<txin_to_key>(tx.vin[0]).k_image = boost::get<txin_to_key>(boost::get<transaction>(events[67]).vin[0]).k_image;}); |
| 410 | } |
| 411 | |
| 412 | bool gen_rct_tx_rct_duplicate_key_image::generate(std::vector<test_event_entry>& events) const |
| 413 | { |
| 414 | const int mixin = 2; |
| 415 | const int out_idx[] = {1, -1}; |
| 416 | const uint64_t amount_paid = 10000; |
| 417 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 418 | NULL, [&events](transaction &tx) {boost::get<txin_to_key>(tx.vin[0]).k_image = boost::get<txin_to_key>(boost::get<transaction>(events[67]).vin[0]).k_image;}); |
| 419 | } |
| 420 | |
| 421 | bool gen_rct_tx_pre_rct_wrong_key_image::generate(std::vector<test_event_entry>& events) const |
| 422 | { |
| 423 | const int mixin = 2; |
| 424 | const int out_idx[] = {0, -1}; |
| 425 | const uint64_t amount_paid = 10000; |
| 426 | // some random key image from the monero blockchain, so we get something that is a valid key image |
| 427 | static const uint8_t k_image[33] = "\x49\x3b\x56\x16\x54\x76\xa8\x75\xb7\xf4\xa8\x51\xf5\x55\xd3\x44\xe7\x3e\xea\x73\xee\xc1\x06\x7c\x7d\xb6\x57\x28\x46\x85\xe1\x07"; |
| 428 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 429 | NULL, [](transaction &tx) {memcpy(&boost::get<txin_to_key>(tx.vin[0]).k_image, k_image, 32);}); |
| 430 | } |
| 431 | |
| 432 | bool gen_rct_tx_rct_wrong_key_image::generate(std::vector<test_event_entry>& events) const |
| 433 | { |
| 434 | const int mixin = 2; |
| 435 | const int out_idx[] = {1, -1}; |
| 436 | const uint64_t amount_paid = 10000; |
| 437 | // some random key image from the monero blockchain, so we get something that is a valid key image |
| 438 | static const uint8_t k_image[33] = "\x49\x3b\x56\x16\x54\x76\xa8\x75\xb7\xf4\xa8\x51\xf5\x55\xd3\x44\xe7\x3e\xea\x73\xee\xc1\x06\x7c\x7d\xb6\x57\x28\x46\x85\xe1\x07"; |
| 439 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 440 | NULL, [](transaction &tx) {memcpy(&boost::get<txin_to_key>(tx.vin[0]).k_image, k_image, 32);}); |
| 441 | } |
| 442 | |
| 443 | bool gen_rct_tx_pre_rct_wrong_fee::generate(std::vector<test_event_entry>& events) const |
| 444 | { |
| 445 | const int mixin = 2; |
| 446 | const int out_idx[] = {0, -1}; |
| 447 | const uint64_t amount_paid = 10000; |
| 448 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 449 | NULL, [](transaction &tx) {tx.rct_signatures.txnFee++;}); |
| 450 | } |
| 451 | |
| 452 | bool gen_rct_tx_rct_wrong_fee::generate(std::vector<test_event_entry>& events) const |
| 453 | { |
| 454 | const int mixin = 2; |
| 455 | const int out_idx[] = {1, -1}; |
| 456 | const uint64_t amount_paid = 10000; |
| 457 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 458 | NULL, [](transaction &tx) {tx.rct_signatures.txnFee++;}); |
| 459 | } |
| 460 | |
| 461 | bool gen_rct_tx_pre_rct_increase_vin_and_fee::generate(std::vector<test_event_entry>& events) const |
| 462 | { |
| 463 | const int mixin = 2; |
| 464 | const int out_idx[] = {0, -1}; |
| 465 | const uint64_t amount_paid = 10000; |
| 466 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 467 | NULL, [](transaction &tx) {boost::get<txin_to_key>(tx.vin[0]).amount++;tx.rct_signatures.txnFee++;}); |
| 468 | } |
| 469 | |
| 470 | bool gen_rct_tx_pre_rct_remove_vin::generate(std::vector<test_event_entry>& events) const |
| 471 | { |
| 472 | const int mixin = 2; |
| 473 | const int out_idx[] = {0, -1}; |
| 474 | const uint64_t amount_paid = 10000; |
| 475 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 476 | NULL, [](transaction &tx) {tx.vin.pop_back();}); |
| 477 | } |
| 478 | |
| 479 | bool gen_rct_tx_rct_remove_vin::generate(std::vector<test_event_entry>& events) const |
| 480 | { |
| 481 | const int mixin = 2; |
| 482 | const int out_idx[] = {1, -1}; |
| 483 | const uint64_t amount_paid = 10000; |
| 484 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 485 | NULL, [](transaction &tx) {tx.vin.pop_back();}); |
| 486 | } |
| 487 | |
| 488 | bool gen_rct_tx_pre_rct_add_vout::generate(std::vector<test_event_entry>& events) const |
| 489 | { |
| 490 | const int mixin = 2; |
| 491 | const int out_idx[] = {0, -1}; |
| 492 | const uint64_t amount_paid = 10000; |
| 493 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 494 | NULL, [](transaction &tx) {tx.vout.push_back(tx.vout.back());}); |
| 495 | } |
| 496 | |
| 497 | bool gen_rct_tx_rct_add_vout::generate(std::vector<test_event_entry>& events) const |
| 498 | { |
| 499 | const int mixin = 2; |
| 500 | const int out_idx[] = {1, -1}; |
| 501 | const uint64_t amount_paid = 10000; |
| 502 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 503 | NULL, [](transaction &tx) {tx.vout.push_back(tx.vout.back());}); |
| 504 | } |
| 505 | |
| 506 | bool gen_rct_tx_pre_rct_altered_extra::generate(std::vector<test_event_entry>& events) const |
| 507 | { |
| 508 | const int mixin = 2; |
| 509 | const int out_idx[] = {0, -1}; |
| 510 | const uint64_t amount_paid = 10000; |
| 511 | bool failed = false; |
| 512 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 513 | NULL, [&failed](transaction &tx) {std::string extra_nonce; crypto::hash pid = crypto::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) failed = true; }) && !failed; |
| 514 | } |
| 515 | |
| 516 | bool gen_rct_tx_rct_altered_extra::generate(std::vector<test_event_entry>& events) const |
| 517 | { |
| 518 | const int mixin = 2; |
| 519 | const int out_idx[] = {1, -1}; |
| 520 | const uint64_t amount_paid = 10000; |
| 521 | bool failed = false; |
| 522 | return generate_with(events, out_idx, mixin, amount_paid, false, |
| 523 | NULL, [&failed](transaction &tx) {std::string extra_nonce; crypto::hash pid = crypto::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) failed = true; }) && !failed; |
| 524 | } |
| 525 | |
| 526 | bool gen_rct_tx_pre_rct_has_no_view_tag_before_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 527 | { |
| 528 | const int mixin = 2; |
| 529 | const int out_idx[] = {0, -1}; |
| 530 | const uint64_t amount_paid = 10000; |
| 531 | bool use_view_tags = false; |
| 532 | bool valid = true; |
| 533 | return generate_with_full(events, out_idx, mixin, amount_paid, 0, 0, {}, use_view_tags, valid, NULL, NULL); |
| 534 | } |
| 535 | |
| 536 | bool gen_rct_tx_pre_rct_has_no_view_tag_from_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 537 | { |
| 538 | const int mixin = 10; |
| 539 | const int out_idx[] = {0, -1}; |
| 540 | const uint64_t amount_paid = 10000; |
| 541 | const rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 3 }; |
| 542 | bool use_view_tags = false; |
| 543 | bool valid = false; |
| 544 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, HF_VERSION_VIEW_TAGS, rct_config, use_view_tags, valid, NULL, NULL); |
| 545 | } |
| 546 | |
| 547 | bool gen_rct_tx_pre_rct_has_view_tag_before_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 548 | { |
| 549 | const int mixin = 2; |
| 550 | const int out_idx[] = {0, -1}; |
| 551 | const uint64_t amount_paid = 10000; |
| 552 | bool use_view_tags = true; |
| 553 | bool valid = false; |
| 554 | return generate_with_full(events, out_idx, mixin, amount_paid, 0, 0, {}, use_view_tags, valid, NULL, NULL); |
| 555 | } |
| 556 | |
| 557 | bool gen_rct_tx_pre_rct_has_view_tag_from_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 558 | { |
| 559 | const int mixin = 10; |
| 560 | const int out_idx[] = {0, -1}; |
| 561 | const uint64_t amount_paid = 10000; |
| 562 | const rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 3 }; |
| 563 | bool use_view_tags = true; |
| 564 | bool valid = true; |
| 565 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, HF_VERSION_VIEW_TAGS, rct_config, use_view_tags, valid, NULL, NULL); |
| 566 | } |
| 567 | |
| 568 | bool gen_rct_tx_rct_has_no_view_tag_before_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 569 | { |
| 570 | const int mixin = 2; |
| 571 | const int out_idx[] = {1, -1}; |
| 572 | const uint64_t amount_paid = 10000; |
| 573 | const rct::RCTConfig rct_config { rct::RangeProofBorromean, 0 }; |
| 574 | bool use_view_tags = false; |
| 575 | bool valid = true; |
| 576 | return generate_with_full(events, out_idx, mixin, amount_paid, 0, 0, rct_config, use_view_tags, valid, NULL, NULL); |
| 577 | } |
| 578 | |
| 579 | bool gen_rct_tx_rct_has_no_view_tag_from_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 580 | { |
| 581 | const int mixin = 10; |
| 582 | const int out_idx[] = {1, -1}; |
| 583 | const uint64_t amount_paid = 10000; |
| 584 | const rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 3 }; |
| 585 | bool use_view_tags = false; |
| 586 | bool valid = false; |
| 587 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, HF_VERSION_VIEW_TAGS+1, rct_config, use_view_tags, valid, NULL, NULL); |
| 588 | } |
| 589 | |
| 590 | bool gen_rct_tx_rct_has_view_tag_before_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 591 | { |
| 592 | const int mixin = 2; |
| 593 | const int out_idx[] = {1, -1}; |
| 594 | const uint64_t amount_paid = 10000; |
| 595 | const rct::RCTConfig rct_config { rct::RangeProofBorromean, 0 }; |
| 596 | bool use_view_tags = true; |
| 597 | bool valid = false; |
| 598 | return generate_with_full(events, out_idx, mixin, amount_paid, 0, 0, rct_config, use_view_tags, valid, NULL, NULL); |
| 599 | } |
| 600 | |
| 601 | bool gen_rct_tx_rct_has_view_tag_from_hf_view_tags::generate(std::vector<test_event_entry>& events) const |
| 602 | { |
| 603 | const int mixin = 10; |
| 604 | const int out_idx[] = {1, -1}; |
| 605 | const uint64_t amount_paid = 10000; |
| 606 | const rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 3 }; |
| 607 | bool use_view_tags = true; |
| 608 | bool valid = true; |
| 609 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, HF_VERSION_VIEW_TAGS, rct_config, use_view_tags, valid, NULL, NULL); |
| 610 | } |
| 611 | |
| 612 | bool gen_rct_tx_uses_output_too_early::generate(std::vector<test_event_entry>& events) const |
| 613 | { |
| 614 | const int mixin = 10; |
| 615 | const int out_idx[] = {1, -1}; |
| 616 | const uint64_t amount_paid = 10000; |
| 617 | const rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 2 }; |
| 618 | bool use_view_tags = false; |
| 619 | bool valid = false; |
| 620 | return generate_with_full(events, out_idx, mixin, amount_paid, CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE-3, HF_VERSION_ENFORCE_MIN_AGE, rct_config, use_view_tags, valid, NULL, NULL); |
| 621 | } |