Skip to content

Commit d2fd0ae

Browse files
committed
Coinbase overspend check issue fix
1 parent ff6f1ec commit d2fd0ae

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/cryptonote_core/blockchain.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,8 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
12641264
return false;
12651265
}
12661266

1267-
txversion min_version = transaction::get_max_version_for_hf(hf_version);
1268-
txversion max_version = transaction::get_min_version_for_hf(hf_version);
1267+
txversion min_version = transaction::get_min_version_for_hf(hf_version);
1268+
txversion max_version = transaction::get_max_version_for_hf(hf_version);
12691269
if (b.miner_tx.version < min_version || b.miner_tx.version > max_version)
12701270
{
12711271
MERROR_VER("Coinbase invalid version: " << b.miner_tx.version << " for hardfork: " << static_cast<int>(hf_version) << " min/max version: " << min_version << "/" << max_version);
@@ -1342,7 +1342,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
13421342
}
13431343
}
13441344

1345-
if (already_generated_coins != 0 && block_has_governance_output(nettype(), b) && version > hf::hf20_bulletproof_plus)
1345+
if (already_generated_coins != 0 && block_has_governance_output(nettype(), b))
13461346
{
13471347
if (version >= hf::hf17_POS && reward_parts.governance_paid == 0)
13481348
{
@@ -1372,7 +1372,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
13721372
// TODO(beldex): eliminate all floating point math in reward calculations.
13731373
uint64_t max_base_reward = reward_parts.base_miner + reward_parts.governance_paid + reward_parts.master_node_total + 1;
13741374
uint64_t max_money_in_use = max_base_reward + reward_parts.miner_fee;
1375-
if (money_in_use > max_money_in_use && version > hf::hf20_bulletproof_plus)
1375+
if (money_in_use > max_money_in_use)
13761376
{
13771377
MERROR_VER("coinbase transaction spends too much money (" << print_money(money_in_use) << "). Maximum block reward is "
13781378
<< print_money(max_money_in_use) << " (= " << print_money(max_base_reward) << " base + " << print_money(reward_parts.miner_fee) << " fees)");
@@ -3417,7 +3417,8 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
34173417
CHECK_AND_ASSERT_MES((*pmax_used_block_height + spendable_age) <= m_db->height(),
34183418
false, "Transaction spends at least one output which is too young");
34193419
}
3420-
if (tx.version >= cryptonote::txversion::v2_ringct)
3420+
3421+
if (tx.version >= cryptonote::txversion::v2_ringct)
34213422
{
34223423
if (!expand_transaction_2(tx, tx_prefix_hash, pubkeys))
34233424
{
@@ -3605,14 +3606,17 @@ if (tx.version >= cryptonote::txversion::v2_ringct)
36053606
}
36063607
else if (tx.type == txtype::coin_burn)
36073608
{
3608-
uint64_t burn = cryptonote::get_burned_amount_from_tx_extra(tx.extra);
3609-
if (burn == 0)
3609+
const uint64_t burn = cryptonote::get_burned_amount_from_tx_extra(tx.extra);
3610+
const uint64_t fee = tx.rct_signatures.txnFee;
3611+
if (burn == 0 || burn > fee)
36103612
{
3611-
std::string fail_reason = "Burn amount must not equals to zero";
3612-
MERROR_VER("Failed to validate Burn TX reason: " << fail_reason);
3613-
tvc.m_verbose_error = std::move(fail_reason);
3613+
tvc.m_verbose_error = (burn == 0)
3614+
? "Burn amount must not be zero"
3615+
: "Burn amount must be <= fee";
3616+
3617+
MERROR_VER("Failed to validate Burn TX reason: " << tvc.m_verbose_error);
36143618
return false;
3615-
}
3619+
}
36163620
}
36173621
}
36183622
}

0 commit comments

Comments
 (0)