Skip to content

Conversation

@eytan-starkware
Copy link
Contributor

@eytan-starkware eytan-starkware commented Nov 13, 2025

TL;DR

Added a new get_temp_ptr libfunc to compute addresses for variables based on type size, with utility segment support for code reuse.

What changed?

  • Added a new Sierra libfunc get_temp_ptr<T> that computes the address where a value of type T would be located
  • Renamed ConstsInfo to SegmentsInfo and extended it to support utility segments for code reuse
  • Implemented the CASM compilation for get_temp_ptr using a shared utility segment
  • Added AP change and gas cost information for the new libfunc
  • Added the libfunc to the Starknet allowed libfuncs list

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@eytan-starkware eytan-starkware marked this pull request as ready for review November 13, 2025 16:22
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.

@orizi reviewed 2 of 14 files at r1, all commit messages.
Reviewable status: 2 of 14 files reviewed, 2 unresolved discussions (waiting on @giladchase and @ilyalesokhin-starkware)


crates/cairo-lang-sierra/src/extensions/core.rs line 132 at r1 (raw file):

        Gas(GasLibfunc),
        GasReserve(GasReserveLibfunc),
        GetTempPtr(GetTempPtrLibfunc),

move to under Box.

Code quote:

        GetTempPtr(GetTempPtrLibfunc),

crates/cairo-lang-sierra/src/extensions/modules/get_temp_ptr.rs line 1 at r1 (raw file):

//! Libfunc for computing the address of a variable based on type size.

box_from_temp_store
all around probably.

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_feature_a_new_libfunc_for_calculating_the_pointer_to_temporary_storage_using_a_double_call branch from f0f324a to c65e1d8 Compare November 16, 2025 08:39
Copy link
Contributor Author

@eytan-starkware eytan-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: 1 of 16 files reviewed, 2 unresolved discussions (waiting on @giladchase, @ilyalesokhin-starkware, and @orizi)


crates/cairo-lang-sierra/src/extensions/core.rs line 132 at r1 (raw file):

Previously, orizi wrote…

move to under Box.

Done.


crates/cairo-lang-sierra/src/extensions/modules/get_temp_ptr.rs line 1 at r1 (raw file):

Previously, orizi wrote…

box_from_temp_store
all around probably.

Done.

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_feature_a_new_libfunc_for_calculating_the_pointer_to_temporary_storage_using_a_double_call branch from c65e1d8 to aa0c9dc Compare November 16, 2025 08:43
… storage using a double call

SIERRA_UPDATE_MINOR_CHANGE_TAG=adding a libfunc for optimizing creating boxes from temp storage
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_feature_a_new_libfunc_for_calculating_the_pointer_to_temporary_storage_using_a_double_call branch from aa0c9dc to c4e803d Compare November 16, 2025 09:23
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.

@orizi reviewed 6 of 14 files at r2.
Reviewable status: 7 of 16 files reviewed, 2 unresolved discussions (waiting on @giladchase and @ilyalesokhin-starkware)


crates/cairo-lang-sierra/src/extensions/modules/boxing.rs line 142 at r2 (raw file):

        // The actual offset is computed in CASM based on type size
        Ok(LibfuncSignature::new_non_branch(
            vec![],

you should have the value as an input.

Code quote:

            vec![],

Copy link
Contributor

@giladchase giladchase 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: 7 of 16 files reviewed, 2 unresolved discussions (waiting on @eytan-starkware, @ilyalesokhin-starkware, and @orizi)


crates/cairo-lang-sierra-to-casm/src/compiler.rs line 376 at r2 (raw file):

                let segment = UtilitySegment { instructions, offset: total_segments_size };
                total_segments_size +=
                    segment.instructions.iter().map(|i| i.body.op_size()).sum::<usize>();

Nonblocking: perhaps this should be a for, side-effects inside map (modifying the external var total_segments_size) can be surprising

Code quote:

            .map(|(id, instructions)| {
                let segment = UtilitySegment { instructions, offset: total_segments_size };
                total_segments_size +=
                    segment.instructions.iter().map(|i| i.body.op_size()).sum::<usize>();

Copy link
Contributor

@giladchase giladchase 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: 7 of 16 files reviewed, 2 unresolved discussions (waiting on @eytan-starkware, @ilyalesokhin-starkware, and @orizi)


crates/cairo-lang-sierra-to-casm/src/compiler.rs line 351 at r2 (raw file):

                Ok(CoreConcreteLibfunc::Box(BoxConcreteLibfunc::FromTempStore(_)))
            )
        });

Might be time to iterate only once on libfunc_ids and match on program_info.registry.get_libfunc(id).unwrap()

Code quote:

        let has_box_from_temp_store = libfunc_ids.into_iter().any(|id| {
            matches!(
                program_info.registry.get_libfunc(id),
                Ok(CoreConcreteLibfunc::Box(BoxConcreteLibfunc::FromTempStore(_)))
            )
        });

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.

5 participants