Skip to content

Commit f021195

Browse files
committed
Fix operator precedence in StackLimitEvader memory guard assertion
Add parentheses so the reservedMemory and requiredSlots bounds correctly evaluate to 2^32. Without them, 'u256(1) << 32 - 1' is parsed as 'u256(1) << (32 - 1)' = 2^31 due to C++ operator precedence. Use '(u256(1) << 32)' and '(uint64_t(1) << 32)' for clearer semantics that allow the full 32-bit range [0, 2^32-1].
1 parent 4e281a7 commit f021195

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libyul/optimiser/StackLimitEvader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void StackLimitEvader::run(
210210

211211
// Make sure all calls to ``memoryguard`` we found have the same value as argument (otherwise, abort).
212212
u256 reservedMemory = literalArgumentValue(*memoryGuardCalls.front());
213-
yulAssert(reservedMemory < u256(1) << 32 - 1, "");
213+
yulAssert(reservedMemory < (u256(1) << 32), "");
214214

215215
for (FunctionCall const* memoryGuardCall: memoryGuardCalls)
216216
if (reservedMemory != literalArgumentValue(*memoryGuardCall))
@@ -230,7 +230,7 @@ void StackLimitEvader::run(
230230

231231
MemoryOffsetAllocator memoryOffsetAllocator{_unreachableVariables, callGraph.functionCalls, functionDefinitions};
232232
uint64_t requiredSlots = memoryOffsetAllocator.run();
233-
yulAssert(requiredSlots < (uint64_t(1) << 32) - 1, "");
233+
yulAssert(requiredSlots < (uint64_t(1) << 32), "");
234234

235235
StackToMemoryMover::run(_context, reservedMemory, memoryOffsetAllocator.slotAllocations, requiredSlots, _astRoot);
236236

0 commit comments

Comments
 (0)