Skip to content

Commit 10b53bc

Browse files
jakelangaxic
authored andcommitted
overflow checks for memory gas calculations
1 parent 558ca3b commit 10b53bc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/eei.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ namespace hera {
132132
ensureCondition(gas >= 0, ArgumentOutOfRange, "Negative gas supplied.");
133133

134134
takeGas(gas);
135+
135136
// FIXME: this may overflow
136-
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage);
137+
heraAssert((ffsl(gas) + ffsl(memory.size()) <= 64), "Memory gas calculation overflow."); //may need to find alternative to ffsl for cross-libc portability
138+
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage + 1); //round gas cost up
137139
}
138140

139141
int64_t EthereumInterface::eeiGetGasLeft()

0 commit comments

Comments
 (0)