fe_analyzer/
builtins.rs

1use crate::namespace::types::Base;
2use strum::{AsRefStr, EnumIter, EnumString};
3
4#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EnumString, AsRefStr)]
5#[strum(serialize_all = "snake_case")]
6pub enum ValueMethod {
7    ToMem,
8    AbiEncode,
9}
10
11#[derive(
12    Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, AsRefStr, EnumIter,
13)]
14#[strum(serialize_all = "snake_case")]
15pub enum GlobalFunction {
16    Keccak256,
17}
18
19#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumString, AsRefStr)]
20#[strum(serialize_all = "snake_case")]
21pub enum ContractTypeMethod {
22    Create,
23    Create2,
24}
25
26impl ContractTypeMethod {
27    pub fn arg_count(&self) -> usize {
28        match self {
29            ContractTypeMethod::Create => 2,
30            ContractTypeMethod::Create2 => 3,
31        }
32    }
33}
34
35/// The evm functions exposed by yul.
36#[allow(non_camel_case_types)]
37#[derive(
38    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, AsRefStr, EnumIter,
39)]
40pub enum Intrinsic {
41    __stop,           // () -> ()
42    __add,            // (x, y)
43    __sub,            // (x, y)
44    __mul,            // (x, y)
45    __div,            // (x, y)
46    __sdiv,           // (x, y)
47    __mod,            // (x, y)
48    __smod,           // (x, y)
49    __exp,            // (x, y)
50    __not,            // (x)
51    __lt,             // (x, y)
52    __gt,             // (x, y)
53    __slt,            // (x, y)
54    __sgt,            // (x, y)
55    __eq,             // (x, y)
56    __iszero,         // (x)
57    __and,            // (x, y)
58    __or,             // (x, y)
59    __xor,            // (x, y)
60    __byte,           // (n, x)
61    __shl,            // (x, y)
62    __shr,            // (x, y)
63    __sar,            // (x, y)
64    __addmod,         // (x, y, m)
65    __mulmod,         // (x, y, m)
66    __signextend,     // (i, x)
67    __keccak256,      // (p, n)
68    __pc,             // ()
69    __pop,            // (x) -> ()
70    __mload,          // (p)
71    __mstore,         // (p, v) -> ()
72    __mstore8,        // (p, v) -> ()
73    __sload,          // (p)
74    __sstore,         // (p, v) -> ()
75    __msize,          // ()
76    __gas,            // ()
77    __address,        // ()
78    __balance,        // (a)
79    __selfbalance,    // ()
80    __caller,         // ()
81    __callvalue,      // ()
82    __calldataload,   // (p)
83    __calldatasize,   // ()
84    __calldatacopy,   // (t, f, s) -> ()
85    __codesize,       // ()
86    __codecopy,       // (t, f, s) -> ()
87    __extcodesize,    // (a)
88    __extcodecopy,    // (a, t, f, s) -> ()
89    __returndatasize, // ()
90    __returndatacopy, // (t, f, s) -> ()
91    __extcodehash,    // (a)
92    __create,         // (v, p, n)
93    __create2,        // (v, p, n, s)
94    __call,           // (g, a, v, in, insize, out, outsize)
95    __callcode,       // (g, a, v, in, insize, out, outsize)
96    __delegatecall,   // (g, a, in, insize, out, outsize)
97    __staticcall,     // (g, a, in, insize, out, outsize)
98    __return,         // (p, s) -> ()
99    __revert,         // (p, s) -> ()
100    __selfdestruct,   // (a) -> ()
101    __invalid,        // () -> ()
102    __log0,           // (p, s) -> ()
103    __log1,           // (p, s, t1) -> ()
104    __log2,           // (p, s, t1, t2) -> ()
105    __log3,           // (p, s, t1, t2, t3) -> ()
106    __log4,           // (p, s, t1, t2, t3, t4) -> ()
107    __chainid,        // ()
108    __basefee,        // ()
109    __origin,         // ()
110    __gasprice,       // ()
111    __blockhash,      // (b)
112    __coinbase,       // ()
113    __timestamp,      // ()
114    __number,         // ()
115    __prevrandao,     // ()
116    __gaslimit,       // ()
117}
118
119impl Intrinsic {
120    pub fn arg_count(&self) -> usize {
121        use Intrinsic::*;
122        match self {
123            __stop | __basefee | __origin | __gasprice | __coinbase | __timestamp | __number
124            | __prevrandao | __gaslimit | __pc | __msize | __gas | __address | __selfbalance
125            | __caller | __callvalue | __calldatasize | __codesize | __returndatasize
126            | __invalid | __chainid => 0,
127
128            __not | __iszero | __pop | __mload | __balance | __sload | __calldataload
129            | __extcodesize | __extcodehash | __selfdestruct | __blockhash => 1,
130
131            __add | __sub | __mul | __div | __sdiv | __mod | __smod | __exp | __lt | __gt
132            | __slt | __sgt | __eq | __and | __or | __xor | __byte | __shl | __shr | __sar
133            | __signextend | __keccak256 | __mstore | __mstore8 | __sstore | __return
134            | __revert | __log0 => 2,
135
136            __addmod | __mulmod | __calldatacopy | __codecopy | __returndatacopy | __create
137            | __log1 => 3,
138            __extcodecopy | __create2 | __log2 => 4,
139            __log3 => 5,
140            __delegatecall | __staticcall | __log4 => 6,
141            __call | __callcode => 7,
142        }
143    }
144
145    pub fn return_type(&self) -> Base {
146        use Intrinsic::*;
147        match self {
148            __stop | __pop | __mstore | __mstore8 | __sstore | __calldatacopy | __codecopy
149            | __extcodecopy | __returndatacopy | __return | __revert | __selfdestruct
150            | __invalid | __log0 | __log1 | __log2 | __log3 | __log4 => Base::Unit,
151            _ => Base::u256(),
152        }
153    }
154}