From 44a989dd8cabfde610625479cc2f8e3f00460c61 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 7 Aug 2019 18:41:18 +0300 Subject: [PATCH] disallow etc_tx_details_unlock_time2 usage prior to hardfork 1 --- src/currency_core/blockchain_storage.cpp | 23 +++++++++++++++++++++++ src/currency_core/blockchain_storage.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 3bc8dfde..53b3e8c2 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3409,6 +3409,8 @@ bool blockchain_storage::add_transaction_from_block(const transaction& tx, const TIME_MEASURE_START_PD(tx_append_is_expired); CHECK_AND_ASSERT_MES(!is_tx_expired(tx), false, "Transaction can't be added to the blockchain since it's already expired. tx expiration time: " << get_tx_expiration_time(tx) << ", blockchain median time: " << get_tx_expiration_median()); TIME_MEASURE_FINISH_PD_COND(need_to_profile, tx_append_is_expired); + + CHECK_AND_ASSERT_MES(validate_tx_for_hardfork_specific_terms(tx, tx_id, bl_height), false, "tx " << tx_id << ": hardfork-specific validation failed"); TIME_MEASURE_START_PD(tx_process_extra); bool r = process_blockchain_tx_extra(tx); @@ -4332,6 +4334,23 @@ void blockchain_storage::get_pos_mining_estimate(uint64_t amount_coins, estimate_result = current_amount; } //------------------------------------------------------------------ +bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id, uint64_t block_height) const +{ + if (block_height <= m_core_runtime_config.hard_fork1_starts_after_height) + { + // before hardfork 1 + + for (const auto& el : tx.extra) + { + // etc_tx_details_unlock_time2 is not allowed in txs in blocks prior to hardfork 1 + CHECK_AND_ASSERT_MES(el.type() != typeid(etc_tx_details_unlock_time2), false, "tx " << tx_id << " contains etc_tx_details_unlock_time2 which is not allowed on height " << block_height); + } + return true; + } + + return true; +} +//------------------------------------------------------------------ bool blockchain_storage::validate_pos_coinbase_outs_unlock_time(const transaction& miner_tx, uint64_t staked_amount, uint64_t max_unlock_time)const { uint64_t major_unlock_time = get_tx_x_detail(miner_tx); @@ -5869,6 +5888,8 @@ bool blockchain_storage::validate_alt_block_txs(const block& b, const crypto::ha } update_alt_out_indexes_for_tx_in_block(b.miner_tx, abei); + CHECK_AND_ASSERT_MES(validate_tx_for_hardfork_specific_terms(b.miner_tx, null_hash, height), false, "miner tx hardfork-specific validation failed"); + for (auto tx_id : b.tx_hashes) { std::shared_ptr tx_ptr; @@ -5899,6 +5920,8 @@ bool blockchain_storage::validate_alt_block_txs(const block& b, const crypto::ha CHECK_AND_ASSERT_MES(false, false, "input #" << n << " has unexpected type (" << tx.vin[n].type().name() << "), tx " << tx_id); } } + + CHECK_AND_ASSERT_MES(validate_tx_for_hardfork_specific_terms(tx, tx_id, height), false, "tx " << tx_id << ": hardfork-specific validation failed"); // Updating abei (and not updating alt_chain) during this cycle is safe because txs in the same block can't reference one another, // so only valid references are either to previous alt blocks (accessed via alt_chain) or to main chain blocks. diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 1314304b..54e9367e 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -273,6 +273,7 @@ namespace currency bool check_tx_inputs(const transaction& tx, const crypto::hash& tx_prefix_hash) const; bool check_tx_inputs(const transaction& tx, const crypto::hash& tx_prefix_hash, uint64_t& max_used_block_height, crypto::hash& max_used_block_id)const; bool check_ms_input(const transaction& tx, size_t in_index, const txin_multisig& txin, const crypto::hash& tx_prefix_hash, const std::vector& sig, const transaction& source_tx, size_t out_n) const; + bool validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id, uint64_t block_height) const; bool get_output_keys_for_input_with_checks(const transaction& tx, const txin_to_key& txin, std::vector& output_keys, uint64_t& max_related_block_height, uint64_t& max_unlock_time) const; bool check_tokey_input(const transaction& tx, size_t in_index, const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector& sig, const std::vector& output_keys_ptrs) const; uint64_t get_current_comulative_blocksize_limit()const;