# anza-xyz/sbpf architecture

> Architecture diagram of the GitHub repository anza-xyz/sbpf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anza-xyz/sbpf
- Repository: https://github.com/anza-xyz/sbpf

## Overview

#### Purpose and entry points
`solana-sbpf` is a Rust library implementing a user-space Solana BPF (SBPF/eBPF) virtual machine: program loading, validation, memory isolation, interpreted execution, and native JIT execution. The public crate root is `src/lib.rs`; the standalone command-line entry point is `cli/src/main.rs`. Programs can be constructed from bytecode or loaded from ELF artifacts.

#### Program ingestion and representation
The executable-program boundary is centered on `src/program.rs`, which represents loaded SBPF programs and their callable functions. ELF loading and relocation are handled by `src/elf.rs` plus the parser subsystem in `src/elf_parser/mod.rs`, with format constants/types separated into `src/elf_parser/consts.rs` and `src/elf_parser/types.rs`. Assembly input can alternatively pass through `src/asm_parser.rs` and `src/assembler.rs`; `src/disassembler.rs` exposes the inverse inspection path.

#### ISA, versioning, and verification
`src/ebpf.rs` defines the SBPF/eBPF instruction model and version-dependent ISA behavior. `src/verifier.rs` is the safety gate before execution, with `src/static_analysis.rs` supplying control-flow or related analysis. This boundary ensures bytecode or ELF-derived instructions are structurally valid before they reach the interpreter or JIT, including differences across SBPF versions.

#### Execution engines
`src/vm.rs` assembles the runtime-facing virtual-machine abstraction from an executable, memory mapping, execution context, and selected engine. `src/interpreter.rs` executes instructions directly. `src/jit.rs` provides native-code compilation/execution, with architecture-specific backends in `src/x86.rs` and `src/aarch64.rs`. JIT availability is platform-sensitive; the README identifies x86_64 JIT support and excludes Windows JIT operation.

#### Memory and host-call boundary
Sandboxed guest addressing is represented through memory regions and mappings in `src/memory_region.rs` and `src/memory_management.rs`; alignment-aware backing storage is in `src/aligned_memory.rs`. This is the principal isolation boundary between SBPF program memory and host process memory. Host-visible built-ins/syscalls and invocation behavior are part of the VM/program execution model, while `doc/syscalls.md` documents the syscall surface.

#### Runtime flow and ecosystem
Typical control flow is: configure loader/built-ins → create an executable from bytecode or ELF → verify/analyze → optionally JIT compile → construct mapped memory regions and an instruction-meter context → create `vm` → execute via interpreter or JIT. The primary runtime is Rust (minimum rustc 1.83); distribution is through crates.io. CI includes normal build/test automation and fuzzing (`.github/workflows/main.yml`, `.github/workflows/fuzz.yml`), with fuzz targets exercising ELF parsing, verification, and JIT/interpreter differential behavior under `fuzz/fuzz_targets/`.

Main entry points: [`src/program.rs`](https://github.com/anza-xyz/sbpf/blob/main/src/program.rs) (Executable program), [`src/vm.rs`](https://github.com/anza-xyz/sbpf/blob/main/src/vm.rs) (Virtual machine), [`src/jit.rs`](https://github.com/anza-xyz/sbpf/blob/main/src/jit.rs) (Native JIT), [`src/verifier.rs`](https://github.com/anza-xyz/sbpf/blob/main/src/verifier.rs) (Verifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Program ingestion"]
  node_program["Executable program<br/>program model<br/>[program.rs]"]
  node_elf_loader["ELF loader and relocation<br/>ELF ingestion<br/>[elf.rs]"]
  node_elf_parser["ELF parser<br/>format parser<br/>[mod.rs]"]
  node_assembler["Assembly pipeline<br/>assembly ingestion<br/>[assembler.rs]"]
  node_disassembler["Disassembler<br/>inspection<br/>[disassembler.rs]"]
end

subgraph group_validation["ISA and validation"]
  node_isa["SBPF ISA and versions<br/>instruction model<br/>[ebpf.rs]"]
  node_verifier{{"Verifier<br/>safety gate<br/>[verifier.rs]"}}
  node_static_analysis["Static analysis<br/>control-flow analysis<br/>[static_analysis.rs]"]
end

subgraph group_runtime["VM execution"]
  node_vm["Virtual machine<br/>runtime facade<br/>[vm.rs]"]
  node_interpreter["Interpreter<br/>execution engine<br/>[interpreter.rs]"]
  node_jit["Native JIT<br/>execution engine<br/>[jit.rs]"]
  node_x86_backend["x86 backend<br/>JIT backend<br/>[x86.rs]"]
  node_aarch64_backend["AArch64 backend<br/>JIT backend<br/>[aarch64.rs]"]
end

subgraph group_memory["Memory isolation"]
  node_memory_mapping{{"Memory regions and mapping<br/>sandbox boundary<br/>[memory_region.rs]"}}
  node_memory_management["Memory management<br/>mapping support"]
  node_aligned_memory["Aligned backing memory<br/>memory storage<br/>[aligned_memory.rs]"]
end

node_library["Public library<br/>Rust crate<br/>[lib.rs]"]
node_cli["CLI<br/>binary entry point<br/>[main.rs]"]
node_syscalls["Syscall surface<br/>host-call contract<br/>[syscalls.md]"]

node_library -->|"constructs"| node_program
node_cli -->|"uses"| node_library
node_elf_loader -->|"parses through"| node_elf_parser
node_elf_loader -->|"loads and relocates"| node_program
node_assembler -->|"emits"| node_program
node_program -->|"submitted for validation"| node_verifier
node_isa -->|"defines rules"| node_verifier
node_static_analysis -->|"supports"| node_verifier
node_verifier -->|"validated executable"| node_vm
node_program -.->|"inspected by"| node_disassembler
node_vm -->|"selects"| node_interpreter
node_vm -->|"optionally selects"| node_jit
node_jit -->|"targets"| node_x86_backend
node_jit -->|"targets"| node_aarch64_backend
node_memory_mapping -->|"mapped guest memory"| node_vm
node_memory_management -->|"manages"| node_memory_mapping
node_aligned_memory -->|"backs regions"| node_memory_mapping
node_syscalls -.->|"documents host calls"| node_vm
node_isa -->|"instruction semantics"| node_interpreter
node_isa -->|"compiles instructions"| node_jit

click node_library "https://github.com/anza-xyz/sbpf/blob/main/src/lib.rs"
click node_cli "https://github.com/anza-xyz/sbpf/blob/main/cli/src/main.rs"
click node_program "https://github.com/anza-xyz/sbpf/blob/main/src/program.rs"
click node_elf_loader "https://github.com/anza-xyz/sbpf/blob/main/src/elf.rs"
click node_elf_parser "https://github.com/anza-xyz/sbpf/blob/main/src/elf_parser/mod.rs"
click node_assembler "https://github.com/anza-xyz/sbpf/blob/main/src/assembler.rs"
click node_disassembler "https://github.com/anza-xyz/sbpf/blob/main/src/disassembler.rs"
click node_isa "https://github.com/anza-xyz/sbpf/blob/main/src/ebpf.rs"
click node_verifier "https://github.com/anza-xyz/sbpf/blob/main/src/verifier.rs"
click node_static_analysis "https://github.com/anza-xyz/sbpf/blob/main/src/static_analysis.rs"
click node_vm "https://github.com/anza-xyz/sbpf/blob/main/src/vm.rs"
click node_interpreter "https://github.com/anza-xyz/sbpf/blob/main/src/interpreter.rs"
click node_jit "https://github.com/anza-xyz/sbpf/blob/main/src/jit.rs"
click node_x86_backend "https://github.com/anza-xyz/sbpf/blob/main/src/x86.rs"
click node_aarch64_backend "https://github.com/anza-xyz/sbpf/blob/main/src/aarch64.rs"
click node_memory_mapping "https://github.com/anza-xyz/sbpf/blob/main/src/memory_region.rs"
click node_memory_management "https://github.com/anza-xyz/sbpf/blob/main/src/memory_management.rs"
click node_aligned_memory "https://github.com/anza-xyz/sbpf/blob/main/src/aligned_memory.rs"
click node_syscalls "https://github.com/anza-xyz/sbpf/blob/main/doc/syscalls.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_elf_loader,node_elf_parser,node_assembler,node_disassembler toneBlue
class node_isa,node_verifier,node_static_analysis toneAmber
class node_vm,node_interpreter,node_jit,node_x86_backend,node_aarch64_backend toneMint
class node_memory_mapping,node_memory_management,node_aligned_memory toneRose
class node_library,node_cli,node_syscalls toneNeutral
```

## Components

### Program ingestion

- [Executable program](https://github.com/anza-xyz/sbpf/blob/main/src/program.rs): program model · Loaded program and callable-function representation. · `src/program.rs`
- [ELF loader and relocation](https://github.com/anza-xyz/sbpf/blob/main/src/elf.rs): ELF ingestion · `src/elf.rs`
- [ELF parser](https://github.com/anza-xyz/sbpf/blob/main/src/elf_parser/mod.rs): format parser · `src/elf_parser/mod.rs`
- [Assembly pipeline](https://github.com/anza-xyz/sbpf/blob/main/src/assembler.rs): assembly ingestion · Parses assembly and emits bytecode. · `src/assembler.rs`
- [Disassembler](https://github.com/anza-xyz/sbpf/blob/main/src/disassembler.rs): inspection · `src/disassembler.rs`

### ISA and validation

- [SBPF ISA and versions](https://github.com/anza-xyz/sbpf/blob/main/src/ebpf.rs): instruction model · `src/ebpf.rs`
- [Verifier](https://github.com/anza-xyz/sbpf/blob/main/src/verifier.rs): safety gate · Rejects structurally invalid programs before execution. · `src/verifier.rs`
- [Static analysis](https://github.com/anza-xyz/sbpf/blob/main/src/static_analysis.rs): control-flow analysis · `src/static_analysis.rs`

### VM execution

- [Virtual machine](https://github.com/anza-xyz/sbpf/blob/main/src/vm.rs): runtime facade · Combines executable, memory mapping, context, and engine. · `src/vm.rs`
- [Interpreter](https://github.com/anza-xyz/sbpf/blob/main/src/interpreter.rs): execution engine · `src/interpreter.rs`
- [Native JIT](https://github.com/anza-xyz/sbpf/blob/main/src/jit.rs): execution engine · Platform-sensitive native compilation and execution. · `src/jit.rs`
- [x86 backend](https://github.com/anza-xyz/sbpf/blob/main/src/x86.rs): JIT backend · `src/x86.rs`
- [AArch64 backend](https://github.com/anza-xyz/sbpf/blob/main/src/aarch64.rs): JIT backend · `src/aarch64.rs`

### Memory isolation

- [Memory regions and mapping](https://github.com/anza-xyz/sbpf/blob/main/src/memory_region.rs): sandbox boundary · Isolates guest addresses from host process memory. · `src/memory_region.rs`
- [Memory management](https://github.com/anza-xyz/sbpf/blob/main/src/memory_management.rs): mapping support · `src/memory_management.rs`
- [Aligned backing memory](https://github.com/anza-xyz/sbpf/blob/main/src/aligned_memory.rs): memory storage · `src/aligned_memory.rs`

### Other components

- [Public library](https://github.com/anza-xyz/sbpf/blob/main/src/lib.rs): Rust crate · Public SBPF VM API. · `src/lib.rs`
- [CLI](https://github.com/anza-xyz/sbpf/blob/main/cli/src/main.rs): binary entry point · `cli/src/main.rs`
- [Syscall surface](https://github.com/anza-xyz/sbpf/blob/main/doc/syscalls.md): host-call contract · `doc/syscalls.md`

## Connections

- Public library → Executable program: constructs
- CLI → Public library: uses
- ELF loader and relocation → ELF parser: parses through
- ELF loader and relocation → Executable program: loads and relocates
- Assembly pipeline → Executable program: emits
- Executable program → Verifier: submitted for validation
- SBPF ISA and versions → Verifier: defines rules
- Static analysis → Verifier: supports
- Verifier → Virtual machine: validated executable
- Executable program → Disassembler: inspected by
- Virtual machine → Interpreter: selects
- Virtual machine → Native JIT: optionally selects
- Native JIT → x86 backend: targets
- Native JIT → AArch64 backend: targets
- Memory regions and mapping → Virtual machine: mapped guest memory
- Memory management → Memory regions and mapping: manages
- Aligned backing memory → Memory regions and mapping: backs regions
- Syscall surface → Virtual machine: documents host calls
- SBPF ISA and versions → Interpreter: instruction semantics
- SBPF ISA and versions → Native JIT: compiles instructions
