Skip to content

Commit 07a15fd

Browse files
committed
overflow checks for memory gas calculations
1 parent dd99a2a commit 07a15fd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/eei.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ inline int64_t maxCallGas(int64_t gas) {
219219
HERA_DEBUG << "useGas " << gas << "\n";
220220

221221
takeGas(gas);
222-
// FIXME: this may overflow
223-
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage);
222+
223+
heraAssert((ffsl(gas) + ffsl(memory.size()) <= 64), "Memory gas calculation overflow."); //may need to find alternative to ffsl for cross-libc portability
224+
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage + 1); //round gas cost up
224225

225226
return Literal();
226227
}

0 commit comments

Comments
 (0)