openethereum/ethcore/src/evm/evm.rs

60 lines
1.8 KiB
Rust
Raw Normal View History

2015-12-30 12:46:10 +01:00
//! Evm interface.
2015-12-28 22:37:15 +01:00
2016-01-11 16:33:08 +01:00
use common::*;
use evm::Ext;
2015-12-28 22:37:15 +01:00
2016-01-11 02:17:29 +01:00
/// Evm errors.
2016-01-11 14:08:03 +01:00
#[derive(Debug)]
pub enum Error {
/// `OutOfGas` is returned when transaction execution runs out of gas.
2016-01-11 02:17:29 +01:00
/// The state should be reverted to the state from before the
/// transaction execution. But it does not mean that transaction
/// was invalid. Balance still should be transfered and nonce
/// should be increased.
2015-12-28 22:37:15 +01:00
OutOfGas,
/// `BadJumpDestination` is returned when execution tried to move
/// to position that wasn't marked with JUMPDEST instruction
BadJumpDestination {
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
destination: usize
},
/// `BadInstructions` is returned when given instruction is not supported
BadInstruction {
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 02:45:16 +01:00
instruction: u8,
},
/// `StackUnderflow` when there is not enough stack elements to execute instruction
/// First parameter says how many elements were needed and the second how many were actually on Stack
2016-01-14 01:31:45 +01:00
StackUnderflow {
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
instruction: &'static str,
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
wanted: usize,
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
on_stack: usize
},
/// When execution would exceed defined Stack Limit
2016-01-14 01:31:45 +01:00
OutOfStack {
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
instruction: &'static str,
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
wanted: usize,
2016-01-19 17:02:01 +01:00
/// TODO [Tomusdrw] Please document me
2016-01-14 01:31:45 +01:00
limit: usize
},
2016-01-11 02:17:29 +01:00
/// Returned on evm internal error. Should never be ignored during development.
/// Likely to cause consensus issues.
Internal,
2015-12-28 22:37:15 +01:00
}
2016-01-11 02:17:29 +01:00
/// Evm result.
///
/// Returns gas_left if execution is successfull, otherwise error.
pub type Result = result::Result<U256, Error>;
2016-01-11 02:17:29 +01:00
/// Evm interface.
2015-12-28 22:37:15 +01:00
pub trait Evm {
2016-01-11 02:17:29 +01:00
/// This function should be used to execute transaction.
2016-01-16 20:11:12 +01:00
fn exec(&self, params: ActionParams, ext: &mut Ext) -> Result;
2015-12-28 22:37:15 +01:00
}