Skip to content

blockifier: update blake estimation for empty input #8323

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

Merged

Conversation

avivg-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@avivg-starkware avivg-starkware marked this pull request as ready for review July 30, 2025 13:35
Copy link
Contributor Author

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

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/update_blake_estimation_for_empty_input branch 3 times, most recently from d4ad56b to 889351d Compare July 30, 2025 14:15
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/update_blake_estimation_for_empty_input branch 3 times, most recently from b99fe38 to 0c14c35 Compare July 31, 2025 06:45
Copy link
Contributor

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @noaov1)


crates/blockifier/src/execution/execution_utils_test.rs line 34 at r2 (raw file):

#[test]
fn test_zero_inputs() {
    // TODO(AvivG): Re-check this case in VM — input 0 was previously invalid when this estimation

Can you remove it now?

Code quote:

// TODO(AvivG): Re-check this case in VM — input 0 was previously invalid when this estimation

crates/blockifier/src/execution/execution_utils.rs line 449 at r2 (raw file):

    if total_u32s == 0 {
        return blake_estimation::STEPS_EMPTY_INPUT;
    }

if total_u32s == 0 {
return blake_estimation::STEPS_EMPTY_INPUT;
}

Suggestion:

    if total_u32s == 0 {
        // The empty input case is a special case.  
        return blake_estimation::STEPS_EMPTY_INPUT;
    }   

crates/blockifier/src/execution/execution_utils.rs line 472 at r2 (raw file):

    let n_felts =
        n_big_felts.checked_add(n_small_felts).expect("Overflow computing total number of felts");
    let builtin_instance_counter = if n_felts == 0 {

Personally, I prefer match here (non-blocking)


crates/blockifier/src/execution/execution_utils.rs line 473 at r2 (raw file):

        n_big_felts.checked_add(n_small_felts).expect("Overflow computing total number of felts");
    let builtin_instance_counter = if n_felts == 0 {
        HashMap::new()

Suggestion:

    let builtin_instance_counter = if n_felts == 0 {
        // The empty case does not use builtins at all.
        HashMap::new()

crates/blockifier/src/execution/execution_utils.rs line 475 at r2 (raw file):

        HashMap::new()
    } else {
        // One `range_check` per input felt to validate its size + Overhead.

Suggestion:

// One `range_check` per input felt to validate its size + Overhead for the non empty case..

crates/blockifier/src/execution/execution_utils.rs line 488 at r2 (raw file):

/// This includes:
/// - ExecutionResources gas.
/// - Blake opcode gas.

What do you mean here?
Why is the Blake opcode gas separated from the others?

Code quote:

/// This includes:
/// - ExecutionResources gas.
/// - Blake opcode gas.

crates/blockifier/src/execution/execution_utils.rs line 514 at r2 (raw file):

             This breaks the assumption that builtin costs are identical between provers.",
        );
    }

I prefer something like it.

Suggestion:

assert!(
    vm_resources
        .builtin_instance_counter
        .keys()
        .all(|&k| k == BuiltinName::range_check),
    "Expected either empty builtins or only `range_check` builtin, got: {:?}. \
     This breaks the assumption that builtin costs are identical between provers.",
    vm_resources.builtin_instance_counter.keys().collect::<Vec<_>>()
);

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/update_blake_estimation_for_empty_input branch from 0c14c35 to 669d234 Compare July 31, 2025 08:26
Copy link
Contributor Author

@avivg-starkware avivg-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 3 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware and @noaov1)


crates/blockifier/src/execution/execution_utils.rs line 449 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

if total_u32s == 0 {
return blake_estimation::STEPS_EMPTY_INPUT;
}

Added


crates/blockifier/src/execution/execution_utils.rs line 472 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

Personally, I prefer match here (non-blocking)

This way?


crates/blockifier/src/execution/execution_utils.rs line 488 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

What do you mean here?
Why is the Blake opcode gas separated from the others?

Is it clearer now? Does the modification to the comment answer your question?


crates/blockifier/src/execution/execution_utils.rs line 514 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

I prefer something like it.

no prob, replaced


crates/blockifier/src/execution/execution_utils_test.rs line 34 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

Can you remove it now?

definatly


crates/blockifier/src/execution/execution_utils.rs line 473 at r2 (raw file):

        n_big_felts.checked_add(n_small_felts).expect("Overflow computing total number of felts");
    let builtin_instance_counter = if n_felts == 0 {
        HashMap::new()

Added


crates/blockifier/src/execution/execution_utils.rs line 475 at r2 (raw file):

        HashMap::new()
    } else {
        // One `range_check` per input felt to validate its size + Overhead.

Changed.

Copy link
Contributor

@AvivYossef-starkware AvivYossef-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)


crates/blockifier/src/execution/execution_utils.rs line 472 at r2 (raw file):

Previously, avivg-starkware wrote…

This way?

Yes


crates/blockifier/src/execution/execution_utils.rs line 488 at r2 (raw file):

Previously, avivg-starkware wrote…

Is it clearer now? Does the modification to the comment answer your question?

Why is Blake's opcode not part of the ExecutionResources?
Is it a problem of the VM?

Copy link
Contributor Author

@avivg-starkware avivg-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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)


crates/blockifier/src/execution/execution_utils.rs line 488 at r2 (raw file):

Previously, AvivYossef-starkware wrote…

Why is Blake's opcode not part of the ExecutionResources?
Is it a problem of the VM?

--- continued discussion via Slack

Copy link
Collaborator

@noaov1 noaov1 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 2 files at r3, 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avivg-starkware)

@avivg-starkware avivg-starkware added this pull request to the merge queue Jul 31, 2025
Merged via the queue into main with commit 3e85e0e Jul 31, 2025
26 of 29 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants