Skip to content

Commit f1ede82

Browse files
jakelangaxic
authored andcommitted
overflow checks for memory gas calculations
1 parent 5a015e8 commit f1ede82

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
@@ -214,8 +214,9 @@ inline int64_t maxCallGas(int64_t gas) {
214214
HERA_DEBUG << "useGas " << gas << "\n";
215215

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

220221
return Literal();
221222
}

0 commit comments

Comments
 (0)