Skip to content

Add_support_for_pies_with_simulated_builtins #2069

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

Open
wants to merge 1 commit into
base: starkware-development
Choose a base branch
from

Conversation

YairVaknin-starkware
Copy link
Collaborator

@YairVaknin-starkware YairVaknin-starkware commented Apr 14, 2025

TITLE

Description

Description of the pull request changes and motivation.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

This change is Reviewable

Copy link

github-actions bot commented Apr 14, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.136 ± 0.025 2.109 2.200 1.00 ± 0.01
head big_factorial 2.133 ± 0.012 2.122 2.164 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.048 ± 0.019 2.023 2.078 1.00
head big_fibonacci 2.055 ± 0.012 2.041 2.076 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.827 ± 0.101 7.734 8.074 1.00
head blake2s_integration_benchmark 8.039 ± 0.137 7.919 8.299 1.03 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.210 ± 0.012 2.192 2.229 1.00
head compare_arrays_200000 2.220 ± 0.022 2.198 2.272 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.446 ± 0.023 1.431 1.508 1.01 ± 0.02
head dict_integration_benchmark 1.433 ± 0.007 1.425 1.450 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.224 ± 0.007 1.212 1.233 1.00
head field_arithmetic_get_square_benchmark 1.238 ± 0.010 1.230 1.264 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.877 ± 0.052 7.768 7.946 1.00
head integration_builtins 7.956 ± 0.034 7.903 8.017 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.186 ± 0.099 8.092 8.443 1.00
head keccak_integration_benchmark 8.310 ± 0.184 8.183 8.822 1.02 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.156 ± 0.012 2.141 2.175 1.00
head linear_search 2.157 ± 0.009 2.144 2.172 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.511 ± 0.008 1.496 1.525 1.00
head math_cmp_and_pow_integration_benchmark 1.516 ± 0.007 1.508 1.529 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.456 ± 0.004 1.451 1.463 1.00
head math_integration_benchmark 1.462 ± 0.023 1.450 1.525 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.211 ± 0.005 1.206 1.221 1.00
head memory_integration_benchmark 1.217 ± 0.005 1.213 1.223 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.580 ± 0.007 1.574 1.596 1.00
head operations_with_data_structures_benchmarks 1.583 ± 0.012 1.569 1.610 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 536.3 ± 1.6 534.5 540.1 1.00
head pedersen 537.6 ± 2.9 535.2 544.3 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 642.7 ± 4.7 632.0 647.4 1.00 ± 0.01
head poseidon_integration_benchmark 640.8 ± 1.6 638.8 643.7 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.862 ± 0.007 1.855 1.872 1.00
head secp_integration_benchmark 1.889 ± 0.018 1.874 1.926 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 629.9 ± 3.0 626.9 635.6 1.00
head set_integration_benchmark 680.4 ± 2.9 677.7 688.1 1.08 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.318 ± 0.041 4.287 4.429 1.00
head uint256_integration_benchmark 4.333 ± 0.012 4.310 4.351 1.00 ± 0.01

Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @YairVaknin-starkware)


vm/src/vm/runners/cairo_pie.rs line 151 at r1 (raw file):

    pub extra_segments: Vec<SegmentInfo>,
    #[serde(default)]
    pub simulated_builtins: Vec<BuiltinName>,

doc - what are simulated builtins


vm/src/vm/runners/cairo_runner.rs line 1418 at r1 (raw file):

            .map(|builtin| builtin.name())
            .collect::<Vec<_>>();
        // Sort the simulated builtins by their order in the program.

why? (doc the answer)


vm/src/cairo_run.rs line 185 at r1 (raw file):

    cairo_runner.vm.finalize_segments_by_cairo_pie(pie);
    // Load builtin additional data
    for builtin_name in pie.metadata.simulated_builtins.iter() {

sorry, missed it, where are these added to the PIE?

Code quote:

pie.metadata.simulated_builtins

vm/src/cairo_run.rs line 203 at r1 (raw file):

                    .vm
                    .simulated_builtin_runners
                    .push(EcOpBuiltinRunner::new(Some(1), false).into());

if included is false, why isn't ratio None?

Code quote:

                    .push(SignatureBuiltinRunner::new(Some(1), false).into());
            }
            BuiltinName::keccak => {
                cairo_runner
                    .vm
                    .simulated_builtin_runners
                    .push(KeccakBuiltinRunner::new(Some(1), false).into());
            }
            BuiltinName::ec_op => {
                cairo_runner
                    .vm
                    .simulated_builtin_runners
                    .push(EcOpBuiltinRunner::new(Some(1), false).into());

Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @YairVaknin-starkware)


a discussion (no related file):
I'd like Titelman's review on it too

Copy link
Collaborator Author

@YairVaknin-starkware YairVaknin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @YairVaknin-starkware)


vm/src/vm/runners/cairo_runner.rs line 1435 at r1 (raw file):

            builtin_segments,
            extra_segments,
            simulated_builtins,

Added here to the PIE (answering above question).

Code quote:

 simulated_builtins,

Copy link
Collaborator Author

@YairVaknin-starkware YairVaknin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @yuvalsw)


vm/src/cairo_run.rs line 185 at r1 (raw file):

Previously, yuvalsw wrote…

sorry, missed it, where are these added to the PIE?

See other comment answering this.


vm/src/cairo_run.rs line 203 at r1 (raw file):

Previously, yuvalsw wrote…

if included is false, why isn't ratio None?

No particular reason. They won't be used. It's just there to align the output PIE if we load a PIE with simulated builtins.

@YairVaknin-starkware YairVaknin-starkware force-pushed the yairv/fix_zero_offset_output_base_assumption branch from e89c602 to 7646a7e Compare April 14, 2025 18:27
Base automatically changed from yairv/fix_zero_offset_output_base_assumption to starkware-development April 14, 2025 19:01
@YairVaknin-starkware YairVaknin-starkware force-pushed the yairv/add_support_for_pies_with_simulated_builtins branch from 9dc6889 to 172c65d Compare April 14, 2025 19:19
Copy link

github-actions bot commented Apr 14, 2025

**Hyper Thereading Benchmark results**




hyperfine -r 2 -n "hyper_threading_main threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_main' -n "hyper_threading_pr threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 1
  Time (mean ± σ):     26.213 s ±  0.004 s    [User: 25.454 s, System: 0.758 s]
  Range (min … max):   26.210 s … 26.216 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     26.426 s ±  0.034 s    [User: 25.617 s, System: 0.808 s]
  Range (min … max):   26.402 s … 26.451 s    2 runs
 
Summary
  hyper_threading_main threads: 1 ran
    1.01 ± 0.00 times faster than hyper_threading_pr threads: 1




hyperfine -r 2 -n "hyper_threading_main threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_main' -n "hyper_threading_pr threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 2
  Time (mean ± σ):     14.623 s ±  0.022 s    [User: 25.605 s, System: 0.773 s]
  Range (min … max):   14.607 s … 14.639 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     14.746 s ±  0.027 s    [User: 25.736 s, System: 0.820 s]
  Range (min … max):   14.726 s … 14.765 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.01 ± 0.00 times faster than hyper_threading_pr threads: 2




hyperfine -r 2 -n "hyper_threading_main threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_main' -n "hyper_threading_pr threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 4
  Time (mean ± σ):     10.685 s ±  0.201 s    [User: 37.546 s, System: 0.900 s]
  Range (min … max):   10.542 s … 10.827 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.755 s ±  0.243 s    [User: 37.768 s, System: 1.010 s]
  Range (min … max):   10.583 s … 10.927 s    2 runs
 
Summary
  hyper_threading_main threads: 4 ran
    1.01 ± 0.03 times faster than hyper_threading_pr threads: 4




hyperfine -r 2 -n "hyper_threading_main threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_main' -n "hyper_threading_pr threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 6
  Time (mean ± σ):     10.393 s ±  0.069 s    [User: 37.994 s, System: 0.933 s]
  Range (min … max):   10.344 s … 10.441 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.618 s ±  0.251 s    [User: 38.228 s, System: 1.032 s]
  Range (min … max):   10.440 s … 10.795 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.02 ± 0.03 times faster than hyper_threading_pr threads: 6




hyperfine -r 2 -n "hyper_threading_main threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_main' -n "hyper_threading_pr threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 8
  Time (mean ± σ):     10.330 s ±  0.101 s    [User: 38.152 s, System: 0.933 s]
  Range (min … max):   10.258 s … 10.401 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.404 s ±  0.046 s    [User: 38.865 s, System: 1.024 s]
  Range (min … max):   10.372 s … 10.437 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.01 ± 0.01 times faster than hyper_threading_pr threads: 8




hyperfine -r 2 -n "hyper_threading_main threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_main' -n "hyper_threading_pr threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 16
  Time (mean ± σ):     10.432 s ±  0.253 s    [User: 38.559 s, System: 1.067 s]
  Range (min … max):   10.253 s … 10.611 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     10.355 s ±  0.064 s    [User: 39.131 s, System: 1.130 s]
  Range (min … max):   10.310 s … 10.401 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.01 ± 0.03 times faster than hyper_threading_main threads: 16


@YairVaknin-starkware YairVaknin-starkware force-pushed the yairv/add_support_for_pies_with_simulated_builtins branch from 172c65d to 51ad4f0 Compare April 14, 2025 20:50
Copy link
Collaborator Author

@YairVaknin-starkware YairVaknin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @yuvalsw)


vm/src/vm/runners/cairo_pie.rs line 151 at r1 (raw file):

Previously, yuvalsw wrote…

doc - what are simulated builtins

Done.


vm/src/vm/runners/cairo_runner.rs line 1418 at r1 (raw file):

Previously, yuvalsw wrote…

why? (doc the answer)

Done.

Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 99.04762% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.56%. Comparing base (9c44e1c) to head (d89ff6e).

Files with missing lines Patch % Lines
vm/src/vm/runners/cairo_runner.rs 98.79% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           starkware-development    #2069      +/-   ##
=========================================================
+ Coverage                  96.53%   96.56%   +0.02%     
=========================================================
  Files                        102      102              
  Lines                      43184    43273      +89     
=========================================================
+ Hits                       41689    41787      +98     
+ Misses                      1495     1486       -9     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@YairVaknin-starkware YairVaknin-starkware force-pushed the yairv/add_support_for_pies_with_simulated_builtins branch 3 times, most recently from fa018bf to b4f5774 Compare April 15, 2025 08:46
Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @YairVaknin-starkware)


vm/src/cairo_run.rs line 203 at r1 (raw file):

Previously, YairVaknin-starkware wrote…

No particular reason. They won't be used. It's just there to align the output PIE if we load a PIE with simulated builtins.

I don't follow, can you elaborate more? Align what exactly in the pie, and to what?
If this alignment is important somehow, I am ok with this, but maybe doc here why Some. If not, I think it makes it much easier to read is you use None as the reader doesn't have to wonder why it's Some, like I did.


vm/src/vm/errors/cairo_run_errors.rs line 30 at r3 (raw file):

    #[error(transparent)]
    CairoPieValidation(#[from] CairoPieValidationError),
    #[error("Unsupported simulated builtin in Cairo PIE: {0:?}")]

I see it impls display

Suggestion:

: {0}

vm/src/tests/cairo_pie_test.rs line 315 at r3 (raw file):

    let runner = result.unwrap();
    let result = runner.get_cairo_pie();
    assert!(result.is_ok());

Suggestion:

    let runner = cairo_run::cairo_run_pie(&pie, &cairo_run_config, &mut hint_processor).unwrap();
    assert!(runner.get_cairo_pie().is_ok());

vm/src/vm/runners/cairo_pie.rs line 153 at r2 (raw file):

    // rather than being outputted as their own segment and proven later (see example implementation
    // of this mechanism in `simple_bootloader.cairo`).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]

Suggestion:

    /// `simulated_builtins` are builtins that are being verified in the executed cairo code
    /// rather than being outputted as their own segment and verified later (see example implementation
    /// of this mechanism in `simple_bootloader.cairo`).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]

vm/src/vm/runners/cairo_runner.rs line 5822 at r3 (raw file):

            }
            _ => panic!("Expected unsupported simulated builtin error."),
        }

Doesn't this work?

Suggestion:

        assert_matches!(result, Err(CairoRunError::UnsupportedSimulatedBuiltin(BuiltinName::pedersen)));

@YairVaknin-starkware YairVaknin-starkware force-pushed the yairv/add_support_for_pies_with_simulated_builtins branch from b4f5774 to d89ff6e Compare April 15, 2025 11:31
Copy link
Collaborator Author

@YairVaknin-starkware YairVaknin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @yuvalsw)


vm/src/cairo_run.rs line 203 at r1 (raw file):

Previously, yuvalsw wrote…

I don't follow, can you elaborate more? Align what exactly in the pie, and to what?
If this alignment is important somehow, I am ok with this, but maybe doc here why Some. If not, I think it makes it much easier to read is you use None as the reader doesn't have to wonder why it's Some, like I did.

I mean that it'd work either way, but followed the practice in other places in code (initialize_program_builtins for example) when initializing runners with ratios that don't matter. added explanation to the doc.

If they won't be present the resulting PIE won't have them in the metadata (since the program inits them in hints when this mechanism's invoked).


vm/src/vm/errors/cairo_run_errors.rs line 30 at r3 (raw file):

Previously, yuvalsw wrote…

I see it impls display

Done.


vm/src/vm/runners/cairo_pie.rs line 153 at r2 (raw file):

    // rather than being outputted as their own segment and proven later (see example implementation
    // of this mechanism in `simple_bootloader.cairo`).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]

revised

Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @YairVaknin-starkware)


vm/src/vm/runners/cairo_runner.rs line 1566 at r4 (raw file):

    /// Loads builtin runners for simulated builtins in the pie's metadata, so the resulted pie is
    /// compatible with the one received. Note: they won't be used during the execution, and are

Great! This was indeed missing and is now much clearer.

Copy link
Collaborator Author

@YairVaknin-starkware YairVaknin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @yuvalsw)


a discussion (no related file):

Previously, yuvalsw wrote…

I'd like Titelman's review on it too

What's the status of this?

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.

2 participants