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)]
|
2016-01-11 17:01:42 +01:00
|
|
|
pub enum Error {
|
2016-01-11 03:13:41 +01:00
|
|
|
/// `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,
|
2016-01-13 00:13:09 +01:00
|
|
|
/// `BadJumpDestination` is returned when execution tried to move
|
|
|
|
/// to position that wasn't marked with JUMPDEST instruction
|
2016-01-14 02:36:48 +01:00
|
|
|
BadJumpDestination {
|
|
|
|
destination: usize
|
|
|
|
},
|
2016-01-13 15:21:13 +01:00
|
|
|
/// `BadInstructions` is returned when given instruction is not supported
|
2016-01-14 02:36:48 +01:00
|
|
|
BadInstruction {
|
2016-01-14 02:45:16 +01:00
|
|
|
instruction: u8,
|
2016-01-14 02:36:48 +01:00
|
|
|
},
|
2016-01-13 15:21:13 +01:00
|
|
|
/// `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 {
|
|
|
|
instruction: &'static str,
|
|
|
|
wanted: usize,
|
|
|
|
on_stack: usize
|
|
|
|
},
|
2016-01-13 15:21:13 +01:00
|
|
|
/// When execution would exceed defined Stack Limit
|
2016-01-14 01:31:45 +01:00
|
|
|
OutOfStack {
|
|
|
|
instruction: &'static str,
|
|
|
|
wanted: usize,
|
|
|
|
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.
|
2016-01-11 17:01:42 +01:00
|
|
|
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-11 17:01:42 +01:00
|
|
|
fn exec(&self, params: &ActionParams, ext: &mut Ext) -> Result;
|
2015-12-28 22:37:15 +01:00
|
|
|
}
|