From 6e98243ead4843a4dd28fcae312f3b8af6cc7b03 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 21 Nov 2015 14:33:55 +0100 Subject: EIP-2.1 Fixes #96. Address a few concerns from prior code review. --- ConstantOptimiser.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ConstantOptimiser.cpp') diff --git a/ConstantOptimiser.cpp b/ConstantOptimiser.cpp index 88874d81..0ebe2eab 100644 --- a/ConstantOptimiser.cpp +++ b/ConstantOptimiser.cpp @@ -22,7 +22,6 @@ #include "libevmasm/ConstantOptimiser.h" #include #include -#include using namespace std; using namespace dev; using namespace dev::eth; @@ -70,12 +69,13 @@ unsigned ConstantOptimisationMethod::optimiseConstants( bigint ConstantOptimisationMethod::simpleRunGas(AssemblyItems const& _items) { + EVMSchedule schedule; // TODO: make relevant to context. bigint gas = 0; for (AssemblyItem const& item: _items) if (item.type() == Push) - gas += GasMeter::runGas(Instruction::PUSH1); + gas += GasMeter::runGas(Instruction::PUSH1, schedule); else if (item.type() == Operation) - gas += GasMeter::runGas(item.instruction()); + gas += GasMeter::runGas(item.instruction(), schedule); return gas; } @@ -85,11 +85,11 @@ bigint ConstantOptimisationMethod::dataGas(bytes const& _data) const { bigint gas; for (auto b: _data) - gas += b ? c_txDataNonZeroGas : c_txDataZeroGas; + gas += b ? m_schedule.txDataNonZeroGas : m_schedule.txDataZeroGas; return gas; } else - return c_createDataGas * dataSize(); + return m_schedule.createDataGas * dataSize(); } size_t ConstantOptimisationMethod::bytesRequired(AssemblyItems const& _items) @@ -121,7 +121,7 @@ bigint LiteralMethod::gasNeeded() return combineGas( simpleRunGas({Instruction::PUSH1}), // PUSHX plus data - (m_params.isCreation ? c_txDataNonZeroGas : c_createDataGas) + dataGas(), + (m_params.isCreation ? m_schedule.txDataNonZeroGas : m_schedule.createDataGas) + dataGas(), 0 ); } @@ -148,9 +148,9 @@ bigint CodeCopyMethod::gasNeeded() { return combineGas( // Run gas: we ignore memory increase costs - simpleRunGas(m_copyRoutine) + c_copyGas, + simpleRunGas(m_copyRoutine) + m_schedule.copyGas, // Data gas for copy routines: Some bytes are zero, but we ignore them. - bytesRequired(m_copyRoutine) * (m_params.isCreation ? c_txDataNonZeroGas : c_createDataGas), + bytesRequired(m_copyRoutine) * (m_params.isCreation ? m_schedule.txDataNonZeroGas : m_schedule.createDataGas), // Data gas for data itself dataGas(toBigEndian(m_value)) ); @@ -217,9 +217,9 @@ bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) { size_t numExps = count(_routine.begin(), _routine.end(), Instruction::EXP); return combineGas( - simpleRunGas(_routine) + numExps * (c_expGas + c_expByteGas), + simpleRunGas(_routine) + numExps * (m_schedule.expGas + m_schedule.expByteGas), // Data gas for routine: Some bytes are zero, but we ignore them. - bytesRequired(_routine) * (m_params.isCreation ? c_txDataNonZeroGas : c_createDataGas), + bytesRequired(_routine) * (m_params.isCreation ? m_schedule.txDataNonZeroGas : m_schedule.createDataGas), 0 ); } -- cgit v1.2.3