aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-08-09 06:13:28 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-09-18 21:47:53 +0800
commit0b68d093b45b71bf976f8cf37a6b917aa29ac4e3 (patch)
tree958526e30f790578847c5500235262c7a6efe010 /libevmasm
parent47b8d998d13ad7365a897fc52496bf5fa1222040 (diff)
downloaddexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.tar.gz
dexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.tar.zst
dexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.zip
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);