Merge pull request #5089 from ethereum/gasmeter

Small pathgasmeter cleanups
This commit is contained in:
Alex Beregszaszi 2018-09-26 15:16:38 +01:00 committed by GitHub
commit 410d94c498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View File

@ -101,8 +101,8 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
break; break;
case Instruction::KECCAK256: case Instruction::KECCAK256:
gas = GasCosts::keccak256Gas; gas = GasCosts::keccak256Gas;
gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1));
gas += memoryGas(0, -1); gas += memoryGas(0, -1);
gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1));
break; break;
case Instruction::CALLDATACOPY: case Instruction::CALLDATACOPY:
case Instruction::CODECOPY: case Instruction::CODECOPY:
@ -214,7 +214,7 @@ GasMeter::GasConsumption GasMeter::memoryGas(ExpressionClasses::Id _position)
if (!value) if (!value)
return GasConsumption::infinite(); return GasConsumption::infinite();
if (*value < m_largestMemoryAccess) if (*value < m_largestMemoryAccess)
return GasConsumption(u256(0)); return GasConsumption(0);
u256 previous = m_largestMemoryAccess; u256 previous = m_largestMemoryAccess;
m_largestMemoryAccess = *value; m_largestMemoryAccess = *value;
auto memGas = [=](u256 const& pos) -> u256 auto memGas = [=](u256 const& pos) -> u256

View File

@ -137,6 +137,8 @@ public:
static unsigned runGas(Instruction _instruction); static unsigned runGas(Instruction _instruction);
/// @returns the gas cost of the supplied data, depending whether it is in creation code, or not. /// @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);
private: private:

View File

@ -57,6 +57,16 @@ public:
GasMeter::GasConsumption estimateMax(size_t _startIndex, std::shared_ptr<KnownState> const& _state); GasMeter::GasConsumption estimateMax(size_t _startIndex, std::shared_ptr<KnownState> const& _state);
static GasMeter::GasConsumption estimateMax(
AssemblyItems const& _items,
solidity::EVMVersion _evmVersion,
size_t _startIndex,
std::shared_ptr<KnownState> const& _state
)
{
return PathGasMeter(_items, _evmVersion).estimateMax(_startIndex, _state);
}
private: private:
/// Adds a new path item to the queue, but only if we do not already have /// Adds a new path item to the queue, but only if we do not already have
/// a higher gas usage at that point. /// a higher gas usage at that point.

View File

@ -160,8 +160,7 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation(
); );
} }
PathGasMeter meter(_items, m_evmVersion); return PathGasMeter::estimateMax(_items, m_evmVersion, 0, state);
return meter.estimateMax(0, state);
} }
GasEstimator::GasConsumption GasEstimator::functionalEstimation( GasEstimator::GasConsumption GasEstimator::functionalEstimation(
@ -183,7 +182,7 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation(
if (parametersSize > 0) if (parametersSize > 0)
state->feedItem(swapInstruction(parametersSize)); state->feedItem(swapInstruction(parametersSize));
return PathGasMeter(_items, m_evmVersion).estimateMax(_offset, state); return PathGasMeter::estimateMax(_items, m_evmVersion, _offset, state);
} }
set<ASTNode const*> GasEstimator::finestNodesAtLocation( set<ASTNode const*> GasEstimator::finestNodesAtLocation(