Decouple virtual machines (#6184)

* work in progress for splitting vms

* evm working

* Evm -> Vm

* wasm converted

* ethcore working

* test fixes
This commit is contained in:
Nikolay Volf
2017-08-01 13:37:57 +03:00
committed by GitHub
parent c4025622de
commit b7006034b1
65 changed files with 534 additions and 400 deletions

View File

@@ -23,17 +23,21 @@ mod stack;
mod memory;
mod shared_cache;
use std::marker::PhantomData;
use vm::{
self, ActionParams, ActionValue, CallType, MessageCallResult,
ContractCreateResult, CreateContractAddress, ReturnData, GasLeft
};
use evm::CostType;
use instructions::{self, Instruction, InstructionInfo};
use self::gasometer::Gasometer;
use self::stack::{Stack, VecStack};
use self::memory::Memory;
pub use self::shared_cache::SharedCache;
use std::marker::PhantomData;
use action_params::{ActionParams, ActionValue};
use call_type::CallType;
use instructions::{self, Instruction, InstructionInfo};
use evm::{self, GasLeft, CostType, ReturnData};
use ext::{self, MessageCallResult, ContractCreateResult, CreateContractAddress};
use bit_set::BitSet;
use util::*;
@@ -107,8 +111,8 @@ pub struct Interpreter<Cost: CostType> {
_type: PhantomData<Cost>,
}
impl<Cost: CostType> evm::Evm for Interpreter<Cost> {
fn exec(&mut self, params: ActionParams, ext: &mut ext::Ext) -> evm::Result<GasLeft> {
impl<Cost: CostType> vm::Vm for Interpreter<Cost> {
fn exec(&mut self, params: ActionParams, ext: &mut vm::Ext) -> vm::Result<GasLeft> {
self.mem.clear();
let mut informant = informant::EvmInformant::new(ext.depth());
@@ -205,7 +209,7 @@ impl<Cost: CostType> Interpreter<Cost> {
}
}
fn verify_instruction(&self, ext: &ext::Ext, instruction: Instruction, info: &InstructionInfo, stack: &Stack<U256>) -> evm::Result<()> {
fn verify_instruction(&self, ext: &vm::Ext, instruction: Instruction, info: &InstructionInfo, stack: &Stack<U256>) -> vm::Result<()> {
let schedule = ext.schedule();
if (instruction == instructions::DELEGATECALL && !schedule.have_delegate_call) ||
@@ -214,25 +218,25 @@ impl<Cost: CostType> Interpreter<Cost> {
((instruction == instructions::RETURNDATACOPY || instruction == instructions::RETURNDATASIZE) && !schedule.have_return_data) ||
(instruction == instructions::REVERT && !schedule.have_revert) {
return Err(evm::Error::BadInstruction {
return Err(vm::Error::BadInstruction {
instruction: instruction
});
}
if info.tier == instructions::GasPriceTier::Invalid {
return Err(evm::Error::BadInstruction {
return Err(vm::Error::BadInstruction {
instruction: instruction
});
}
if !stack.has(info.args) {
Err(evm::Error::StackUnderflow {
Err(vm::Error::StackUnderflow {
instruction: info.name,
wanted: info.args,
on_stack: stack.size()
})
} else if stack.size() - info.args + info.ret > schedule.stack_limit {
Err(evm::Error::OutOfStack {
Err(vm::Error::OutOfStack {
instruction: info.name,
wanted: info.ret - info.args,
limit: schedule.stack_limit
@@ -272,12 +276,12 @@ impl<Cost: CostType> Interpreter<Cost> {
&mut self,
gas: Cost,
params: &ActionParams,
ext: &mut ext::Ext,
ext: &mut vm::Ext,
instruction: Instruction,
code: &mut CodeReader,
stack: &mut Stack<U256>,
provided: Option<Cost>
) -> evm::Result<InstructionResult<Cost>> {
) -> vm::Result<InstructionResult<Cost>> {
match instruction {
instructions::JUMP => {
let jump = stack.pop_back();
@@ -593,13 +597,13 @@ impl<Cost: CostType> Interpreter<Cost> {
}
}
fn verify_jump(&self, jump_u: U256, valid_jump_destinations: &BitSet) -> evm::Result<usize> {
fn verify_jump(&self, jump_u: U256, valid_jump_destinations: &BitSet) -> vm::Result<usize> {
let jump = jump_u.low_u64() as usize;
if valid_jump_destinations.contains(jump) && U256::from(jump) == jump_u {
Ok(jump)
} else {
Err(evm::Error::BadJumpDestination {
Err(vm::Error::BadJumpDestination {
destination: jump
})
}
@@ -617,7 +621,7 @@ impl<Cost: CostType> Interpreter<Cost> {
}
}
fn exec_stack_instruction(&self, instruction: Instruction, stack: &mut Stack<U256>) -> evm::Result<()> {
fn exec_stack_instruction(&self, instruction: Instruction, stack: &mut Stack<U256>) -> vm::Result<()> {
match instruction {
instructions::DUP1...instructions::DUP16 => {
let position = instructions::get_dup_position(instruction);
@@ -822,7 +826,7 @@ impl<Cost: CostType> Interpreter<Cost> {
}
},
_ => {
return Err(evm::Error::BadInstruction {
return Err(vm::Error::BadInstruction {
instruction: instruction
});
}