aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-09-18 22:46:15 +0800
committerGitHub <noreply@github.com>2018-09-18 22:46:15 +0800
commitc42dfc5b1083a0d49c64a6e3cbe2d3f220d1f519 (patch)
tree2530a0d9fac8acdc9833504db94b9b1aa570d39a /libevmasm
parent48a3fe204f0e0865fb8f85349f196299c40b79ca (diff)
parent0b68d093b45b71bf976f8cf37a6b917aa29ac4e3 (diff)
downloaddexon-solidity-c42dfc5b1083a0d49c64a6e3cbe2d3f220d1f519.tar.gz
dexon-solidity-c42dfc5b1083a0d49c64a6e3cbe2d3f220d1f519.tar.zst
dexon-solidity-c42dfc5b1083a0d49c64a6e3cbe2d3f220d1f519.zip
Merge pull request #4967 from ethereum/const-opt-cost
Move dataGas calculation helper to GasMeter
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/ConstantOptimiser.cpp10
-rw-r--r--libevmasm/GasMeter.cpp14
-rw-r--r--libevmasm/GasMeter.h3
3 files changed, 17 insertions, 10 deletions
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp
index 07ece12c..9844ba3a 100644
--- a/libevmasm/ConstantOptimiser.cpp
+++ b/libevmasm/ConstantOptimiser.cpp
@@ -94,15 +94,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;
- for (auto b: _data)
- gas += b ? GasCosts::txDataNonZeroGas : GasCosts::txDataZeroGas;
- return gas;
- }
- else
- return GasCosts::createDataGas * _data.size();
+ return bigint(GasMeter::dataGas(_data, m_params.isCreation));
}
size_t ConstantOptimisationMethod::bytesRequired(AssemblyItems const& _items)
diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp
index caa06fc0..3554f809 100644
--- a/libevmasm/GasMeter.cpp
+++ b/libevmasm/GasMeter.cpp
@@ -258,4 +258,16 @@ unsigned GasMeter::runGas(Instruction _instruction)
return 0;
}
-
+u256 GasMeter::dataGas(bytes const& _data, bool _inCreation)
+{
+ bigint gas = 0;
+ if (_inCreation)
+ {
+ for (auto b: _data)
+ gas += (b != 0) ? GasCosts::txDataNonZeroGas : GasCosts::txDataZeroGas;
+ }
+ else
+ gas = bigint(GasCosts::createDataGas) * _data.size();
+ assertThrow(gas < bigint(u256(-1)), OptimizerException, "Gas cost exceeds 256 bits.");
+ return u256(gas);
+}
diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h
index fc3740d2..7cb8015f 100644
--- a/libevmasm/GasMeter.h
+++ b/libevmasm/GasMeter.h
@@ -136,6 +136,9 @@ public:
/// change with EVM versions)
static unsigned runGas(Instruction _instruction);
+ /// @returns the gas cost of the supplied data, depending whether it is in creation code, or not.
+ static u256 dataGas(bytes const& _data, bool _inCreation);
+
private:
/// @returns _multiplier * (_value + 31) / 32, if _value is a known constant and infinite otherwise.
GasConsumption wordGas(u256 const& _multiplier, ExpressionClasses::Id _value);