Skip to content

Expose core gas utilities for external consumption #7851

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: main
Choose a base branch
from

Conversation

ksew1
Copy link
Contributor

@ksew1 ksew1 commented Jun 18, 2025

Will be used in cairo-profiler

Will be used in `cairo-profiler`
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@orizi orizi 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: 0 of 1 files reviewed, 1 unresolved discussion


a discussion (no related file):
what is the specific usage?
for calculating gas there's already existing functionalities.

Copy link
Contributor Author

@ksew1 ksew1 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @orizi)


a discussion (no related file):

Previously, orizi wrote…

what is the specific usage?
for calculating gas there's already existing functionalities.

core_libfunc_cost is used there

Copy link
Collaborator

@orizi orizi 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ksew1)


a discussion (no related file):

Previously, ksew1 wrote…

core_libfunc_cost is used there

the result here would just be wrong using it.
this is the function for deprecated way of computing costs.

Copy link
Collaborator

@orizi orizi 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ksew1)


a discussion (no related file):

Previously, orizi wrote…

the result here would just be wrong using it.
this is the function for deprecated way of computing costs.

i was wrong - but - it seems that you would have some wrong data in any case.

the correct full way to calculate total gas usage is at:
crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs:344.
which isn't fully equivalent.

Copy link

@THenry14 THenry14 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @orizi)


a discussion (no related file):

Previously, orizi wrote…

i was wrong - but - it seems that you would have some wrong data in any case.

the correct full way to calculate total gas usage is at:
crates/cairo-lang-sierra-to-casm/src/invocations/mod.rs:344.
which isn't fully equivalent.

At the moment, we only need to get builtin costs of libfuncs (when tracking sierra gas in snforge).

As we depend on snforge generated traces (which still uses cairo vm for execution), we are still kind of tracking steps and then convert to sierra gas (a refactor will be needed on snforge and profiler first to change it - which is planned, but no eta; then we will probably go the route you've suggested in profiler for getting the most accurate costs), so this is actually good enough at the moment for us.

This seems to be the easiest way for us to have sierra gas estimations correctly include builtin costs without said refactors.

Copy link
Collaborator

@orizi orizi 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ksew1 and @THenry14)


a discussion (no related file):

Previously, THenry14 (Wojciech Szymczyk) wrote…

At the moment, we only need to get builtin costs of libfuncs (when tracking sierra gas in snforge).

As we depend on snforge generated traces (which still uses cairo vm for execution), we are still kind of tracking steps and then convert to sierra gas (a refactor will be needed on snforge and profiler first to change it - which is planned, but no eta; then we will probably go the route you've suggested in profiler for getting the most accurate costs), so this is actually good enough at the moment for us.

This seems to be the easiest way for us to have sierra gas estimations correctly include builtin costs without said refactors.

if this is aimed more as a temporary hack - just have a local implementation that is similar to this, and you'd be able to locally delete (unlike adding pub to things that shouldn't really be pub)

Copy link

@THenry14 THenry14 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @orizi)


a discussion (no related file):

Previously, orizi wrote…

if this is aimed more as a temporary hack - just have a local implementation that is similar to this, and you'd be able to locally delete (unlike adding pub to things that shouldn't really be pub)

I see your point, but I don't think it is that simple - core\_libfunc\_cost is quite large, and from what I can see it still is getting some modifications (I can see some commits from last month) - not only it would mean we basically need to copy over bigger part of cairo-lang-sierra-gas crate (at least), that would also mean we need to constantly track upstream changes to make sure we do not omit something new accidentally. Given that there is no eta on the refactors (I don't think it will happen any time soon for various reasons), and plans to put a bit less effort into profiler in the near future, I'm sure you see how this is somewhat suboptimal from our PoV.

Btw do you mind sharing what are the reasons why these should not be public? that would perhaps help me better understand the exact issue/pain point here

Copy link
Collaborator

@orizi orizi 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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ksew1 and @THenry14)


a discussion (no related file):

Previously, THenry14 (Wojciech Szymczyk) wrote…

I see your point, but I don't think it is that simple - core\_libfunc\_cost is quite large, and from what I can see it still is getting some modifications (I can see some commits from last month) - not only it would mean we basically need to copy over bigger part of cairo-lang-sierra-gas crate (at least), that would also mean we need to constantly track upstream changes to make sure we do not omit something new accidentally. Given that there is no eta on the refactors (I don't think it will happen any time soon for various reasons), and plans to put a bit less effort into profiler in the near future, I'm sure you see how this is somewhat suboptimal from our PoV.

Btw do you mind sharing what are the reasons why these should not be public? that would perhaps help me better understand the exact issue/pain point here

you don't need to duplicate the large logic at all - you just need to implement simple implementations for:
InvocationApChangeInfoProvider and InvocationCostInfoProvider.

this would allow you to get the basic prices - no need to duplicate the full logic.

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