# succinctlabs/sp1 architecture

> Architecture diagram of the GitHub repository succinctlabs/sp1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/succinctlabs/sp1
- Repository: https://github.com/succinctlabs/sp1

## Overview

##### Main Components Overview
The system architecture should be divided into these key components:

a) Core zkVM Infrastructure:
- RISC-V Execution Environment
- Proof Generation System
- Verification System
- Precompiles System

b) Development Tools:
- Rust Toolchain Integration
- Build System
- CLI Interface

##### Detailed Component Breakdown

A. RISC-V Layer (Bottom Layer):
- CPU Executor (crates/core/executor)
- Memory Management
- Instruction Set Implementation
- System Calls Handler

B. Zero-Knowledge Layer (Middle Layer):
- STARK Proof Generation (crates/stark)
- Circuit Components (crates/recursion)
- Verification System (crates/verifier)
- Precompiles for Cryptographic Operations

C. Developer Interface Layer (Top Layer):
- SDK Interface (crates/sdk)
- CLI Tools (crates/cli)
- Build System (crates/build)
- Program Compilation Pipeline

##### Data Flow Connections

- Program Compilation Flow: Rust Code → RISC-V Binary → ZK Circuit
- Proof Generation Flow: Program Execution → STARK Proof → Final Verification
- Precompile Integration: Cryptographic Operations ↔ Main Execution

##### Component Relationships

Interactions between:
- Machine Layer (crates/core/machine) ↔ Executor
- STARK Proof Generation ↔ Verification
- SDK ↔ All Lower Layers
- Precompiles ↔ Core Execution

##### Technical Details

Annotations for:
- Supported cryptographic curves (BLS12-381, BN254, etc.)
- RISC-V specification compliance
- Proof system parameters
- Performance optimization points

Remember to emphasize the unique aspects of SP1, such as its precompile system, Rust integration, and performance optimizations, while keeping the fundamental zkVM architecture clear and comprehensible.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Developer Interface Layer"
        SDK["SDK Interface"]
        CLI["CLI Tools"]
        Build["Build System"]
        Compile["Program Compilation"]
    end

    subgraph "Zero-Knowledge Layer"
        STARK["STARK Proof Generation"]
        Circuit["Circuit Components"]
        Verify["Verification System"]
        ZKCore["Zero-Knowledge Core"]
    end

    subgraph "RISC-V Layer"
        CPU["CPU Executor"]
        Memory["Memory Management"]
        ISA["Instruction Set"]
        Syscall["System Calls"]
        Machine["Machine Layer"]
    end

    subgraph "Auxiliary Systems"
        CUDA["Hardware Acceleration (CUDA)"]
        Crypto["Cryptographic Curves"]
        Precompiles["Precompiles System"]
    end

    %% Relationships
    SDK --> Build
    SDK --> CLI
    Build --> Compile
    Compile --> CPU
    CPU <--> Memory
    CPU <--> ISA
    CPU <--> Syscall
    CPU <--> Machine
    Machine <--> STARK
    STARK <--> Circuit
    Circuit <--> Verify
    ZKCore <--> STARK
    Precompiles <--> CPU
    CUDA <--> STARK
    Crypto <--> Precompiles

    %% Click Events
    click SDK "https://github.com/succinctlabs/sp1/tree/dev/crates/sdk"
    click CLI "https://github.com/succinctlabs/sp1/tree/dev/crates/cli"
    click Build "https://github.com/succinctlabs/sp1/tree/dev/crates/build"
    click STARK "https://github.com/succinctlabs/sp1/tree/dev/crates/stark"
    click Circuit "https://github.com/succinctlabs/sp1/tree/dev/crates/recursion/circuit"
    click Verify "https://github.com/succinctlabs/sp1/tree/dev/crates/verifier"
    click CPU "https://github.com/succinctlabs/sp1/tree/dev/crates/core/executor"
    click Machine "https://github.com/succinctlabs/sp1/tree/dev/crates/core/machine"
    click Precompiles "https://github.com/succinctlabs/sp1/tree/dev/crates/core/executor/src/events/precompiles"
    click CUDA "https://github.com/succinctlabs/sp1/tree/dev/crates/cuda"
    click ZKCore "https://github.com/succinctlabs/sp1/tree/dev/crates/zkvm"
    click Crypto "https://github.com/succinctlabs/sp1/tree/dev/crates/curves"

    %% Styling
    classDef core fill:#2374ab
    classDef proof fill:#2a9d8f
    classDef dev fill:#e76f51
    classDef crypto fill:#7b2cbf
    classDef interface fill:#grey

    class CPU,Memory,ISA,Syscall,Machine core
    class STARK,Circuit,Verify,ZKCore proof
    class SDK,CLI,Build,Compile dev
    class Precompiles,Crypto,CUDA crypto

    %% Legend
    subgraph Legend
        L1["Core VM Components"]:::core
        L2["Proof Generation"]:::proof
        L3["Developer Tools"]:::dev
        L4["Cryptographic Systems"]:::crypto
    end
```
