aboutsummaryrefslogtreecommitdiffstats
path: root/ConstantOptimiser.cpp
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2015-11-21 21:33:55 +0800
committerGav Wood <i@gavwood.com>2015-11-21 21:33:55 +0800
commit6e98243ead4843a4dd28fcae312f3b8af6cc7b03 (patch)
tree037736e4017eb7f03da4f8dadc61bdbd1baf4e43 /ConstantOptimiser.cpp
parent5caad351f88e54afa6c38074938c18705fdd319c (diff)
downloaddexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar.gz
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar.bz2
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar.lz
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar.xz
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.tar.zst
dexon-solidity-6e98243ead4843a4dd28fcae312f3b8af6cc7b03.zip
EIP-2.1 Fixes #96.
Address a few concerns from prior code review.
Diffstat (limited to 'ConstantOptimiser.cpp')
-rw-r--r--ConstantOptimiser.cpp20
1 files changed, 10 insertions, 10 deletions
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 <libevmasm/Assembly.h>
#include <libevmasm/GasMeter.h>
-#include <libevmcore/Params.h>
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
);
}