Browse Source

Change VM interface to return a copy of output.

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

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::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _step)
bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _step)
{
using namespace jit;
@ -33,7 +33,7 @@ bytesConstRef JitVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, ui
{
cwarn << "Execution rejected by EVM JIT (gas limit: " << io_gas << "), executing with interpreter";
m_fallbackVM = VMFactory::create(VMKind::Interpreter);
return m_fallbackVM->go(io_gas, _ext, _onOp, _step);
return m_fallbackVM->execImpl(io_gas, _ext, _onOp, _step);
}
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 go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
private:
jit::RuntimeData m_data;

12
libethereum/Executive.cpp

@ -46,7 +46,7 @@ u256 Executive::gasUsed() const
ExecutionResult Executive::executionResult() const
{
return ExecutionResult(gasUsed(), m_excepted, m_newAddress, m_out, m_codeDeposit, m_ext ? m_ext->sub.refunds : 0, m_depositSize, m_gasForDeposit);
return ExecutionResult(gasUsed(), m_excepted, m_newAddress, out(), m_codeDeposit, m_ext ? m_ext->sub.refunds : 0, m_depositSize, m_gasForDeposit);
}
void Executive::accrueSubState(SubState& _parentContext)
@ -145,8 +145,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co
else
{
m_gas = (u256)(_p.gas - g);
m_precompiledOut = it->second.exec(_p.data);
m_out = &m_precompiledOut;
m_out = it->second.exec(_p.data);
}
}
else
@ -219,7 +218,7 @@ bool Executive::go(OnOpFunc const& _onOp)
#endif
try
{
m_out = m_vm->go(m_gas, *m_ext, _onOp);
m_out = m_vm->exec(m_gas, *m_ext, _onOp);
if (m_isCreation)
{
@ -232,11 +231,10 @@ bool Executive::go(OnOpFunc const& _onOp)
}
else
{
m_codeDeposit = CodeDeposit::Failed;
m_out.reset();
m_out.clear();
}
m_s.m_cache[m_newAddress].setCode(m_out.toBytes());
m_s.m_cache[m_newAddress].setCode(std::move(m_out));
}
}
catch (StepsDone const&)

5
libethereum/Executive.h

@ -109,7 +109,7 @@ public:
/// @returns gas remaining after the transaction/operation. Valid after the transaction has been executed.
u256 gas() const { return m_gas; }
/// @returns output data of the transaction/operation.
bytesConstRef out() const { return m_out; }
bytesConstRef out() const { return {m_out.data(), m_out.size()}; }
/// @returns the new address for the created contract in the CREATE operation.
h160 newAddress() const { return m_newAddress; }
/// @returns true iff the operation ended with a VM exception.
@ -123,8 +123,7 @@ private:
LastHashes m_lastHashes;
std::shared_ptr<ExtVM> m_ext; ///< The VM externality object for the VM execution or null if no VM is required.
std::unique_ptr<VMFace> m_vm; ///< The VM object or null if no VM is required.
bytes m_precompiledOut; ///< Used for the output when there is no VM for a contract (i.e. precompiled).
bytesConstRef m_out; ///< The copyable output.
bytes m_out; ///< The VM execution output.
Address m_newAddress; ///< The address of the created contract in the case of create() being called.
unsigned m_depth = 0; ///< The context's call-depth.

4
libevm/SmartVM.cpp

@ -41,7 +41,7 @@ namespace
}
}
bytesConstRef SmartVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
bytesConstRef SmartVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{
auto codeHash = sha3(_ext.code);
auto vmKind = VMKind::Interpreter; // default VM
@ -68,7 +68,7 @@ bytesConstRef SmartVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp,
// 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->go(io_gas, _ext, _onOp, _steps);
return m_selectedVM->execImpl(io_gas, _ext, _onOp, _steps);
}
}

2
libevm/SmartVM.h

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

2
libevm/VM.cpp

@ -45,7 +45,7 @@ static array<InstructionMetric, 256> metrics()
return s_ret;
}
bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{
// Reset leftovers from possible previous run
m_curPC = 0;

2
libevm/VM.h

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

7
libevm/VMFace.h

@ -43,7 +43,12 @@ public:
VMFace(VMFace const&) = delete;
VMFace& operator=(VMFace const&) = delete;
virtual bytesConstRef go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0;
bytes exec(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1)
{
return execImpl(io_gas, _ext, _onOp, _steps).toVector();
}
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0;
};
}

4
test/fuzzTesting/checkRandomVMTest.cpp

@ -98,9 +98,9 @@ bool doVMTest(mValue& _v)
try
{
auto vm = eth::VMFactory::create();
output = vm->go(fev.gas, fev, fev.simpleTrace()).toBytes();
output = vm->exec(fev.gas, fev, fev.simpleTrace());
}
catch (eth::VMException)
catch (eth::VMException const&)
{
cnote << "Safe VM Exception";
vmExceptionOccured = true;

2
test/fuzzTesting/createRandomVMTest.cpp

@ -160,7 +160,7 @@ void doMyTests(json_spirit::mValue& _v)
bool vmExceptionOccured = false;
try
{
output = vm->go(fev.gas, fev, fev.simpleTrace()).toBytes();
output = vm->exec(fev.gas, fev, fev.simpleTrace());
}
catch (eth::VMException const& _e)
{

4
test/libevm/vm.cpp

@ -329,12 +329,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
{
auto vm = eth::VMFactory::create();
auto vmtrace = Options::get().vmtrace ? fev.simpleTrace() : OnOpFunc{};
auto outputRef = bytesConstRef{};
{
Listener::ExecTimeGuard guard{i.first};
outputRef = vm->go(fev.gas, fev, vmtrace);
output = vm->exec(fev.gas, fev, vmtrace);
}
output = outputRef.toBytes();
}
catch (VMException const&)
{

Loading…
Cancel
Save