Skip to content

starknet_os: recompute and assert the blake constants#14032

Open
dorimedini-starkware wants to merge 1 commit into
05-16-blockifier_fix_blake_estimation_offset_by_fixing_constantsfrom
05-15-starknet_os_recompute_and_assert_the_blake_constants
Open

starknet_os: recompute and assert the blake constants#14032
dorimedini-starkware wants to merge 1 commit into
05-16-blockifier_fix_blake_estimation_offset_by_fixing_constantsfrom
05-15-starknet_os_recompute_and_assert_the_blake_constants

Conversation

@dorimedini-starkware
Copy link
Copy Markdown
Collaborator

No description provided.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

dorimedini-starkware commented May 15, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@cursor
Copy link
Copy Markdown

cursor Bot commented May 15, 2026

PR Summary

Medium Risk
Test-only change, but it hard-codes empiric Cairo VM step counts and derived deltas, which may become brittle across Cairo program/toolchain/layout changes and cause CI failures.

Overview
Adds a new test_blake_step_constants in blake2s_test.rs that empirically measures Cairo VM step counts for encode_felt252_data_and_calc_blake_hash and asserts they match CasmV2HashResourceEstimate constants (empty-input base cost, per-felt costs, full-message base overhead, and partial-message remainder overhead).

Introduces a small helper (cairo_encode_felt252_data_and_calc_blake_hash_steps) to simplify extracting n_steps from the Cairo runner results.

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

Copy link
Copy Markdown
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

@dorimedini-starkware made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on AvivYossef-starkware and Yoni-Starkware).


crates/blockifier/src/execution/casm_hash_estimation.rs line 266 at r1 (raw file):

    pub const BASE_STEPS_PARTIAL_MSG: usize = 195;
    // Extra VM steps added per 2-u32 remainder in partial Blake messages.
    pub const STEPS_PER_2_U32_REMINDER: usize = 3;

all 6 constants are tested, 3 needed a one-step adjustment

Code quote:

    // Base number of VM steps applied when the input to Blake hashing is empty.
    // Determined empirically by running `encode_felt252_data_and_calc_blake_hash` on empty input.
    pub const STEPS_EMPTY_INPUT: usize = 170;

    // The constants used are empirical, based on running `encode_felt252_data_and_calc_blake_hash`
    // on combinations of large and small felts.
    // VM steps per large felt.
    pub const STEPS_PER_LARGE_FELT: usize = 45;
    // VM steps per small felt.
    pub const STEPS_PER_SMALL_FELT: usize = 15;
    // Base overhead when input exactly fills a 16-u32 Blake message.
    pub const BASE_STEPS_FULL_MSG: usize = 217;
    // Base overhead when the input leaves a remainder (< 16 u32s) for a Blake message.
    pub const BASE_STEPS_PARTIAL_MSG: usize = 195;
    // Extra VM steps added per 2-u32 remainder in partial Blake messages.
    pub const STEPS_PER_2_U32_REMINDER: usize = 3;

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7d9a724. Configure here.

Comment thread crates/blockifier/src/execution/casm_hash_estimation.rs
@dorimedini-starkware dorimedini-starkware force-pushed the 05-15-starknet_os_recompute_and_assert_the_blake_constants branch 2 times, most recently from 3f84cb4 to 94c6189 Compare May 15, 2026 16:53
@dorimedini-starkware dorimedini-starkware changed the base branch from 05-15-starknet_os_move_blake_constants_to_struct_scope to graphite-base/14032 May 16, 2026 09:40
@dorimedini-starkware dorimedini-starkware force-pushed the 05-15-starknet_os_recompute_and_assert_the_blake_constants branch from 94c6189 to af285f6 Compare May 16, 2026 09:40
@dorimedini-starkware dorimedini-starkware force-pushed the 05-15-starknet_os_recompute_and_assert_the_blake_constants branch from af285f6 to 30206ec Compare May 16, 2026 09:43
@dorimedini-starkware dorimedini-starkware force-pushed the 05-15-starknet_os_recompute_and_assert_the_blake_constants branch from 30206ec to 139758c Compare May 16, 2026 12:34
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/14032 to 05-16-blockifier_fix_blake_estimation_offset_by_fixing_constants May 16, 2026 12:34
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.

2 participants