Skip to content

Commit f36a649

Browse files
jakelangaxic
authored andcommitted
overflow checks for memory gas calculations
1 parent b1cdae3 commit f36a649

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
@@ -215,8 +215,9 @@ string toHex(evmc_uint256be const& value) {
215215
HERA_DEBUG << "useGas " << gas << "\n";
216216

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

221222
return Literal();
222223
}

0 commit comments

Comments
 (0)