diff options
-rw-r--r-- | libevmasm/GasMeter.cpp | 4 | ||||
-rw-r--r-- | libevmasm/GasMeter.h | 2 | ||||
-rw-r--r-- | libevmasm/PathGasMeter.h | 10 | ||||
-rw-r--r-- | libsolidity/interface/GasEstimator.cpp | 5 |
4 files changed, 16 insertions, 5 deletions
diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp index b525c301..b40617c1 100644 --- a/libevmasm/GasMeter.cpp +++ b/libevmasm/GasMeter.cpp @@ -101,8 +101,8 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _ break; case Instruction::KECCAK256: gas = GasCosts::keccak256Gas; - gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1)); gas += memoryGas(0, -1); + gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1)); break; case Instruction::CALLDATACOPY: case Instruction::CODECOPY: @@ -214,7 +214,7 @@ GasMeter::GasConsumption GasMeter::memoryGas(ExpressionClasses::Id _position) if (!value) return GasConsumption::infinite(); if (*value < m_largestMemoryAccess) - return GasConsumption(u256(0)); + return GasConsumption(0); u256 previous = m_largestMemoryAccess; m_largestMemoryAccess = *value; auto memGas = [=](u256 const& pos) -> u256 diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h index 7cb8015f..da90b028 100644 --- a/libevmasm/GasMeter.h +++ b/libevmasm/GasMeter.h @@ -137,6 +137,8 @@ public: static unsigned runGas(Instruction _instruction); /// @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); private: diff --git a/libevmasm/PathGasMeter.h b/libevmasm/PathGasMeter.h index 9537b176..fb821684 100644 --- a/libevmasm/PathGasMeter.h +++ b/libevmasm/PathGasMeter.h @@ -57,6 +57,16 @@ public: 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: /// Adds a new path item to the queue, but only if we do not already have /// a higher gas usage at that point. diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index a532f86e..e70e23a2 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -160,8 +160,7 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation( ); } - PathGasMeter meter(_items, m_evmVersion); - return meter.estimateMax(0, state); + return PathGasMeter::estimateMax(_items, m_evmVersion, 0, state); } GasEstimator::GasConsumption GasEstimator::functionalEstimation( @@ -183,7 +182,7 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation( if (parametersSize > 0) 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( |