Documentation
¶
Overview ¶
Package evmole provides EVM bytecode analysis functionality.
EVMole extracts function selectors, arguments, state mutability, storage layout, and control flow graphs from Ethereum Virtual Machine bytecode.
Basic usage:
// Single contract analysis
info, err := evmole.ContractInfo(ctx, bytecode, evmole.Options{Selectors: true})
// Multiple contracts (efficient - compile WASM once)
analyzer, err := evmole.NewAnalyzer(ctx)
if err != nil {
return err
}
defer analyzer.Close(ctx)
for _, bytecode := range contracts {
info, err := analyzer.ContractInfo(ctx, bytecode, opts)
// ...
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer holds the compiled WASM module for reuse. Create once with NewAnalyzer(), use for many contracts.
func NewAnalyzer ¶
NewAnalyzer creates a new analyzer with AOT-compiled WASM. This takes ~50ms for compilation, so create once and reuse.
type BasicBlock ¶
BasicBlock represents a sequence of instructions with single entry and exit.
func (BasicBlock) MarshalJSON ¶
func (b BasicBlock) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshaling for BasicBlock as [start, end] array.
func (*BasicBlock) UnmarshalJSON ¶
func (b *BasicBlock) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling for BasicBlock from [start, end] array.
type Block ¶
type Block struct {
// ID is the unique block identifier (CFG key).
ID int `json:"id"`
// Start is the byte offset where the block's first opcode begins.
Start int `json:"start"`
// End is the byte offset where the block's last opcode begins.
End int `json:"end"`
// Type indicates how control flow continues after this block.
Type BlockType `json:"-"`
}
Block is a basic block in the control flow graph.
func (Block) MarshalJSON ¶
MarshalJSON implements custom marshaling for Block with type and data fields.
func (*Block) UnmarshalJSON ¶
UnmarshalJSON implements custom unmarshaling for Block.
type BlockType ¶
type BlockType struct {
Kind BlockKind
Terminate *TerminateData
Jump *JumpData
Jumpi *JumpiData
DynamicJump *DynamicJumpData
DynamicJumpi *DynamicJumpiData
}
BlockType represents the type of control flow at the end of a block.
type Contract ¶
type Contract struct {
// Functions is the list of contract functions with their metadata.
Functions []Function `json:"functions,omitempty"`
// Storage is the contract storage layout.
Storage []StorageRecord `json:"storage,omitempty"`
// Disassembled is the list of disassembled opcodes (offset, instruction).
Disassembled []Instruction `json:"disassembled,omitempty"`
// BasicBlocks are sequences of instructions that execute sequentially.
BasicBlocks []BasicBlock `json:"basic_blocks,omitempty"`
// ControlFlowGraph represents the program's execution paths.
ControlFlowGraph *ControlFlowGraph `json:"control_flow_graph,omitempty"`
}
Contract contains analyzed information about a smart contract.
type ControlFlowGraph ¶
type ControlFlowGraph struct {
// Blocks is the list of basic blocks in the control flow graph.
Blocks []Block `json:"blocks"`
}
ControlFlowGraph represents the structure and flow of EVM bytecode.
type DynamicJump ¶
type DynamicJump struct {
// Path is the sequence of block offsets representing the path taken to reach this jump.
Path []int `json:"path"`
// To is the resolved destination of the jump, if known.
To *int `json:"to,omitempty"`
}
DynamicJump represents a dynamic jump destination with the path taken to reach it.
type DynamicJumpData ¶
type DynamicJumpData struct {
// To is the list of possible jump destinations and paths to reach them.
To []DynamicJump `json:"to"`
}
DynamicJumpData contains data for DynamicJump block type.
type DynamicJumpiData ¶
type DynamicJumpiData struct {
// TrueTo is the list of possible destinations for the true branch.
TrueTo []DynamicJump `json:"true_to"`
// FalseTo is the static destination for the false branch.
FalseTo int `json:"false_to"`
}
DynamicJumpiData contains data for DynamicJumpi block type.
type Function ¶
type Function struct {
// Selector is the 4-byte function selector as hex string (e.g., "a9059cbb").
Selector string `json:"selector"`
// BytecodeOffset is the starting byte offset within EVM bytecode for the function body.
BytecodeOffset int `json:"bytecode_offset"`
// Arguments is the function parameter types (e.g., "uint256,address[]").
Arguments *string `json:"arguments,omitempty"`
// StateMutability is the function state mutability ("pure", "view", "payable", "nonpayable").
StateMutability *string `json:"state_mutability,omitempty"`
}
Function represents a public smart contract function.
type Instruction ¶
Instruction represents a disassembled EVM opcode.
func (Instruction) MarshalJSON ¶
func (i Instruction) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshaling for Instruction as [offset, opcode] array.
func (*Instruction) UnmarshalJSON ¶
func (i *Instruction) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling for Instruction from [offset, opcode] array.
type JumpData ¶
type JumpData struct {
// To is the destination of the jump.
To int `json:"to"`
}
JumpData contains data for Jump block type.
type JumpiData ¶
type JumpiData struct {
// TrueTo is the destination if condition is true.
TrueTo int `json:"true_to"`
// FalseTo is the destination if condition is false.
FalseTo int `json:"false_to"`
}
JumpiData contains data for Jumpi block type.
type Options ¶
type Options struct {
// Selectors enables extraction of function selectors.
Selectors bool
// Arguments enables extraction of function parameter types.
Arguments bool
// StateMutability enables detection of function state mutability.
StateMutability bool
// Storage enables extraction of storage layout.
Storage bool
// Disassemble enables bytecode disassembly.
Disassemble bool
// BasicBlocks enables extraction of basic blocks.
BasicBlocks bool
// ControlFlowGraph enables generation of control flow graph.
ControlFlowGraph bool
}
Options configures which analyses to perform.
type StorageRecord ¶
type StorageRecord struct {
// Slot is the storage slot location as hex string (32 bytes).
Slot string `json:"slot"`
// Offset is the byte offset within the storage slot (0-31).
Offset int `json:"offset"`
// Type is the variable type descriptor.
Type string `json:"type"`
// Reads is the list of function selectors that read from this storage location.
Reads []string `json:"reads"`
// Writes is the list of function selectors that write to this storage location.
Writes []string `json:"writes"`
}
StorageRecord represents a storage variable record in a contract's storage layout.
type TerminateData ¶
type TerminateData struct {
// Success indicates whether the termination was successful (true for STOP/RETURN).
Success bool `json:"success"`
}
TerminateData contains data for Terminate block type.