-
Notifications
You must be signed in to change notification settings - Fork 118
chore(l2): granulize SP1 zkVM cycles report #5226
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
base: main
Are you sure you want to change the base?
Conversation
Lines of code reportTotal lines added: Detailed view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds cycle tracking capabilities for the SP1 zkVM and refactors the stateless_validation_l1 function to inline the execution logic. The main changes include introducing a report_cycles! macro that wraps code blocks with cycle tracking instrumentation, and expanding the previously abstracted execute_stateless call into explicit step-by-step validation and execution logic with cycle tracking at each step.
Key Changes
- Introduced
report_cycles!macro for cycle tracking in SP1 zkVM with a newsp1-cyclesfeature flag - Refactored
stateless_validation_l1to inline block execution logic with granular cycle tracking - Changed function signature from borrowing blocks (
&[Block]) to taking ownership (Vec<Block>)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| crates/l2/prover/src/guest_program/Cargo.toml | Added sp1-cycles feature flag for cycle tracking |
| crates/l2/prover/src/guest_program/src/sp1/Cargo.toml | Enabled report-cycles feature for guest_program dependency (has naming inconsistency) |
| crates/l2/prover/src/guest_program/src/lib.rs | Introduced report_cycles! macro with cycle tracking instrumentation |
| crates/l2/prover/src/guest_program/src/execution.rs | Refactored stateless_validation_l1 to inline execution logic with cycle tracking at each major step |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| /// When the feature "sp1-cycles" is enabled, it will print start and end cycle | ||
| /// tracking messages that are compatible with SP1's cycle tracking system. | ||
| #[macro_export] | ||
| macro_rules! report_cycles { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this macro not always report cycles, maybe another name like try_report_cycles or something else
Motivation
For SP1 we already have profiling tools like Samply to generate flamegraphs of the execution and get an idea of the spent cycles during the execution, but it is not always desired to run those.
As an alternative, granulating the current cycle's report is very useful.
Description
report_cycles!macro that wraps a block of code with optional cycle-tracking printsreport_cycles!macro to track cycles of them.Example Output