mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into merge_develop_060
This commit is contained in:
@@ -96,7 +96,7 @@ bigint ConstantOptimisationMethod::simpleRunGas(AssemblyItems const& _items)
|
||||
bigint ConstantOptimisationMethod::dataGas(bytes const& _data) const
|
||||
{
|
||||
assertThrow(_data.size() > 0, OptimizerException, "Empty bytecode generated.");
|
||||
return bigint(GasMeter::dataGas(_data, m_params.isCreation));
|
||||
return bigint(GasMeter::dataGas(_data, m_params.isCreation, m_params.evmVersion));
|
||||
}
|
||||
|
||||
size_t ConstantOptimisationMethod::bytesRequired(AssemblyItems const& _items)
|
||||
@@ -131,7 +131,7 @@ bigint LiteralMethod::gasNeeded() const
|
||||
return combineGas(
|
||||
simpleRunGas({Instruction::PUSH1}),
|
||||
// PUSHX plus data
|
||||
(m_params.isCreation ? GasCosts::txDataNonZeroGas : GasCosts::createDataGas) + dataGas(toCompactBigEndian(m_value, 1)),
|
||||
(m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas) + dataGas(toCompactBigEndian(m_value, 1)),
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ bigint CodeCopyMethod::gasNeeded() const
|
||||
// Run gas: we ignore memory increase costs
|
||||
simpleRunGas(copyRoutine()) + GasCosts::copyGas,
|
||||
// Data gas for copy routines: Some bytes are zero, but we ignore them.
|
||||
bytesRequired(copyRoutine()) * (m_params.isCreation ? GasCosts::txDataNonZeroGas : GasCosts::createDataGas),
|
||||
bytesRequired(copyRoutine()) * (m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas),
|
||||
// Data gas for data itself
|
||||
dataGas(toBigEndian(m_value))
|
||||
);
|
||||
@@ -322,7 +322,7 @@ bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) const
|
||||
return combineGas(
|
||||
simpleRunGas(_routine) + numExps * (GasCosts::expGas + GasCosts::expByteGas(m_params.evmVersion)),
|
||||
// Data gas for routine: Some bytes are zero, but we ignore them.
|
||||
bytesRequired(_routine) * (m_params.isCreation ? GasCosts::txDataNonZeroGas : GasCosts::createDataGas),
|
||||
bytesRequired(_routine) * (m_params.isCreation ? GasCosts::txDataNonZeroGas(m_params.evmVersion) : GasCosts::createDataGas),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -266,13 +266,13 @@ unsigned GasMeter::runGas(Instruction _instruction)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u256 GasMeter::dataGas(bytes const& _data, bool _inCreation)
|
||||
u256 GasMeter::dataGas(bytes const& _data, bool _inCreation, langutil::EVMVersion _evmVersion)
|
||||
{
|
||||
bigint gas = 0;
|
||||
if (_inCreation)
|
||||
{
|
||||
for (auto b: _data)
|
||||
gas += (b != 0) ? GasCosts::txDataNonZeroGas : GasCosts::txDataZeroGas;
|
||||
gas += (b != 0) ? GasCosts::txDataNonZeroGas(_evmVersion) : GasCosts::txDataZeroGas;
|
||||
}
|
||||
else
|
||||
gas = bigint(GasCosts::createDataGas) * _data.size();
|
||||
|
||||
+17
-4
@@ -53,7 +53,12 @@ namespace GasCosts
|
||||
}
|
||||
inline unsigned balanceGas(langutil::EVMVersion _evmVersion)
|
||||
{
|
||||
return _evmVersion >= langutil::EVMVersion::tangerineWhistle() ? 400 : 20;
|
||||
if (_evmVersion >= langutil::EVMVersion::istanbul())
|
||||
return 700;
|
||||
else if (_evmVersion >= langutil::EVMVersion::tangerineWhistle())
|
||||
return 400;
|
||||
else
|
||||
return 20;
|
||||
}
|
||||
static unsigned const expGas = 10;
|
||||
inline unsigned expByteGas(langutil::EVMVersion _evmVersion)
|
||||
@@ -64,7 +69,12 @@ namespace GasCosts
|
||||
static unsigned const keccak256WordGas = 6;
|
||||
inline unsigned sloadGas(langutil::EVMVersion _evmVersion)
|
||||
{
|
||||
return _evmVersion >= langutil::EVMVersion::tangerineWhistle() ? 200 : 50;
|
||||
if (_evmVersion >= langutil::EVMVersion::istanbul())
|
||||
return 800;
|
||||
else if (_evmVersion >= langutil::EVMVersion::tangerineWhistle())
|
||||
return 200;
|
||||
else
|
||||
return 50;
|
||||
}
|
||||
static unsigned const sstoreSetGas = 20000;
|
||||
static unsigned const sstoreResetGas = 5000;
|
||||
@@ -92,7 +102,10 @@ namespace GasCosts
|
||||
static unsigned const txGas = 21000;
|
||||
static unsigned const txCreateGas = 53000;
|
||||
static unsigned const txDataZeroGas = 4;
|
||||
static unsigned const txDataNonZeroGas = 68;
|
||||
inline unsigned txDataNonZeroGas(langutil::EVMVersion _evmVersion)
|
||||
{
|
||||
return _evmVersion >= langutil::EVMVersion::istanbul() ? 16 : 68;
|
||||
}
|
||||
static unsigned const copyGas = 3;
|
||||
}
|
||||
|
||||
@@ -139,7 +152,7 @@ public:
|
||||
/// @returns the gas cost of the supplied data, depending whether it is in creation code, or not.
|
||||
/// In case of @a _inCreation, the data is only sent as a transaction and is not stored, whereas
|
||||
/// otherwise code will be stored and have to pay "createDataGas" cost.
|
||||
static u256 dataGas(bytes const& _data, bool _inCreation);
|
||||
static u256 dataGas(bytes const& _data, bool _inCreation, langutil::EVMVersion _evmVersion);
|
||||
|
||||
private:
|
||||
/// @returns _multiplier * (_value + 31) / 32, if _value is a known constant and infinite otherwise.
|
||||
|
||||
Reference in New Issue
Block a user