rct: split rct checks between semantics and other

Semantics can be checked early
This commit is contained in:
moneromooo-monero 2017-01-14 13:29:08 +00:00
parent 2806842200
commit ba3968f6ce
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
4 changed files with 149 additions and 85 deletions

View file

@ -2333,10 +2333,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
CHECK_AND_ASSERT_MES(false, false, "Unsupported rct tx type: " + boost::lexical_cast<std::string>(rv.type));
}
// outPk
CHECK_AND_ASSERT_MES(rv.outPk.size() == tx.vout.size(), false, "Bad outPk size");
for (size_t n = 0; n < tx.rct_signatures.outPk.size(); ++n)
rv.outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key);
// outPk was already done by handle_incoming_tx
return true;
}
@ -2641,7 +2638,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
}
}
if (!rct::verRctSimple(rv))
if (!rct::verRctSimple(rv, false))
{
LOG_PRINT_L1("Failed to check ringct signatures!");
return false;
@ -2699,7 +2696,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
}
}
if (!rct::verRct(rv))
if (!rct::verRct(rv, false))
{
LOG_PRINT_L1("Failed to check ringct signatures!");
return false;

View file

@ -49,6 +49,7 @@ using namespace epee;
#if defined(BERKELEY_DB)
#include "blockchain_db/berkeleydb/db_bdb.h"
#endif
#include "ringct/rctSigs.h"
DISABLE_VS_WARNINGS(4355)
@ -494,6 +495,22 @@ namespace cryptonote
return false;
}
// resolve outPk references in rct txes
// outPk aren't the only thing that need resolving for a fully resolved tx,
// but outPk (1) are needed now to check range proof semantics, and
// (2) do not need access to the blockchain to find data
if (tx.version >= 2)
{
rct::rctSig &rv = tx.rct_signatures;
if (rv.outPk.size() != tx.vout.size())
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Bad outPk size in tx " << tx_hash << ", rejected");
return false;
}
for (size_t n = 0; n < tx.rct_signatures.outPk.size(); ++n)
rv.outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key);
}
if(!check_tx_semantic(tx, keeped_by_block))
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected");
@ -584,6 +601,33 @@ namespace cryptonote
return false;
}
if (tx.version >= 2)
{
const rct::rctSig &rv = tx.rct_signatures;
switch (rv.type) {
case rct::RCTTypeNull:
// coinbase should not come here, so we reject for all other types
LOG_PRINT_RED_L1("Unexpected Null rctSig type");
return false;
case rct::RCTTypeSimple:
if (!rct::verRctSimple(rv, true))
{
LOG_PRINT_RED_L1("rct signature semantics check failed");
return false;
}
break;
case rct::RCTTypeFull:
if (!rct::verRct(rv, true))
{
LOG_PRINT_RED_L1("rct signature semantics check failed");
return false;
}
break;
default:
LOG_PRINT_RED_L1("Unknown rct type: " << rv.type);
return false;
}
}
return true;
}