Added sanity checks for height and difficulty

This commit is contained in:
SChernykh 2024-04-23 18:29:19 +02:00
parent a847baf331
commit b3f562caab
2 changed files with 14 additions and 0 deletions

View file

@ -53,6 +53,12 @@ static constexpr uint64_t MAX_BLOCK_SIZE = 128 * 1024 - 5;
// 0.6 XMR
static constexpr uint64_t BASE_BLOCK_REWARD = 600000000000ULL;
// 1000 years at 1 TH/s. It should be enough for any normal use.
static constexpr difficulty_type MAX_CUMULATIVE_DIFFICULTY{ 13019633956666736640ULL, 1710ULL };
// 1000 years at 1 block/second. It should be enough for any normal use.
static constexpr uint64_t MAX_SIDECHAIN_HEIGHT = 31556952000ULL;
struct DifficultyData
{
FORCEINLINE DifficultyData(uint64_t t, const difficulty_type& d) : m_timestamp(t), m_cumulativeDifficulty(d) {}

View file

@ -306,12 +306,20 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
READ_VARINT(m_sidechainHeight);
if (m_sidechainHeight > MAX_SIDECHAIN_HEIGHT) {
return __LINE__;
}
READ_VARINT(m_difficulty.lo);
READ_VARINT(m_difficulty.hi);
READ_VARINT(m_cumulativeDifficulty.lo);
READ_VARINT(m_cumulativeDifficulty.hi);
if (m_cumulativeDifficulty > MAX_CUMULATIVE_DIFFICULTY) {
return __LINE__;
}
READ_BUF(m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf));
#undef READ_BYTE