From e31a621d6fb65719d31a4a8a48ce13b73969bac6 Mon Sep 17 00:00:00 2001 From: tevador <37503146+tevador@users.noreply.github.com> Date: Fri, 14 Jun 2019 23:16:27 +0200 Subject: [PATCH] Fix possible overflow in static_assert (#67) --- src/common.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index 08fe7f3..e6682ff 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -69,7 +69,7 @@ namespace randomx { static_assert(wtSum == 256, "Sum of instruction frequencies must be 256."); - constexpr int ArgonBlockSize = 1024; + constexpr uint32_t ArgonBlockSize = 1024; constexpr int ArgonSaltSize = sizeof("" RANDOMX_ARGON_SALT) - 1; constexpr int SuperscalarMaxSize = 3 * RANDOMX_SUPERSCALAR_LATENCY + 2; constexpr int CacheLineSize = RANDOMX_DATASET_ITEM_SIZE; @@ -84,7 +84,7 @@ namespace randomx { //Prevent some unsafe configurations. #ifndef RANDOMX_UNSAFE - static_assert(RANDOMX_CACHE_ACCESSES * RANDOMX_ARGON_MEMORY * ArgonBlockSize + 33554432 >= RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE, "Unsafe configuration: Memory-time tradeoffs"); + static_assert((uint64_t)ArgonBlockSize * RANDOMX_CACHE_ACCESSES * RANDOMX_ARGON_MEMORY + 33554432 >= (uint64_t)RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE, "Unsafe configuration: Memory-time tradeoffs"); static_assert((128 + RANDOMX_PROGRAM_SIZE * RANDOMX_FREQ_ISTORE / 256) * (RANDOMX_PROGRAM_COUNT * RANDOMX_PROGRAM_ITERATIONS) >= RANDOMX_SCRATCHPAD_L3, "Unsafe configuration: Insufficient Scratchpad writes"); static_assert(RANDOMX_PROGRAM_COUNT > 1, "Unsafe configuration: Program filtering strategies"); static_assert(RANDOMX_PROGRAM_SIZE >= 64, "Unsafe configuration: Low program entropy");