Skip to content
Permalink
Browse files

blockchain: ensure the block timestamp can't go below recent median

This would create an invalid block, though would require an attacker
to have mined a long blockchain with drifting times (assuming the
miner's clock is roughly correct)

Fixed by crCr62U0
  • Loading branch information...
moneromooo-monero committed Sep 10, 2019
1 parent d0d76f7 commit 661c5af4225525dd21e5294fc67b95527be5a459
Showing with 3 additions and 1 deletion.
  1. +3 −1 src/cryptonote_core/blockchain.cpp
@@ -1385,7 +1385,9 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
if (!memcmp(&miner_address, &m_btc_address, sizeof(cryptonote::account_public_address)) && m_btc_nonce == ex_nonce
&& m_btc_pool_cookie == m_tx_pool.cookie() && m_btc.prev_id == get_tail_id()) {
MDEBUG("Using cached template");
m_btc.timestamp = time(NULL); // update timestamp unconditionally
const uint64_t now = time(NULL);
if (m_btc.timestamp < now) // ensures it can't get below the median of the last few blocks
m_btc.timestamp = now;
b = m_btc;
diffic = m_btc_difficulty;
height = m_btc_height;

0 comments on commit 661c5af

Please sign in to comment.
You can’t perform that action at this time.