diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-08-09 06:13:28 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-09-18 21:47:53 +0800 |
commit | 0b68d093b45b71bf976f8cf37a6b917aa29ac4e3 (patch) | |
tree | 958526e30f790578847c5500235262c7a6efe010 /libevmasm/GasMeter.cpp | |
parent | 47b8d998d13ad7365a897fc52496bf5fa1222040 (diff) | |
download | dexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.tar.gz dexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.tar.zst dexon-solidity-0b68d093b45b71bf976f8cf37a6b917aa29ac4e3.zip |
Move dataGas calculation helper to GasMeter
Diffstat (limited to 'libevmasm/GasMeter.cpp')
-rw-r--r-- | libevmasm/GasMeter.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
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); +} |