Naor/reapply/cairo function runner after revert#2359
Conversation
a532efe to
9132d25
Compare
|
71b7b31 to
507035f
Compare
|
Benchmark Results for unmodified programs 🚀
|
OmriEshhar1
left a comment
There was a problem hiding this comment.
@OmriEshhar1 reviewed 10 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on efrat-starkware, igaray, juanbono, pefontana, and YairVaknin-starkware).
efrat-starkware
left a comment
There was a problem hiding this comment.
@efrat-starkware reviewed 4 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on igaray, juanbono, pefontana, and YairVaknin-starkware).
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware reviewed 1 file and all commit messages, and made 8 comments.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
CHANGELOG.md line 23 at r1 (raw file):
* chore: Add `CairoFunctionRunner` for running Cairo entrypoints by name or PC, and broaden `CairoArg`/`MaybeRelocatable` conversions to support primitive signed/unsigned integers and big integers [#2352](https://github.com/lambdaclass/cairo-vm/pull/2352) * chore: Add unit tests for `CairoFunctionRunner`, `CairoArg` conversions/macros, and `MaybeRelocatable` conversion macro coverage [#2354](https://github.com/lambdaclass/cairo-vm/pull/2354)
Why are there two added PRs here? Also, pls change the PR to the new one (this one) after the revert.
Code quote:
* chore: Add `CairoFunctionRunner` for running Cairo entrypoints by name or PC, and broaden `CairoArg`/`MaybeRelocatable` conversions to support primitive signed/unsigned integers and big integers [#2352](https://github.com/lambdaclass/cairo-vm/pull/2352)
* chore: Add unit tests for `CairoFunctionRunner`, `CairoArg` conversions/macros, and `MaybeRelocatable` conversion macro coverage [#2354](https://github.com/lambdaclass/cairo-vm/pull/2354)vm/src/math_utils/mod.rs line 400 at r1 (raw file):
// Simplified as a & p are nonnegative // Asumes p is a prime number pub(crate) fn is_quad_residue(a: &BigUint, p: &BigUint) -> Result<bool, MathError> {
why?
Code quote:
pub(crate) fn is_quad_residuevm/src/types/relocatable.rs line 109 at r1 (raw file):
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, BigUint, BigInt, &BigUint, &BigInt );
Do we really need all of these?
Code quote:
impl_from_for_maybe_relocatable!(
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, BigUint, BigInt, &BigUint,
&BigInt
);vm/src/vm/runners/cairo_function_runner.rs line 53 at r1 (raw file):
$runner.vm.builtin_runners.push($builtin.into()); }; }
Isn't this overkill? Why not make this a method of the runner's? I prefer to avoid macros unless it's a must/ much cleaner.
Code quote:
/// Pushes a builtin runner into `runner.vm.builtin_runners` after converting it with `.into()`.
///
/// Example expansion:
/// `push_builtin!(runner, HashBuiltinRunner::new(Some(32), true));`
/// becomes:
/// `runner.vm.builtin_runners.push(HashBuiltinRunner::new(Some(32), true).into());`
macro_rules! push_builtin {
($runner:expr, $builtin:expr) => {
$runner.vm.builtin_runners.push($builtin.into());
};
}vm/src/vm/runners/cairo_function_runner.rs line 67 at r1 (raw file):
&mut self.runner } }
This isn't a very good design choice in rust in my opinion. Makes the CairoFunctionRunner wrapper redundant. I would prefer you access self.runner, or consider just having the added functionality in the runner itself. I'm not convinced we need a CairoFunctionRunner struct...
Code quote:
impl std::ops::Deref for CairoFunctionRunner {
type Target = CairoRunner;
fn deref(&self) -> &Self::Target {
&self.runner
}
}
impl std::ops::DerefMut for CairoFunctionRunner {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.runner
}
}vm/src/vm/runners/cairo_function_runner.rs line 128 at r1 (raw file):
/// Initializes a fixed set of 11 builtins used by this function runner. fn initialize_all_builtins(runner: &mut CairoRunner) -> Result<(), RunnerError> { runner.vm.builtin_runners.clear();
Maybe you should just fail if it's not empty? It doesn't seem we ever expect this to be invoked on a non new runner.
Code quote:
runner.vm.builtin_runners.clear();vm/src/vm/runners/cairo_function_runner.rs line 171 at r1 (raw file):
/// verification fails. #[allow(clippy::result_large_err)] pub fn run(
Do we really need both this and run_from_entrypoint? Just add the logic from run_from_entrypoint here.
Code quote:
pub fn run(vm/src/vm/runners/mod.rs line 4 at r1 (raw file):
pub mod cairo_function_runner; #[cfg(test)] mod cairo_function_runner_test;
Maybe add the tests to mod cairo_function_runner, the same way it is across the repo?
Code quote:
pub mod cairo_function_runner;
#[cfg(test)]
mod cairo_function_runner_test;|
Previously, YairVaknin-starkware wrote…
I discussed this design with Omri, and we decided to go with this approach to maintain a clear separation between production code and test code. |
|
Previously, YairVaknin-starkware wrote…
I think it makes sense to keep these functions separate for readability and clarity. The This also allows us to introduce additional |
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 2 comments.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/vm/runners/cairo_function_runner.rs line 67 at r1 (raw file):
Previously, naor-starkware wrote…
I discussed this design with Omri, and we decided to go with this approach to maintain a clear separation between production code and test code.
In addition, the use ofDereftoCairoRunnerwas introduced following Efrat’s suggestion, in order to improve code cleanliness and avoid repetitive patterns
You can create a trait and have the runner impl it instead of this and/or introduce the added functionality under a feature flag. It's such a shallow wrapper and I don't see a justification for it.
vm/src/vm/runners/cairo_function_runner.rs line 171 at r1 (raw file):
Previously, naor-starkware wrote…
I think it makes sense to keep these functions separate for readability and clarity.
The
runfunction is responsible for preparing and initializing all the arguments required byrun_from_entrypoint, whilerun_from_entrypointcontains the actual execution logic.This also allows us to introduce additional
runvariants in the future for different use cases that may require different initialization flows, which we’ll likely need as the code evolves
It's not good practice to leave unecessary code in case it's needed in the future. The run function doesn't do anything much aside from calling run_from_entrypoint. I don't see the point in both and it's less clear/readable imo.
|
Previously, YairVaknin-starkware wrote…
This is a bit of messiness on my side across PRs, but I’ll need this for my next PR for the |
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 1 comment.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/math_utils/mod.rs line 400 at r1 (raw file):
Previously, naor-starkware wrote…
This is a bit of messiness on my side across PRs, but I’ll need this for my next PR for the
math.cairotests.
Pls revert for this PR, then
|
Previously, YairVaknin-starkware wrote…
This effectively closes the transitivity: each of these types can be converted into This makes the usage much more convenient, as it avoids having to write conversions like |
|
Previously, YairVaknin-starkware wrote…
The previous implementation initialized all the builtins manually. Following Efrat’s suggestion, I refactored this into a macro to make the code cleaner and more maintainable. |
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 2 comments.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/types/relocatable.rs line 109 at r1 (raw file):
Previously, naor-starkware wrote…
This effectively closes the transitivity: each of these types can be converted into
Felt, andFeltcan be converted intoMaybeRelocatable.This makes the usage much more convenient, as it avoids having to write conversions like
mr_value = MaybeRelocatable::from(Felt252::from(value))every time.
Do we have usages for all theses types?
vm/src/vm/runners/cairo_function_runner.rs line 53 at r1 (raw file):
Previously, naor-starkware wrote…
The previous implementation initialized all the builtins manually. Following Efrat’s suggestion, I refactored this into a macro to make the code cleaner and more maintainable.
Why not make it a method? Nothing here requires a macro is what I mean.
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 1 comment.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/vm/runners/cairo_function_runner.rs line 53 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Why not make it a method? Nothing here requires a macro is what I mean.
Something like fn push_builtin(&mut self, builtin: impl Into<BuiltinRunner>) { ....
|
Previously, YairVaknin-starkware wrote…
I’ll need to wrap |
|
Previously, YairVaknin-starkware wrote…
I initially split this into two PRs : |
|
Previously, YairVaknin-starkware wrote…
Most types require this |
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 2 comments.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
CHANGELOG.md line 23 at r1 (raw file):
Previously, naor-starkware wrote…
I initially split this into two PRs :
one for the logic and one for the tests .
but Codecov failed, so I combined them to get it passing.
Okay, so create a single cahngelog entry with the correct PR number.
vm/src/vm/runners/cairo_function_runner.rs line 171 at r1 (raw file):
Previously, naor-starkware wrote…
I’ll need to wrap
run_from_entrypoint, since some Cairo files use a differentHintProcessor, such asBootloaderHintProcessororBuiltinHintProcessor. This also mirrors the execution flow of the Python VM
wdym? You can pass a different hint processor to run or am I missing your point?
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 1 comment.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/types/relocatable.rs line 109 at r1 (raw file):
Previously, naor-starkware wrote…
Most types require this
cursor scan didn't find any usages for u16, u32, u64, u128, i8, i16, i128, isize. Let's add them when/if needed.
|
Previously, YairVaknin-starkware wrote…
Would it make more sense for each For example, for the
This way, each wrapper would define the initialization flow according to its specific use case. |
|
Previously, naor-starkware wrote…
I think we shouldn’t fail it, since it’s for tests |
|
Previously, YairVaknin-starkware wrote…
The 0.into() was ambiguous because MaybeRelocatable implements From for multiple integer types. |
|
Previously, YairVaknin-starkware wrote…
I wrote these two tests: Or should I add more? |
naor-starkware
left a comment
There was a problem hiding this comment.
@naor-starkware made 6 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on igaray, juanbono, pefontana, and YairVaknin-starkware).
CHANGELOG.md line 23 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Okay, so create a single cahngelog entry with the correct PR number.
Done.
vm/src/types/relocatable.rs line 109 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Some of the types you listed are still used in the state of the code of this PR, so could leave those.
Done.
vm/src/vm/runners/mod.rs line 4 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Maybe add the tests to
mod cairo_function_runner, the same way it is across the repo?
Done.
vm/src/math_utils/mod.rs line 400 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Pls revert for this PR, then
Done.
vm/src/vm/runners/cairo_function_runner.rs line 53 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
something like:
fn push_builtin(&mut self, builtin: impl Into<BuiltinRunner>) { self.vm.builtin_runners.push(builtin.into()); }
Then use it like your macro.
Done.
vm/src/vm/runners/cairo_function_runner.rs line 67 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
Yeah, you can use a "factory" function to create the runner with the init logic that's needed. Just call this instead of calling
CairoFunctionRunner::new. This is the same overhead in this regard. It's just that it's a shallow wrapper that doesnt have any additional state justifying it.
Done.
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 3 comments.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/tests/mod.rs line 264 at r2 (raw file):
Previously, naor-starkware wrote…
The 0.into() was ambiguous because MaybeRelocatable implements From for multiple integer types.
Adding _i64 tells the compiler which conversion to use.
I think it's fine. The compiler knows how to handle it. It defaults to i32.
Please try to remove these from this PR as much as possible (I see you used this in a lot of places). This make the code much messier and isn't necessary.
vm/src/vm/runners/function_runner.rs line 119 at r2 (raw file):
Previously, naor-starkware wrote…
I wrote these two tests:
get_function_pc_assert_nn_resolves_alias_to_pc_0
get_function_pc_assert_nn_manual_implementation_returns_pc_4Or should I add more?
I meant a one calling get_pc_from_identifier directly.
vm/src/tests/mod.rs line 149 at r2 (raw file):
0_i64.into(), 0_i64.into(), 0_i64.into(),
also here
Code quote:
0_i64.into(),
0_i64.into(),
0_i64.into(),
0_i64.into(),
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 1 comment.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/vm/runners/cairo_function_runner.rs line 128 at r1 (raw file):
Previously, naor-starkware wrote…
I think we shouldn’t fail it, since it’s for tests
I still see you clearing at the start of pub fn initialize_all_builtins
naor-starkware
left a comment
There was a problem hiding this comment.
@naor-starkware made 3 comments.
Reviewable status: 9 of 11 files reviewed, 4 unresolved discussions (waiting on igaray, juanbono, pefontana, and YairVaknin-starkware).
vm/src/tests/mod.rs line 264 at r2 (raw file):
Previously, YairVaknin-starkware wrote…
I think it's fine. The compiler knows how to handle it. It defaults to i32.
Please try to remove these from this PR as much as possible (I see you used this in a lot of places). This make the code much messier and isn't necessary.
Done.
vm/src/vm/runners/function_runner.rs line 119 at r2 (raw file):
Previously, YairVaknin-starkware wrote…
I meant a one calling
get_pc_from_identifierdirectly.
Done.
vm/src/vm/runners/cairo_function_runner.rs line 128 at r1 (raw file):
Previously, YairVaknin-starkware wrote…
I still see you clearing at the start of
pub fn initialize_all_builtins
Done.
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware made 1 comment and resolved 3 discussions.
Reviewable status: 9 of 11 files reviewed, 1 unresolved discussion (waiting on igaray, juanbono, naor-starkware, and pefontana).
vm/src/vm/runners/function_runner.rs line 119 at r2 (raw file):
Previously, naor-starkware wrote…
Done.
Can you also add one also for the happy flow? I see you only added error-case tests.
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware reviewed 2 files and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on igaray, juanbono, naor-starkware, and pefontana).
naor-starkware
left a comment
There was a problem hiding this comment.
@naor-starkware made 1 comment.
Reviewable status: 10 of 11 files reviewed, 1 unresolved discussion (waiting on igaray, juanbono, pefontana, and YairVaknin-starkware).
vm/src/vm/runners/function_runner.rs line 119 at r2 (raw file):
Previously, YairVaknin-starkware wrote…
Can you also add one also for the happy flow? I see you only added error-case tests.
Done.
…macro for pushing builtin
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace `builtin_runners.clear()` with an assert in `initialize_all_builtins` to catch accidental double-initialization instead of silently discarding state - Remove unnecessary `_i64` type suffixes from numeric literals - Add unit tests for `get_pc_from_identifier` error paths (function without pc, alias without destination) and the new assert Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65f14ae to
f393a09
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2359 +/- ##
==========================================
+ Coverage 96.02% 96.07% +0.04%
==========================================
Files 104 105 +1
Lines 37470 37737 +267
==========================================
+ Hits 35979 36254 +275
+ Misses 1491 1483 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…s type and refactor run_from_entrypoint_substitute_error_message_test to avoid panic! Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
YairVaknin-starkware
left a comment
There was a problem hiding this comment.
@YairVaknin-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on igaray, juanbono, and pefontana).
TITLE
Description
Description of the pull request changes and motivation.
Checklist
This change is