openethereum/src/evm/evm.rs

40 lines
1.4 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,
/// `BadInstructions` is returned when given instruction is not supported
BadInstruction,
/// `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
StackUnderflow(/*wanted*/usize, /*on_stack*/usize),
/// When execution would exceed defined Stack Limit
OutOfStack(/*wanted*/usize, /*stack_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.
fn exec(&self, params: &ActionParams, ext: &mut Ext) -> Result;
2015-12-28 22:37:15 +01:00
}