Skip to content

Comments

starknet_os_runner: prove CairoPie in memory#12709

Open
avi-starkware wants to merge 1 commit intoavi/privacy/stwo-proving-feature-gatesfrom
avi/privacy/prove-cairopie-in-memory
Open

starknet_os_runner: prove CairoPie in memory#12709
avi-starkware wants to merge 1 commit intoavi/privacy/stwo-proving-feature-gatesfrom
avi/privacy/prove-cairopie-in-memory

Conversation

@avi-starkware
Copy link
Collaborator

@avi-starkware avi-starkware commented Feb 18, 2026

Summary

  • Add stwo_run_and_prove module that passes CairoPie directly to the prover library via SimpleBootloaderInput, offloading sync work to spawn_blocking.
  • Add proving::error module with StwoRunAndProveError.
  • Simplify prover::prove to create temp files only for outputs and call prove_pie_in_memory.
  • Un-ignore the integration test (no external binary needed).

Stack: 3/4 — pure behavior PR for the in-memory proving path (no workflow/container noise).

Depends on: #12708

Test plan

  • cargo test -p starknet_os_runner --features stwo_proving --release
  • cargo test -p starknet_os_runner (default features still compile)

🤖 Generated with Claude Code


Note

Medium Risk
Touches the core proving execution path and changes how inputs are constructed and passed into the prover, which could affect correctness/performance and error propagation despite limited surface area.

Overview
Updates prover::prove to use a new in-memory proving path: it no longer writes the Cairo PIE and bootloader input to temp files, and instead calls prove_pie_in_memory while still emitting proof and program output to temporary files.

Adds proving::stwo_run_and_prove as a thin wrapper around stwo_run_and_prove_lib that builds SimpleBootloaderInput from a CairoPie and runs the synchronous prover via tokio::task::spawn_blocking, plus a dedicated StwoRunAndProveError type for join/prover failures. The previously ignored proving integration test is un-ignored since it no longer depends on an external stwo_run_and_prove binary.

Written by Cursor Bugbot for commit 73bc9ab. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link

This change is Reviewable

@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from 621fe36 to f154ccc Compare February 18, 2026 19:05
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from 371dca2 to 9905d53 Compare February 18, 2026 19:05
@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from f154ccc to 24179e3 Compare February 18, 2026 20:54
@avi-starkware avi-starkware requested a review from a team as a code owner February 18, 2026 20:54
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from 9905d53 to 25ae321 Compare February 18, 2026 20:55
@github-actions
Copy link

github-actions bot commented Feb 18, 2026

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from 24179e3 to 0058dfb Compare February 18, 2026 21:16
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch 2 times, most recently from 1549f14 to c5adae0 Compare February 18, 2026 21:23
@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from 0058dfb to bb7f513 Compare February 18, 2026 21:23
Copy link
Contributor

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AvivYossef-starkware reviewed 5 files and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on avi-starkware, noaov1, and Yoni-Starkware).


crates/starknet_os_runner/src/proving/prover.rs line 44 at r2 (raw file):

/// Passes CairoPie directly to the prover library, avoiding disk I/O for the input.
/// The proof output is still written to a temporary file. The synchronous proving work
/// is offloaded to a blocking thread inside `prove_pie_in_memory`.

Suggestion:

/// Proves a Cairo PIE using the stwo prover lib.
/// The synchronous proving work
/// is offloaded to a blocking thread inside `prove_pie_in_memory`.

crates/starknet_os_runner/src/proving/prover_test.rs line 22 at r2 (raw file):

/// Run with: `cargo test -p starknet_os_runner -- --ignored test_prove_cairo_pie_10_transfers`
#[tokio::test]
#[ignore]

Can devs run it locally without OOM?

Code quote:

#[ignore]

crates/starknet_os_runner/src/proving/stwo_run_and_prove.rs line 24 at r2 (raw file):

    let task_spec = TaskSpec { task: Rc::new(task), program_hash_function: HashFunc::Blake };
    SimpleBootloaderInput { fact_topologies_path: None, single_page: true, tasks: vec![task_spec] }
}
SimpleBootloaderInput::from(cairo_pie)

Code quote:

/// Creates a `SimpleBootloaderInput` from a `CairoPie` for in-memory proving.
///
/// This wraps the CairoPie in the appropriate task structures expected by the
/// simple bootloader, avoiding the need to serialize to disk.
fn create_bootloader_input_from_pie(cairo_pie: CairoPie) -> SimpleBootloaderInput {
    let task = Task::Pie(cairo_pie);
    let task_spec = TaskSpec { task: Rc::new(task), program_hash_function: HashFunc::Blake };
    SimpleBootloaderInput { fact_topologies_path: None, single_page: true, tasks: vec![task_spec] }
}

crates/starknet_os_runner/src/proving/stwo_run_and_prove.rs line 52 at r2 (raw file):

    })
    .await??)
}

consider deleting it

Code quote:

/// Runs the stwo prover on a CairoPie in-memory.
///
/// The synchronous proving work is offloaded to a blocking thread via
/// `tokio::task::spawn_blocking`.
///
/// # Arguments
///
/// * `bootloader_program_path` - Path to the compiled simple bootloader program.
/// * `cairo_pie` - The CairoPie to prove.
/// * `program_output_path` - Optional path for program output (proof facts).
/// * `prove_config` - Configuration for the prover.
pub(crate) async fn prove_pie_in_memory(
    bootloader_program_path: PathBuf,
    cairo_pie: CairoPie,
    program_output_path: Option<PathBuf>,
    prove_config: ProveConfig,
) -> Result<(), StwoRunAndProveError> {
    Ok(tokio::task::spawn_blocking(move || {
        prove_pie_in_memory_sync(
            bootloader_program_path,
            cairo_pie,
            program_output_path,
            prove_config,
        )
    })
    .await??)
}

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoni-Starkware made 1 comment.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on avi-starkware and noaov1).


crates/starknet_os_runner/src/proving/prover.rs line 11 at r2 (raw file):

use cairo_air::utils::ProofFormat;
use cairo_vm::vm::runners::cairo_pie::CairoPie;
use proving_utils::proof_encoding::ProofBytes;

Are you planning to remove this crate at the end? its name is problematic (similar to stwo's repo) so easier is to merge the leftovers with the starknet_os_runner (and maybe rename this one to *_prover)

Code quote:

proving_utils

@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from c5adae0 to 2fb5f63 Compare February 22, 2026 15:15
@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch 2 times, most recently from dfb2fc9 to b8c3814 Compare February 22, 2026 15:38
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from 2fb5f63 to 88d7b14 Compare February 22, 2026 15:38
@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from b8c3814 to bbfce30 Compare February 22, 2026 16:08
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from 88d7b14 to abf0d3c Compare February 22, 2026 16:08
@avi-starkware avi-starkware force-pushed the avi/privacy/stwo-proving-feature-gates branch from bbfce30 to d5460a7 Compare February 22, 2026 16:50
Replace the subprocess-based prover invocation with an in-memory call to the
stwo_run_and_prove library, removing the need for temporary Cairo PIE files
and the external stwo_run_and_prove binary.

Changes:
- Add stwo_run_and_prove module that passes CairoPie directly to the prover
  via SimpleBootloaderInput, offloading sync work to spawn_blocking.
- Add proving::error module with StwoRunAndProveError.
- Simplify prover::prove to create temp files only for outputs (proof,
  program_output) and call prove_pie_in_memory.
- Remove ProvingError variants for disk-based input (WriteCairoPie,
  WriteProgramInput, SerializeProgramInput).
- Un-ignore the integration test (no external binary needed).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@avi-starkware avi-starkware force-pushed the avi/privacy/prove-cairopie-in-memory branch from abf0d3c to 73bc9ab Compare February 22, 2026 16:51
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.

4 participants