Skip to content

Commit a0af200

Browse files
jakelangaxic
authored andcommitted
overflow checks for memory gas calculations
1 parent cbb74bb commit a0af200

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

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

209210
return Literal();
210211
}

0 commit comments

Comments
 (0)