From affa54f1e1df385a83315944c5eed04a4cffe4b3 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 28 Jul 2023 04:15:27 +0200 Subject: [PATCH] partially fixed a bug with alias registration for hf4 + gen_alias_update_for_free test updated --- src/currency_core/currency_format_utils.cpp | 3 +- tests/core_tests/alias_tests.cpp | 20 +++++++++---- tests/core_tests/chaingen_helpers.h | 32 ++++++++++++--------- tests/core_tests/chaingen_main.cpp | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index f7e39eca..7513d384 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1139,7 +1139,8 @@ namespace currency crypto::scalar_t amount_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_AMOUNT_MASK, h); out.encrypted_amount = de.amount ^ amount_mask.m_u64[0]; - asset_blinding_mask = crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_ASSET_BLINDING_MASK, h); // f = Hs(domain_sep, d, i) + CHECK_AND_ASSERT_MES(~de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id || de.asset_id == currency::native_coin_asset_id, false, "explicit_native_asset_id may be used only with native asset id"); + asset_blinding_mask = de.flags & tx_destination_entry_flags::tdef_explicit_native_asset_id ? 0 : crypto::hash_helper_t::hs(CRYPTO_HDS_OUT_ASSET_BLINDING_MASK, h); // f = Hs(domain_sep, d, i) blinded_asset_id = crypto::point_t(de.asset_id) + asset_blinding_mask * crypto::c_point_X; out.blinded_asset_id = (crypto::c_scalar_1div8 * blinded_asset_id).to_public_key(); // T = 1/8 * (H_asset + s * X) diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index bdb68673..039f65eb 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -1432,18 +1432,28 @@ bool gen_alias_update_for_free::generate(std::vector& events) for (auto se : sources) input_amount += se.amount; if (input_amount > TESTS_DEFAULT_FEE) - destinations.push_back(tx_destination_entry(input_amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address())); + { + uint64_t d = input_amount - TESTS_DEFAULT_FEE; + destinations.push_back(tx_destination_entry(d / 2, miner_acc.get_public_address())); + d -= d / 2; + destinations.push_back(tx_destination_entry(d, miner_acc.get_public_address())); + } - tx_builder tb; + transaction tx{}; + uint64_t tx_version = currency::get_tx_version(get_block_height(blk_0r) + 1, generator.get_hardforks()); + crypto::secret_key sk{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx, tx_version, sk, 0); + + /*tx_builder tb; tb.step1_init(); tb.step2_fill_inputs(miner_acc.get_keys(), sources); tb.step3_fill_outputs(destinations); tb.m_tx.extra.push_back(ai); tb.step4_calc_hash(); - tb.step5_sign(sources); + tb.step5_sign(sources);*/ - events.push_back(tb.m_tx); - MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1, miner_acc, tb.m_tx); + ADD_CUSTOM_EVENT(events, tx); + MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1, miner_acc, tx); return true; } diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index b984fde7..7d0aabad 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -283,8 +283,8 @@ inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, const alias_entry_t& ae, test_generator& generator) { - std::vector ex; - ex.push_back(ae); + std::vector extra; + extra.push_back(ae); currency::account_base reward_acc; currency::account_keys& ak = const_cast(reward_acc.get_keys()); currency::get_aliases_reward_account(ak.account_address, ak.view_secret_key); @@ -295,18 +295,24 @@ inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, else LOCAL_ASSERT(false); // not implemented yet, see also all the mess around blockchain_storage::get_tx_fee_median(), get_tx_fee_median_effective_index() etc. - MAKE_TX_MIX_LIST_EXTRA_MIX_ATTR(events, - tx_set, - miner_acc, - reward_acc, - alias_reward, - 0, - head_block, - CURRENCY_TO_KEY_OUT_RELAXED, - ex, - std::vector()); - + std::vector sources; + std::vector destinations; + bool r = fill_tx_sources_and_destinations(events, head_block, miner_acc, reward_acc, alias_reward, TESTS_DEFAULT_FEE, 0, sources, destinations); + CHECK_AND_ASSERT_MES(r, false, "alias: fill_tx_sources_and_destinations failed"); + for(auto& el : destinations) + { + if (el.addr.front() == reward_acc.get_public_address()) + el.flags |= tx_destination_entry_flags::tdef_explicit_native_asset_id; // all alias-burn outputs must have explicit native asset id + } + + uint64_t tx_version = currency::get_tx_version(get_block_height(head_block) + 1, generator.get_hardforks()); // assuming the tx will be in the next block (head_block + 1) + tx_set.emplace_back(); + r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_set.back(), tx_version, generator.last_tx_generated_secret_key, 0); + PRINT_EVENT_N_TEXT(events, "put_alias_via_tx_to_list()"); + events.push_back(tx_set.back()); + + // make sure the tx's amount commitments balance each other correctly uint64_t burnt_amount = 0; if (!check_native_coins_amount_burnt_in_outs(tx_set.back(), alias_reward, &burnt_amount)) { diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index bdd04695..770c077f 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1045,7 +1045,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY_HF(gen_alias_tx_no_outs, "*"); GENERATE_AND_PLAY(gen_alias_switch_and_check_block_template); GENERATE_AND_PLAY(gen_alias_too_many_regs_in_block_template); - GENERATE_AND_PLAY(gen_alias_update_for_free); + GENERATE_AND_PLAY_HF(gen_alias_update_for_free, "3-*"); GENERATE_AND_PLAY(gen_alias_in_coinbase); GENERATE_AND_PLAY(gen_wallet_basic_transfer);