Skip to content

blockifier: unify from felts and from bytecode to counts #8716

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

Open
wants to merge 1 commit into
base: main-v0.14.1
Choose a base branch
from

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 August 20, 2025 11:50
Copy link

github-actions bot commented Aug 20, 2025

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: 0 of 1 files reviewed, 1 unresolved discussion


crates/blockifier/src/execution/contract_class.rs line 99 at r1 (raw file):

impl From<&[BigUintAsHex]> for FeltSizeCount {
    fn from(bytecode: &[BigUintAsHex]) -> Self {
        count_felts_by_size(bytecode, |x| Felt::from(&x.value) < SMALL_THRESHOLD)

Alternative

Suggestion (i):

x.value.bits() <= SMALL_THRESHOLD_BITS

Code snippet (ii):

const SMALL_THRESHOLD_BITS: u32 = 63;

#[test]
    fn small_threshold_consistency() {
        let reconstructed = Felt::from(1u128 << SMALL_THRESHOLD_BITS);
        assert_eq!(reconstructed, SMALL_THRESHOLD);
    }

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.

@AvivYossef-starkware reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1)


crates/blockifier/src/execution/contract_class.rs line 108 at r1 (raw file):

        count_felts_by_size(bytecode, |felt| *felt < SMALL_THRESHOLD)
    }
}

You need to impl from only once,

from <T> for  FeltSizeCount where T impl is small 

you can fo it,

but I prefer new function that get T as an input

Code quote:

/// Counts elements into “small” vs “large” buckets using the provided predicate.
#[inline]
fn count_felts_by_size<T>(slice: &[T], mut is_small: impl FnMut(&T) -> bool) -> FeltSizeCount {
    let mut small = 0;
    let mut large = 0;
    for it in slice {
        if is_small(it) { small += 1 } else { large += 1 }
    }
    FeltSizeCount { small, large }
}

/// Classifies bytecode words by felt size using `SMALL_THRESHOLD = 2^63`.
impl From<&[BigUintAsHex]> for FeltSizeCount {
    fn from(bytecode: &[BigUintAsHex]) -> Self {
        count_felts_by_size(bytecode, |x| Felt::from(&x.value) < SMALL_THRESHOLD)
    }
}

/// Classifies felts by size using `SMALL_THRESHOLD = 2^63`.
impl From<&[Felt]> for FeltSizeCount {
    fn from(bytecode: &[Felt]) -> Self {
        count_felts_by_size(bytecode, |felt| *felt < SMALL_THRESHOLD)
    }
}

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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware and @noaov1)


crates/blockifier/src/execution/contract_class.rs line 108 at r1 (raw file):

Previously, AvivYossef-starkware wrote…

You need to impl from only once,

from <T> for  FeltSizeCount where T impl is small 

you can fo it,

but I prefer new function that get T as an input

WDYT?

@avivg-starkware avivg-starkware changed the base branch from avivg/blockifier/encode_recieve_felts_counts to graphite-base/8716 August 20, 2025 13:30
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/unify_from_felt_to_counts branch from 604aef8 to a567966 Compare August 20, 2025 13:30
@avivg-starkware avivg-starkware changed the base branch from graphite-base/8716 to main-v0.14.1 August 20, 2025 13:30
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