From e94e5c0a970df182181cc29eed677968f30245e0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 25 Jun 2022 00:06:26 +0200 Subject: [PATCH] multiple fixes over sig refactoring --- src/currency_core/blockchain_storage.cpp | 4 ++-- src/currency_core/currency_format_utils.cpp | 2 +- src/currency_core/currency_format_utils.h | 1 + src/currency_core/currency_format_utils_transactions.cpp | 1 + src/wallet/wallet2_escrow.cpp | 7 ++++--- tests/core_tests/chaingen.h | 2 +- tests/core_tests/chaingen_helpers.h | 2 +- tests/core_tests/escrow_wallet_common.h | 2 +- tests/core_tests/tx_builder.h | 2 +- tests/core_tests/tx_validation.cpp | 6 +++--- 10 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index ce804515..2544a096 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -4344,7 +4344,7 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha TIME_MEASURE_START_PD(tx_check_inputs_attachment_check); if (!m_is_in_checkpoint_zone) { - CHECK_AND_ASSERT_MES(tx.signatures.s.size() == sig_index, false, "tx signatures count differs from inputs"); + CHECK_AND_ASSERT_MES(tx.signatures.size() == sig_index, false, "tx signatures count differs from inputs"); if (!(get_tx_flags(tx) & TX_FLAG_SIGNATURE_MODE_SEPARATE)) { bool r = validate_attachment_info(tx.extra, tx.attachment, false); @@ -4649,7 +4649,7 @@ bool blockchain_storage::check_ms_input(const transaction& tx, size_t in_index, VARIANT_SWITCH_END(); - } + return true; #undef LOC_CHK diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 2a374c53..97b6a90e 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1693,7 +1693,7 @@ namespace currency LOC_CHK(ms_input_index < tx.signatures.size(), "transaction does not have signatures vector entry for ms input #" << ms_input_index); LOC_CHK(tx.signatures[ms_input_index].type() == typeid(NLSAG_sig), "Wrong type of signature"); - auto& sigs = boost::get(tx.signatures[ms_input_index]); + auto& sigs = boost::get(tx.signatures[ms_input_index]).s; LOC_CHK(!sigs.empty(), "empty signatures container"); bool extra_signature_expected = (get_tx_flags(tx) & TX_FLAG_SIGNATURE_MODE_SEPARATE) && ms_input_index == tx.vin.size() - 1; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index a6271037..701bd267 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -667,6 +667,7 @@ namespace currency size_t operator()(const txin_to_key& txin) const { return txin.key_offsets.size(); } size_t operator()(const txin_multisig& txin) const { return txin.sigs_count; } size_t operator()(const txin_htlc& txin) const { return 1; } + size_t operator()(const tx_in_zarcanum& txin) const { throw std::runtime_error("Not implemented yet"); return 0; } //@#@ }; return boost::apply_visitor(txin_signature_size_visitor(), tx_in); diff --git a/src/currency_core/currency_format_utils_transactions.cpp b/src/currency_core/currency_format_utils_transactions.cpp index bb12d893..6e31904d 100644 --- a/src/currency_core/currency_format_utils_transactions.cpp +++ b/src/currency_core/currency_format_utils_transactions.cpp @@ -237,6 +237,7 @@ namespace currency ++sig_count; // count in one more signature for the last input in a complete separately signed tx tx_blob_size += tools::get_varint_packed_size(sig_count); // size of transaction::signatures[i] tx_blob_size += sizeof(crypto::signature) * sig_count; // size of signatures' data itself + tx_blob_size += sizeof(binary_archive::variant_tag_type); //tools::get_varint_packed_size(variant_serialization_traits, currency::NLSAG_sig>::get_tag()); // sizeof variant tag } // 2. attachments (try to find extra_attachment_info in tx prefix and count it in if succeed) diff --git a/src/wallet/wallet2_escrow.cpp b/src/wallet/wallet2_escrow.cpp index 542db5f2..f59f828e 100644 --- a/src/wallet/wallet2_escrow.cpp +++ b/src/wallet/wallet2_escrow.cpp @@ -237,8 +237,9 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n LOC_CHK(tx.signatures.size() == 1, "invalid singatures size: " << tx.signatures.size()); // only 1 input means only 1 signature vector VARIANT_SWITCH_BEGIN(tx.signatures[0]); - VARIANT_CASE_CONST(NLSAG_sig, signature) + VARIANT_CASE_CONST(NLSAG_sig, signature_NLSAG) { + auto& signature = signature_NLSAG.s; // As we don't have b_keys we can't be sure which signature is B's and which is reserved for A (should be a null-placeholder, if present). // Having a_keys, we determine index of A key in multisig output keys array. // Thus it's possible to determine the order of signatures (A, B or B, A), and, eventually, validate B signature. @@ -420,9 +421,9 @@ bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, co // (5/5) signatures LOC_CHK(tx.signatures.size() == 1, "invalid singatures size: " << tx.signatures.size()); // only 1 input means only 1 signature vector VARIANT_SWITCH_BEGIN(tx.signatures[0]); - VARIANT_CASE_CONST(NLSAG_sig, signatures) + VARIANT_CASE_CONST(NLSAG_sig, signature_NLSAG) { - + auto& signature = signature_NLSAG.s; LOC_CHK(signature.size() == 2, "invalid signature[0] size: " << signature.size()); // it's expected to contain A-party signature and null-sig placeholder LOC_CHK(source_ms_out.keys.size() == 2, "internal error: invalid source ms output keys array, size: " << source_ms_out.keys.size()); diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 2b1574c2..999ed870 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -846,7 +846,7 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons ss_ring_s << o.second << ENDL; } - tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + tx.signatures.push_back(currency::NLSAG_sig()); std::vector& sigs = boost::get(tx.signatures.back()).s; sigs.resize(src_entr.outputs.size()); crypto::generate_ring_signature(tx_prefix_hash, boost::get(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index f77d6b56..f56a87e8 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -234,7 +234,7 @@ inline bool resign_tx(const currency::account_keys& sender_keys, const std::vect return false; crypto::derive_secret_key(recv_derivation, se.real_output_in_tx_index, sender_keys.spend_secret_key, in_ephemeral_sec); - tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + tx.signatures.push_back(currency::NLSAG_sig()); std::vector& sigs = boost::get(tx.signatures.back()).s; if (se.is_multisig()) diff --git a/tests/core_tests/escrow_wallet_common.h b/tests/core_tests/escrow_wallet_common.h index d23f5140..85264e9b 100644 --- a/tests/core_tests/escrow_wallet_common.h +++ b/tests/core_tests/escrow_wallet_common.h @@ -254,7 +254,7 @@ inline bool build_custom_escrow_template(const std::vector& ev if (custom_config_mask & eccf_template_no_a_sigs) { escrow_template_tx.signatures.clear(); - escrow_template_tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + escrow_template_tx.signatures.push_back(currency::NLSAG_sig()); } append_vector_by_another_vector(used_sources, sources); diff --git a/tests/core_tests/tx_builder.h b/tests/core_tests/tx_builder.h index 1cfb8ffd..ed171b64 100644 --- a/tests/core_tests/tx_builder.h +++ b/tests/core_tests/tx_builder.h @@ -109,7 +109,7 @@ struct tx_builder keys_ptrs.push_back(&o.second); } - m_tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + m_tx.signatures.push_back(currency::NLSAG_sig()); std::vector& sigs = boost::get(m_tx.signatures.back()).s; sigs.resize(src_entr.outputs.size()); generate_ring_signature(m_tx_prefix_hash, boost::get(m_tx.vin[i]).k_image, keys_ptrs, m_in_contexts[i].sec, src_entr.real_output, sigs.data()); diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index 7ec03b6a..71b92a71 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -660,7 +660,7 @@ bool gen_tx_signatures_are_invalid::generate(std::vector& even // Tx with nmix = 0 have a few inputs, and too many signatures (2/2) broken_tx = tx_0; - broken_tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + broken_tx.signatures.push_back(currency::NLSAG_sig()); boost::get(broken_tx.signatures.back()).s.push_back(invalid_signature); check_broken_tx(events, broken_tx, prev_block, miner_account, generator); @@ -677,7 +677,7 @@ bool gen_tx_signatures_are_invalid::generate(std::vector& even // Tx with nmix = 1 have not enough signatures (2/2) broken_tx = tx_1; - broken_tx.signatures.back().resize(boost::get(broken_tx.signatures.back()).s.size() - 1); + boost::get(broken_tx.signatures.back()).s.resize(boost::get(broken_tx.signatures.back()).s.size() - 1); check_broken_tx(events, broken_tx, prev_block, miner_account, generator); // Tx with nmix = 1 have too many signatures (1/2) @@ -687,7 +687,7 @@ bool gen_tx_signatures_are_invalid::generate(std::vector& even // Tx with nmix = 1 have too many signatures (2/2) broken_tx = tx_1; - broken_tx.signatures.push_back(currency::NLSAG_sig(std::vector())); + broken_tx.signatures.push_back(currency::NLSAG_sig()); boost::get(broken_tx.signatures.back()).s.push_back(invalid_signature); check_broken_tx(events, broken_tx, prev_block, miner_account, generator);