Use rct::is_rct_<whatever> where appropriate

Also inline them into the header and simplify them.

Someone added functions for is_rct_whatever but used them almost
nowhere.  This uses them (which would have saved a bunch of changes and
bugs in adding CLSAG in the first place).
This commit is contained in:
Jason Rhinelander 2020-09-16 20:21:48 -03:00
parent f34568cb8d
commit 4e7a2e315f
7 changed files with 20 additions and 60 deletions

View File

@ -378,7 +378,7 @@ namespace boost
a & x.p.MGs;
if (ver >= 1u)
a & x.p.CLSAGs;
if (tools::equals_any(x.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG))
if (rct::is_rct_bulletproof(x.type))
a & x.p.pseudoOuts;
}

View File

@ -1304,7 +1304,7 @@ namespace cryptonote
{
if (!tx_info[n].result || tx_info[n].already_have)
continue;
if (!tools::equals_any(tx_info[n].tx.rct_signatures.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG))
if (!rct::is_rct_bulletproof(tx_info[n].tx.rct_signatures.type))
continue;
if (assumed_bad || !rct::verRctSemanticsSimple(tx_info[n].tx.rct_signatures))
{

View File

@ -300,7 +300,7 @@ namespace tx {
if (!m_ct.rv){
throw std::invalid_argument("RV not initialized");
}
return tools::equals_any(m_ct.rv->type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG);
return rct::is_rct_bulletproof(m_ct.rv->type);
}
bool is_offloading() const {

View File

@ -585,7 +585,7 @@ namespace rct {
hashes.push_back(hash2rct(h));
keyV kv;
if (tools::equals_any(rv.type, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG))
if (rct::is_rct_bulletproof(rv.type))
{
kv.reserve((6*2+9) * rv.p.bulletproofs.size());
for (const auto &p: rv.p.bulletproofs)
@ -1332,8 +1332,7 @@ namespace rct {
{
CHECK_AND_ASSERT_MES(rvp, false, "rctSig pointer is NULL");
const rctSig &rv = *rvp;
CHECK_AND_ASSERT_MES(tools::equals_any(rv.type, RCTTypeSimple, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG),
false, "verRctSemanticsSimple called on non simple rctSig");
CHECK_AND_ASSERT_MES(rct::is_rct_simple(rv.type), false, "verRctSemanticsSimple called on non simple rctSig");
const bool bulletproof = is_rct_bulletproof(rv.type);
if (bulletproof)
{
@ -1441,8 +1440,7 @@ namespace rct {
{
PERF_TIMER(verRctNonSemanticsSimple);
CHECK_AND_ASSERT_MES(tools::equals_any(rv.type, RCTTypeSimple, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG),
false, "verRctNonSemanticsSimple called on non simple rctSig");
CHECK_AND_ASSERT_MES(rct::is_rct_simple(rv.type), false, "verRctNonSemanticsSimple called on non simple rctSig");
const bool bulletproof = is_rct_bulletproof(rv.type);
// semantics check is early, and mixRing/MGs aren't resolved yet
if (bulletproof)
@ -1537,7 +1535,7 @@ namespace rct {
}
xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, key &mask, hw::device &hwdev) {
CHECK_AND_ASSERT_MES(tools::equals_any(rv.type, RCTTypeSimple, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG), false, "decodeRct called on non simple rctSig");
CHECK_AND_ASSERT_MES(rct::is_rct_simple(rv.type), false, "decodeRct called on non simple rctSig");
CHECK_AND_ASSERT_THROW_MES(i < rv.ecdhInfo.size(), "Bad index");
CHECK_AND_ASSERT_THROW_MES(rv.outPk.size() == rv.ecdhInfo.size(), "Mismatched sizes of rv.outPk and rv.ecdhInfo");

View File

@ -188,45 +188,6 @@ namespace rct {
return vali;
}
bool is_rct_simple(int type)
{
switch (type)
{
case RCTTypeSimple:
case RCTTypeBulletproof:
case RCTTypeBulletproof2:
case RCTTypeCLSAG:
return true;
default:
return false;
}
}
bool is_rct_bulletproof(int type)
{
switch (type)
{
case RCTTypeBulletproof:
case RCTTypeBulletproof2:
case RCTTypeCLSAG:
return true;
default:
return false;
}
}
bool is_rct_borromean(int type)
{
switch (type)
{
case RCTTypeSimple:
case RCTTypeFull:
return true;
default:
return false;
}
}
size_t n_bulletproof_amounts(const Bulletproof &proof)
{
CHECK_AND_ASSERT_MES(proof.L.size() >= 6, 0, "Invalid bulletproof L size");

View File

@ -264,6 +264,11 @@ namespace rct {
RCTTypeBulletproof2 = 4,
RCTTypeCLSAG = 5,
};
inline bool is_rct_simple(int type) { return tools::equals_any(type, RCTTypeSimple, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG); }
inline bool is_rct_bulletproof(int type) { return tools::equals_any(type, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG); }
inline bool is_rct_borromean(int type) { return tools::equals_any(type, RCTTypeSimple, RCTTypeFull); }
enum RangeProofType { RangeProofBorromean, RangeProofBulletproof, RangeProofMultiOutputBulletproof, RangeProofPaddedBulletproof };
struct RCTConfig {
RangeProofType range_proof_type;
@ -338,7 +343,7 @@ namespace rct {
return;
if (!tools::equals_any(type, RCTTypeFull, RCTTypeSimple, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG))
throw std::invalid_argument{"invalid ringct type"};
if (tools::equals_any(type, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG))
if (rct::is_rct_bulletproof(type))
{
uint32_t nbp = bulletproofs.size();
if (tools::equals_any(type, RCTTypeBulletproof2, RCTTypeCLSAG))
@ -434,12 +439,12 @@ namespace rct {
keyV& get_pseudo_outs()
{
return tools::equals_any(type, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG) ? p.pseudoOuts : pseudoOuts;
return rct::is_rct_bulletproof(type) ? p.pseudoOuts : pseudoOuts;
}
keyV const& get_pseudo_outs() const
{
return tools::equals_any(type, RCTTypeBulletproof, RCTTypeBulletproof2, RCTTypeCLSAG) ? p.pseudoOuts : pseudoOuts;
return rct::is_rct_bulletproof(type) ? p.pseudoOuts : pseudoOuts;
}
};
@ -544,10 +549,6 @@ namespace rct {
//int[64] to uint long long
xmr_amount b2d(bits amountb);
bool is_rct_simple(int type);
bool is_rct_bulletproof(int type);
bool is_rct_borromean(int type);
static inline const rct::key &pk2rct(const crypto::public_key &pk) { return (const rct::key&)pk; }
static inline const rct::key &sk2rct(const crypto::secret_key &sk) { return (const rct::key&)sk; }
static inline const rct::key &ki2rct(const crypto::key_image &ki) { return (const rct::key&)ki; }

View File

@ -271,7 +271,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
uint64_t amount = 0;
const uint8_t type = rct_txes.back().rct_signatures.type;
if (tools::equals_any(type, rct::RCTTypeSimple, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG))
if (rct::is_rct_simple(type))
amount = rct::decodeRctSimple(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
else
amount = rct::decodeRct(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
@ -436,7 +436,7 @@ bool gen_bp_tx_invalid_not_enough_proofs::generate(std::vector<test_event_entry>
const uint64_t amounts_paid[] = {5, 5, (uint64_t)-1};
const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 0 } };
return generate_with(events, 1, amounts_paid, false, rct_config, 0, NULL, [&](cryptonote::transaction &tx, size_t idx){
CHECK_TEST_CONDITION(tools::equals_any(tx.rct_signatures.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG));
CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type));
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
tx.rct_signatures.p.bulletproofs.pop_back();
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
@ -450,7 +450,7 @@ bool gen_bp_tx_invalid_empty_proofs::generate(std::vector<test_event_entry>& eve
const uint64_t amounts_paid[] = {50, 50, (uint64_t)-1};
const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 0 } };
return generate_with(events, 1, amounts_paid, false, rct_config, 0, NULL, [&](cryptonote::transaction &tx, size_t idx){
CHECK_TEST_CONDITION(tools::equals_any(tx.rct_signatures.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG));
CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type));
tx.rct_signatures.p.bulletproofs.clear();
return true;
});
@ -462,7 +462,7 @@ bool gen_bp_tx_invalid_too_many_proofs::generate(std::vector<test_event_entry>&
const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 0 } };
return generate_with(events, 1, amounts_paid, false, rct_config, 0, NULL, [&](cryptonote::transaction &tx, size_t idx){
CHECK_TEST_CONDITION(tools::equals_any(tx.rct_signatures.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG));
CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type));
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
tx.rct_signatures.p.bulletproofs.push_back(tx.rct_signatures.p.bulletproofs.back());
return true;
@ -475,7 +475,7 @@ bool gen_bp_tx_invalid_wrong_amount::generate(std::vector<test_event_entry>& eve
const uint64_t amounts_paid[] = {10, (uint64_t)-1};
const rct::RCTConfig rct_config[] = { { rct::RangeProofBulletproof, 0 } };
return generate_with(events, 1, amounts_paid, false, rct_config, 0, NULL, [&](cryptonote::transaction &tx, size_t idx){
CHECK_TEST_CONDITION(tools::equals_any(tx.rct_signatures.type, rct::RCTTypeBulletproof, rct::RCTTypeBulletproof2, rct::RCTTypeCLSAG));
CHECK_TEST_CONDITION(rct::is_rct_bulletproof(tx.rct_signatures.type));
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
tx.rct_signatures.p.bulletproofs.back() = rct::bulletproof_PROVE(1000, rct::skGen());
return true;