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 authored and axic committed May 15, 2018
1 parent cbb74bb commit a0af200
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 @@ -203,8 +203,9 @@ string toHex(evmc_uint256be const& value) {
HERA_DEBUG << "useGas " << gas << "\n";

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

ensureCondition((ffsl(gas) + ffsl(memory.size()) <= 64), OutOfGasException, "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 a0af200

Please sign in to comment.