Skip to content

Commit

Permalink
overflow checks for memory gas calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed May 29, 2018
1 parent dd99a2a commit 07a15fd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ inline int64_t maxCallGas(int64_t gas) {
HERA_DEBUG << "useGas " << gas << "\n";

takeGas(gas);
// FIXME: this may overflow
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage);

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

return Literal();
}
Expand Down

0 comments on commit 07a15fd

Please sign in to comment.