Skip to content

Conversation

@raefko
Copy link

@raefko raefko commented Oct 22, 2025

Fix: Prevent DoS from Malformed ELF Binaries

Summary

This PR addresses a critical security vulnerability where malformed ELF binaries could cause the SP1 prover to panic, resulting in a Denial of Service (DoS) condition. This issue was discovered during a security audit where the SP1 library was causing DoS on a client's node.

Problem

The setup() method and related functions were using .unwrap() calls when parsing ELF binaries and setting up the prover. When a malformed ELF binary was provided, these unwrap calls would cause the application to panic and crash entirely.

Reproduction

The following code demonstrates the vulnerability with a malformed ELF binary:

use sp1_sdk::{EnvProver, ProverClient};
use std::sync::OnceLock;

static SP1_PROVER_CLIENT: OnceLock<EnvProver> = OnceLock::new();

fn main() {
    // Malformed ELF binary that triggers the DoS
    let malformed_elf = vec![0xfb, 0x34, 0x00, 0x00, 0x00, 0x00];

    let prover_client = SP1_PROVER_CLIENT.get_or_init(ProverClient::from_env);

    // This call will crash the application
    let (_pk, _vk) = prover_client.setup(&malformed_elf);
}

Changes

1. Core Changes - Proper Error Propagation

  • crates/prover/src/lib.rs: Modified SP1Prover::setup() to return Result instead of panicking on invalid ELF

    • Changed return type from tuple to eyre::Result<(...)>
    • Added proper error handling for Program::from(elf) calls with descriptive error messages
  • crates/prover/src/build.rs: Updated dummy_proof() to handle setup errors gracefully with panic message

2. SDK Layer - Result Type Updates

Updated all SDK prover implementations to propagate errors properly:

  • crates/sdk/src/prover.rs: Changed trait definition of Prover::setup() to return Result<(SP1ProvingKey, SP1VerifyingKey), Error>
  • crates/sdk/src/cpu/mod.rs: Updated CpuProver::setup() implementation
  • crates/sdk/src/cuda/mod.rs: Updated CudaProver::setup() implementation
  • crates/sdk/src/env/mod.rs: Updated EnvProver::setup() implementation
  • crates/sdk/src/network/prover.rs: Updated NetworkProver::setup() implementation

3. Build Tools

  • crates/build/src/lib.rs: Updated vkey() and vkeys() functions to return Result and handle setup errors

Error Messages

The error messages in this PR are functional but may not be ideal for your use case. Error messages currently use generic formats like:

return Err(eyre::eyre!("Failed to parse ELF into program: {}", e));

Feel free to modify these error messages to be more specific, user-friendly, or aligned with your project's error handling conventions. The important fix is the proper error propagation rather than panicking.

Breaking Changes

This is a breaking change for any code that calls the setup() method, as it now returns a Result instead of a tuple. Callers will need to handle the potential error case:

Before:

let (pk, vk) = prover.setup(&elf);

After:

let (pk, vk) = prover.setup(&elf)?;
// or
let (pk, vk) = match prover.setup(&elf) {
    Ok(keys) => keys,
    Err(e) => {
        // Handle error appropriately
    }
};

Security Impact

This fix prevents malicious or malformed ELF binaries from crashing applications that use the SP1 SDK. Instead of a panic that brings down the entire process, errors are now properly propagated and can be handled by the calling code, allowing for graceful degradation and proper error logging.


This PR was created based on findings from a security audit where SP1 was integrated into a client's system.
Made by FuzzingLabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant