| 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 "ringct/bulletproofs.h" |
| 33 | #include "chaingen.h" |
| 34 | #include "bulletproofs.h" |
| 35 | #include "device/device.hpp" |
| 36 | |
| 37 | using namespace epee; |
| 38 | using namespace crypto; |
| 39 | using namespace cryptonote; |
| 40 | |
| 41 | //---------------------------------------------------------------------------------------------------------------------- |
| 42 | // Tests |
| 43 | |
| 44 | bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& events, |
| 45 | size_t mixin, size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RCTConfig *rct_config, uint8_t hf_version, |
| 46 | const std::function<bool(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations, size_t tx_idx)> &pre_tx, |
| 47 | const std::function<bool(transaction &tx, size_t tx_idx)> &post_tx) const |
| 48 | { |
| 49 | uint64_t ts_start = 1338224400; |
| 50 | |
| 51 | GENERATE_ACCOUNT(miner_account); |
| 52 | MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start); |
| 53 | |
| 54 | // create 12 miner accounts, and have them mine the next 12 blocks |
| 55 | cryptonote::account_base miner_accounts[12]; |
| 56 | const cryptonote::block *prev_block = &blk_0; |
| 57 | cryptonote::block blocks[12 + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW]; |
| 58 | for (size_t n = 0; n < 12; ++n) { |
| 59 | miner_accounts[n].generate(); |
| 60 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n], |
| 61 | test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, |
| 62 | 2, 2, prev_block->timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 63 | crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2), |
| 64 | false, "Failed to generate block"); |
| 65 | events.push_back(blocks[n]); |
| 66 | prev_block = blocks + n; |
| 67 | } |
| 68 | |
| 69 | // rewind |
| 70 | cryptonote::block blk_r, blk_last; |
| 71 | { |
| 72 | blk_last = blocks[11]; |
| 73 | for (size_t i = 0; i < CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; ++i) |
| 74 | { |
| 75 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[12+i], 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(blocks[12+i]); |
| 81 | blk_last = blocks[12+i]; |
| 82 | } |
| 83 | blk_r = blk_last; |
| 84 | } |
| 85 | |
| 86 | // create 4 txes from these miners in another block, to generate some rct outputs |
| 87 | std::vector<transaction> rct_txes; |
| 88 | cryptonote::block blk_txes; |
| 89 | std::vector<crypto::hash> starting_rct_tx_hashes; |
| 90 | uint64_t fees = 0; |
| 91 | static const uint64_t input_amounts_available[] = {5000000000000, 30000000000000, 100000000000, 80000000000}; |
| 92 | for (size_t n = 0; n < n_txes; ++n) |
| 93 | { |
| 94 | std::vector<tx_source_entry> sources; |
| 95 | |
| 96 | sources.resize(1); |
| 97 | tx_source_entry& src = sources.back(); |
| 98 | |
| 99 | const uint64_t needed_amount = input_amounts_available[n]; |
| 100 | src.amount = input_amounts_available[n]; |
| 101 | size_t real_index_in_tx = 0; |
| 102 | for (size_t m = 0; m <= mixin; ++m) { |
| 103 | size_t index_in_tx = 0; |
| 104 | for (size_t i = 0; i < blocks[m].miner_tx.vout.size(); ++i) |
| 105 | if (blocks[m].miner_tx.vout[i].amount == needed_amount) |
| 106 | index_in_tx = i; |
| 107 | CHECK_AND_ASSERT_MES(blocks[m].miner_tx.vout[index_in_tx].amount == needed_amount, false, "Expected amount not found"); |
| 108 | src.push_output(m, boost::get<txout_to_key>(blocks[m].miner_tx.vout[index_in_tx].target).key, src.amount); |
| 109 | if (m == n) |
| 110 | real_index_in_tx = index_in_tx; |
| 111 | } |
| 112 | src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(blocks[n].miner_tx); |
| 113 | src.real_output = n; |
| 114 | src.real_output_in_tx_index = real_index_in_tx; |
| 115 | src.mask = rct::identity(); |
| 116 | src.rct = false; |
| 117 | |
| 118 | //fill outputs entry |
| 119 | tx_destination_entry td; |
| 120 | td.addr = miner_accounts[n].get_keys().m_account_address; |
| 121 | std::vector<tx_destination_entry> destinations; |
| 122 | for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o) |
| 123 | { |
| 124 | td.amount = amounts_paid[o]; |
| 125 | destinations.push_back(td); |
| 126 | } |
| 127 | |
| 128 | if (pre_tx && !pre_tx(sources, destinations, n)) |
| 129 | { |
| 130 | MDEBUG("pre_tx returned failure"); |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | crypto::secret_key tx_key; |
| 135 | std::vector<crypto::secret_key> additional_tx_keys; |
| 136 | std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses; |
| 137 | subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0}; |
| 138 | rct_txes.resize(rct_txes.size() + 1); |
| 139 | bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, boost::none, std::vector<uint8_t>(), rct_txes.back(), tx_key, additional_tx_keys, true, rct_config[n]); |
| 140 | CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction"); |
| 141 | |
| 142 | if (post_tx && !post_tx(rct_txes.back(), n)) |
| 143 | { |
| 144 | MDEBUG("post_tx returned failure"); |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | //events.push_back(rct_txes.back()); |
| 149 | starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes.back())); |
| 150 | LOG_PRINT_L0("Test tx: " << obj_to_json_str(rct_txes.back())); |
| 151 | |
| 152 | for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o) |
| 153 | { |
| 154 | crypto::key_derivation derivation; |
| 155 | bool r = crypto::generate_key_derivation(destinations[o].addr.m_view_public_key, tx_key, derivation); |
| 156 | CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation"); |
| 157 | crypto::secret_key amount_key; |
| 158 | crypto::derivation_to_scalar(derivation, o, amount_key); |
| 159 | rct::key rct_tx_mask; |
| 160 | const uint8_t type = rct_txes.back().rct_signatures.type; |
| 161 | if (rct::is_rct_simple(type)) |
| 162 | rct::decodeRctSimple(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default")); |
| 163 | else |
| 164 | rct::decodeRct(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default")); |
| 165 | } |
| 166 | |
| 167 | while (amounts_paid[0] != (size_t)-1) |
| 168 | ++amounts_paid; |
| 169 | ++amounts_paid; |
| 170 | |
| 171 | uint64_t fee = 0; |
| 172 | get_tx_fee(rct_txes.back(), fee); |
| 173 | fees += fee; |
| 174 | } |
| 175 | if (!valid) |
| 176 | DO_CALLBACK(events, "mark_invalid_tx"); |
| 177 | events.push_back(rct_txes); |
| 178 | |
| 179 | CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes, blk_last, miner_account, |
| 180 | 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, |
| 181 | hf_version, hf_version, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long |
| 182 | crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, 6, hf_version, fees), |
| 183 | false, "Failed to generate block"); |
| 184 | if (!valid) |
| 185 | DO_CALLBACK(events, "mark_invalid_block"); |
| 186 | events.push_back(blk_txes); |
| 187 | blk_last = blk_txes; |
| 188 | |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | bool gen_bp_tx_validation_base::check_bp(const cryptonote::transaction &tx, size_t tx_idx, const size_t *sizes, const char *context) const |
| 193 | { |
| 194 | DEFINE_TESTS_ERROR_CONTEXT(context); |
| 195 | CHECK_TEST_CONDITION(tx.version >= 2); |
| 196 | CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type)); |
| 197 | size_t n_sizes = 0, n_amounts = 0; |
| 198 | for (size_t n = 0; n < tx_idx; ++n) |
| 199 | { |
| 200 | while (sizes[0] != (size_t)-1) |
| 201 | ++sizes; |
| 202 | ++sizes; |
| 203 | } |
| 204 | while (sizes[n_sizes] != (size_t)-1) |
| 205 | n_amounts += sizes[n_sizes++]; |
| 206 | CHECK_TEST_CONDITION(tx.rct_signatures.p.bulletproofs.size() == n_sizes); |
| 207 | CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs) == n_amounts); |
| 208 | for (size_t n = 0; n < n_sizes; ++n) |
| 209 | CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs[n]) == sizes[n]); |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | bool gen_bp_tx_valid_1_before_12::generate(std::vector<test_event_entry>& events) const |
| 214 | { |
| 215 | const size_t mixin = 10; |
| 216 | const uint64_t amounts_paid[] = {10000, (uint64_t)-1}; |
| 217 | const size_t bp_sizes[] = {1, (size_t)-1}; |
| 218 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 2 } }; |
| 219 | return generate_with(events, mixin, 1, amounts_paid, true, rct_config, 11, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_1_before_12"); }); |
| 220 | } |
| 221 | |
| 222 | bool gen_bp_tx_invalid_1_from_12::generate(std::vector<test_event_entry>& events) const |
| 223 | { |
| 224 | const size_t mixin = 10; |
| 225 | const uint64_t amounts_paid[] = {10000, (uint64_t)-1}; |
| 226 | const size_t bp_sizes[] = {1, (size_t)-1}; |
| 227 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 2 } }; |
| 228 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, 12, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_invalid_1_from_12"); }); |
| 229 | } |
| 230 | |
| 231 | bool gen_bp_tx_invalid_1_1::generate(std::vector<test_event_entry>& events) const |
| 232 | { |
| 233 | const size_t mixin = 10; |
| 234 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 235 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof , 3 } }; |
| 236 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, NULL); |
| 237 | } |
| 238 | |
| 239 | bool gen_bp_tx_valid_2::generate(std::vector<test_event_entry>& events) const |
| 240 | { |
| 241 | const size_t mixin = 10; |
| 242 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 243 | const size_t bp_sizes[] = {2, (size_t)-1}; |
| 244 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 3 } }; |
| 245 | return generate_with(events, mixin, 1, amounts_paid, true, rct_config, HF_VERSION_CLSAG, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_2"); }); |
| 246 | } |
| 247 | |
| 248 | bool gen_bp_tx_valid_3::generate(std::vector<test_event_entry>& events) const |
| 249 | { |
| 250 | const size_t mixin = 10; |
| 251 | const uint64_t amounts_paid[] = {5000, 5000, 5000, (uint64_t)-1}; |
| 252 | const size_t bp_sizes[] = {4, (size_t)-1}; |
| 253 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 3 } }; |
| 254 | return generate_with(events, mixin, 1, amounts_paid, true, rct_config, HF_VERSION_CLSAG, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_3"); }); |
| 255 | } |
| 256 | |
| 257 | bool gen_bp_tx_valid_16::generate(std::vector<test_event_entry>& events) const |
| 258 | { |
| 259 | const size_t mixin = 10; |
| 260 | const uint64_t amounts_paid[] = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, (uint64_t)-1}; |
| 261 | const size_t bp_sizes[] = {16, (size_t)-1}; |
| 262 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 3 } }; |
| 263 | return generate_with(events, mixin, 1, amounts_paid, true, rct_config, HF_VERSION_CLSAG, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_16"); }); |
| 264 | } |
| 265 | |
| 266 | bool gen_bp_tx_invalid_4_2_1::generate(std::vector<test_event_entry>& events) const |
| 267 | { |
| 268 | const size_t mixin = 10; |
| 269 | const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1}; |
| 270 | const rct::RCTConfig rct_config[] = { { rct::RangeProofMultiOutputBulletproof, 3 } }; |
| 271 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, NULL); |
| 272 | } |
| 273 | |
| 274 | bool gen_bp_tx_invalid_16_16::generate(std::vector<test_event_entry>& events) const |
| 275 | { |
| 276 | const size_t mixin = 10; |
| 277 | const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1}; |
| 278 | const rct::RCTConfig rct_config[] = { { rct::RangeProofMultiOutputBulletproof, 3 } }; |
| 279 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, NULL); |
| 280 | } |
| 281 | |
| 282 | bool gen_bp_txs_valid_2_and_2::generate(std::vector<test_event_entry>& events) const |
| 283 | { |
| 284 | const size_t mixin = 10; |
| 285 | const uint64_t amounts_paid[] = {1000, 1000, (size_t)-1, 1000, 1000, (uint64_t)-1}; |
| 286 | const size_t bp_sizes[] = {2, (size_t)-1, 2, (size_t)-1}; |
| 287 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 3 }, {rct::RangeProofPaddedBulletproof, 3 } }; |
| 288 | return generate_with(events, mixin, 2, amounts_paid, true, rct_config, HF_VERSION_CLSAG, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_and_2"); }); |
| 289 | } |
| 290 | |
| 291 | bool gen_bp_txs_invalid_2_and_8_2_and_16_16_1::generate(std::vector<test_event_entry>& events) const |
| 292 | { |
| 293 | const size_t mixin = 10; |
| 294 | const uint64_t amounts_paid[] = {1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1}; |
| 295 | const rct::RCTConfig rct_config[] = {{rct::RangeProofMultiOutputBulletproof, 3}, {rct::RangeProofMultiOutputBulletproof, 3}, {rct::RangeProofMultiOutputBulletproof, 3}}; |
| 296 | return generate_with(events, mixin, 3, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, NULL); |
| 297 | } |
| 298 | |
| 299 | bool gen_bp_txs_valid_2_and_3_and_2_and_4::generate(std::vector<test_event_entry>& events) const |
| 300 | { |
| 301 | const size_t mixin = 10; |
| 302 | const uint64_t amounts_paid[] = {11111115000, 11111115000, (uint64_t)-1, 11111115000, 11111115000, 11111115001, (uint64_t)-1, 11111115000, 11111115002, (uint64_t)-1, 11111115000, 11111115000, 11111115000, 11111115003, (uint64_t)-1}; |
| 303 | const rct::RCTConfig rct_config[] = {{rct::RangeProofPaddedBulletproof, 3}, {rct::RangeProofPaddedBulletproof, 3}, {rct::RangeProofPaddedBulletproof, 3}, {rct::RangeProofPaddedBulletproof, 3}}; |
| 304 | const size_t bp_sizes[] = {2, (size_t)-1, 4, (size_t)-1, 2, (size_t)-1, 4, (size_t)-1}; |
| 305 | return generate_with(events, mixin, 4, amounts_paid, true, rct_config, HF_VERSION_CLSAG, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx) { return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_and_3_and_2_and_4"); }); |
| 306 | } |
| 307 | |
| 308 | bool gen_bp_tx_invalid_not_enough_proofs::generate(std::vector<test_event_entry>& events) const |
| 309 | { |
| 310 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_not_enough_proofs"); |
| 311 | const size_t mixin = 10; |
| 312 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 313 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 3 } }; |
| 314 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, [&](cryptonote::transaction &tx, size_t idx){ |
| 315 | CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof || tx.rct_signatures.type == rct::RCTTypeBulletproof2 || tx.rct_signatures.type == rct::RCTTypeCLSAG); |
| 316 | CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty()); |
| 317 | tx.rct_signatures.p.bulletproofs.pop_back(); |
| 318 | CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty()); |
| 319 | return true; |
| 320 | }); |
| 321 | } |
| 322 | |
| 323 | bool gen_bp_tx_invalid_empty_proofs::generate(std::vector<test_event_entry>& events) const |
| 324 | { |
| 325 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_empty_proofs"); |
| 326 | const size_t mixin = 10; |
| 327 | const uint64_t amounts_paid[] = {50000, 50000, (uint64_t)-1}; |
| 328 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 3 } }; |
| 329 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, [&](cryptonote::transaction &tx, size_t idx){ |
| 330 | CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof || tx.rct_signatures.type == rct::RCTTypeBulletproof2 || tx.rct_signatures.type == rct::RCTTypeCLSAG); |
| 331 | tx.rct_signatures.p.bulletproofs.clear(); |
| 332 | return true; |
| 333 | }); |
| 334 | } |
| 335 | |
| 336 | bool gen_bp_tx_invalid_too_many_proofs::generate(std::vector<test_event_entry>& events) const |
| 337 | { |
| 338 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_too_many_proofs"); |
| 339 | const size_t mixin = 10; |
| 340 | const uint64_t amounts_paid[] = {10000, (uint64_t)-1}; |
| 341 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 3 } }; |
| 342 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, [&](cryptonote::transaction &tx, size_t idx){ |
| 343 | CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof || tx.rct_signatures.type == rct::RCTTypeBulletproof2 || tx.rct_signatures.type == rct::RCTTypeCLSAG); |
| 344 | CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty()); |
| 345 | tx.rct_signatures.p.bulletproofs.push_back(tx.rct_signatures.p.bulletproofs.back()); |
| 346 | return true; |
| 347 | }); |
| 348 | } |
| 349 | |
| 350 | bool gen_bp_tx_invalid_wrong_amount::generate(std::vector<test_event_entry>& events) const |
| 351 | { |
| 352 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_wrong_amount"); |
| 353 | const size_t mixin = 10; |
| 354 | const uint64_t amounts_paid[] = {10000, (uint64_t)-1}; |
| 355 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 3 } }; |
| 356 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG, NULL, [&](cryptonote::transaction &tx, size_t idx){ |
| 357 | CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof || tx.rct_signatures.type == rct::RCTTypeBulletproof2 || tx.rct_signatures.type == rct::RCTTypeCLSAG); |
| 358 | CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty()); |
| 359 | tx.rct_signatures.p.bulletproofs.back() = rct::bulletproof_PROVE(1000, rct::skGen()); |
| 360 | return true; |
| 361 | }); |
| 362 | } |
| 363 | |
| 364 | bool gen_bp_tx_invalid_borromean_type::generate(std::vector<test_event_entry>& events) const |
| 365 | { |
| 366 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_borromean_type"); |
| 367 | const size_t mixin = 10; |
| 368 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 369 | const rct::RCTConfig rct_config[] = { { rct::RangeProofBorromean, 3 } }; |
| 370 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, 11, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){ |
| 371 | return true; |
| 372 | }); |
| 373 | } |
| 374 | |
| 375 | bool gen_bp_tx_invalid_bulletproof2_type::generate(std::vector<test_event_entry>& events) const |
| 376 | { |
| 377 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_bulletproof2_type"); |
| 378 | const size_t mixin = 10; |
| 379 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 380 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 2 } }; |
| 381 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_CLSAG + 1, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){ |
| 382 | return true; |
| 383 | }); |
| 384 | } |
| 385 | |
| 386 | bool gen_bp_tx_invalid_clsag_type::generate(std::vector<test_event_entry>& events) const |
| 387 | { |
| 388 | DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_clsag_type"); |
| 389 | const size_t mixin = 10; |
| 390 | const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1}; |
| 391 | const rct::RCTConfig rct_config[] = { { rct::RangeProofPaddedBulletproof, 3 } }; |
| 392 | return generate_with(events, mixin, 1, amounts_paid, false, rct_config, HF_VERSION_BULLETPROOF_PLUS + 1, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){ |
| 393 | return true; |
| 394 | }); |
| 395 | } |