eva_asm/instruction/
system.rs

1//! System and SHA3 operations.
2
3use derive_more::Display;
4
5use crate::{
6    instruction::Instruction,
7    opcode::{Mnemonic, OpCode},
8};
9
10/// Compute Keccak-256 hash.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
12#[display("{}", self.opcode())]
13pub struct Keccak256;
14
15impl Instruction for Keccak256 {
16    fn opcode(&self) -> OpCode {
17        OpCode::Known(Mnemonic::KECCAK256)
18    }
19}
20
21/// Create a new account with associated code.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
23#[display("{}", self.opcode())]
24pub struct Create;
25
26impl Instruction for Create {
27    fn opcode(&self) -> OpCode {
28        OpCode::Known(Mnemonic::CREATE)
29    }
30}
31
32/// Message-call into an account.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
34#[display("{}", self.opcode())]
35pub struct Call;
36
37impl Instruction for Call {
38    fn opcode(&self) -> OpCode {
39        OpCode::Known(Mnemonic::CALL)
40    }
41}
42
43/// Message-call into this account with alternative account’s code.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
45#[display("{}", self.opcode())]
46pub struct CallCode;
47
48impl Instruction for CallCode {
49    fn opcode(&self) -> OpCode {
50        OpCode::Known(Mnemonic::CALLCODE)
51    }
52}
53
54/// Halt execution returning output data.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
56#[display("{}", self.opcode())]
57pub struct Return;
58
59impl Instruction for Return {
60    fn opcode(&self) -> OpCode {
61        OpCode::Known(Mnemonic::RETURN)
62    }
63}
64
65/// Message-call into this account with an alternative account’s code, but persisting the current values for sender and value.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
67#[display("{}", self.opcode())]
68pub struct DelegateCall;
69
70impl Instruction for DelegateCall {
71    fn opcode(&self) -> OpCode {
72        OpCode::Known(Mnemonic::DELEGATECALL)
73    }
74}
75
76/// Create a new account with associated code at a predictable address.
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
78#[display("{}", self.opcode())]
79pub struct Create2;
80
81impl Instruction for Create2 {
82    fn opcode(&self) -> OpCode {
83        OpCode::Known(Mnemonic::CREATE2)
84    }
85}
86
87/// Static message-call into an account.
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
89#[display("{}", self.opcode())]
90pub struct StaticCall;
91
92impl Instruction for StaticCall {
93    fn opcode(&self) -> OpCode {
94        OpCode::Known(Mnemonic::STATICCALL)
95    }
96}
97
98/// Halt execution reverting state changes but returning data and remaining gas.
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
100#[display("{}", self.opcode())]
101pub struct Revert;
102
103impl Instruction for Revert {
104    fn opcode(&self) -> OpCode {
105        OpCode::Known(Mnemonic::REVERT)
106    }
107}
108
109/// Designated invalid instruction.
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
111#[display("{}", self.opcode())]
112pub struct Invalid;
113
114impl Instruction for Invalid {
115    fn opcode(&self) -> OpCode {
116        OpCode::Known(Mnemonic::INVALID)
117    }
118}
119
120/// Halt execution and register account for later deletion or send all Ether to address (post-Cancun).
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
122#[display("{}", self.opcode())]
123pub struct SelfDestruct;
124
125impl Instruction for SelfDestruct {
126    fn opcode(&self) -> OpCode {
127        OpCode::Known(Mnemonic::SELFDESTRUCT)
128    }
129}
130
131/// An identified instruction.
132/// The difference between this instruction and [`Invalid`] is that the [`Invalid`] instruction is explicitly
133/// defined in the specification and this instruction is a catch-all instruction for any operation
134/// code not defined in the specification. Otherwise they behave the exact same way.
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
136#[display("{}", self.opcode())]
137pub struct Unknown(
138    /// The unidentified operation code.
139    pub u8,
140);
141
142impl Instruction for Unknown {
143    fn opcode(&self) -> OpCode {
144        OpCode::Unknown(self.0)
145    }
146}