Sitelet https://github.com/starkware-libs/cairo/pull/10221
Skip to content

(refactor): validate entry-point signatures before compilation in class-to-casm - #10221

Merged
eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/casm_entry_point_checks_before_compilation
Jul 20, 2026
Merged

eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/casm_entry_point_checks_before_compilation

Conversation

@eytan-starkware

Copy link
Copy Markdown
Contributor

Summary


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

⚠️ Note:
To keep maintainer workload sustainable, we generally do not accept PRs that
are only minor wording, grammar, formatting, or style changes.
Such PRs may be closed without detailed review.


Why is this change needed?


What was the behavior or documentation before?


What is the behavior or documentation after?


Related issue or discussion (if any)


Additional context

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor Author

@eytan-starkware
eytan-starkware marked this pull request as ready for review July 20, 2026 08:15
@cursor

cursor Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Control-flow refactor in Starknet class compilation with the same validation rules and output shape; main effect is earlier errors on bad entry points.

Overview
Entry-point checks now run before Sierra→CASM compilation in from_contract_class_with_debug_info, so invalid external, L1 handler, or constructor signatures fail without running metadata calculation and compilation.

Signature validation is split from CASM entry-point assembly: validate_entry_point only checks the ABI and returns (entry statement, function id, builtin names); after compilation, as_casm_entry_points pairs each ContractEntryPoint with that cached info via zip_eq to set bytecode offsets and assert entry-point gas costs.

Reviewed by Cursor Bugbot for commit 46939ec. Bugbot is set up for automated code reviews on this repo. Configure here.

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed all commit messages and made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).


crates/cairo-lang-starknet-classes/src/casm_contract_class.rs line 587 at r1 (raw file):

                }
                Ok::<Vec<CasmContractEntryPoint>, StarknetSierraCompilationError>(entry_points)
            };

Suggestion:

        let as_casm_entry_points =
            |contract_entry_points: Vec<ContractEntryPoint>,
             infos: Vec<(StatementIdx, &FunctionId, Vec<String>)>| -> Vec<CasmContractEntryPoint> {
                zip_eq(contract_entry_points, infos).map(
                    |(contract_entry_point, (statement_id, function_id, builtins))| {
                    let code_offset = cairo_program
                        .debug_info
                        .sierra_statement_info
                        .get(statement_id.0)
                        .ok_or(StarknetSierraCompilationError::EntryPointError)?
                        .start_offset;
                    assert_eq!(
                        metadata.gas_info.function_costs[function_id],
                        CostTokenMap::from_iter([(CostTokenType::Const, ENTRY_POINT_COST as i64)]),
                        "Unexpected entry point cost."
                    );
                    CasmContractEntryPoint {
                        selector: contract_entry_point.selector,
                        offset: code_offset,
                        builtins,
                    }
                }).collect()
            };

crates/cairo-lang-starknet-classes/src/casm_contract_class.rs line 623 at r1 (raw file):

                    constructor_infos,
                )?,
            },

Suggestion:

            entry_points_by_type: CasmContractEntryPoints {
                external: as_casm_entry_points(
                    contract_class.entry_points_by_type.external,
                    external_infos,
                ),
                l1_handler: as_casm_entry_points(
                    contract_class.entry_points_by_type.l1_handler,
                    l1_handler_infos,
                ),
                constructor: as_casm_entry_points(
                    contract_class.entry_points_by_type.constructor,
                    constructor_infos,
                ),
            },

…ss-to-casm

Move the entry-point signature checks (return/panic shape, input == output
builtins, felt252-span argument, builtin types, trailing gas/system) out of the
post-compilation `as_casm_entry_point` into an `entry_point_builtins` closure
that runs over all entry points before the (much heavier) sierra-to-casm
compilation. `as_casm_entry_point` reuses it for the builtin names and keeps
only the compilation-dependent parts (code offset, cost assert).

This reports signature errors without paying for compilation, and also fixes a
potential panic: an out-of-range entry-point function index used to be indexed
unchecked when building the metadata config; validation now precedes it.
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/casm_entry_point_checks_before_compilation branch from d5c0814 to 46939ec Compare July 20, 2026 09:50

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@orizi reviewed 1 file and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@eytan-starkware
eytan-starkware added this pull request to the merge queue Jul 20, 2026
Merged via the queue into main with commit eb655e5 Jul 20, 2026
55 checks passed
@eytan-starkware
eytan-starkware deleted the eytan_graphite/casm_entry_point_checks_before_compilation branch July 20, 2026 10:59
pull Bot pushed a commit to AKJUS/cairo that referenced this pull request Jul 21, 2026
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.

3 participants