aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-04-11 12:41:07 +0200
committerRiccardo Spagni <ric@spagni.net>2019-04-11 12:41:07 +0200
commit76fbcfe2ddf597b4d8f6d2f5e6f387d57db427eb (patch)
tree4d9fdf15d9e1eab2482dd11e3c8d2e69864e1765 /src/cryptonote_core
parentMerge pull request #4939 (diff)
parentcryptonote: rework block blob size sanity check (diff)
downloadmonero-76fbcfe2ddf597b4d8f6d2f5e6f387d57db427eb.tar.xz
Merge pull request #5123
089c7637 cryptonote: rework block blob size sanity check (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp6
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp26
2 files changed, 24 insertions, 8 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 73c60760b..503267a1a 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3873,6 +3873,8 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
LOG_PRINT_L3("Blockchain::" << __func__);
+ m_db->block_txn_start(false);
+
// when we reach this, the last hf version is not yet written to the db
const uint64_t db_height = m_db->height();
const uint8_t hf_version = get_current_hard_fork_version();
@@ -3935,6 +3937,10 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
if (long_term_effective_median_block_weight)
*long_term_effective_median_block_weight = m_long_term_effective_median_block_weight;
+ m_db->add_max_block_size(m_current_block_cumul_weight_limit);
+
+ m_db->block_txn_stop();
+
return true;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 8ab7d174c..6b0052dc0 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -62,6 +62,9 @@ DISABLE_VS_WARNINGS(4355)
#define BAD_SEMANTICS_TXES_MAX_SIZE 100
+// basically at least how many bytes the block itself serializes to without the miner tx
+#define BLOCK_SIZE_SANITY_LEEWAY 100
+
namespace cryptonote
{
const command_line::arg_descriptor<bool, false> arg_testnet_on = {
@@ -1417,18 +1420,21 @@ namespace cryptonote
{
TRY_ENTRY();
- // load json & DNS checkpoints every 10min/hour respectively,
- // and verify them with respect to what blocks we already have
- CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
-
bvc = boost::value_initialized<block_verification_context>();
- if(block_blob.size() > get_max_block_size())
+
+ if (!check_incoming_block_size(block_blob))
{
- LOG_PRINT_L1("WRONG BLOCK BLOB, too big size " << block_blob.size() << ", rejected");
bvc.m_verifivation_failed = true;
return false;
}
+ if (((size_t)-1) <= 0xffffffff && block_blob.size() >= 0x3fffffff)
+ MWARNING("This block's size is " << block_blob.size() << ", closing on the 32 bit limit");
+
+ // load json & DNS checkpoints every 10min/hour respectively,
+ // and verify them with respect to what blocks we already have
+ CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
+
block lb;
if (!b)
{
@@ -1453,9 +1459,13 @@ namespace cryptonote
// block_blob
bool core::check_incoming_block_size(const blobdata& block_blob) const
{
- if(block_blob.size() > get_max_block_size())
+ // note: we assume block weight is always >= block blob size, so we check incoming
+ // blob size against the block weight limit, which acts as a sanity check without
+ // having to parse/weigh first; in fact, since the block blob is the block header
+ // plus the tx hashes, the weight will typically be much larger than the blob size
+ if(block_blob.size() > m_blockchain_storage.get_current_cumulative_block_weight_limit() + BLOCK_SIZE_SANITY_LEEWAY)
{
- LOG_PRINT_L1("WRONG BLOCK BLOB, too big size " << block_blob.size() << ", rejected");
+ LOG_PRINT_L1("WRONG BLOCK BLOB, sanity check failed on size " << block_blob.size() << ", rejected");
return false;
}
return true;