diff --git a/src/eei.cpp b/src/eei.cpp index 24a1f3246..c64e0cebb 100644 --- a/src/eei.cpp +++ b/src/eei.cpp @@ -132,6 +132,10 @@ namespace hera { ensureCondition(gas >= 0, ArgumentOutOfRange, "Negative gas supplied."); takeGas(gas); + + // FIXME: this may overflow + 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 } int64_t EthereumInterface::eeiGetGasLeft() diff --git a/src/eei.h b/src/eei.h index c79d8cd6b..623382d30 100644 --- a/src/eei.h +++ b/src/eei.h @@ -163,6 +163,9 @@ class EthereumInterface { }; struct GasSchedule { + static constexpr unsigned memoryPageSize = 65536; + static constexpr unsigned memoryCostPerPage = 1; + static constexpr unsigned storageLoad = 200; static constexpr unsigned storageStoreCreate = 20000; static constexpr unsigned storageStoreChange = 5000;