Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable proof mode in Rust #955

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Mar 7, 2025

PR: Integrate Rust Cairo VM Runner with Proof Mode into Python Testing Framework

Closes #952
Closes #960

Overview

This pull request further pushed the functional parity between the Rust-based Cairo VM runner (PyCairoRunner) and the existing Python VM runner (run_python_vm) by adding support for Proof Mode.

Key changes include a refactored runner.py file with an 8-step structure, mirrored in both vm runs, extended Rust bindings in runner.rs.

Changes

  1. Refactored run_rust_vm in runner.py

    • Objective: Mirror the 8-step structure of run_python_vm for consistency and maintainability.
    • Details:
      • Step 1: Program selection and entrypoint metadata extraction using build_entrypoint.
      • Step 2: Runner initialization with RustCairoRunner, supporting proof mode and layout configuration.
      • Step 3: Stack construction with builtins and arguments, integrating gen_arg_builder for type conversion.
      • Step 4: VM setup done in python rather than in Rust
      • Step 5: Execution via run_until_pc with exception handling and coverage support.
      • Step 6: Return value processing with read_return_values, proof mode updates, and security verification.
      • Step 7: Output file generation (trace, memory) using Rust methods, with proof mode leveraging the Rust approach (e.g., write_binary_trace, write_binary_memory).
      • Step 8: Output serialization via Serde, matching Python VM behavior.
    • Impact: Ensures a modular, debuggable flow aligned with run_python_vm, while respecting Rust’s proof mode handling. Both jmp rel 0 "hacks" are applied to both vm runs.
  2. Enhanced PyCairoRunner in runner.rs

    • Objective: Extend Rust bindings to support all execution phases and proof mode outputs.
    • Details:
      • Modified initialize_vm to not handle stack setup, which is now handled in python.
      • Implemented execution methods: run_until_pc, verify_auto_deductions, read_return_values, verify_secure_runner, relocate, to be closer from the python vm runner
      • Added getters for state inspection: initial_pc, initial_ap, initial_fp, program_base, execution_base, ap, relocated_trace, trace_df.
      • Introduced proof mode output methods: finalize_segments, write_binary_trace, write_binary_memory, update_execution_public_memory.
      • Kept write_binary_air_public_input and write_binary_air_private_input for Rust-native AIR file generation (per your decision to retain the Rust approach).
    • Impact: Provides a robust Rust API for Python to control execution and generate proof mode artifacts natively.

Rationale

  • Parity: The 8-step structure ensures run_rust_vm behaves like run_python_vm, easing contributor onboarding and maintenance by clearly defining the rational behind each step.
  • Constraints: Retained existing Rust APIs (e.g., write_binary_air_*) per project limitations, delegating AIR file details to Rust where applicable.

Testing

  • Verified execution parity with run_python_vm on sample Cairo programs. (test_rlp.py)
  • Verified execution was working in proof mode for EF-Tests
  • DID NOT Try to verify a produced proof.

Copy link

codecov bot commented Mar 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.83%. Comparing base (28166bc) to head (3760c2a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #955      +/-   ##
==========================================
- Coverage   83.87%   82.83%   -1.05%     
==========================================
  Files          64       65       +1     
  Lines       16725    17032     +307     
==========================================
+ Hits        14028    14108      +80     
- Misses       2697     2924     +227     
Flag Coverage Δ
ci-ef-tests 79.94% <ø> (?)
ci-unit 76.95% <ø> (?)
nightly-ef-tests ?
nightly-unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@enitrat enitrat force-pushed the feat/enable-proof-mode branch from f986d44 to 4abae08 Compare March 8, 2025 14:17
@enitrat enitrat marked this pull request as ready for review March 8, 2025 14:26
@enitrat enitrat force-pushed the feat/enable-proof-mode branch from 4abae08 to f062f07 Compare March 8, 2025 15:12
@enitrat enitrat requested a review from ClementWalter March 10, 2025 19:04
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.

dev: remove output_ptr from legacy tests feat: restore proof mode in runner
2 participants