Browse Source

Kill steps limit option in VM.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
f042abc3e7
  1. 4
      evmjit/libevmjit-cpp/JitVM.cpp
  2. 2
      evmjit/libevmjit-cpp/JitVM.h
  3. 4
      libethereum/Executive.cpp
  4. 4
      libevm/SmartVM.cpp
  5. 2
      libevm/SmartVM.h
  6. 9
      libevm/VM.cpp
  7. 2
      libevm/VM.h
  8. 11
      libevm/VMFace.h

4
evmjit/libevmjit-cpp/JitVM.cpp

@ -18,7 +18,7 @@ namespace eth
extern "C" void env_sload(); // fake declaration for linker symbol stripping workaround, see a call below
bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _step)
bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{
using namespace jit;
@ -33,7 +33,7 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on
{
cwarn << "Execution rejected by EVM JIT (gas limit: " << io_gas << "), executing with interpreter";
m_fallbackVM = VMFactory::create(VMKind::Interpreter);
return m_fallbackVM->execImpl(io_gas, _ext, _onOp, _step);
return m_fallbackVM->execImpl(io_gas, _ext, _onOp);
}
m_data.gas = static_cast<decltype(m_data.gas)>(io_gas);

2
evmjit/libevmjit-cpp/JitVM.h

@ -11,7 +11,7 @@ namespace eth
class JitVM: public VMFace
{
public:
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) override final;
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
private:
jit::RuntimeData m_data;

4
libethereum/Executive.cpp

@ -246,10 +246,6 @@ bool Executive::go(OnOpFunc const& _onOp)
vm->exec(m_gas, *m_ext, m_outRef, _onOp); // take only expected output
}
}
catch (StepsDone const&)
{
return false;
}
catch (VMException const& _e)
{
clog(StateSafeExceptions) << "Safe VM Exception. " << diagnostic_information(_e);

4
libevm/SmartVM.cpp

@ -41,7 +41,7 @@ namespace
}
}
bytesConstRef SmartVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
bytesConstRef SmartVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{
auto codeHash = sha3(_ext.code);
auto vmKind = VMKind::Interpreter; // default VM
@ -68,7 +68,7 @@ bytesConstRef SmartVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _
// TODO: Selected VM must be kept only because it returns reference to its internal memory.
// VM implementations should be stateless, without escaping memory reference.
m_selectedVM = VMFactory::create(vmKind);
return m_selectedVM->execImpl(io_gas, _ext, _onOp, _steps);
return m_selectedVM->execImpl(io_gas, _ext, _onOp);
}
}

2
libevm/SmartVM.h

@ -31,7 +31,7 @@ namespace eth
class SmartVM: public VMFace
{
public:
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) override final;
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
private:
std::unique_ptr<VMFace> m_selectedVM;

9
libevm/VM.cpp

@ -45,7 +45,7 @@ static array<InstructionMetric, 256> metrics()
return s_ret;
}
bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{
// Reset leftovers from possible previous run
m_curPC = 0;
@ -73,8 +73,7 @@ bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp,
i += _ext.code[i] - (unsigned)Instruction::PUSH1 + 1;
}
u256 nextPC = m_curPC + 1;
auto osteps = _steps;
for (bool stopped = false; !stopped && _steps--; m_curPC = nextPC, nextPC = m_curPC + 1)
for (uint64_t steps = 0; true; m_curPC = nextPC, nextPC = m_curPC + 1, ++steps)
{
// INSTRUCTION...
Instruction inst = (Instruction)_ext.getCode(m_curPC);
@ -97,7 +96,7 @@ bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp,
auto onOperation = [&]()
{
if (_onOp)
_onOp(osteps - _steps - 1, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, io_gas, this, &_ext);
_onOp(steps, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, io_gas, this, &_ext);
};
switch (inst)
@ -670,7 +669,5 @@ bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp,
}
}
if (_steps == (uint64_t)-1)
BOOST_THROW_EXCEPTION(StepsDone());
return bytesConstRef();
}

2
libevm/VM.h

@ -52,7 +52,7 @@ inline u256 fromAddress(Address _a)
class VM: public VMFace
{
public:
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) override final;
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
u256 curPC() const { return m_curPC; }

11
libevm/VMFace.h

@ -26,7 +26,6 @@ namespace eth
{
struct VMException: virtual Exception {};
struct StepsDone: virtual VMException {};
struct BreakPointHit: virtual VMException {};
struct BadInstruction: virtual VMException {};
struct BadJumpDestination: virtual VMException {};
@ -46,19 +45,19 @@ public:
/// Execute EVM code by VM.
///
/// @param _out Expected output
void exec(u256& io_gas, ExtVMFace& _ext, bytesRef _out, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1)
void exec(u256& io_gas, ExtVMFace& _ext, bytesRef _out, OnOpFunc const& _onOp = {})
{
execImpl(io_gas, _ext, _onOp, _steps).copyTo(_out);
execImpl(io_gas, _ext, _onOp).copyTo(_out);
}
/// The same as above but returns a copy of full output.
bytes exec(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1)
bytes exec(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {})
{
return execImpl(io_gas, _ext, _onOp, _steps).toVector();
return execImpl(io_gas, _ext, _onOp).toVector();
}
/// VM implementation
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) = 0;
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) = 0;
};
}

Loading…
Cancel
Save