Skip to content

starknet_os: define sha256 batch resources constants#14140

Open
dorimedini-starkware wants to merge 1 commit into
05-23-starknet_os_os_resources_test_-_add_keccakfrom
05-23-starknet_os_define_sha256_batch_resources_constants
Open

starknet_os: define sha256 batch resources constants#14140
dorimedini-starkware wants to merge 1 commit into
05-23-starknet_os_os_resources_test_-_add_keccakfrom
05-23-starknet_os_define_sha256_batch_resources_constants

Conversation

@dorimedini-starkware

Copy link
Copy Markdown
Collaborator

No description provided.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

dorimedini-starkware commented May 24, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor

cursor Bot commented May 24, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only resource constants and a VM integration test; no production OS or syscall logic changes in this diff.

Overview
Adds documented Cairo execution resource costs for the OS program’s SHA-256 batch phase, split into per-round linear and constant ExecutionResources (SHA256_BATCH_RESOURCES_LINEAR / SHA256_BATCH_RESOURCES_CONSTANT in test_utils).

A new integration test runs finalize_sha256 from OS_PROGRAM_BYTES via the existing Cairo runner helpers, samples two block counts that differ by one batch round (7 blocks per round), and regression-checks that measured linear and constant factors match those constants.

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

@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_os_resources_test_-_add_keccak branch from 25d1fa1 to 61397d7 Compare May 29, 2026 14:04
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from fd6b95e to 062b998 Compare May 29, 2026 14:04
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_os_resources_test_-_add_keccak branch from 61397d7 to 4417771 Compare June 1, 2026 08:37
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from 062b998 to 09cbdec Compare June 1, 2026 08:37
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_os_resources_test_-_add_keccak branch from 4417771 to f287752 Compare June 1, 2026 10:24
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from 09cbdec to c5b45e5 Compare June 1, 2026 10:24

@yoavGrs yoavGrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yoavGrs reviewed 2 files and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware and Yoni-Starkware).


crates/starknet_os/src/resource_utils_test.rs line 44 at r1 (raw file):

        let len = input.len();
        let message: &[u32; 16] = input[len - 24..len - 8].try_into().unwrap();
        let state: &[u32; 8] = input[len - 8..].try_into().unwrap();

Try to avoid the indexing

Suggestion:

        let message: [u32; 16] = rng.gen();
        let state: [u32; 8] = rng.gen();
        input.extend_from_slice(&message.into());
        input.extend_from_slice(&state.into());

crates/starknet_os/src/resource_utils_test.rs line 100 at r1 (raw file):

#[test]
fn test_finalize_sha256() {
    // Sha256 batching resources has a linear factor and a constant factor. Sample the execution at

Suggestion:

has a linear factor by the number of rounds 

crates/starknet_os/src/resource_utils_test.rs line 102 at r1 (raw file):

    // Sha256 batching resources has a linear factor and a constant factor. Sample the execution at
    // two points to compute both factors.
    let block_to_round = 7_usize;

From where this number come from?

Suggestion:

let blocks_in_round = 7_usize;

crates/starknet_os/src/test_utils.rs line 22 at r1 (raw file):

// Resources consumed by the SHA-256 batch phase, separated into linear and constant factors.
pub static SHA256_BATCH_RESOURCES_LINEAR: LazyLock<ExecutionResources> =

Why don't we need it in the VC?

@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from c5b45e5 to a1487a4 Compare June 2, 2026 10:21

@yoavGrs yoavGrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yoavGrs made 1 comment.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware and Yoni-Starkware).


crates/starknet_os/src/test_utils.rs line 22 at r1 (raw file):

Previously, yoavGrs wrote…

Why don't we need it in the VC?

OK, these are the resources of a round.
Reflect it in the constant name / the comment.

@dorimedini-starkware dorimedini-starkware changed the base branch from 05-23-starknet_os_os_resources_test_-_add_keccak to graphite-base/14140 June 3, 2026 07:17
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from a1487a4 to db6000c Compare June 3, 2026 07:51
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/14140 to 05-23-starknet_os_os_resources_test_-_add_keccak June 3, 2026 07:51

@dorimedini-starkware dorimedini-starkware left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dorimedini-starkware made 4 comments.
Reviewable status: 1 of 2 files reviewed, 4 unresolved discussions (waiting on yoavGrs and Yoni-Starkware).


crates/starknet_os/src/resource_utils_test.rs line 44 at r1 (raw file):

Previously, yoavGrs wrote…

Try to avoid the indexing

Done.


crates/starknet_os/src/resource_utils_test.rs line 102 at r1 (raw file):

Previously, yoavGrs wrote…

From where this number come from?

this is called BATCH_SIZE in the cairo common library implementing SHA


crates/starknet_os/src/test_utils.rs line 22 at r1 (raw file):

Previously, yoavGrs wrote…

OK, these are the resources of a round.
Reflect it in the constant name / the comment.

the resources of a batch, I think, is the terminology; hence BATCH_RESOURCES


crates/starknet_os/src/resource_utils_test.rs line 100 at r1 (raw file):

#[test]
fn test_finalize_sha256() {
    // Sha256 batching resources has a linear factor and a constant factor. Sample the execution at

Done.

@yoavGrs yoavGrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yoavGrs reviewed 1 file and all commit messages, and resolved 4 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on Yoni-Starkware).

@dorimedini-starkware dorimedini-starkware changed the base branch from 05-23-starknet_os_os_resources_test_-_add_keccak to graphite-base/14140 June 7, 2026 15:50
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from db6000c to 2a07010 Compare June 7, 2026 15:52
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/14140 to 05-23-starknet_os_os_resources_test_-_add_keccak June 7, 2026 15:52
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_os_resources_test_-_add_keccak branch from 8b873b5 to 636be17 Compare June 7, 2026 16:01
@dorimedini-starkware dorimedini-starkware force-pushed the 05-23-starknet_os_define_sha256_batch_resources_constants branch from 2a07010 to 335dd5f Compare June 7, 2026 16:01
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