From 0d004524f3ecef7074cd618f4e3a84c1b7fd5432 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 2 Mar 2015 15:30:22 +0100 Subject: [PATCH] New gas pricing for PoC-9. --- libethereum/ExtVM.h | 2 +- libevm/VM.cpp | 14 ++++++++------ libevmcore/Instruction.cpp | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index d63cd943a..a4ab7ead3 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -70,7 +70,7 @@ public: virtual u256 txCount(Address _a) override final { return m_s.transactionsFrom(_a); } /// Does the account exist? - virtual bool exists(Address _a) override final { return m_s.addressInUse(_a); } + virtual bool exists(Address _a) { return m_s.addressInUse(_a); } /// Suicide the associated contract to the given address. virtual void suicide(Address _a) override final diff --git a/libevm/VM.cpp b/libevm/VM.cpp index e0b487c9b..9f2fa6874 100644 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -82,13 +82,19 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) BOOST_THROW_EXCEPTION(BadInstruction()); // FEES... - bigint runGas = c_tierStepGas[metric.gasPriceTier]; + bigint runGas; bigint newTempSize = m_temp.size(); bigint copySize = 0; // should work, but just seems to result in immediate errorless exit on initial execution. yeah. weird. //m_onFail = std::function(onOperation); + auto metric = c_metrics[(int)inst]; + int gasPriceTier = metric.gasPriceTier; + if (gasPriceTier == InvalidTier) + BOOST_THROW_EXCEPTION(BadInstruction()); + else + runGas = c_tierStepGas[metric.gasPriceTier]; require(metric.args); auto onOperation = [&]() @@ -145,10 +151,6 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) newTempSize = memNeed(m_stack[m_stack.size() - 2], m_stack[m_stack.size() - 4]); break; - case Instruction::JUMPDEST: - runGas = 1; - break; - case Instruction::LOG0: case Instruction::LOG1: case Instruction::LOG2: @@ -164,7 +166,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) case Instruction::CALL: case Instruction::CALLCODE: runGas = (bigint)c_callGas + m_stack[m_stack.size() - 1]; - if (inst != Instruction::CALLCODE && !_ext.exists(asAddress(m_stack[m_stack.size() - 2]))) + if (!_ext.exists(asAddress(m_stack[m_stack.size() - 2]))) runGas += c_callNewAccountGas; if (m_stack[m_stack.size() - 3] > 0) runGas += c_callValueTransferGas; diff --git a/libevmcore/Instruction.cpp b/libevmcore/Instruction.cpp index 23f19ac94..eba075a4d 100644 --- a/libevmcore/Instruction.cpp +++ b/libevmcore/Instruction.cpp @@ -217,7 +217,7 @@ static const std::map c_instructionInfo = { Instruction::PC, { "PC", 0, 0, 1, false, BaseTier } }, { Instruction::MSIZE, { "MSIZE", 0, 0, 1, false, BaseTier } }, { Instruction::GAS, { "GAS", 0, 0, 1, false, BaseTier } }, - { Instruction::JUMPDEST, { "JUMPDEST", 0, 0, 0, true, SpecialTier } }, + { Instruction::JUMPDEST, { "JUMPDEST", 0, 1, 0, true, SpecialTier } }, { Instruction::PUSH1, { "PUSH1", 1, 0, 1, false, VeryLowTier } }, { Instruction::PUSH2, { "PUSH2", 2, 0, 1, false, VeryLowTier } }, { Instruction::PUSH3, { "PUSH3", 3, 0, 1, false, VeryLowTier } },