From 6475571781540c712d488eefb2c78685f2edc2ad Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 15 Jan 2024 19:38:53 +0100 Subject: [PATCH] re-factored code for mixins count verification(moved to core check, suggested by @sowle) --- src/currency_core/blockchain_storage.cpp | 6 ------ src/currency_core/blockchain_storage.h | 9 +++++++++ src/currency_core/currency_format_utils.cpp | 19 ------------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 265113ba..47cc4bd8 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5826,13 +5826,7 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti { return false; } - uint64_t keys_count = get_hf4_inputs_key_offsets_count(tx); - if (keys_count != 0 && keys_count - 1 < CURRENCY_HF4_MANDATORY_DECOY_SET_SIZE) - return false; - } - - return true; } //------------------------------------------------------------------ diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index cd1c0057..edc74728 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -852,6 +852,15 @@ namespace currency r = is_mixattr_applicable_for_fake_outs_counter(out_zc.mix_attr, key_offsets.size() - 1); CHECK_AND_ASSERT_MES(r, false, "tx input ref #" << output_index << " violates mixin restrictions: mix_attr = " << static_cast(out_zc.mix_attr) << ", key_offsets.size = " << key_offsets.size()); + //after hf4 we're not allow unmixed outputs unless it's CURRENCY_TO_KEY_OUT_FORCED_NO_MIX + if (out_zc.mix_attr != CURRENCY_TO_KEY_OUT_FORCED_NO_MIX && key_offsets.size() - 1 < CURRENCY_HF4_MANDATORY_DECOY_SET_SIZE) + { + size_t verified_input_index = std::find(validated_tx.vin.begin(), validated_tx.vin.end(), verified_input) - validated_tx.vin.begin(); + LOG_PRINT_RED_L0("handle_output failed for output #" << n << " in " << tx_id << " referenced by input #" << verified_input_index << " in tx " << get_transaction_hash(validated_tx) << ", mixins count: " << key_offsets.size() - 1); + return false; + } + + TIME_MEASURE_START_PD(tx_check_inputs_loop_scan_outputkeys_loop_handle_output); if (!vis.handle_output(tx_ptr->tx, validated_tx, out_zc, n)) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 080f251e..7797956c 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3751,25 +3751,6 @@ namespace currency return true; } //--------------------------------------------------------------- - //if return 0 -> no txin_zc_input seen - uint64_t get_hf4_inputs_key_offsets_count(const transaction& tx) - { - uint64_t key_offsets_count = 0; - - for (const auto& e : tx.vin) - { - if (e.type() != typeid(txin_zc_input)) - continue; - - if (boost::get(e).key_offsets.size() > key_offsets_count) - { - key_offsets_count = boost::get(e).key_offsets.size(); - } - } - - return key_offsets_count; - } - //--------------------------------------------------------------- bool check_native_coins_amount_burnt_in_outs(const transaction& tx, const uint64_t amount, uint64_t* p_amount_burnt /* = nullptr */) { if (tx.version <= TRANSACTION_VERSION_PRE_HF4)