diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index b339e020..aefd7a0e 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1308,7 +1308,7 @@ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t if (is_hardfork_active(ZANO_HARDFORK_04_ZARCANUM)) { CHECK_AND_ASSERT_MES(b.miner_tx.attachment.size() == 2, false, "coinbase transaction has incorrect number of attachments (" << b.miner_tx.attachment.size() << "), expected 2"); - CHECK_AND_ASSERT_MES(b.miner_tx.attachment[0].type() == typeid(zarcanum_outs_range_proof), false, "coinbase transaction wrong attachment #0 type (expected: zarcanum_outs_range_proof)"); + CHECK_AND_ASSERT_MES(b.miner_tx.attachment[0].type() == typeid(zc_outs_range_proof), false, "coinbase transaction wrong attachment #0 type (expected: zc_outs_range_proof)"); CHECK_AND_ASSERT_MES(b.miner_tx.attachment[1].type() == typeid(zc_balance_proof), false, "coinbase transaction wrong attachmenttype #1 (expected: zc_balance_proof)"); } else @@ -5548,7 +5548,7 @@ bool get_tx_from_cache(const crypto::hash& tx_id, transactions_map& tx_cache, tr return true; } //------------------------------------------------------------------ -bool blockchain_storage::collect_rangeproofs_data_from_tx(std::vector& agregated_proofs, const transaction& tx /*, std::vector& tx_outs_commitments*/) +bool blockchain_storage::collect_rangeproofs_data_from_tx(std::vector& agregated_proofs, const transaction& tx) { if (tx.version <= TRANSACTION_VERSION_PRE_HF4) { @@ -5557,12 +5557,12 @@ bool blockchain_storage::collect_rangeproofs_data_from_tx(std::vector(a); + const zc_outs_range_proof& zcrp = boost::get(a); agregated_proofs.emplace_back(zcrp); for (uint8_t i = 0; i != zcrp.outputs_count; i++) { @@ -5586,17 +5586,20 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt TIME_MEASURE_START_PD_MS(block_processing_time_0_ms); CRITICAL_REGION_LOCAL(m_read_lock); TIME_MEASURE_START_PD(block_processing_time_1); + + uint64_t height = get_current_blockchain_size(); // height <-> block height correspondence is validated in prevalidate_miner_transaction() + if(bl.prev_id != get_top_block_id()) { - LOG_PRINT_L0("Block with id: " << id << ENDL - << "have wrong prev_id: " << bl.prev_id << ENDL + LOG_PRINT_L0("Block with id: " << id << " @ " << height << ENDL + << "has wrong prev_id: " << bl.prev_id << ENDL << "expected: " << get_top_block_id()); return false; } if(!check_block_timestamp_main(bl)) { - LOG_PRINT_L0("Block with id: " << id << ENDL + LOG_PRINT_L0("Block with id: " << id << " @ " << height << ENDL << "has invalid timestamp: " << bl.timestamp); // do not add this block to invalid block list prior to proof of work check bvc.m_verification_failed = true; @@ -5608,7 +5611,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt m_is_in_checkpoint_zone = true; if (!m_checkpoints.check_block(get_current_blockchain_size(), id)) { - LOG_ERROR("CHECKPOINT VALIDATION FAILED"); + LOG_ERROR("CHECKPOINT VALIDATION FAILED @ " << height); bvc.m_verification_failed = true; return false; } @@ -5657,8 +5660,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt if (!prevalidate_miner_transaction(bl, m_db_blocks.size(), is_pos_bl)) { - LOG_PRINT_L0("Block with id: " << id - << " failed to pass prevalidation"); + LOG_PRINT_L0("Block with id: " << id << " @ " << height << " failed to pass miner tx prevalidation"); bvc.m_verification_failed = true; return false; } @@ -5681,7 +5683,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt TIME_MEASURE_START_PD(all_txs_insert_time_5); if (!add_transaction_from_block(bl.miner_tx, get_transaction_hash(bl.miner_tx), id, get_current_blockchain_size(), get_block_datetime(bl))) { - LOG_PRINT_L0("Block with id: " << id << " failed to add transaction to blockchain storage"); + LOG_PRINT_L0("Block with id: " << id << " failed to add miner transaction to the blockchain storage"); bvc.m_verification_failed = true; return false; } @@ -5697,7 +5699,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt uint64_t burned_coins = 0; std::list block_summary_kimages; - std::vector range_proofs_agregated; + std::vector range_proofs_agregated; for(const crypto::hash& tx_id : bl.tx_hashes) { @@ -5836,7 +5838,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt //validate range proofs - if (!verify_multiple_zarcanum_outs_range_proofs(range_proofs_agregated)) + if (!verify_multiple_zc_outs_range_proofs(range_proofs_agregated)) { LOG_PRINT_L0("Block with id: " << id << " have failed to verify multiple rangeproofs"); diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index d96bdf67..15d027bb 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -584,7 +584,7 @@ namespace currency wide_difficulty_type get_next_difficulty_for_alternative_chain(const alt_chain_type& alt_chain, block_extended_info& bei, bool pos) const; bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc); bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc); - bool collect_rangeproofs_data_from_tx(std::vector& agregated_proofs, const transaction& tx/*, std::vector& tx_outs_commitments*/); + bool collect_rangeproofs_data_from_tx(std::vector& agregated_proofs, const transaction& tx); std::string print_alt_chain(alt_chain_type alt_chain); bool handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc); bool is_reorganize_required(const block_extended_info& main_chain_bei, const alt_chain_type& alt_chain, const crypto::hash& proof_alt); diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index afc3803b..6148830b 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -436,7 +436,7 @@ namespace currency // non-consoditated txs must have one of this objects in the attachments (outputs_count == vout.size()) // consolidated -- one pre consolidated part (sum(outputs_count) == vout.size()) - struct zarcanum_outs_range_proof + struct zc_outs_range_proof { crypto::bpp_signature_serialized bpp; uint8_t outputs_count; // how many outputs are included in the proof @@ -754,7 +754,7 @@ namespace currency typedef boost::mpl::vector24< tx_service_attachment, tx_comment, tx_payer_old, tx_receiver_old, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry_old, extra_user_data, extra_padding, etc_tx_flags16_t, etc_tx_details_unlock_time2, - tx_payer, tx_receiver, extra_alias_entry, zarcanum_tx_data_v1, zarcanum_outs_range_proof, zc_balance_proof + tx_payer, tx_receiver, extra_alias_entry, zarcanum_tx_data_v1, zc_outs_range_proof, zc_balance_proof > all_payload_types; typedef boost::make_variant_over::type payload_items_v; @@ -1077,7 +1077,7 @@ SET_VARIANT_TAGS(crypto::bppe_signature_serialized, 41, "bppe_signature_serializ SET_VARIANT_TAGS(currency::NLSAG_sig, 42, "NLSAG_sig"); SET_VARIANT_TAGS(currency::ZC_sig, 43, "ZC_sig"); SET_VARIANT_TAGS(currency::void_sig, 44, "void_sig"); -SET_VARIANT_TAGS(currency::zarcanum_outs_range_proof, 45, "zarcanum_outs_range_proof"); +SET_VARIANT_TAGS(currency::zc_outs_range_proof, 45, "zc_outs_range_proof"); SET_VARIANT_TAGS(currency::zc_balance_proof, 46, "zc_balance_proof"); SET_VARIANT_TAGS(currency::open_asset_id, 47, "asset_id"); diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4bf3ad8c..3851dd92 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -68,8 +68,8 @@ namespace currency //-------------------------------------------------------------------------------- - bool generate_zarcanum_outs_range_proof(size_t out_index_start, size_t outs_count, const crypto::scalar_vec_t& amounts, const crypto::scalar_vec_t& blinding_masks, - const std::vector& vouts, zarcanum_outs_range_proof& result) + bool generate_zc_outs_range_proof(size_t out_index_start, size_t outs_count, const crypto::scalar_vec_t& amounts, const crypto::scalar_vec_t& blinding_masks, + const std::vector& vouts, zc_outs_range_proof& result) { //TODO: review for Andre CHECK_AND_ASSERT_MES(amounts.size() == outs_count, false, ""); @@ -318,9 +318,9 @@ namespace currency if (tx.version > TRANSACTION_VERSION_PRE_HF4) { //add range proofs - currency::zarcanum_outs_range_proof range_proofs = AUTO_VAL_INIT(range_proofs); - bool r = generate_zarcanum_outs_range_proof(0, amounts.size(), amounts, blinding_masks, tx.vout, range_proofs); - CHECK_AND_ASSERT_MES(r, false, "Failed to generate zarcanum_outs_range_proof()"); + currency::zc_outs_range_proof range_proofs = AUTO_VAL_INIT(range_proofs); + bool r = generate_zc_outs_range_proof(0, amounts.size(), amounts, blinding_masks, tx.vout, range_proofs); + CHECK_AND_ASSERT_MES(r, false, "Failed to generate zc_outs_range_proof()"); tx.attachment.push_back(range_proofs); if (!pos) @@ -1708,7 +1708,8 @@ namespace currency const uint8_t& tx_outs_attr = ftp.tx_outs_attr; const bool& shuffle = ftp.shuffle; const uint64_t& flags = ftp.flags; - + + bool r = false; transaction& tx = result.tx; crypto::secret_key& one_time_secret_key = result.one_time_key; @@ -1929,7 +1930,7 @@ namespace currency for(const tx_destination_entry& dst_entr : shuffled_dsts) { CHECK_AND_ASSERT_MES(dst_entr.amount > 0, false, "Destination with wrong amount: " << dst_entr.amount); // <<-- TODO @#@# consider removing this check - bool r = construct_tx_out(dst_entr, txkey.sec, output_index, tx, deriv_cache, sender_account_keys, blinding_masks[output_index], result, tx_outs_attr); + r = construct_tx_out(dst_entr, txkey.sec, output_index, tx, deriv_cache, sender_account_keys, blinding_masks[output_index], result, tx_outs_attr); CHECK_AND_ASSERT_MES(r, false, "Failed to construct tx out"); amounts[output_index - range_proof_start_index] = dst_entr.amount; summary_outs_money += dst_entr.amount; @@ -1959,7 +1960,7 @@ namespace currency { CHECK_AND_ASSERT_MES(tsa.security.size() == 1, false, "Wrong tsa.security.size() = " << tsa.security.size()); - bool r = derive_public_key_from_target_address(sender_account_keys.account_address, one_time_secret_key, att_count, tsa.security.back()); + r = derive_public_key_from_target_address(sender_account_keys.account_address, one_time_secret_key, att_count, tsa.security.back()); CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_target_address"); } att_count++; @@ -1980,11 +1981,18 @@ namespace currency if (tx.version > TRANSACTION_VERSION_PRE_HF4) { - //add range proofs - currency::zarcanum_outs_range_proof range_proofs = AUTO_VAL_INIT(range_proofs); - bool r = generate_zarcanum_outs_range_proof(range_proof_start_index, amounts.size(), amounts, blinding_masks, tx.vout, range_proofs); - CHECK_AND_ASSERT_MES(r, false, "Failed to generate zarcanum_outs_range_proof()"); + // add range proofs + currency::zc_outs_range_proof range_proofs = AUTO_VAL_INIT(range_proofs); + bool r = generate_zc_outs_range_proof(range_proof_start_index, amounts.size(), amounts, blinding_masks, tx.vout, range_proofs); + CHECK_AND_ASSERT_MES(r, false, "Failed to generate zc_outs_range_proof()"); tx.attachment.push_back(range_proofs); + + // add explicit fee info + r = add_tx_fee_amount_to_extra(tx, summary_inputs_money - summary_outs_money); + CHECK_AND_ASSERT_MES(r, false, "add_tx_fee_amount_to_extra failed"); + + r = generate_tx_balance_proof(tx, blinding_masks_sum); + CHECK_AND_ASSERT_MES(r, false, "generate_tx_balance_proof failed"); } if (flags & TX_FLAG_SIGNATURE_MODE_SEPARATE) @@ -2018,7 +2026,7 @@ namespace currency //size_t input_index = input_starter_index; //size_t in_context_index = 0; crypto::scalar_t local_blinding_masks_sum = 0; // ZC only - bool r = false; + r = false; for (size_t i = 0; i != sources.size(); i++) { const tx_source_entry& source_entry = sources[inputs_mapping[i]]; @@ -3299,9 +3307,9 @@ namespace currency tv.details_view = tv.short_view; return true; } - bool operator()(const zarcanum_outs_range_proof& rp) + bool operator()(const zc_outs_range_proof& rp) { - tv.type = "zarcanum_outs_range_proof"; + tv.type = "zc_outs_range_proof"; tv.short_view = "outputs_count = " + std::to_string(rp.outputs_count); return true; } @@ -3889,7 +3897,7 @@ namespace currency } //-------------------------------------------------------------------------------- - bool verify_multiple_zarcanum_outs_range_proofs(const std::vector& range_proofs) + bool verify_multiple_zc_outs_range_proofs(const std::vector& range_proofs) { if (range_proofs.empty()) return true; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 0e0da357..566efc5f 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -215,20 +215,20 @@ namespace currency }; - struct zarcanum_outs_range_proof_commit_ref_t + struct zc_outs_range_proofs_with_commitments { - zarcanum_outs_range_proof_commit_ref_t(const zarcanum_outs_range_proof& range_proof, const std::vector& amount_commitments) + zc_outs_range_proofs_with_commitments(const zc_outs_range_proof& range_proof, const std::vector& amount_commitments) : range_proof(range_proof) , amount_commitments(amount_commitments) {} - zarcanum_outs_range_proof_commit_ref_t(const zarcanum_outs_range_proof& range_proof) + zc_outs_range_proofs_with_commitments(const zc_outs_range_proof& range_proof) : range_proof(range_proof) {} - const zarcanum_outs_range_proof& range_proof; - std::vector amount_commitments; + zc_outs_range_proof range_proof; + std::vector amount_commitments; }; - bool verify_multiple_zarcanum_outs_range_proofs(const std::vector& range_proofs); + bool verify_multiple_zc_outs_range_proofs(const std::vector& range_proofs); bool check_tx_balance(const transaction& tx, uint64_t additional_inputs_amount_and_fees_for_mining_tx = 0); //--------------------------------------------------------------- bool construct_miner_tx(size_t height, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d79093aa..4b390e96 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5536,10 +5536,7 @@ bool wallet2::get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) c //---------------------------------------------------------------------------------------------------- bool wallet2::is_need_to_split_outputs() { - if (this->m_core_runtime_config.hard_forks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, this->get_blockchain_current_size())) - return false; - else - return true; + return !is_in_hardfork_zone(ZANO_HARDFORK_04_ZARCANUM); } //---------------------------------------------------------------------------------------------------- void wallet2::prepare_tx_destinations(const assets_selection_context& needed_money_map,