From 558ca3b0b21307a48ab48fa8aa9d29da5728aec4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 11 Jan 2018 17:41:36 +0000 Subject: [PATCH 1/2] EEI: charge for memory gas cost in useGas --- src/eei.cpp | 2 ++ src/eei.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/eei.cpp b/src/eei.cpp index 24a1f3246..782513155 100644 --- a/src/eei.cpp +++ b/src/eei.cpp @@ -132,6 +132,8 @@ namespace hera { ensureCondition(gas >= 0, ArgumentOutOfRange, "Negative gas supplied."); takeGas(gas); + // FIXME: this may overflow + takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage); } 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; From 10b53bcd787e2b98c6dd8da10783cbb922fb6efe Mon Sep 17 00:00:00 2001 From: Jake Lang Date: Sat, 28 Apr 2018 14:20:11 -0400 Subject: [PATCH 2/2] overflow checks for memory gas calculations --- src/eei.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/eei.cpp b/src/eei.cpp index 782513155..c64e0cebb 100644 --- a/src/eei.cpp +++ b/src/eei.cpp @@ -132,8 +132,10 @@ namespace hera { ensureCondition(gas >= 0, ArgumentOutOfRange, "Negative gas supplied."); 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 } int64_t EthereumInterface::eeiGetGasLeft()