diff options
Diffstat (limited to '')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 35 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_boost_serialization.h | 23 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 8 |
3 files changed, 53 insertions, 13 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 456a78eaf..9972b25e5 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2468,11 +2468,12 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context { rct::ctkeyM reconstructed_mixRing; std::vector<rct::keyV> reconstructed_II; + rct::ctkeyV reconstructed_outPk; // if the tx already has a non empty mixRing, use them, // else reconstruct them const rct::ctkeyM &mixRing = tx.rct_signatures.mixRing.empty() ? reconstructed_mixRing : tx.rct_signatures.mixRing; - // always do II, because it's split in the simple version + // always do II, because it's split in the simple version, and always do outPk // all MGs should have the same II size (1) for (size_t n = 0; n < tx.rct_signatures.MGs.size(); ++n) @@ -2491,6 +2492,18 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context reconstructed_II[n].push_back(tx.rct_signatures.MGs[n].II[0]); } + if (tx.rct_signatures.outPk.size() != tx.vout.size()) + { + LOG_PRINT_L1("Failed to check ringct signatures: outPk and vout have different sizes"); + return false; + } + reconstructed_outPk.resize(tx.vout.size()); + for (size_t n = 0; n < tx.vout.size(); ++n) + { + reconstructed_outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key); + reconstructed_outPk[n].mask = tx.rct_signatures.outPk[n].mask; + } + if (tx.rct_signatures.mixRing.empty()) { reconstructed_mixRing.resize(pubkeys.size()); @@ -2551,7 +2564,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context } } - if (!rct::verRctSimple(tx.rct_signatures, mixRing, &reconstructed_II, rct::hash2rct(tx_prefix_hash))) + if (!rct::verRctSimple(tx.rct_signatures, mixRing, &reconstructed_II, reconstructed_outPk, rct::hash2rct(tx_prefix_hash))) { LOG_PRINT_L1("Failed to check ringct signatures!"); return false; @@ -2561,11 +2574,13 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context { rct::ctkeyM reconstructed_mixRing; rct::keyV reconstructed_II; + rct::ctkeyV reconstructed_outPk; // if the tx already has a non empty mixRing and/or II, use them, - // else reconstruct them + // else reconstruct them. Always do outPk. const rct::ctkeyM &mixRing = tx.rct_signatures.mixRing.empty() ? reconstructed_mixRing : tx.rct_signatures.mixRing; const rct::keyV &II = tx.rct_signatures.MG.II.size() == 1 ? reconstructed_II : tx.rct_signatures.MG.II; + const rct::ctkeyV outPk = reconstructed_outPk; // RCT needs the same mixin for all inputs for (size_t n = 1; n < pubkeys.size(); ++n) @@ -2599,6 +2614,18 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context reconstructed_II.push_back(tx.rct_signatures.MG.II.back()); } + if (tx.rct_signatures.outPk.size() != tx.vout.size()) + { + LOG_PRINT_L1("Failed to check ringct signatures: outPk and vout have different sizes"); + return false; + } + reconstructed_outPk.resize(tx.vout.size()); + for (size_t n = 0; n < tx.vout.size(); ++n) + { + reconstructed_outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key); + reconstructed_outPk[n].mask = tx.rct_signatures.outPk[n].mask; + } + // check all this, either recontructed (so should really pass), or not { bool size_matches = true; @@ -2644,7 +2671,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context } } - if (!rct::verRct(tx.rct_signatures, mixRing, II, rct::hash2rct(tx_prefix_hash))) + if (!rct::verRct(tx.rct_signatures, mixRing, II, outPk, rct::hash2rct(tx_prefix_hash))) { LOG_PRINT_L1("Failed to check ringct signatures!"); return false; diff --git a/src/cryptonote_core/cryptonote_boost_serialization.h b/src/cryptonote_core/cryptonote_boost_serialization.h index 35fabe7fb..81f5f081a 100644 --- a/src/cryptonote_core/cryptonote_boost_serialization.h +++ b/src/cryptonote_core/cryptonote_boost_serialization.h @@ -43,6 +43,7 @@ #include "common/unordered_containers_boost_serialization.h" #include "crypto/crypto.h" #include "ringct/rctTypes.h" +#include "ringct/rctOps.h" //namespace cryptonote { namespace boost @@ -221,6 +222,26 @@ namespace boost a & x.senderPk; } + inline void serializeOutPk(boost::archive::binary_iarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver) + { + rct::keyV outPk; + a & outPk; + outPk_.resize(outPk.size()); + for (size_t n = 0; n < outPk_.size(); ++n) + { + outPk_[n].dest = rct::identity(); + outPk_[n].mask = outPk[n]; + } + } + + inline void serializeOutPk(boost::archive::binary_oarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver) + { + rct::keyV outPk(outPk_.size()); + for (size_t n = 0; n < outPk_.size(); ++n) + outPk[n] = outPk_[n].mask; + a & outPk; + } + template <class Archive> inline void serialize(Archive &a, rct::rctSig &x, const boost::serialization::version_type ver) { @@ -235,7 +256,7 @@ namespace boost if (x.simple) a & x.pseudoOuts; a & x.ecdhInfo; - a & x.outPk; + serializeOutPk(a, x.outPk, ver); a & x.txnFee; } } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 880162ed2..511f50616 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -569,14 +569,6 @@ namespace cryptonote LOG_PRINT_RED_L1("tx with mismatched vout/outPk count, rejected for tx id= " << get_transaction_hash(tx)); return false; } - for (size_t n = 0; n < tx.vout.size(); ++n) - { - if (tx.rct_signatures.outPk[n].dest != boost::get<txout_to_key>(tx.vout[n].target).key) - { - LOG_PRINT_RED_L1("tx ringct public key does not match output public key for tx id= " << get_transaction_hash(tx)); - return false; - } - } } if(!check_money_overflow(tx)) |