mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move dataGas calculation helper to GasMeter
This commit is contained in:
parent
47b8d998d1
commit
0b68d093b4
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user