Skip to content

Commit 9aa4dbb

Browse files
committed
overflow checks for memory gas calculations
1 parent 9c939fa commit 9aa4dbb

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

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

204205
return Literal();
205206
}

0 commit comments

Comments
 (0)