1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Represents a public smart contract function.
Attributes:
selector (str): Function selector as a 4-byte hex string without '0x' prefix (e.g., 'aabbccdd').
bytecode_offset (int): Starting byte offset within the EVM bytecode for the function body.
arguments (Optional[str]): Function argument types in canonical format (e.g., 'uint256,address[]').
None if arguments were not extracted
state_mutability (Optional[str]): Function's state mutability ('pure', 'view', 'payable', or 'nonpayable').
None if state mutability was not extracted
"""
:
:
:
:
"""
Represents a storage variable record in a smart contract's storage layout.
Attributes:
slot (str): Storage slot number as a hex string (e.g., '0', '1b').
offset (int): Byte offset within the storage slot (0-31).
type (str): Variable type (e.g., 'uint256', 'mapping(address => uint256)', 'bytes32').
reads (List[str]): List of function selectors that read from this storage location.
writes (List[str]): List of function selectors that write to this storage location.
"""
:
:
:
:
:
"""
Represents a dynamic jump destination in the control flow.
Attributes:
path (List[int]): Path of basic blocks leading to this jump.
to (Optional[int]): Target basic block offset if known, None otherwise.
"""
:
:
"""
Represents the type of a basic block and its control flow.
This is an enum-like class, all child classes are derived from BlockType class
"""
"""Block terminates execution"""
: # True for normal termination (STOP/RETURN), False for REVERT/INVALID
"""Block ends with unconditional jump"""
: # Destination basic block offset
"""Block ends with conditional jump"""
: # Destination if condition is true
: # Destination if condition is false (fall-through)
"""Block ends with jump to computed destination"""
: # Possible computed jump destinations
"""Block ends with conditional jump to computed destination"""
: # Possible computed jump destinations if true
: # Destination if condition is false (fall-through)
"""
Represents a basic block in the control flow graph.
Attributes:
start (int): Byte offset where the block's first opcode begins
end (int): Byte offset where the block's last opcode begins
btype (BlockType): Type of the block and its control flow.
"""
:
:
:
"""
Represents the control flow graph of the contract bytecode.
Attributes:
blocks (List[Block]): List of basic blocks in the control flow graph.
"""
:
"""
Contains analyzed information about a smart contract.
Attributes:
functions (Optional[List[Function]]): List of detected contract functions.
None if no functions were extracted
storage (Optional[List[StorageRecord]]): List of contract storage records.
None if storage layout was not extracted
disassembled (Optional[List[Tuple[int, str]]]): List of bytecode instructions, where each element is [offset, instruction].
None if disassembly was not requested
basic_blocks (Optional[List[Tuple[int, int]]]): List of basic block ranges as (first_op, last_op) offsets.
None if basic blocks were not requested
control_flow_graph (Optional[ControlFlowGraph]): Control flow graph of the contract.
None if control flow analysis was not requested
"""
:
:
:
:
:
"""
Extracts information about a smart contract from its EVM bytecode.
Args:
code (Union[bytes, str]): Runtime bytecode as a hex string (with or without '0x' prefix)
or raw bytes.
selectors (bool, optional): When True, extracts function selectors. Defaults to False.
arguments (bool, optional): When True, extracts function arguments. Defaults to False.
state_mutability (bool, optional): When True, extracts function state mutability.
Defaults to False.
storage (bool, optional): When True, extracts the contract's storage layout.
Defaults to False.
disassemble (bool, optional): When True, includes disassembled bytecode.
Defaults to False.
basic_blocks (bool, optional): When True, extracts basic block ranges.
Defaults to False.
control_flow_graph (bool, optional): When True, builds control flow graph.
Defaults to False.
Returns:
Contract: Object containing the requested smart contract information. Fields that
weren't requested to be extracted will be None.
"""
...