From 261917b1ada262547b55f0cf2de0cd4d54d0493b Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 15 Jul 2020 12:16:30 -0700 Subject: [PATCH] Bug fix --- .../cryptonote_format_utils.cpp | 84 ++++++++++++------- src/cryptonote_core/cryptonote_format_utils.h | 2 - 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 05a5376..b7f13dd 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -87,8 +87,13 @@ namespace cryptonote uint64_t amount_out = 0; BOOST_FOREACH(auto& in, tx.vin) { - CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction"); - amount_in += boost::get(in).amount; + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction"); + amount_in += boost::get(in).amount; + } else { + CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore), 0, "unexpected type id in transaction"); + amount_in += in.type() == typeid(txin_to_key) ? boost::get(in).amount : in.type() == typeid(txin_onshore) ? boost::get(in).amount : boost::get(in).amount; + } } BOOST_FOREACH(auto& o, tx.vout) amount_out += o.amount; @@ -235,10 +240,15 @@ namespace cryptonote { BOOST_FOREACH(const auto& in, tx.vin) { - CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: " - << in.type().name() << ", expected " << typeid(txin_to_key).name() - << ", in transaction id=" << get_transaction_hash(tx)); - + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: " + << in.type().name() << ", expected " << typeid(txin_to_key).name() + << ", in transaction id=" << get_transaction_hash(tx)); + } else { + CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore), false, "wrong variant type: " + << in.type().name() << ", expected " << typeid(txin_to_key).name() << "or " << typeid(txin_onshore).name() + << ", in transaction id=" << get_transaction_hash(tx)); + } } return true; } @@ -247,14 +257,29 @@ namespace cryptonote { BOOST_FOREACH(const tx_out& out, tx.vout) { - CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key), false, "wrong variant type: " - << out.target.type().name() << ", expected " << typeid(txout_to_key).name() - << ", in transaction id=" << get_transaction_hash(tx)); + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key), false, "wrong variant type: " + << out.target.type().name() << ", expected " << typeid(txout_to_key).name() + << ", in transaction id=" << get_transaction_hash(tx)); + } else { + CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key) || out.target.type() == typeid(txout_offshore), false, "wrong variant type: " + << out.target.type().name() << ", expected " << typeid(txout_to_key).name() + << "or " << typeid(txout_offshore).name() + << ", in transaction id=" << get_transaction_hash(tx)); + } - CHECK_AND_NO_ASSERT_MES(0 < out.amount, false, "zero amount ouput in transaction id=" << get_transaction_hash(tx)); + if (tx.version == 1) + { + CHECK_AND_NO_ASSERT_MES(0 < out.amount, false, "zero amount ouput in transaction id=" << get_transaction_hash(tx)); + } - if(!check_key(boost::get(out.target).key)) - return false; + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + if(!check_key(boost::get(out.target).key)) + return false; + } else { + if(!check_key(out.target.type() == typeid(txout_to_key) ? boost::get(out.target).key : boost::get(out.target).key)) + return false; + } } return true; } @@ -269,7 +294,13 @@ namespace cryptonote uint64_t money = 0; BOOST_FOREACH(const auto& in, tx.vin) { - CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false); + if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.vin[0].type() == typeid(txin_offshore)) { + CHECKED_GET_SPECIFIC_VARIANT(in, const txin_offshore, tokey_in, false); + } else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && tx.vin[0].type() == typeid(txin_onshore)) { + CHECKED_GET_SPECIFIC_VARIANT(in, const txin_onshore, tokey_in, false); + } else { + CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false); + } if(money > tokey_in.amount + money) return false; money += tokey_in.amount; @@ -406,7 +437,16 @@ namespace cryptonote binary_archive ba(ss); const size_t inputs = t.vin.size(); const size_t outputs = t.vout.size(); - const size_t mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : 0; + size_t mixin; + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : 0; + } else { + mixin = t.vin.empty() ? 0 : + t.vin[0].type() == typeid(txin_to_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : + t.vin[0].type() == typeid(txin_offshore) ? boost::get(t.vin[0]).key_offsets.size() - 1 : + t.vin[0].type() == typeid(txin_onshore) ? boost::get(t.vin[0]).key_offsets.size() - 1 : + 0; + } bool r = tt.rct_signatures.p.serialize_rctsig_prunable(ba, t.rct_signatures.type, inputs, outputs, mixin); CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures prunable"); cryptonote::get_blob_hash(ss.str(), hashes[2]); @@ -491,15 +531,6 @@ namespace cryptonote return get_object_hash(blob, res); } //--------------------------------------------------------------- - bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) - { - blobdata bd; - if(!get_block_hashing_blob(b, bd)) - return false; - crypto::cn_slow_hash(bd.data(), bd.size(), res); - return true; - } - //--------------------------------------------------------------- std::vector relative_output_offsets_to_absolute(const std::vector& off) { std::vector res = off; @@ -520,13 +551,6 @@ namespace cryptonote return res; } //--------------------------------------------------------------- - crypto::hash get_block_longhash(const block& b, uint64_t height) - { - crypto::hash p = null_hash; - get_block_longhash(b, p, height); - return p; - } - //--------------------------------------------------------------- bool get_bytecoin_block_longhash(const block& b, crypto::hash& res) { blobdata bd; diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 915e487..a2ed58a 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -82,8 +82,6 @@ namespace cryptonote bool get_block_hash(const block& b, crypto::hash& res); crypto::hash get_block_hash(const block& b); bool get_block_header_hash(const block& b, crypto::hash& res); - bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); - crypto::hash get_block_longhash(const block& b, uint64_t height); bool get_bytecoin_block_longhash(const block& blk, crypto::hash& res); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money);