rpc: return error gracefully on cryptonight v1 check

This commit is contained in:
jeffro256
2026-01-31 10:14:05 -06:00
parent 74dd968cd9
commit 6a99c22cbc
3 changed files with 30 additions and 3 deletions
@@ -1622,7 +1622,9 @@ namespace cryptonote
}
else // CryptoNight
{
const int pow_variant = major_version >= 7 ? major_version - 6 : 0;
static_assert(HF_VERSION_CRYPTONIGHT_VARIANT_1 >= 1);
const int pow_variant = major_version >= HF_VERSION_CRYPTONIGHT_VARIANT_1
? major_version - (HF_VERSION_CRYPTONIGHT_VARIANT_1 - 1) : 0;
crypto::cn_slow_hash(block_hashing_blob.data(), block_hashing_blob.size(), res, pow_variant, height);
}
+1
View File
@@ -174,6 +174,7 @@
#define HF_VERSION_DYNAMIC_FEE 4
#define HF_VERSION_MIN_MIXIN_4 6
#define HF_VERSION_MIN_MIXIN_6 7
#define HF_VERSION_CRYPTONIGHT_VARIANT_1 7
#define HF_VERSION_MIN_MIXIN_10 8
#define HF_VERSION_MIN_MIXIN_15 15
#define HF_VERSION_ENFORCE_RCT 6
+26 -2
View File
@@ -2081,6 +2081,20 @@ namespace cryptonote
error_resp.message = "Wrong block blob";
return false;
}
if (req.major_version == HF_VERSION_CRYPTONIGHT_VARIANT_1 && req.major_version < RX_BLOCK_VERSION)
{
try
{
crypto::cn_variant1_check(blockblob.size(), /*variant=*/1);
}
catch(const std::exception& e)
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE;
error_resp.message = "Block blob size is too small for CryptoNight v1, rejecting block";
return false;
}
}
if(!m_core.check_incoming_block_size(blockblob))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE;
@@ -2101,8 +2115,18 @@ namespace cryptonote
buf.copy(reinterpret_cast<char *>(&seed_hash), sizeof(crypto::hash));
}
cryptonote::get_block_longhash(&(m_core.get_blockchain_storage()), blockblob, pow_hash, req.height,
req.major_version, req.seed_hash.size() ? &seed_hash : NULL, 0);
try
{
cryptonote::get_block_longhash(&(m_core.get_blockchain_storage()), blockblob, pow_hash, req.height,
req.major_version, req.seed_hash.size() ? &seed_hash : NULL, 0);
}
catch (const std::exception &e)
{
MERROR("Caught unexpected error while hashing in " << __PRETTY_FUNCTION__ << ": " << e.what());
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = e.what();
return false;
}
res = string_tools::pod_to_hex(pow_hash);
return true;
}