diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h index 9469d2630..189d814b6 100644 --- a/src/cryptonote_basic/cryptonote_basic.h +++ b/src/cryptonote_basic/cryptonote_basic.h @@ -470,10 +470,12 @@ namespace cryptonote VARINT_FIELD(timestamp) FIELD(prev_id) FIELD(nonce) - if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && major_version < HF_VERSION_P2POOL) + if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { - FIELD(signature) + FIELD(signature) + if (major_version < HF_VERSION_P2POOL) { FIELD(vote) + } } END_SERIALIZE() }; diff --git a/src/cryptonote_basic/cryptonote_boost_serialization.h b/src/cryptonote_basic/cryptonote_boost_serialization.h index 74c8098da..d7b67599d 100644 --- a/src/cryptonote_basic/cryptonote_boost_serialization.h +++ b/src/cryptonote_basic/cryptonote_boost_serialization.h @@ -196,10 +196,12 @@ namespace boost a & b.timestamp; a & b.prev_id; a & b.nonce; - if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL) + if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { a & b.signature; - a & b.vote; + if (b.major_version < HF_VERSION_P2POOL) { + a & b.vote; + } } //------------------ a & b.miner_tx; diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index a951f5c97..76b34d280 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -610,7 +610,7 @@ namespace cryptonote b.nonce = nonce; // Miner Block Header Signing - if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL) + if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { // tx key derivation crypto::key_derivation derivation; @@ -627,7 +627,10 @@ namespace cryptonote crypto::generate_signature(sig_data, eph_pub_key, eph_secret_key, signature); // amend signature to block header before PoW hashing b.signature = signature; - b.vote = m_int_vote; + + if (b.major_version < HF_VERSION_P2POOL) { + b.vote = m_int_vote; + } } crypto::hash h; diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index a670787c7..cba24b353 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1411,50 +1411,45 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std: // valid output types bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height, uint8_t hf_version) { + bool hasValidSig = false // Miner Block Header Signing if (hf_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && hf_version < HF_VERSION_P2POOL) { - // sanity checks - if (b.miner_tx.vout.size() != 1) - { - MWARNING("Only 1 output in miner transaction allowed"); - return false; - } - if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key)) - { - MWARNING("Wrong txout type"); - return false; - } - if (b.vote > 2) - { + if (hf_version >= HF_VERSION_P2POOL && b.miner_tx.vout.size() > MIN_MINER_OUTPUTS) { + LOG_PRINT_L3("Miner transaction has enough outputs, it doesn't need a valid signature") + } else { + // Check tx signature + // sanity checks + if (b.miner_tx.vout.size() != 1) + { + MWARNING("Only 1 output in miner transaction allowed"); + return false; + } + if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key)) + { + MWARNING("Wrong txout type"); + return false; + } + if (hf_version < HF_VERSION_P2POOL && b.vote > 2) + { MWARNING("Vote integer must be either 0, 1, or 2"); return false; - } - // keccak hash block header data and check miner signature - // if signature is invalid, reject block - crypto::hash sig_data = get_sig_data(b); - crypto::signature signature = b.signature; - crypto::public_key eph_pub_key = boost::get(b.miner_tx.vout[0].target).key; - if (!crypto::check_signature(sig_data, eph_pub_key, signature)) - { + } + // keccak hash block header data and check miner signature + // if signature is invalid, reject block + crypto::hash sig_data = get_sig_data(b); + crypto::signature signature = b.signature; + crypto::public_key eph_pub_key = boost::get(b.miner_tx.vout[0].target).key; + if (!crypto::check_signature(sig_data, eph_pub_key, signature)) + { MWARNING("Miner signature is invalid"); return false; - } else { + } else { LOG_PRINT_L1("Miner signature is good"); - LOG_PRINT_L1("Vote: " << b.vote); - } - } - - if (hf_version >= HF_VERSION_P2POOL) - { - if (b.miner_tx.vout.size() < MIN_MINER_OUTPUTS) - { - MWARNING("Coinbase transaction must have more than " << MIN_MINER_OUTPUTS << " outputs"); - return false; - } - for (const auto &o: b.miner_tx.vout) - { - CHECK_AND_ASSERT_MES(o.target.type() == typeid(txout_to_key), false, "Wrong txout type: " << o.target.type().name() << ", expected txout_to_key in transaction id=" << get_transaction_hash(b.miner_tx)); + if (hf_version < HF_VERSION_P2POOL) { + LOG_PRINT_L1("Vote: " << b.vote); + } + } } } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 63b6ad72f..ad6dbebd3 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -2203,10 +2203,12 @@ namespace cryptonote return false; } b.nonce = req.starting_nonce; - if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL) + if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { b.signature = {}; - b.vote = 0; + if (b.major_version < HF_VERSION_P2POOL) { + b.vote = 0; + } } crypto::hash seed_hash = crypto::null_hash; if (b.major_version >= RX_BLOCK_VERSION && !epee::string_tools::hex_to_pod(template_res.seed_hash, seed_hash)) diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index cdd6ba004..494ac38c7 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -900,10 +900,12 @@ namespace rpc header.minor_version = b.minor_version; header.timestamp = b.timestamp; header.nonce = b.nonce; - if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL) + if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { header.signature = b.signature; - header.vote = b.vote; + if (b.major_version < HF_VERSION_P2POOL) { + header.vote = b.vote; + } } header.prev_id = b.prev_id;