make BLOCK_HEADER_MINER_SIG optional

long-unlock
wowario 1 year ago
parent 5b67d16cdf
commit f9c45ad9bf
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111

@ -627,6 +627,10 @@ namespace cryptonote
// amend signature to block header before PoW hashing
b.signature = signature;
b.vote = m_int_vote;
if (b.major_version >= OPTIONAL_BLOCK_HEADER_MINER_SIG)
{
b.miner_tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO;
}
}
crypto::hash h;

@ -40,11 +40,14 @@
#define CRYPTONOTE_MAX_TX_SIZE 1000000
#define CRYPTONOTE_MAX_TX_PER_BLOCK 0x10000000
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3 52560 // 6 months
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO 144 // 12 hours
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 288
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
#define CURRENT_TRANSACTION_VERSION 2
#define CURRENT_BLOCK_MAJOR_VERSION 7
#define CURRENT_BLOCK_MINOR_VERSION 7
#define OPTIONAL_BLOCK_HEADER_MINER_SIG 20
#define BLOCK_HEADER_MINER_SIG 18
#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 300*2
#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT 60*60*2

@ -1393,34 +1393,40 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
// Miner Block Header Signing
if (hf_version >= BLOCK_HEADER_MINER_SIG)
{
// 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)
{
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, reject block
// 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))
if (!crypto::check_signature(sig_data, eph_pub_key, signature) && b.miner_tx.unlock_time != height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3)
{
MWARNING("Miner signature is invalid");
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");
LOG_PRINT_L1("Vote: " << b.vote);
// 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.miner_tx.unlock_time != height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO)
{
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;
}
}
}
@ -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));
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);
} 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;
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,
"\nHeight: " << height << ", Unlock window: " << unlock_window << ", Unlock time: " << b.miner_tx.unlock_time <<
"\nblk_height: " << height-N << ", blk_id: " << blk_id <<
"\nhex_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);
}

@ -171,7 +171,7 @@ namespace cryptonote
tx.version = 1;
//lock
if (hard_fork_version >= HF_VERSION_FIXED_UNLOCK)
if (hard_fork_version >= HF_VERSION_FIXED_UNLOCK < OPTIONAL_BLOCK_HEADER_MINER_SIG)
{
tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2;
} else if (hard_fork_version < HF_VERSION_FIXED_UNLOCK && hard_fork_version >= HF_VERSION_DYNAMIC_UNLOCK)
@ -182,6 +182,8 @@ namespace cryptonote
uint64_t blk_num = std::stol(hex_str,nullptr,16)*2;
uint64_t unlock_window = blk_num + 288;
tx.unlock_time = height + unlock_window;
} else if (hard_fork_version > OPTIONAL_BLOCK_HEADER_MINER_SIG) {
tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3_SOLO;
} else {
tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW;
}

@ -8706,7 +8706,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
const uint64_t amount = td.is_rct() ? 0 : td.amount();
std::unordered_set<uint64_t> seen_indices;
// request more for rct in base recent (locked) coinbases are picked, since they're locked for longer
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
size_t start = req.outputs.size();
bool use_histogram = amount != 0;
@ -9039,7 +9039,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
for(size_t idx: selected_transfers)
{
const transfer_details &td = m_transfers[idx];
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V3 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
outs.push_back(std::vector<get_outs_entry>());
outs.back().reserve(fake_outputs_count + 1);
const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount());

Loading…
Cancel
Save