@ -1393,6 +1393,24 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
// Miner Block Header Signing
// Miner Block Header Signing
if ( hf_version > = BLOCK_HEADER_MINER_SIG )
if ( hf_version > = BLOCK_HEADER_MINER_SIG )
{
{
if ( b . vote > 2 )
{
MWARNING ( " Vote integer must be either 0, 1, or 2 " ) ;
return false ;
} else {
LOG_PRINT_L1 ( " Vote: " < < b . vote ) ;
}
// keccak hash block header data and check miner signature
// if signature is invalid, check unlock window
crypto : : hash sig_data = get_sig_data ( b ) ;
crypto : : signature signature = b . signature ;
crypto : : public_key eph_pub_key = boost : : get < txout_to_key > ( b . miner_tx . vout [ 0 ] . target ) . key ;
if ( ! crypto : : check_signature ( sig_data , eph_pub_key , signature ) & & b . miner_tx . unlock_time ! = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3 )
{
MWARNING ( " Coinbase transaction has the wrong unlock time, " < < " Unlock: " < < b . miner_tx . unlock_time < < " , Expected: " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3 ) ;
return false ;
} else {
LOG_PRINT_L1 ( " Miner signature is good " ) ;
// sanity checks
// sanity checks
if ( b . miner_tx . vout . size ( ) ! = 1 )
if ( b . miner_tx . vout . size ( ) ! = 1 )
{
{
@ -1404,23 +1422,11 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
MWARNING ( " Wrong txout type " ) ;
MWARNING ( " Wrong txout type " ) ;
return false ;
return false ;
}
}
if ( b . vote > 2 )
if ( b . miner_tx . unlock_time ! = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO )
{
{
MWARNING ( " Vote integer must be either 0, 1, or 2 " ) ;
MWARNING ( " Coinbase transaction has the wrong unlock time, " < < " Unlock: " < < b . miner_tx . unlock_time < < " , Expected: " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO ) ;
return false ;
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 < txout_to_key > ( 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 {
LOG_PRINT_L1 ( " Miner signature is good " ) ;
LOG_PRINT_L1 ( " Vote: " < < b . vote ) ;
}
}
}
}
@ -1442,11 +1448,13 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
}
}
MDEBUG ( " Miner tx hash: " < < get_transaction_hash ( b . miner_tx ) ) ;
MDEBUG ( " Miner tx hash: " < < get_transaction_hash ( b . miner_tx ) ) ;
if ( hf_version > = HF_VERSION_FIXED_UNLOCK )
if ( hf_version > = HF_VERSION_FIXED_UNLOCK & & hf_version < OPTIONAL_BLOCK_HEADER_MINER_SIG )
{
{
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 , false , " coinbase transaction transaction has the wrong unlock time="
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 , false , " Coinbase transaction has the wrong unlock time="
< < b . miner_tx . unlock_time < < " , expected " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 ) ;
< < b . miner_tx . unlock_time < < " , expected " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 ) ;
} else if ( hf_version < HF_VERSION_FIXED_UNLOCK & & hf_version > = HF_VERSION_DYNAMIC_UNLOCK )
}
if ( hf_version < HF_VERSION_FIXED_UNLOCK & & hf_version > = HF_VERSION_DYNAMIC_UNLOCK )
{
{
uint64_t N = m_nettype = = MAINNET ? 1337 : 5 ;
uint64_t N = m_nettype = = MAINNET ? 1337 : 5 ;
crypto : : hash blk_id = get_block_id_by_height ( height - N ) ;
crypto : : hash blk_id = get_block_id_by_height ( height - N ) ;
@ -1462,8 +1470,11 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
" \n Height: " < < height < < " , Unlock window: " < < unlock_window < < " , Unlock time: " < < b . miner_tx . unlock_time < <
" \n Height: " < < height < < " , Unlock window: " < < unlock_window < < " , Unlock time: " < < b . miner_tx . unlock_time < <
" \n blk_height: " < < height - N < < " , blk_id: " < < blk_id < <
" \n blk_height: " < < height - N < < " , blk_id: " < < blk_id < <
" \n hex_str: " < < hex_str < < " , blk_num: " < < blk_num ) ;
" \n hex_str: " < < hex_str < < " , blk_num: " < < blk_num ) ;
} else {
}
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW , false , " coinbase transaction transaction has the wrong unlock time= "
if ( hf_version < HF_VERSION_DYNAMIC_UNLOCK )
{
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW , false , " Coinbase transaction has the wrong unlock time= "
< < b . miner_tx . unlock_time < < " , expected " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW ) ;
< < b . miner_tx . unlock_time < < " , expected " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW ) ;
}
}