aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-14 23:53:48 +0800
committerGitHub <noreply@github.com>2018-08-14 23:53:48 +0800
commitcc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03 (patch)
tree6953422720b9e5d943c8307874d5626f7af4e203
parent3f42118d1987ce99b6088d7076b32413373dd09c (diff)
parent0b6a26f8544f632b557681e26ebc2b395bf03b20 (diff)
downloaddexon-solidity-cc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03.tar.gz
dexon-solidity-cc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03.tar.zst
dexon-solidity-cc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03.zip
Merge pull request #4776 from ethereum/const-opt-cost
Calculate the dataGas correctly in the constant optimiser
-rw-r--r--Changelog.md1
-rw-r--r--libevmasm/ConstantOptimiser.cpp3
-rw-r--r--libevmasm/ConstantOptimiser.h2
3 files changed, 3 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md
index 2f4ce1f9..ea4504ac 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -92,6 +92,7 @@ Bugfixes:
* Code Generator: Properly handle negative number literals in ABIEncoderV2.
* Commandline Interface: Correctly handle paths with backslashes on windows.
* Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions.
+ * Optimizer: Correctly estimate gas costs of constants for special cases.
* References Resolver: Do not crash on using ``_slot`` and ``_offset`` suffixes on their own.
* References Resolver: Enforce ``storage`` as data location for mappings.
* References Resolver: Properly handle invalid references used together with ``_slot`` and ``_offset``.
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp
index d0b6843c..07ece12c 100644
--- a/libevmasm/ConstantOptimiser.cpp
+++ b/libevmasm/ConstantOptimiser.cpp
@@ -93,6 +93,7 @@ bigint ConstantOptimisationMethod::simpleRunGas(AssemblyItems const& _items)
bigint ConstantOptimisationMethod::dataGas(bytes const& _data) const
{
+ assertThrow(_data.size() > 0, OptimizerException, "Empty bytecode generated.");
if (m_params.isCreation)
{
bigint gas;
@@ -101,7 +102,7 @@ bigint ConstantOptimisationMethod::dataGas(bytes const& _data) const
return gas;
}
else
- return GasCosts::createDataGas * dataSize();
+ return GasCosts::createDataGas * _data.size();
}
size_t ConstantOptimisationMethod::bytesRequired(AssemblyItems const& _items)
diff --git a/libevmasm/ConstantOptimiser.h b/libevmasm/ConstantOptimiser.h
index f0deb387..2c753fa8 100644
--- a/libevmasm/ConstantOptimiser.h
+++ b/libevmasm/ConstantOptimiser.h
@@ -75,8 +75,6 @@ public:
virtual AssemblyItems execute(Assembly& _assembly) const = 0;
protected:
- size_t dataSize() const { return std::max<size_t>(1, dev::bytesRequired(m_value)); }
-
/// @returns the run gas for the given items ignoring special gas costs
static bigint simpleRunGas(AssemblyItems const& _items);
/// @returns the gas needed to store the given data literally