Skip to content

Commit

Permalink
Added sanity checks for height and difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Apr 23, 2024
1 parent a847baf commit b3f562c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pool_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
8 changes: 8 additions & 0 deletions src/pool_block_parser.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3f562c

Please sign in to comment.