Skip to content

Commit 02da176

Browse files
authored
Merge pull request #189 from victor-tucci/dev
Fix: Coinbase overspend
2 parents 598dedb + d2fd0ae commit 02da176

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/checkpoints/checkpoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace cryptonote
7171
{266284, "446fb044ad9f920d2c1607b792b7667b1d9994edc7fcc72f89282983cb7044cc"},
7272
{301187, "a9676c3fbae6ad42434db2d1ebac90c2e75dbbd02a6b2d45c69d123554c7578f"},
7373
{3126052,"d3c6d7e2b79c3b455861e99eaed7fc9c47677abe665d0e6b27bf9311397e4c9b"},
74-
74+
{5170000,"36c013fb4223e0d003e7f0fad473f08e123d0233026531d1cf9f9a7bc55da05f"},
7575
};
7676

7777
crypto::hash get_newest_hardcoded_checkpoint(cryptonote::network_type nettype, uint64_t *height)

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)