diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-09-15 15:19:54 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-09-15 15:19:54 +0200 |
commit | ce5367452063e4e74e8a690d876274b9395eef69 (patch) | |
tree | 447161d53d5f86eb435df8b924dfeeca18373c2b /src/crypto | |
parent | Merge pull request #1066 (diff) | |
parent | wallet: fix misdetection of duplicates (diff) | |
download | monero-ce5367452063e4e74e8a690d876274b9395eef69.tar.xz |
Merge pull request #1067
70b78bb wallet: fix misdetection of duplicates (moneromooo-monero)
7d413f6 rct: rework serialization to avoid storing vector sizes (moneromooo-monero)
0ce79ef core: cleanup some typecasting (moneromooo-monero)
Diffstat (limited to '')
-rw-r--r-- | src/cryptonote_core/cryptonote_basic.h | 28 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_boost_serialization.h | 16 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 42 |
3 files changed, 60 insertions, 26 deletions
diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index f54b8c2b3..da069a21a 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -230,24 +230,22 @@ namespace cryptonote } else { - FIELD(rct_signatures) - switch (rct_signatures.type) + ar.tag("rct_signatures"); + if (!vin.empty()) { - case rct::RCTTypeNull: - break; - case rct::RCTTypeSimple: - if (rct_signatures.mixRing.size() && rct_signatures.mixRing.size() != vin.size()) - return false; - break; - case rct::RCTTypeFull: - for (size_t i = 0; i < rct_signatures.mixRing.size(); ++i) + ar.begin_object(); + bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size()); + if (!r || !ar.stream().good()) return false; + ar.end_object(); + if (rct_signatures.type != rct::RCTTypeNull) { - if (rct_signatures.mixRing[i].size() != vin.size()) - return false; + ar.tag("rctsig_prunable"); + ar.begin_object(); + r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(), + vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0); + if (!r || !ar.stream().good()) return false; + ar.end_object(); } - break; - default: - return false; } } END_SERIALIZE() diff --git a/src/cryptonote_core/cryptonote_boost_serialization.h b/src/cryptonote_core/cryptonote_boost_serialization.h index c91f78c58..19b1a687e 100644 --- a/src/cryptonote_core/cryptonote_boost_serialization.h +++ b/src/cryptonote_core/cryptonote_boost_serialization.h @@ -162,12 +162,17 @@ namespace boost a & x.vout; a & x.extra; if (x.version == 1) + { a & x.signatures; + } else - a & x.rct_signatures; + { + a & (rct::rctSigBase&)x.rct_signatures; + if (x.rct_signatures.type != rct::RCTTypeNull) + a & x.rct_signatures.p; + } } - template <class Archive> inline void serialize(Archive &a, cryptonote::block &b, const boost::serialization::version_type ver) { @@ -263,6 +268,13 @@ namespace boost } template <class Archive> + inline void serialize(Archive &a, rct::rctSigPrunable &x, const boost::serialization::version_type ver) + { + a & x.rangeSigs; + a & x.MGs; + } + + template <class Archive> inline void serialize(Archive &a, rct::rctSig &x, const boost::serialization::version_type ver) { a & x.type; diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 32b96f1fc..9667006a3 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -471,11 +471,11 @@ namespace cryptonote //--------------------------------------------------------------- bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct) { - std::vector<crypto::secret_key> amount_keys; + std::vector<rct::key> amount_keys; tx.vin.clear(); tx.vout.clear(); tx.signatures.clear(); - tx.rct_signatures = rct::rctSig(); + tx.rct_signatures.type = rct::RCTTypeNull; amount_keys.clear(); tx.version = rct ? 2 : 1; @@ -593,7 +593,7 @@ namespace cryptonote { crypto::secret_key scalar1; crypto::derivation_to_scalar(derivation, output_index, scalar1); - amount_keys.push_back(scalar1); + amount_keys.push_back(rct::sk2rct(scalar1)); } r = crypto::derive_public_key(derivation, output_index, dst_entr.addr.m_spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << output_index << ", "<< dst_entr.addr.m_spend_public_key << ")"); @@ -750,9 +750,9 @@ namespace cryptonote get_transaction_prefix_hash(tx, tx_prefix_hash); rct::ctkeyV outSk; if (use_simple_rct) - tx.rct_signatures = rct::genRctSimple(rct::hash2rct(tx_prefix_hash), inSk, destinations, inamounts, outamounts, amount_in - amount_out, mixRing, (const rct::keyV&)amount_keys, index, outSk); + tx.rct_signatures = rct::genRctSimple(rct::hash2rct(tx_prefix_hash), inSk, destinations, inamounts, outamounts, amount_in - amount_out, mixRing, amount_keys, index, outSk); else - tx.rct_signatures = rct::genRct(rct::hash2rct(tx_prefix_hash), inSk, destinations, outamounts, mixRing, (const rct::keyV&)amount_keys, sources[0].real_output, outSk); // same index assumption + tx.rct_signatures = rct::genRct(rct::hash2rct(tx_prefix_hash), inSk, destinations, outamounts, mixRing, amount_keys, sources[0].real_output, outSk); // same index assumption CHECK_AND_ASSERT_MES(tx.vout.size() == outSk.size(), false, "outSk size does not match vout"); @@ -948,11 +948,35 @@ namespace cryptonote // prefix get_transaction_prefix_hash(t, hashes[0]); - // base rct data - get_blob_hash(t_serializable_object_to_blob((const rct::rctSigBase&)t.rct_signatures), hashes[1]); + transaction &tt = const_cast<transaction&>(t); - // prunable rct data - get_blob_hash(t_serializable_object_to_blob(t.rct_signatures.p), hashes[2]); + // base rct + { + std::stringstream ss; + binary_archive<true> ba(ss); + const size_t inputs = t.vin.size(); + const size_t outputs = t.vout.size(); + bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs); + CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base"); + cryptonote::get_blob_hash(ss.str(), hashes[1]); + } + + // prunable rct + if (t.rct_signatures.type == rct::RCTTypeNull) + { + hashes[2] = cryptonote::null_hash; + } + else + { + std::stringstream ss; + binary_archive<true> 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<txin_to_key>(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]); + } // the tx hash is the hash of the 3 hashes res = cn_fast_hash(hashes, sizeof(hashes)); |